1212
1313use Forter \Forter \Model \RequestBuilder \Customer as CustomerPreper ;
1414use Forter \Forter \Model \RequestBuilder \Payment \PaymentMethods ;
15+ use Forter \Forter \Model \ThirdParty \Stripe \StripePayment ;
1516
1617/**
1718 * Class Payment
@@ -29,17 +30,21 @@ class Payment
2930 */
3031 protected $ customerPreper ;
3132
33+ protected $ stripePayment ;
34+
3235 /**
3336 * Payment constructor.
3437 * @param PaymentMethods $paymentMethods
3538 * @param CustomerPreper $customerPreper
3639 */
3740 public function __construct (
3841 PaymentMethods $ paymentMethods ,
39- CustomerPreper $ customerPreper
42+ CustomerPreper $ customerPreper ,
43+ StripePayment $ stripePayment
4044 ) {
4145 $ this ->paymentMethods = $ paymentMethods ;
4246 $ this ->customerPreper = $ customerPreper ;
47+ $ this ->stripePayment = $ stripePayment ;
4348 }
4449
4550 /**
@@ -77,11 +82,13 @@ public function generatePaymentInfo($order)
7782 $ cardDetails = $ this ->paymentMethods ->getBraintreeDetails ($ payment );
7883 } elseif (strpos ($ payment_method , 'mercadopago ' ) !== false ) {
7984 $ cardDetails = $ this ->paymentMethods ->getMercadopagoDetails ($ payment );
85+ } elseif (strpos ($ payment_method , 'stripe ' ) !== false ) {
86+ $ cardDetails = $ this ->paymentMethods ->getStripePaymentDetails ($ payment , $ this ->stripePayment ->getPaymentData ($ order ));
8087 } else {
8188 $ cardDetails = $ this ->paymentMethods ->preferCcDetails ($ payment );
8289 }
8390
84- if (array_key_exists ("expirationMonth " , $ cardDetails ) || array_key_exists ("expirationYear " , $ cardDetails ) || array_key_exists ("lastFourDigits " , $ cardDetails )) {
91+ if (array_key_exists ("expirationMonth " , $ cardDetails ?? [] ) || array_key_exists ("expirationYear " , $ cardDetails ?? [] ) || array_key_exists ("lastFourDigits " , $ cardDetails ?? [] )) {
8592 $ paymentData ["creditCard " ] = $ cardDetails ;
8693 }
8794
@@ -94,13 +101,42 @@ public function generatePaymentInfo($order)
94101 $ paymentData ['applePay ' ] = $ cardDetails ;
95102 unset($ paymentData ["creditCard " ]);
96103 }
104+ if (strpos ($ payment ->getMethod (), 'stripe_payments ' ) !== false ) {
105+ $ stripeData = json_decode ($ payment ->getAdditionalInformation ('stripeChargeData ' ) ?? '' );
106+ if ($ stripeData && isset ($ stripeData ->payment_method )) {
107+ $ paymentData ['tokenizedCard ' ] = $ cardDetails ;
108+ unset($ paymentData ["creditCard " ]);
109+ }
110+
111+ if ($ stripeData && isset ($ stripeData ->payment_method_details )
112+ && isset ($ stripeData ->payment_method_details ->card )
113+ && isset ($ stripeData ->payment_method_details ->card ->wallet )
114+ && isset ($ stripeData ->payment_method_details ->card ->wallet ->type )
115+ && $ stripeData ->payment_method_details ->card ->wallet ->type === 'google_pay ' ) {
116+
117+ $ paymentData ['androidPay ' ] = $ cardDetails ;
118+ unset($ paymentData ["tokenizedCard " ]);
119+ unset($ paymentData ["creditCard " ]);
120+ }
121+
122+ if ($ stripeData && isset ($ stripeData ->payment_method_details )
123+ && isset ($ stripeData ->payment_method_details ->card )
124+ && isset ($ stripeData ->payment_method_details ->card ->wallet )
125+ && isset ($ stripeData ->payment_method_details ->card ->wallet ->type )
126+ && $ stripeData ->payment_method_details ->card ->wallet ->type === 'apple_pay ' ) {
127+
128+ $ paymentData ['applePay ' ] = $ cardDetails ;
129+ unset($ paymentData ["tokenizedCard " ]);
130+ unset($ paymentData ["creditCard " ]);
131+ }
132+ }
97133
98134 // Attempt to set tokenized card information if available
99- if ( !isset ($ paymentData ["creditCard " ]) && $ payment ->getAdditionalInformation ('forter_cc_token ' ) && $ payment ->getAdditionalInformation ('forter_cc_bin ' ) ) {
100- $ paymentData ["tokenizedCard " ] = array (
135+ if (!isset ($ paymentData ["creditCard " ]) && $ payment ->getAdditionalInformation ('forter_cc_token ' ) && $ payment ->getAdditionalInformation ('forter_cc_bin ' )) {
136+ $ paymentData ["tokenizedCard " ] = [
101137 'bin ' => $ payment ->getAdditionalInformation ('forter_cc_bin ' ),
102138 'token ' => $ payment ->getAdditionalInformation ('forter_cc_token ' )
103- ) ;
139+ ] ;
104140 }
105141 }
106142
@@ -113,4 +149,4 @@ public function generatePaymentInfo($order)
113149
114150 return [$ paymentData ];
115151 }
116- }
152+ }
0 commit comments