diff --git a/jest/sfccCartridgeMocks.js b/jest/sfccCartridgeMocks.js index 7f75ba6d2..16282f5e8 100644 --- a/jest/sfccCartridgeMocks.js +++ b/jest/sfccCartridgeMocks.js @@ -389,6 +389,7 @@ jest.mock( getValue: jest.fn(() => lineItem.getAdjustedTax / quantity), })), })), + getAllLineItems: jest.fn((lineItem) => lineItem), }), { virtual: true }, ); diff --git a/src/cartridges/int_adyen_overlay/cartridge/scripts/__tests__/paypalHelper.test.js b/src/cartridges/int_adyen_overlay/cartridge/scripts/__tests__/paypalHelper.test.js index 6637fb43a..3eb43dded 100644 --- a/src/cartridges/int_adyen_overlay/cartridge/scripts/__tests__/paypalHelper.test.js +++ b/src/cartridges/int_adyen_overlay/cartridge/scripts/__tests__/paypalHelper.test.js @@ -4,11 +4,7 @@ describe('paypalHelper', () => { beforeEach(() => { args = (item) => ({ Order: { - getProductLineItems: jest.fn(() => { - return { - toArray: jest.fn(() => ([item])) - } - }) + getAllLineItems: jest.fn(() => ([item])) } }) diff --git a/src/cartridges/int_adyen_overlay/cartridge/scripts/adyenGetOpenInvoiceData.js b/src/cartridges/int_adyen_overlay/cartridge/scripts/adyenGetOpenInvoiceData.js index cbfddf694..7d40903bf 100644 --- a/src/cartridges/int_adyen_overlay/cartridge/scripts/adyenGetOpenInvoiceData.js +++ b/src/cartridges/int_adyen_overlay/cartridge/scripts/adyenGetOpenInvoiceData.js @@ -16,8 +16,6 @@ * This file is open source and available under the MIT license. * See the LICENSE file for more info. * - * Generate the parameters needed for the redirect to the Adyen Hosted Payment Page. - * A signature is calculated based on the configured HMAC code */ // script include @@ -26,43 +24,29 @@ const LineItemHelper = require('*/cartridge/scripts/util/lineItemHelper'); function getLineItems({ Order: order, Basket: basket, addTaxPercentage }) { if (!(order || basket)) return null; const orderOrBasket = order || basket; - const allLineItems = orderOrBasket.getAllLineItems(); + const allLineItems = LineItemHelper.getAllLineItems(orderOrBasket.getAllLineItems()); // Add all product and shipping line items to request - const lineItems = []; - for (const item in allLineItems) { - const lineItem = allLineItems[item]; - if ( - (lineItem instanceof dw.order.ProductLineItem && - !lineItem.bonusProductLineItem) || - lineItem instanceof dw.order.ShippingLineItem || - (lineItem instanceof dw.order.PriceAdjustment && - lineItem.promotion.promotionClass === - dw.campaign.Promotion.PROMOTION_CLASS_ORDER) - ) { - const lineItemObject = {}; - const description = LineItemHelper.getDescription(lineItem); - const id = LineItemHelper.getId(lineItem); - const quantity = LineItemHelper.getQuantity(lineItem); - const itemAmount = LineItemHelper.getItemAmount(lineItem).divide(quantity); - const vatAmount = LineItemHelper.getVatAmount(lineItem).divide(quantity); - const vatPercentage = LineItemHelper.getVatPercentage(lineItem); + return allLineItems.map((lineItem) => { + const lineItemObject = {}; + const description = LineItemHelper.getDescription(lineItem); + const id = LineItemHelper.getId(lineItem); + const quantity = LineItemHelper.getQuantity(lineItem); + const itemAmount = LineItemHelper.getItemAmount(lineItem).divide(quantity); + const vatAmount = LineItemHelper.getVatAmount(lineItem).divide(quantity); + const vatPercentage = LineItemHelper.getVatPercentage(lineItem); - lineItemObject.amountExcludingTax = itemAmount.getValue().toFixed(); - lineItemObject.taxAmount = vatAmount.getValue().toFixed(); - lineItemObject.amountIncludingTax = itemAmount.getValue() + vatAmount.getValue(); - lineItemObject.description = description; - lineItemObject.id = id; - lineItemObject.quantity = quantity; - lineItemObject.taxPercentage = addTaxPercentage ? ( - new Number(vatPercentage) * 10000 - ).toFixed() : 0; - - lineItems.push(lineItemObject); - } - } - - return lineItems; + lineItemObject.amountExcludingTax = itemAmount.getValue().toFixed(); + lineItemObject.taxAmount = vatAmount.getValue().toFixed(); + lineItemObject.amountIncludingTax = itemAmount.getValue() + vatAmount.getValue(); + lineItemObject.description = description; + lineItemObject.id = id; + lineItemObject.quantity = quantity; + lineItemObject.taxPercentage = addTaxPercentage ? ( + new Number(vatPercentage) * 10000 + ).toFixed() : 0; + return lineItemObject; + }) } module.exports = { diff --git a/src/cartridges/int_adyen_overlay/cartridge/scripts/paypalHelper.js b/src/cartridges/int_adyen_overlay/cartridge/scripts/paypalHelper.js index 73de6b8ac..59fd73aa6 100644 --- a/src/cartridges/int_adyen_overlay/cartridge/scripts/paypalHelper.js +++ b/src/cartridges/int_adyen_overlay/cartridge/scripts/paypalHelper.js @@ -21,25 +21,25 @@ const LineItemHelper = require('*/cartridge/scripts/util/lineItemHelper'); -const PAYPAL_ITEM_CATEGORY = { - DIGITAL_GOODS: "DIGITAL_GOODS", - PHYSICAL_GOODS: "PHYSICAL_GOODS", - DONATION: "DONATION" -} +const PAYPAL_ITEM_CATEGORY = ["PHYSICAL_GOODS","DIGITAL_GOODS","DONATION"] function getLineItems({ Order: order, Basket: basket }) { if (!(order || basket)) return null; const orderOrBasket = order || basket; - const allLineItems = orderOrBasket.getProductLineItems(); - return allLineItems.toArray().map((lineItem) => { + const allLineItems = LineItemHelper.getAllLineItems(orderOrBasket.getAllLineItems()); + return allLineItems.map((lineItem) => { const description = LineItemHelper.getDescription(lineItem); const id = LineItemHelper.getId(lineItem); const quantity = LineItemHelper.getQuantity(lineItem); const itemAmount = LineItemHelper.getItemAmount(lineItem).divide(quantity); const vatAmount = LineItemHelper.getVatAmount(lineItem).divide(quantity); + let category = PAYPAL_ITEM_CATEGORY[0]; + if (lineItem.hasOwnProperty('category')) { + category = PAYPAL_ITEM_CATEGORY.indexOf(lineItem.category) > -1 ? lineItem.category : PAYPAL_ITEM_CATEGORY[0] + } return { quantity: quantity, description: description, - itemCategory: Object.values(PAYPAL_ITEM_CATEGORY).indexOf(lineItem.category) > -1 ? lineItem.category : PAYPAL_ITEM_CATEGORY.PHYSICAL_GOODS, + itemCategory: category, sku: id, amountExcludingTax: itemAmount.getValue().toFixed(), taxAmount: vatAmount.getValue().toFixed() diff --git a/src/cartridges/int_adyen_overlay/cartridge/scripts/util/lineItemHelper.js b/src/cartridges/int_adyen_overlay/cartridge/scripts/util/lineItemHelper.js index 371b801b0..19f8efc74 100644 --- a/src/cartridges/int_adyen_overlay/cartridge/scripts/util/lineItemHelper.js +++ b/src/cartridges/int_adyen_overlay/cartridge/scripts/util/lineItemHelper.js @@ -95,6 +95,24 @@ const __LineItemHelper = { } return new dw.value.Money(0, lineItem.getPrice().getCurrencyCode()); }, + + getAllLineItems(allLineItems) { + const lineItems = []; + for (const item in allLineItems) { + const lineItem = allLineItems[item]; + if ( + (lineItem instanceof dw.order.ProductLineItem && + !lineItem.bonusProductLineItem) || + lineItem instanceof dw.order.ShippingLineItem || + (lineItem instanceof dw.order.PriceAdjustment && + lineItem.promotion.promotionClass === + dw.campaign.Promotion.PROMOTION_CLASS_ORDER) + ) { + lineItems.push(lineItem) + } + } + return lineItems + } }; module.exports = __LineItemHelper; diff --git a/tests/playwright/pages/CheckoutPageSFRA5.mjs b/tests/playwright/pages/CheckoutPageSFRA5.mjs index f1311fc40..6c4a5d015 100644 --- a/tests/playwright/pages/CheckoutPageSFRA5.mjs +++ b/tests/playwright/pages/CheckoutPageSFRA5.mjs @@ -175,11 +175,11 @@ export default class CheckoutPageSFRA5 { }; submitPayment = async () => { - await this.page.waitForLoadState('networkidle', { timeout: 20000 }); + await this.page.waitForLoadState('load', { timeout: 30000 }); await this.submitPaymentButton.click(); }; placeOrder = async () => { - await this.page.waitForLoadState('networkidle', { timeout: 20000 }); + await this.page.waitForLoadState('load', { timeout: 30000 }); await this.placeOrderButton.click(); }; diff --git a/tests/playwright/pages/CheckoutPageSFRA6.mjs b/tests/playwright/pages/CheckoutPageSFRA6.mjs index 1514172d1..11563f6f6 100644 --- a/tests/playwright/pages/CheckoutPageSFRA6.mjs +++ b/tests/playwright/pages/CheckoutPageSFRA6.mjs @@ -184,7 +184,7 @@ export default class CheckoutPageSFRA { }; submitPayment = async () => { - await this.page.waitForLoadState('load', { timeout: 20000 }); + await this.page.waitForLoadState('load', { timeout: 30000 }); await this.submitPaymentButton.click(); }; @@ -192,7 +192,7 @@ export default class CheckoutPageSFRA { let retries = 3; while (retries > 0) { try { - await this.page.waitForLoadState('load', { timeout: 20000 }); + await this.page.waitForLoadState('load', { timeout: 30000 }); await this.placeOrderButton.click(); break; // Break out of the loop if successful } catch (error) { diff --git a/tests/playwright/pages/PaymentMethodsPage.mjs b/tests/playwright/pages/PaymentMethodsPage.mjs index 7c055ff02..5cadfa8a4 100644 --- a/tests/playwright/pages/PaymentMethodsPage.mjs +++ b/tests/playwright/pages/PaymentMethodsPage.mjs @@ -222,7 +222,6 @@ export default class PaymentMethodsPage { timeout: 20000, }); await giftCardBrand.click(); - await this.page.waitForLoadState('networkidle', { timeout: 20000 }); const giftCardNumberInputField = giftCardComponentWrapper .frameLocator('.adyen-checkout__card__cardNumber__input iframe') @@ -322,7 +321,6 @@ export default class PaymentMethodsPage { }; initiateKlarnaPayment = async (klarnaVariant) => { - await this.page.waitForLoadState('networkidle', { timeout: 20000 }); let klarnaSelector = this.page.locator('#rb_klarna'); if (klarnaVariant) { klarnaSelector =