mardi 16 mars 2021

How in laravel with stripe-php get balance after payment?

In laravel 5.8 app with stripe/stripe-php: ^7.50 when customer pays fir provided services it has code:

    \Stripe\Stripe::setApiKey( config('app.STRIPE_TEST_KEY') );
    $user = User::where('id', $request->user_id)->first();
    $customer_id = $user->stripe_customer_id;

    $charge = \Stripe\Charge::create([
        'amount' => $request->amount * 100, // Say $request->amount= 50
        'currency' => $request->currency,   // USD
        'customer' => $customer_id
    ]);
    TransactionsTable::create([
        'user_id' => $user->id,
        'type' => $request->card['brand'],
        'amount' => $request->amount,
        'currency' => $request->currency,
        'transaction_id' => $charge->id,
        'status' => $charge->status
    ]);

And USD 50 is subtracted from customer card and is added to the owner of stripe account (in dev app.STRIPE_TEST_KEY) My questions 1) as I want to send email to owner of stripe account in which way can I get balance of his after successfull operation? How ths sum is differ under test/live?

  1. How can I check error in case of invalid operation? Say if customers card has no enough money or expired? In catch block with $e->getMessage() or are there some better way?

Thanks!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3vutqdx
via IFTTT

Aucun commentaire:

Enregistrer un commentaire