Skip to content

Commit

Permalink
feat: create temp basket if express payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
amihajlovski committed Dec 2, 2024
1 parent 5949951 commit a83af37
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const helpers = require('./adyen_checkout/helpers');
const {
checkIfExpressMethodsAreReady,
updateLoadedExpressMethods,
createTemporaryBasket,
} = require('./commons');
const { GOOGLE_PAY } = require('./constants');

Expand Down Expand Up @@ -260,6 +261,15 @@ async function onShippingOptionChange(
return false;
}

async function onInitTrigger() {
if (window.isExpressPdp) {
const tempBasketResponse = await createTemporaryBasket();
if (tempBasketResponse?.basketId) {
temporaryBasketId = tempBasketResponse.basketId;
}
}
}

async function init(paymentMethodsResponse) {
initializeCheckout(paymentMethodsResponse)
.then(async () => {
Expand Down Expand Up @@ -300,7 +310,11 @@ async function init(paymentMethodsResponse) {
paymentType: 'express',
};
const customer = formatCustomerObject(data);
paymentFromComponent({ ...stateData, customer });
paymentFromComponent({
...stateData,
customer,
basketId: temporaryBasketId,
});
},
onSubmit: async () => {},
paymentDataCallbacks: {
Expand All @@ -312,10 +326,15 @@ async function init(paymentMethodsResponse) {
let onShippingAddressChangeStatus = true;
let onShippingOptionChangeStatus = true;

if (
callbackTrigger === CALLBACK_TRIGGERS.INITIALIZE ||
callbackTrigger === CALLBACK_TRIGGERS.SHIPPING_ADDRESS
) {
if (callbackTrigger === CALLBACK_TRIGGERS.INITIALIZE) {
await onInitTrigger();
onShippingAddressChangeStatus = await onShippingAddressChange(
shippingAddress,
paymentDataRequestUpdate,
);
}

if (callbackTrigger === CALLBACK_TRIGGERS.SHIPPING_ADDRESS) {
onShippingAddressChangeStatus = await onShippingAddressChange(
shippingAddress,
paymentDataRequestUpdate,
Expand Down

0 comments on commit a83af37

Please sign in to comment.