|
|
@@ -9,6 +9,7 @@ use Stripe\PaymentIntent; |
|
|
|
use Stripe\PaymentMethod; |
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
use Illuminate\Support\Facades\Auth; |
|
|
|
use App\Models\Transaction; |
|
|
|
|
|
|
|
class BillingController extends Controller |
|
|
|
{ |
|
|
@@ -24,13 +25,27 @@ class BillingController extends Controller |
|
|
|
$request->packs[ 'credits50' ]*5499 + $request->packs[ 'credits100' ]*10999 |
|
|
|
+ $request->packs[ 'credits1000' ]*101000; |
|
|
|
|
|
|
|
// Pass customer and setup_future_usage values here. Maybe metadata can |
|
|
|
// also hold pack information |
|
|
|
$transaction = new Transaction; |
|
|
|
$transaction->credits = $request->packs['credits10']*10 + |
|
|
|
$request->packs['credits50']*50 + |
|
|
|
$request->packs['credits[100]']*100 + |
|
|
|
$request->packs['credits[1000]']*1000; |
|
|
|
$transaction->credits_extra = |
|
|
|
$request->packs['credits50']*5 + |
|
|
|
$request->packs['credits[100]']*10 + |
|
|
|
$request->packs['credits[1000]']*150; |
|
|
|
|
|
|
|
$transaction->user_id = Auth::user()->id; |
|
|
|
$transaction->charge = $amount; |
|
|
|
$transaction->status = 'processing'; |
|
|
|
$transaction->completed = false; |
|
|
|
$transaction->save(); |
|
|
|
|
|
|
|
$intent = PaymentIntent::create([ |
|
|
|
'amount' => $amount, |
|
|
|
'currency' => 'usd', |
|
|
|
'customer' => Auth::user()->customer_id, |
|
|
|
'metadata' => ['transaction_id' => 'accept_a_payment'] |
|
|
|
'metadata' => ['transaction_id' => $transaction->id] |
|
|
|
]); |
|
|
|
|
|
|
|
return $intent->client_secret; |
|
|
|