From cedd5db6b41a391330d1c6f5553c02f03916e21f Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Thu, 14 Sep 2023 12:35:59 +0100 Subject: [PATCH] fix: Stripe handlePaymentResult for direct payment --- app/Http/Controllers/StripeController.php | 25 +++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/StripeController.php b/app/Http/Controllers/StripeController.php index 6ec4b9f..44243f4 100644 --- a/app/Http/Controllers/StripeController.php +++ b/app/Http/Controllers/StripeController.php @@ -335,7 +335,7 @@ class StripeController extends Controller ], ResponseAlias::HTTP_MOVED_PERMANENTLY); } - return $this->handlePaymentIntentResult($transaction, $paymentIntent); + return $this->handlePaymentIntentResult($transaction, $paymentIntent, false); } } @@ -482,18 +482,24 @@ class StripeController extends Controller return $this->errorResponse(__('errors.unexpected_error')); } - private function handlePaymentIntentResult(PaymentTransaction $transaction, PaymentIntent $intent){ + private function handlePaymentIntentResult(PaymentTransaction $transaction, PaymentIntent $intent , bool $returnView = true){ if($intent->status == 'succeeded'){ $transaction->update([ 'status' => PaymentTransactionStatus::ACCEPTED ]); - return redirect()->route('paymentResult',[ + $data = [ 'message' => 'Payment Accepted', 'transaction_id' => $transaction->transaction_id, 'status' => 1 - ]); + ]; + + if($returnView){ + return redirect()->route('paymentResult',$data); + }else{ + return $this->successResponse($data); + } }else{ @@ -501,10 +507,17 @@ class StripeController extends Controller 'status' => strtolower($intent->status) ]); - return redirect()->route('paymentResult', [ + $data = [ 'message' => "Payment ".$transaction->status, 'status' => 0 - ]); + ]; + + if($returnView){ + return redirect()->route('paymentResult', $data); + }else{ + return $this->errorResponse($data); + } + } } }