<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Stripe\Stripe; use Stripe\Customer; use Stripe\PaymentIntent; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Auth; class BillingController extends Controller { //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. //Should validate that all amounts are positive integers in a reasonable range 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; // Pass customer and setup_future_usage values here. Maybe metadata can // also hold pack information $intent = PaymentIntent::create([ 'amount' => $amount, 'currency' => 'usd', 'customer' => Auth::user()->customer_id, 'metadata' => ['integration_check' => 'accept_a_payment'] ]); return $intent->client_secret; } }