1414
1515class PaypalPaymentGateway extends AbstractPaymentGateway
1616{
17+ const PAYPAL_CHECKOUT_FLOW_TEMPLATE_MAPPING = [
18+ 'PAY_NOW ' => 'paypal_pay_now.html.twig ' ,
19+ // 'SMART_BUTTON' => 'paypal_smart_button.html.twig',
20+ ];
21+
1722 public function initialize (
1823 PaymentGatewayConfigurationInterface $ paymentGatewayConfiguration ,
1924 Transaction $ transaction
@@ -23,7 +28,7 @@ public function initialize(
2328 'transaction ' => $ transaction ,
2429 'callbackUrl ' => $ paymentGatewayConfiguration ->get ('callback_url ' ),
2530 'returnUrl ' => $ paymentGatewayConfiguration ->get ('return_url ' ),
26- 'environment ' => $ paymentGatewayConfiguration ->get ('environment ' ),
31+ 'mode ' => $ paymentGatewayConfiguration ->get ('mode ' ),
2732 ];
2833 }
2934
@@ -33,9 +38,25 @@ public function buildHTMLView(
3338 ): string {
3439 $ initializationData = $ this ->initialize ($ paymentGatewayConfiguration , $ transaction );
3540
36- return $ this ->templating ->render ('@IDCIPaymentBundle/Resources/views/Gateway/paypal.html.twig ' , [
37- 'initializationData ' => $ initializationData ,
38- ]);
41+ if (!array_key_exists ($ paymentGatewayConfiguration ->get ('checkout_flow ' ), self ::PAYPAL_CHECKOUT_FLOW_TEMPLATE_MAPPING )) {
42+ throw new \UnexpectedValueException (
43+ sprintf (
44+ 'The checkout flow "%s" is not yet implemented in %s ' ,
45+ $ paymentGatewayConfiguration ->get ('checkout_flow ' ),
46+ self ::class
47+ )
48+ );
49+ }
50+
51+ return $ this ->templating ->render (
52+ sprintf (
53+ '@IDCIPaymentBundle/Resources/views/Gateway/%s ' ,
54+ self ::PAYPAL_CHECKOUT_FLOW_TEMPLATE_MAPPING [$ paymentGatewayConfiguration ->get ('checkout_flow ' )]
55+ ),
56+ [
57+ 'initializationData ' => $ initializationData ,
58+ ]
59+ );
3960 }
4061
4162 public function getResponse (
@@ -57,6 +78,10 @@ public function getResponse(
5778 $ paymentGatewayConfiguration ->get ('client_secret ' )
5879 ));
5980
81+ $ apiContext ->setConfig ([
82+ 'mode ' => $ paymentGatewayConfiguration ->get ('mode ' ),
83+ ]);
84+
6085 $ paypalPayment = PaypalPayment::get ($ request ->get ('paymentID ' ), $ apiContext );
6186
6287 $ amount = $ paypalPayment ->getTransactions ()[0 ]->getAmount ();
@@ -88,7 +113,8 @@ public static function getParameterNames(): ?array
88113 [
89114 'client_id ' ,
90115 'client_secret ' ,
91- 'environment ' ,
116+ 'mode ' ,
117+ 'checkout_flow ' ,
92118 ]
93119 );
94120 }
0 commit comments