From a6c146f47780e1f0a86e8a161db594d05462d288 Mon Sep 17 00:00:00 2001 From: Joshua Shea Date: Thu, 9 Jan 2025 15:22:37 -0600 Subject: [PATCH] [CHK-7187] Adding promise logic solving for race condition --- .../express-pay/get-required-order-data-action.js | 4 +++- view/frontend/web/js/model/spi.js | 15 +++++++++++---- .../callbacks/on-create-payment-order-callback.js | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/view/frontend/web/js/action/express-pay/get-required-order-data-action.js b/view/frontend/web/js/action/express-pay/get-required-order-data-action.js index d9028b1..bdc131b 100644 --- a/view/frontend/web/js/action/express-pay/get-required-order-data-action.js +++ b/view/frontend/web/js/action/express-pay/get-required-order-data-action.js @@ -20,7 +20,9 @@ define( */ return function (requirements) { const payload = {}; - if (window.checkoutConfig.bold.payment_type_clicked == 'apple') { + if (window.checkoutConfig.quoteData.entity_id === '' + && (window.checkoutConfig.bold.payment_type_clicked === 'apple' + || window.checkoutConfig.bold.payment_type_clicked === "google")) { payload.totals = { order_total: 0, order_balance: 1000, diff --git a/view/frontend/web/js/model/spi.js b/view/frontend/web/js/model/spi.js index d61f620..160a201 100644 --- a/view/frontend/web/js/model/spi.js +++ b/view/frontend/web/js/model/spi.js @@ -47,6 +47,7 @@ define([ localStorage.setItem(AGREEMENT_DATE_KEY, currentTime.toString()); return true; }; + let onClickPromise = null; /** * Fastlane init model. @@ -114,6 +115,9 @@ define([ } try { + if (window.checkoutConfig.bold.payment_type_clicked === "apple" || window.checkoutConfig.bold.payment_type_clicked === "google") { + await onClickPromise; + } return await onUpdatePaymentOrderCallback(paymentType, paymentPayload); } catch (e) { console.error(e); @@ -139,7 +143,7 @@ define([ throw e; } }, - 'onRequireOrderData': async function (requirements) { + 'onRequireOrderData': function (requirements) { try { return onRequireOrderDataCallback(requirements); } catch (e) { @@ -155,9 +159,12 @@ define([ 'onClickPaymentOrder': async (paymentType, paymentPayload) => { const pageSource = paymentPayload.containerId.replace('express-pay-buttons-', ''); window.checkoutConfig.bold.payment_type_clicked = paymentPayload?.payment_data?.payment_type; - - try { - onClickPaymentOrderCallback(pageSource); + try { + if (window.checkoutConfig.bold.payment_type_clicked === "apple" || window.checkoutConfig.bold.payment_type_clicked === "google") { + onClickPromise = onClickPaymentOrderCallback(pageSource); + } else { + await onClickPaymentOrderCallback(pageSource); + } } catch (e) { console.error(e); fullScreenLoader.stopLoader(); diff --git a/view/frontend/web/js/model/spi/callbacks/on-create-payment-order-callback.js b/view/frontend/web/js/model/spi/callbacks/on-create-payment-order-callback.js index 8ea7331..34508e8 100644 --- a/view/frontend/web/js/model/spi/callbacks/on-create-payment-order-callback.js +++ b/view/frontend/web/js/model/spi/callbacks/on-create-payment-order-callback.js @@ -3,13 +3,17 @@ define( 'Bold_CheckoutPaymentBooster/js/action/express-pay/update-quote-address-action', 'Bold_CheckoutPaymentBooster/js/action/express-pay/update-quote-shipping-method-action', 'Bold_CheckoutPaymentBooster/js/action/express-pay/save-shipping-information-action', - 'Bold_CheckoutPaymentBooster/js/action/express-pay/create-wallet-pay-order-action' + 'Bold_CheckoutPaymentBooster/js/action/express-pay/create-wallet-pay-order-action', + 'Bold_CheckoutPaymentBooster/js/action/express-pay/get-active-quote-action', + 'Magento_Checkout/js/model/quote' ], function ( updateQuoteAddressAction, updateQuoteShippingMethodAction, saveShippingInformationAction, - createWalletPayOrderAction + createWalletPayOrderAction, + getActiveQuote, + quote ) { 'use strict'; @@ -29,6 +33,12 @@ define( return; } + if (!quote.getQuoteId()) { + let response = await getActiveQuote(); + response = JSON.parse(response); + window.checkoutConfig.quoteData.entity_id = response.quoteId; + } + if (addressProvided) { if (isWalletPayment && paymentData['shipping_address']) { updateQuoteAddressAction('shipping', paymentData['shipping_address']);