@@ -45,7 +45,7 @@ public static function notify($message, $error = false, $data = null)
4545 ]);
4646 }
4747
48- public function createIntent (Cart $ cart ): string
48+ public function createIntent (Cart $ cart )
4949 {
5050 $ meta = (array ) $ cart ->meta ;
5151
@@ -55,24 +55,32 @@ public function createIntent(Cart $cart): string
5555 $ cart
5656 );
5757
58- $ paymentIntent = $ result ['intent ' ];
58+ $ response = $ result ['response ' ];
5959 $ orderId = $ result ['order_id ' ];
6060
61+ if ($ response ->result !== 'SUCCESS ' ) {
62+ return [
63+ 'error ' => true ,
64+ ];
65+ }
66+
6167 if (! $ meta ) {
6268 $ cart ->update ([
6369 'meta ' => [
64- 'payment_intent ' => $ paymentIntent ->session ->id ,
70+ 'checkout_session ' => $ response ->session ->id ,
71+ 'success_indicator ' => $ response ->successIndicator ,
6572 'order_id ' => $ orderId ,
6673 ],
6774 ]);
6875 } else {
69- $ meta ['payment_intent ' ] = $ paymentIntent ->session ->id ;
76+ $ meta ['checkout_session ' ] = $ response ->session ->id ;
77+ $ meta ['success_indicator ' ] = $ response ->successIndicator ;
7078 $ meta ['order_id ' ] = $ orderId ;
7179 $ cart ->meta = $ meta ;
7280 $ cart ->save ();
7381 }
7482
75- return $ paymentIntent ->session -> id ;
83+ return $ response ->session ;
7684 }
7785
7886 public static function initiateCheckoutUsing (Closure $ initiateCheckoutUsing )
@@ -90,7 +98,7 @@ protected function buildIntent($value, $currencyCode, $cart)
9098
9199 return [
92100 'order_id ' => $ data ['order ' ]['id ' ] ?? null ,
93- 'intent ' => Mpgs::initiateCheckout ($ data ),
101+ 'response ' => Mpgs::initiateCheckout ($ data ),
94102 ];
95103 }
96104}
0 commit comments