PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 20, 2022

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

 February 20, 2022     laravel-5, stripe-payments     No comments   

Issue

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!


Solution

  1. You can use the Balance API to retrieve that: https://stripe.com/docs/api/balance

  2. You need to catch errors in your Charge::create: https://stripe.com/docs/api/errors/handling?lang=php

Also you should consider using Payment Intents instead of Charges: https://stripe.com/docs/payments/payment-intents/migration



Answered By - floatingLomas
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing