Skip to content

Commit

Permalink
Merge pull request #88 from bold-commerce/fastlane-payments-sdk
Browse files Browse the repository at this point in the history
Fix PPCP Fastlane is destroying SDK components in case Fastlane is loaded after.
  • Loading branch information
NickolasMalovanets authored Oct 18, 2024
2 parents 84cd605 + 89cf603 commit 6909fc3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
define(
[
'Bold_CheckoutPaymentBooster/js/model/fastlane',
'Bold_CheckoutPaymentBooster/js/model/spi',
'Bold_CheckoutPaymentBooster/js/action/set-quote-shipping-address'
], function (
fastlane,
spi,
setQuoteShippingAddressAction
) {
'use strict';
Expand All @@ -21,7 +21,7 @@ define(
* @private
*/
const showFastlaneAddressModal = async function () {
const fastlaneInstance = await fastlane.getFastlaneInstance();
const fastlaneInstance = await spi.getFastlaneInstance();
if (!fastlaneInstance) {
return {selectionChanged: false, selectedAddress: {}};
}
Expand Down
6 changes: 2 additions & 4 deletions view/frontend/web/js/model/fastlane.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
define([
'ko',
'Bold_CheckoutPaymentBooster/js/model/spi',
'prototype'
], function (
ko,
spi,
) {
'use strict';

Expand Down Expand Up @@ -42,7 +41,7 @@ define([
*
* @return {Promise<{profile: {showShippingAddressSelector: function}, identity: {lookupCustomerByEmail: function, triggerAuthenticationFlow: function}, FastlanePaymentComponent: function}>}
*/
getFastlaneInstance: async function () {
getFastlaneInstance: async function (boldPaymentsInstance) {
if (!this.isAvailable()) {
return null;
}
Expand All @@ -62,7 +61,6 @@ define([
window.boldFastlaneInstanceCreateInProgress = true;
try {
if (!this.gatewayData) {
const boldPaymentsInstance = await spi.getPaymentsClient();
boldPaymentsInstance.state = {options: {fastlane: this.isAvailable()}};
this.gatewayData = (await boldPaymentsInstance.getFastlaneClientInit())[window.checkoutConfig.bold.gatewayId] || null;
}
Expand Down
15 changes: 13 additions & 2 deletions view/frontend/web/js/model/spi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ define([
'Bold_CheckoutPaymentBooster/js/action/create-wallet-pay-order-action',
'Bold_CheckoutPaymentBooster/js/action/payment-sca-action',
'Magento_Checkout/js/model/quote',
'Bold_CheckoutPaymentBooster/js/model/fastlane',
'prototype'
], function (
registry,
createOrderAction,
paymentScaAction,
quote
quote,
fastlane
) {
'use strict';

Expand Down Expand Up @@ -100,9 +102,18 @@ define([
}.bind(this)
}
};
this.paymentsInstance = new window.bold.Payments(initialData);
const paymentInstance = new window.bold.Payments(initialData);
this.fastlaneInstance = await fastlane.getFastlaneInstance(paymentInstance);
this.paymentsInstance = paymentInstance;
this.createPaymentsInstanceInProgress = false;
return this.paymentsInstance;
},
getFastlaneInstance: async function () {
if (this.fastlaneInstance) {
return this.fastlaneInstance;
}
await this.getPaymentsClient();
return this.fastlaneInstance;
},
};
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define(
[
'Bold_CheckoutPaymentBooster/js/model/spi',
'Bold_CheckoutPaymentBooster/js/model/fastlane',
'Bold_CheckoutPaymentBooster/js/view/shipping-address/list',
'Magento_Customer/js/model/address-list',
Expand All @@ -12,6 +13,7 @@ define(
'Bold_CheckoutPaymentBooster/js/action/reset-shipping-address',
'Magento_Checkout/js/model/quote'
], function (
spi,
fastlane,
addressList,
customerAddressList,
Expand Down Expand Up @@ -44,7 +46,7 @@ define(
return;
}
this.template = 'Bold_CheckoutPaymentBooster/form/element/email';
fastlane.getFastlaneInstance().then((fastlaneInstance) => {
spi.getFastlaneInstance().then((fastlaneInstance) => {
if (!fastlaneInstance) {
return;
}
Expand Down Expand Up @@ -85,7 +87,7 @@ define(
lookupEmail: async function () {
try {
fullScreenLoader.startLoader();
const fastlaneInstance = await fastlane.getFastlaneInstance();
const fastlaneInstance = await spi.getFastlaneInstance();
if (!fastlaneInstance) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ define(
'Magento_Checkout/js/action/select-payment-method',
'Magento_Checkout/js/action/select-billing-address',
'Bold_CheckoutPaymentBooster/js/model/bold-frontend-client',
'Bold_CheckoutPaymentBooster/js/model/spi',
'Bold_CheckoutPaymentBooster/js/model/fastlane',
'Bold_CheckoutPaymentBooster/js/action/convert-fastlane-address',
'Magento_Checkout/js/model/quote',
Expand All @@ -21,6 +22,7 @@ define(
selectPaymentMethodAction,
selectBillingAddressAction,
boldFrontendClient,
spi,
fastlane,
convertFastlaneAddressAction,
quote,
Expand Down Expand Up @@ -100,7 +102,7 @@ define(
*/
renderCardComponent: async function () {
try {
const fastlaneInstance = await fastlane.getFastlaneInstance();
const fastlaneInstance = await spi.getFastlaneInstance();
if (!fastlaneInstance) {
this.isPlaceOrderActionAllowed(false);
this.isVisible(false);
Expand Down
4 changes: 3 additions & 1 deletion view/frontend/web/js/view/shipping-address/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ define(
'Magento_Checkout/js/view/shipping-address/list',
'Magento_Customer/js/model/address-list',
'Bold_CheckoutPaymentBooster/js/action/show-shipping-address-form',
'Bold_CheckoutPaymentBooster/js/model/spi',
'Bold_CheckoutPaymentBooster/js/model/fastlane',
'Magento_Checkout/js/model/quote'
],
Expand All @@ -12,6 +13,7 @@ define(
shippingAddressList,
customerAddressList,
showShippingAddressFormAction,
spi,
fastlane,
quote
) {
Expand Down Expand Up @@ -61,7 +63,7 @@ define(
return;
}
this.visible(true);
fastlane.getFastlaneInstance().then((fastlaneInstance) => {
spi.getFastlaneInstance().then((fastlaneInstance) => {
if (!fastlaneInstance) {
return;
}
Expand Down

0 comments on commit 6909fc3

Please sign in to comment.