@@ -5,10 +5,28 @@ namespace App\Http\Controllers; | |||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
use Stripe\Stripe; | use Stripe\Stripe; | ||||
use Stripe\Customer; | use Stripe\Customer; | ||||
use Stripe\PaymentIntent; | |||||
use Illuminate\Support\Facades\Log; | |||||
class BillingController extends Controller | class BillingController extends Controller | ||||
{ | { | ||||
public function charge() { | //Expects an array 'packs' representing the amount of each multiple of credits. | ||||
//This controller should have a way of figuring out how much of each pack | |||||
//was bought later. | |||||
public function secret(Request $request) { | |||||
Stripe::setApiKey(env('STRIPE_SECRET')); | |||||
Log::debug($request->packs); | |||||
$amount = $request->packs[ 'credits10' ]*1099 + | |||||
$request->packs[ 'credits50' ]*5499 + $request->packs[ 'credits100' ]*10999 | |||||
+ $request->packs[ 'credits1000' ]*101000; | |||||
$intent = PaymentIntent::create([ | |||||
'amount' => $amount, | |||||
'currency' => 'usd', | |||||
'metadata' => ['integration_check' => 'accept_a_payment'] | |||||
]); | |||||
return $intent->client_secret; | |||||
} | } | ||||
} | } |
@@ -16,7 +16,7 @@ class CreateOrdersTable extends Migration | |||||
Schema::create('orders', function (Blueprint $table) { | Schema::create('orders', function (Blueprint $table) { | ||||
$table->id(); | $table->id(); | ||||
$table->timestamps(); | $table->timestamps(); | ||||
$table->foreignId('service_id')->constrained(); | $table->foreignId('service_id')->constrained()->nullable(); | ||||
$table->foreignId('user_id')->constrained(); | $table->foreignId('user_id')->constrained(); | ||||
$table->bigInteger('quantity'); | $table->bigInteger('quantity'); | ||||
$table->string('note')->default(''); | $table->string('note')->default(''); | ||||
@@ -13,12 +13,13 @@ | |||||
</div> | </div> | ||||
<div class="credits-pane"><div><h2>1000 Credits</h2><span>+150 Free Credits</span></div> | <div class="credits-pane"><div><h2>1000 Credits</h2><span>+150 Free Credits</span></div> | ||||
<h3>$1010</h3> <div><span>Qty</span><input min="0" max="1000" v-model="packs.credits1000" type="number"></div> | <h3>$1010.00</h3> <div><span>Qty</span><input min="0" max="1000" v-model="packs.credits1000" type="number"></div> | ||||
</div> | </div> | ||||
</section> | |||||
<section class="credits-confirm"> | |||||
<h3>Total: ${{total.toLocaleString('en')}}</h3> | <h3>Total: ${{total.toLocaleString('en')}}</h3> | ||||
<button class="brand-btn">Continue</button> | <button @click="getSecret" :disabled="total == 0 || loading" class="brand-btn">Continue</button> | ||||
</section> | </section> | ||||
</template> | </template> | ||||
@@ -29,11 +30,32 @@ function total() { | |||||
+ this.packs.credits100*109.99 + this.packs.credits1000*1010 | + this.packs.credits100*109.99 + this.packs.credits1000*1010 | ||||
} | } | ||||
function getSecret() { | |||||
fetch('/panel/secret', { | |||||
method: 'POST', | |||||
headers: {'Content-Type': 'application/json', | |||||
'Accept': 'application/json', | |||||
'X-XSRF-TOKEN': this.token}, | |||||
body: JSON.stringify({'packs': this.packs}) | |||||
}).then((response) => { | |||||
if (response.ok) { | |||||
return response.text() | |||||
} else { | |||||
//handle errors here | |||||
console.log('an error occured') | |||||
} | |||||
}).then(data => { | |||||
console.log(data) | |||||
}) | |||||
} | |||||
export default { | export default { | ||||
data() { | data() { | ||||
return {packs: {credits10: 0, credits50: 0, | return {packs: {credits10: 0, credits50: 0, | ||||
credits100: 0, credits1000: 0}} | credits100: 0, credits1000: 0}, loading: false} | ||||
}, | }, | ||||
computed: {total} | computed: {total}, | ||||
methods: {getSecret}, | |||||
props: ['token'] | |||||
} | } | ||||
</script> | </script> |
@@ -5,7 +5,7 @@ | |||||
<a href="#credits" :class="{selected: page == 'credits'}">Credits</a> | <a href="#credits" :class="{selected: page == 'credits'}">Credits</a> | ||||
<div :class="page" class="menu-slider"><div></div></div> | <div :class="page" class="menu-slider"><div></div></div> | ||||
</div> | </div> | ||||
<h4 class="credits-display">Credits: {{credits.toLocaleString('en')}}</h4> | <h4 class="credits-display"><img class="icon" src="../../images/coin-stack.svg" alt=""><span> {{credits.toLocaleString('en')}}</span></h4> | ||||
<template v-if="page == 'new-order'"> | <template v-if="page == 'new-order'"> | ||||
@@ -68,7 +68,7 @@ | |||||
</template> | </template> | ||||
<credits v-if="page == 'credits'"></credits> | <credits :token="token" v-if="page == 'credits'"></credits> | ||||
</div> | </div> | ||||
</template> | </template> | ||||
@@ -1154,6 +1154,9 @@ button .loading-icon { | |||||
text-align: center; | text-align: center; | ||||
margin: 1em; | margin: 1em; | ||||
color: vars.getColor('brand-orange'); | color: vars.getColor('brand-orange'); | ||||
display: flex; | |||||
justify-content: center; | |||||
align-items: center; | |||||
} | } | ||||
.select-credits .credits-pane { | .select-credits .credits-pane { | ||||
@@ -1172,7 +1175,7 @@ button .loading-icon { | |||||
margin: 0; | margin: 0; | ||||
} | } | ||||
.select-credits h3 { | .credits-confirm h3 { | ||||
text-align: center; | text-align: center; | ||||
} | } | ||||
@@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; | |||||
use App\Http\Controllers\UserController; | use App\Http\Controllers\UserController; | ||||
use App\Http\Controllers\ServiceController; | use App\Http\Controllers\ServiceController; | ||||
use App\Http\Controllers\TransactionController; | use App\Http\Controllers\TransactionController; | ||||
use App\Http\Controllers\BillingController; | |||||
use Illuminate\Foundation\Auth\EmailVerificationRequest; | use Illuminate\Foundation\Auth\EmailVerificationRequest; | ||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
use Illuminate\Support\Facades\Auth; | use Illuminate\Support\Facades\Auth; | ||||
@@ -86,3 +87,5 @@ Route::get('/reset-email', [UserController::class, | |||||
Route::post('/panel/orders', [TransactionController::class, | Route::post('/panel/orders', [TransactionController::class, | ||||
'newOrder'])->middleware([ 'auth', 'verified' ]); | 'newOrder'])->middleware([ 'auth', 'verified' ]); | ||||
Route::post('/panel/secret', [BillingController::class, | |||||
'secret'])->middleware([ 'auth', 'verified' ]); |