Deduct 5% commission on stripe during Payout to the seller

226 Views Asked by At
$currency = 'cad';
    //$customerId = $request->customerId;
    $intent = \Stripe\PaymentIntent::create([
        'amount' => ($finalAmount *100),
        'currency' => $currency,
        'customer' => $customerId,
        'description' => $description
    ]);

I Have an app where the seller post products and buyer can buy , During checkout I am charging from buyer (Customers) and after the order status is changed to completed I want to payout to seller but deduct 5% commission from the order amount. This is what I am doing but it send the total amount without the deduction of 5% commission on live Mode, ON the test mode the deduction is okay.

    if($commission->commission_type == 'percentage'){
       $amount = $totalAmount - (($commission->commission_amount/100)*$totalAmount);
      }
$finalAmount = (round( $amount,2));
  //Paying to the seller
   $transfer = \Stripe\Transfer::create([
   "amount" => ($finalAmount*100),
    "currency" => "cad",
    "destination" => $seller_account,
   ]);
1

There are 1 best solutions below

0
Nasir On

The issue fixed by passing the charge id to transfer

 $intentRes = \Stripe\PaymentIntent::retrieve($updateStatus->intent_id);
                                 if(!$intentRes){
                                     return response()->json(["success" => false,"message" => "Buyer Payment Confirmation Is Incomplete"]);
                                 }
                                 $transfer = \Stripe\Transfer::create([
                                     "amount" => ($finalAmount*100),
                                     'source_transaction' => $intentRes->latest_charge, // this did the trick for me and also resolve the Insufficient fund issue
                                     "currency" => $seller_bank_account->currency,
                                     "destination" => $seller_account,
                                 ]);