@@ -52,20 +52,11 @@ public function build(array $buildSubject): array
5252 $ paymentToken = $ extensionAttributes ->getVaultPaymentToken ();
5353 $ details = json_decode ((string ) ($ paymentToken ->getTokenDetails () ?: '{} ' ), true );
5454
55- if ($ paymentToken ->getType () === PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD ) {
56- // Build base request for card token payments (including card wallets)
57-
58- $ isInstantPurchase = (bool ) $ payment ->getAdditionalInformation ('instant-purchase ' );
59-
60- if ($ isInstantPurchase ) {
61- // `Instant Purchase` doesn't have the component and state data. Build the `paymentMethod` object.
62- $ requestBody ['paymentMethod ' ]['type ' ] = 'scheme ' ;
63- $ requestBody ['paymentMethod ' ]['storedPaymentMethodId ' ] = $ paymentToken ->getGatewayToken ();
64- } else {
65- // Initialize the request body with the current state data if it's not `Instant Purchase`.
66- $ requestBody = $ this ->stateData ->getStateData ($ order ->getQuoteId ());
67- }
55+ // Initialize the request body with the current state data
56+ $ requestBody = $ this ->stateData ->getStateData ($ order ->getQuoteId ());
6857
58+ // Build base request for card token payments (including card wallets)
59+ if ($ paymentToken ->getType () === PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD ) {
6960 /*
7061 * `allow3DS: true` flag is required to trigger the native 3DS challenge.
7162 * Otherwise, shopper will be redirected to the issuer for challenge.
@@ -78,13 +69,21 @@ public function build(array $buildSubject): array
7869
7970 // Due to new VISA compliance requirements, holderName is added to the payments call
8071 $ requestBody ['paymentMethod ' ]['holderName ' ] = $ details ['cardHolderName ' ] ?? null ;
81- } else {
82- // Build base request for alternative payment methods for regular checkout and Instant Purchase
72+ }
8373
84- $ requestBody ['paymentMethod ' ] = [
85- 'type ' => $ details ['type ' ],
86- 'storedPaymentMethodId ' => $ paymentToken ->getGatewayToken ()
87- ];
74+ /*
75+ * `paymentMethod.type` and `paymentMethod.storedPaymentMethodId` need to be manually populated
76+ * for all recurring alternative payment methods, recurring card payments where state data is missing and
77+ * `Instant Purchase` payments.
78+ */
79+ if (empty ($ requestBody ['paymentMethod ' ]['type ' ])) {
80+ $ requestBody ['paymentMethod ' ]['type ' ] =
81+ $ paymentToken ->getType () === PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD
82+ ? 'scheme '
83+ : $ details ['type ' ];
84+ }
85+ if (empty ($ requestBody ['paymentMethod ' ]['storedPaymentMethodId ' ])) {
86+ $ requestBody ['paymentMethod ' ]['storedPaymentMethodId ' ] = $ paymentToken ->getGatewayToken ();
8887 }
8988
9089 // Check the `stateData` if `recurringProcessingModel` is added through a headless request.
0 commit comments