My SMM panel
 
 
 
 
 
 

47 lines
1.3 KiB

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Stripe\Stripe;
  5. use Stripe\Customer;
  6. use Stripe\PaymentIntent;
  7. use Stripe\PaymentMethod;
  8. use Illuminate\Support\Facades\Log;
  9. use Illuminate\Support\Facades\Auth;
  10. class BillingController extends Controller
  11. {
  12. //Expects an array 'packs' representing the amount of each multiple of credits.
  13. //This controller should have a way of figuring out how much of each pack
  14. //was bought later.
  15. //Should validate that all amounts are positive integers in a reasonable range
  16. public function secret(Request $request) {
  17. Stripe::setApiKey(env('STRIPE_SECRET'));
  18. Log::debug($request->packs);
  19. $amount = $request->packs[ 'credits10' ]*1099 +
  20. $request->packs[ 'credits50' ]*5499 + $request->packs[ 'credits100' ]*10999
  21. + $request->packs[ 'credits1000' ]*101000;
  22. // Pass customer and setup_future_usage values here. Maybe metadata can
  23. // also hold pack information
  24. $intent = PaymentIntent::create([
  25. 'amount' => $amount,
  26. 'currency' => 'usd',
  27. 'customer' => Auth::user()->customer_id,
  28. 'metadata' => ['transaction_id' => 'accept_a_payment']
  29. ]);
  30. return $intent->client_secret;
  31. }
  32. public function getCards() {
  33. Stripe::setApiKey(env('STRIPE_SECRET'));
  34. return PaymentMethod::all([
  35. 'customer' => Auth::user()->customer_id,
  36. 'type' => 'card'
  37. ]);
  38. }
  39. }