Skip to content

Commit

Permalink
feat(SFI-876): create temporary basket for express pdp
Browse files Browse the repository at this point in the history
  • Loading branch information
shanikantsingh committed Oct 8, 2024
1 parent d011755 commit 12efef7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function selectShippingMethod({ shipmentUUID, ID }, basketId) {
});
}

function getShippingMethod(shippingContact, basketId, isExpressPdp) {
function getShippingMethod(shippingContact, basketId) {
const request = {
paymentMethodType: APPLE_PAY,
basketId,
Expand All @@ -140,11 +140,7 @@ function getShippingMethod(shippingContact, basketId, isExpressPdp) {
postalCode: shippingContact.postalCode,
};
}
let url = window.shippingMethodsUrl;
if (isExpressPdp) {
url += '?expressPdp=true';
}
return fetch(url, {
return fetch(window.shippingMethodsUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
Expand All @@ -154,14 +150,8 @@ function getShippingMethod(shippingContact, basketId, isExpressPdp) {
}

async function initializeCheckout() {
const paymentMethods = await getPaymentMethods(window.isExpressPdp);
const paymentMethods = await getPaymentMethods();
paymentMethodsResponse = await paymentMethods.json();
const shippingMethods = await getShippingMethod(
null,
null,
window.isExpressPdp,
);
shippingMethodsData = await shippingMethods.json();
const applicationInfo = paymentMethodsResponse?.applicationInfo;
checkout = await AdyenCheckout({
environment: window.environment,
Expand Down Expand Up @@ -233,7 +223,7 @@ async function init() {
};

await callPaymentFromComponent(
{ ...stateData, customer },
{ ...stateData, customer, basketId: temporaryBasketId },
resolveApplePay,
reject,
);
Expand Down Expand Up @@ -266,6 +256,8 @@ async function init() {
} else {
reject();
}
} else {
resolve();
}
},
onShippingMethodSelected: async (resolve, reject, event) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,12 @@ module.exports.fetchGiftCards = async function fetchGiftCards() {
/**
* Makes an ajax call to the controller function GetPaymentMethods
*/
module.exports.getPaymentMethods = async function getPaymentMethods(
isExpressPdp,
) {
const request = {
isExpressPdp,
};
module.exports.getPaymentMethods = async function getPaymentMethods() {
return fetch(window.getPaymentMethodsURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(request),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
window.locale = "${request.locale}";
window.getPaymentMethodsURL = "${URLUtils.https('Adyen-GetPaymentMethods')}";
window.shippingMethodsUrl = "${URLUtils.https('Adyen-ShippingMethods')}";
window.selectShippingMethodUrl = "${URLUtils.https('Adyen-SelectShippingMethod')}";
window.paymentsDetailsURL = "${URLUtils.https('Adyen-PaymentsDetails')}";
window.paymentFromComponentURL = "${URLUtils.https('Adyen-PaymentFromComponent')}";
window.showConfirmationAction = "${URLUtils.https('Adyen-ShowConfirmationPaymentFromComponent')}";
window.returnUrl = "${URLUtils.https('Cart-Show')}";
window.createTemporaryBasketUrl = "${URLUtils.https('Adyen-CreateTemporaryBasket')}";
window.isExpressPdp = true;
window.isApplePayExpressOnPdpEnabled = "${AdyenConfigs.isApplePayExpressOnPdpEnabled()}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function createTemporaryBasket(req, res, next) {

// Create a new temporary basket
const tempBasket = BasketMgr.createTemporaryBasket();
// AdyenLogs.debug_log(JSON.stringify(req.form['selected-express-product']));
const product = JSON.parse(req.form['selected-express-product']);
const productId = product.id;
const childProducts = product.bundledProducts || [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,19 @@ const getRemainingAmount = (giftCardResponse, currency, currentBasket) => {

function getCheckoutPaymentMethods(req, res, next) {
try {
const { isExpressPdp } = JSON.parse(req.body);
const currentBasket = BasketMgr.getCurrentBasket();
const countryCode = getCountryCode(currentBasket, req.locale);
const adyenURL = `${AdyenHelper.getLoadingContext()}images/logos/medium/`;
const connectedTerminals = JSON.parse(getConnectedTerminals());
const currency = currentBasket
? currentBasket.getTotalGrossPrice().currencyCode
: session.currency.currencyCode;
let paymentAmount = getRemainingAmount(
const paymentAmount = getRemainingAmount(
session.privacy.giftCardResponse,
currency,
currentBasket,
);

if (isExpressPdp) {
paymentAmount = new dw.value.Money(1000, currency);
}

const paymentMethods = getPaymentMethods.getMethods(
paymentAmount,
AdyenHelper.getCustomer(req.currentCustomer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ function canSkipSummaryPage(reqDataObj) {
* Make a payment from inside a component, skipping the summary page. (paypal, QRcodes, MBWay)
*/
function paymentFromComponent(req, res, next) {
const reqDataObj = JSON.parse(req.form.data);
const { basketId, ...reqDataObj } = JSON.parse(req.form.data);
if (reqDataObj.cancelTransaction) {
return handleCancellation(res, next, reqDataObj);
}
const currentBasket = BasketMgr.getCurrentBasket();
const currentBasket = basketId
? BasketMgr.getTemporaryBasket(basketId)
: BasketMgr.getCurrentBasket();
let paymentInstrument;
Transaction.wrap(() => {
collections.forEach(currentBasket.getPaymentInstruments(), (item) => {
Expand Down

0 comments on commit 12efef7

Please sign in to comment.