diff --git a/processor/src/service/payment.service.ts b/processor/src/service/payment.service.ts index 61c4700..c0f5cd7 100644 --- a/processor/src/service/payment.service.ts +++ b/processor/src/service/payment.service.ts @@ -420,7 +420,7 @@ export const handleCreatePayment = async (ctPayment: Payment): Promise { const { amountPlanned, paymentMethodInfo } = payment; @@ -121,9 +127,12 @@ export const createMollieCreatePaymentParams = ( ); const mollieLines = paymentRequest.lines ?? []; + + // Add another line for creating Mollie payment request if surcharge exists if (surchargeAmountInCent > 0) { mollieLines.push( - createMollieLineForSurchargeAmount( + createMollieLineForAdditionalAmount( + MOLLIE_SURCHARGE_LINE_DESCRIPTION, surchargeAmountInCent, amountPlanned.fractionDigits, amountPlanned.currencyCode, @@ -131,6 +140,18 @@ export const createMollieCreatePaymentParams = ( ); } + // Add another line for creating Mollie payment request if shipping cost exists + if (cart?.shippingInfo?.price) { + mollieLines.push( + createMollieLineForAdditionalAmount( + MOLLIE_SHIPPING_LINE_DESCRIPTION, + cart.shippingInfo.price.centAmount, + cart.shippingInfo.price.fractionDigits, + cart.shippingInfo.price.currencyCode, + ), + ); + } + const defaultWebhookEndpoint = new URL(extensionUrl).origin + '/webhook'; const createPaymentParams = { @@ -194,21 +215,24 @@ export const createCartUpdateActions = ( return updateActions; }; -export const createMollieLineForSurchargeAmount = ( - surchargeAmountInCent: number, +export const createMollieLineForAdditionalAmount = ( + description: string, + amountInCent: number, fractionDigits: number, currency: string, + quantity: number = 1, + quantityUnit: string = 'pcs', ) => { - const totalSurchargeAmount = { + const unitPrice = { currency, - value: convertCentToEUR(surchargeAmountInCent, fractionDigits).toFixed(2), + value: convertCentToEUR(amountInCent, fractionDigits).toFixed(2), }; return { - description: MOLLIE_SURCHARGE_LINE_DESCRIPTION, - quantity: 1, - quantityUnit: 'pcs', - unitPrice: totalSurchargeAmount, - totalAmount: totalSurchargeAmount, + description, + quantity, + quantityUnit, + unitPrice: unitPrice, + totalAmount: unitPrice, }; }; diff --git a/processor/tests/utils/constant.utils.spec.ts b/processor/tests/utils/constant.utils.spec.ts index 0355877..a9397f2 100644 --- a/processor/tests/utils/constant.utils.spec.ts +++ b/processor/tests/utils/constant.utils.spec.ts @@ -11,6 +11,7 @@ import { DEFAULT_DUE_DATE, MOLLIE_SURCHARGE_CUSTOM_LINE_ITEM, MOLLIE_SURCHARGE_LINE_DESCRIPTION, + MOLLIE_SHIPPING_LINE_DESCRIPTION, } from '../../src/utils/constant.utils'; import { version } from '../../package.json'; @@ -90,4 +91,9 @@ describe('Test constant.utils.ts', () => { expect(MOLLIE_SURCHARGE_LINE_DESCRIPTION).toBeDefined(); expect(MOLLIE_SURCHARGE_LINE_DESCRIPTION).toBe('Total surcharge amount'); }); + + test('should return correct {MOLLIE_SHIPPING_LINE_DESCRIPTION} pattern', () => { + expect(MOLLIE_SHIPPING_LINE_DESCRIPTION).toBeDefined(); + expect(MOLLIE_SHIPPING_LINE_DESCRIPTION).toBe('Shipping amount'); + }); }); diff --git a/processor/tests/utils/map.utils.spec.ts b/processor/tests/utils/map.utils.spec.ts index 2cf3d97..bc748c8 100644 --- a/processor/tests/utils/map.utils.spec.ts +++ b/processor/tests/utils/map.utils.spec.ts @@ -2,719 +2,859 @@ import { describe, test, expect, it, jest } from '@jest/globals'; import { createCartUpdateActions, createMollieCreatePaymentParams, - createMollieLineForSurchargeAmount, + createMollieLineForAdditionalAmount, mapCommercetoolsPaymentCustomFieldsToMollieListParams, } from '../../src/utils/map.utils'; import { Cart, Payment } from '@commercetools/platform-sdk'; import { MethodsListParams, PaymentCreateParams, PaymentMethod } from '@mollie/api-client'; -import { calculateDueDate, makeMollieAmount } from '../../src/utils/mollie.utils'; -import { CustomPaymentMethod } from '../../src/types/mollie.types'; -import { MOLLIE_SURCHARGE_CUSTOM_LINE_ITEM, MOLLIE_SURCHARGE_LINE_DESCRIPTION } from '../../src/utils/constant.utils'; +import { + MOLLIE_SHIPPING_LINE_DESCRIPTION, + MOLLIE_SURCHARGE_CUSTOM_LINE_ITEM, + MOLLIE_SURCHARGE_LINE_DESCRIPTION, +} from '../../src/utils/constant.utils'; jest.mock('../../src/utils/mollie.utils.ts', () => ({ // @ts-expect-error ignore type error ...jest.requireActual('../../src/utils/mollie.utils.ts'), // __esModule: true, - calculateDueDate: jest.fn(), -})); - -describe('Test map.utils.ts', () => { - let mockCtPayment: Payment; - let mockMolObject: MethodsListParams; - test('call mapCommercetoolsPaymentCustomFieldsToMollieListParams()', async () => { - mockCtPayment = { - amountPlanned: { - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - type: 'centPrecision', - }, - custom: { - fields: { - sctm_payment_methods_request: JSON.stringify({ - sequenceType: 'oneoff', - locale: 'de_DE', - billingCountry: 'DE', - resouce: 'payments', - includeWallets: 'applepay', - orderLineCategories: 'demo,test,sandbox', - }), - }, - }, - } as unknown as Payment; - - mockMolObject = { - amount: { - value: '10.00', - currency: 'EUR', - }, - resource: 'payments', - sequenceType: 'oneoff', - locale: 'de_DE', - billingCountry: 'DE', - includeWallets: 'applepay', - orderLineCategories: 'demo,test,sandbox', - } as unknown as MethodsListParams; - - const response = await mapCommercetoolsPaymentCustomFieldsToMollieListParams(mockCtPayment); - - expect(mapCommercetoolsPaymentCustomFieldsToMollieListParams).toBeDefined(); - expect(response).toBeDefined(); - expect(response).toStrictEqual(mockMolObject); - }); -}); - -describe('createMollieCreatePaymentParams', () => { - it('should able to create a mollie payment params from CommerceTools payment object for with method as creditcard', async () => { - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: 'creditcard', - }, - }; - const extensionUrl = 'https://example.com/webhook'; - - const mollieCreatePaymentParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - const mollieAmount = makeMollieAmount(CTPayment.amountPlanned); - - expect(mollieCreatePaymentParams).toEqual({ - method: CTPayment.paymentMethodInfo.method, - amount: { - currency: mollieAmount.currency, - value: mollieAmount.value, - }, - webhookUrl: extensionUrl, - lines: [], - }); - }); - - it('should able to create a mollie payment params from CommerceTools payment object for with method as creditcard and surcharge amount is not 0', async () => { - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: 'creditcard', - }, - }; - const extensionUrl = 'https://example.com/webhook'; - - const surchargeAmountInCent = 1000; - - const mollieCreatePaymentParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, surchargeAmountInCent); - const mollieAmount = { - currency: CTPayment.amountPlanned.currencyCode, - value: '20.00', - }; - - expect(mollieCreatePaymentParams).toEqual({ - method: CTPayment.paymentMethodInfo.method, - amount: mollieAmount, - webhookUrl: extensionUrl, - lines: [ - { - description: MOLLIE_SURCHARGE_LINE_DESCRIPTION, - quantity: 1, - quantityUnit: 'pcs', - unitPrice: { - currency: CTPayment.amountPlanned.currencyCode, - value: '10.00', - }, - totalAmount: { - currency: CTPayment.amountPlanned.currencyCode, - value: '10.00', - }, - }, - ], - }); - }); - - it('should able to create a mollie payment params from CommerceTools payment object with method as creditcard which has custom field', async () => { - const customFieldObject = { - description: 'Test payment', - locale: 'en_GB', - redirectUrl: 'https://example.com/success', - webhookUrl: 'https://example.com/webhook', - cardToken: 'card_token_12345', - }; - - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: 'creditcard', - }, - custom: { - type: { - typeId: 'type', - id: 'sctm_payment', - }, - fields: { - sctm_create_payment_request: JSON.stringify(customFieldObject), - }, - }, - }; - const extensionUrl = 'https://example.com/webhook'; - - const mollieCreatePaymentParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - - expect(mollieCreatePaymentParams).toEqual({ - method: 'creditcard', - amount: { - currency: 'EUR', - value: '10.00', - }, - locale: customFieldObject.locale, - redirectUrl: customFieldObject.redirectUrl, - webhookUrl: extensionUrl, // Always use our default webhook endpoint - description: customFieldObject.description, - cardToken: customFieldObject.cardToken, - lines: [], - }); - }); - - it('should able to create a mollie payment params from CommerceTools payment object with method as ideal', async () => { - const customFieldObject = { - description: 'Test payment', - locale: 'en_GB', - redirectUrl: 'https://example.com/success', - include: { - 'details.qrCode': { - width: 100, - height: 100, - src: 'qr_code_url', - }, - }, - }; - - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: PaymentMethod.ideal + ',ideal_TEST', - }, - custom: { - type: { - typeId: 'type', - id: 'sctm_payment', - }, - fields: { - sctm_create_payment_request: JSON.stringify(customFieldObject), - }, - }, - }; - const extensionUrl = 'https://example.com/webhook'; - - const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - expect(mollieCreatePaymentParams).toEqual({ - method: PaymentMethod.ideal, - amount: { - currency: 'EUR', - value: '10.00', - }, - locale: customFieldObject.locale, - redirectUrl: customFieldObject.redirectUrl, - webhookUrl: extensionUrl, - description: customFieldObject.description, - issuer: 'ideal_TEST', - include: customFieldObject.include, - lines: [], - }); - }); - - it('should able to create a mollie payment params from CommerceTools payment object with method as bancontact', async () => { - const customFieldObject = { - description: 'Test payment', - locale: 'en_GB', - redirectUrl: 'https://example.com/success', - webhookUrl: 'https://example.com/webhook', - include: { - 'details.qrCode': { - width: 100, - height: 100, - src: 'qr_code_url', - }, - }, - }; - - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: PaymentMethod.bancontact, - }, - custom: { - type: { - typeId: 'type', - id: 'sctm_payment', - }, - fields: { - sctm_create_payment_request: JSON.stringify(customFieldObject), - }, - }, - }; - const extensionUrl = 'https://example.com/webhook'; - - const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - expect(mollieCreatePaymentParams).toEqual({ - method: PaymentMethod.bancontact, - amount: { - currency: 'EUR', - value: '10.00', - }, - locale: customFieldObject.locale, - redirectUrl: customFieldObject.redirectUrl, - webhookUrl: extensionUrl, - description: customFieldObject.description, - include: customFieldObject.include, - lines: [], - }); - }); - - it('should able to create a mollie payment params from CommerceTools payment object with method as banktransfer', async () => { - const customFieldObject = { - description: 'Test payment', - locale: 'en_GB', - redirectUrl: 'https://example.com/success', - webhookUrl: 'https://example.com/webhook', - billingAddress: { - email: 'test@mollie.com', - }, - }; - - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: PaymentMethod.banktransfer, - }, - custom: { - type: { - typeId: 'type', - id: 'sctm_payment', - }, - fields: { - sctm_create_payment_request: JSON.stringify(customFieldObject), - }, - }, - }; - const extensionUrl = 'https://example.com/webhook'; - - const dueDate = '2024-01-01'; - (calculateDueDate as jest.Mock).mockReturnValueOnce(dueDate); - - const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - - expect(mollieCreatePaymentParams).toEqual({ - method: PaymentMethod.banktransfer, - amount: { - currency: 'EUR', - value: '10.00', - }, - locale: customFieldObject.locale, - redirectUrl: customFieldObject.redirectUrl, - webhookUrl: extensionUrl, - description: customFieldObject.description, - billingAddress: customFieldObject.billingAddress, - dueDate, - lines: [], - }); - }); - - it('should able to create a mollie payment params from CommerceTools payment object with method as przelewy24', async () => { - const customFieldObject = { - description: 'Test payment', - locale: 'en_GB', - redirectUrl: 'https://example.com/success', - webhookUrl: 'https://example.com/webhook', - billingEmail: 'test@mollie.com', - }; - - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: PaymentMethod.przelewy24, - }, - custom: { - type: { - typeId: 'type', - id: 'sctm_payment', - }, - fields: { - sctm_create_payment_request: JSON.stringify(customFieldObject), - }, - }, - }; - const extensionUrl = 'https://example.com/webhook'; - - const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - expect(mollieCreatePaymentParams).toEqual({ - method: PaymentMethod.przelewy24, - amount: { - currency: 'EUR', - value: '10.00', - }, - locale: customFieldObject.locale, - redirectUrl: customFieldObject.redirectUrl, - webhookUrl: extensionUrl, - description: customFieldObject.description, - billingEmail: customFieldObject.billingEmail, - lines: [], - }); - }); - - it('should able to create a mollie payment params from CommerceTools payment object with method as kbc', async () => { - const customFieldObject = { - description: 'Test payment', - locale: 'en_GB', - redirectUrl: 'https://example.com/success', - webhookUrl: 'https://example.com/webhook', - }; - - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: PaymentMethod.kbc, - }, - custom: { - type: { - typeId: 'type', - id: 'sctm_payment', - }, - fields: { - sctm_create_payment_request: JSON.stringify(customFieldObject), - }, - }, - }; - const extensionUrl = 'https://example.com/webhook'; - - const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - expect(mollieCreatePaymentParams).toEqual({ - method: PaymentMethod.kbc, - amount: { - currency: 'EUR', - value: '10.00', - }, - locale: customFieldObject.locale, - redirectUrl: customFieldObject.redirectUrl, - webhookUrl: extensionUrl, - description: customFieldObject.description, - lines: [], - }); - }); - - it('should able to create a mollie payment params from CommerceTools payment object with method as blik', () => { - const customFieldObject = { - description: 'Test payment', - locale: 'en_GB', - redirectUrl: 'https://example.com/success', - webhookUrl: 'https://example.com/webhook', - billingEmail: 'n.tran@shopmacher.de', - }; + calculateDueDate: jest.fn(), +})); - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', +describe('Test map.utils.ts', () => { + let mockCtPayment: Payment; + let mockMolObject: MethodsListParams; + test('call mapCommercetoolsPaymentCustomFieldsToMollieListParams()', async () => { + mockCtPayment = { amountPlanned: { - type: 'centPrecision', currencyCode: 'EUR', centAmount: 1000, fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: CustomPaymentMethod.blik, + type: 'centPrecision', }, custom: { - type: { - typeId: 'type', - id: 'sctm_payment', - }, fields: { - sctm_create_payment_request: JSON.stringify(customFieldObject), + sctm_payment_methods_request: JSON.stringify({ + sequenceType: 'oneoff', + locale: 'de_DE', + billingCountry: 'DE', + resouce: 'payments', + includeWallets: 'applepay', + orderLineCategories: 'demo,test,sandbox', + }), }, }, - }; - - const extensionUrl = 'https://example.com/webhook'; + } as unknown as Payment; - const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - expect(mollieCreatePaymentParams).toEqual({ - method: CustomPaymentMethod.blik, + mockMolObject = { amount: { - currency: 'EUR', value: '10.00', + currency: 'EUR', }, - locale: customFieldObject.locale, - redirectUrl: customFieldObject.redirectUrl, - webhookUrl: customFieldObject.webhookUrl, - description: customFieldObject.description, - billingEmail: customFieldObject.billingEmail, - lines: [], - }); + resource: 'payments', + sequenceType: 'oneoff', + locale: 'de_DE', + billingCountry: 'DE', + includeWallets: 'applepay', + orderLineCategories: 'demo,test,sandbox', + } as unknown as MethodsListParams; + + const response = await mapCommercetoolsPaymentCustomFieldsToMollieListParams(mockCtPayment); + + expect(mapCommercetoolsPaymentCustomFieldsToMollieListParams).toBeDefined(); + expect(response).toBeDefined(); + expect(response).toStrictEqual(mockMolObject); }); +}); - it('should able to create a mollie payment params from CommerceTools payment object with method as applepay', async () => { - const customFieldObject = { - description: 'Test payment', - locale: 'en_GB', - redirectUrl: 'https://example.com/success', - webhookUrl: 'https://example.com/webhook', - applePayPaymentToken: '{"paymentData": {"version": "EC_v1", "data": "vK3BbrCbI/...."}}', - }; +describe('createMollieCreatePaymentParams', () => { + // it('should able to create a mollie payment params from CommerceTools payment object for with method as creditcard', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: PaymentMethod.applepay, - }, - custom: { - type: { - typeId: 'type', - id: 'sctm_payment', - }, - fields: { - sctm_create_payment_request: JSON.stringify(customFieldObject), - }, - }, - }; - const extensionUrl = 'https://example.com/webhook'; + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: 'creditcard', + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; - const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - expect(mollieCreatePaymentParams).toEqual({ - method: PaymentMethod.applepay, - amount: { - currency: 'EUR', - value: '10.00', - }, - locale: customFieldObject.locale, - redirectUrl: customFieldObject.redirectUrl, - webhookUrl: extensionUrl, - description: customFieldObject.description, - applePayPaymentToken: JSON.stringify(customFieldObject.applePayPaymentToken), - lines: [], - }); - }); + // const mollieCreatePaymentParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + // const mollieAmount = makeMollieAmount(CTPayment.amountPlanned); - it('should able to create a mollie payment params from CommerceTools payment object with method as paypal', async () => { - const customFieldObject = { - description: 'Test payment', - locale: 'en_GB', - redirectUrl: 'https://example.com/success', - webhookUrl: 'https://example.com/webhook', - sessionId: '12345', - digitalGoods: true, - }; + // expect(mollieCreatePaymentParams).toEqual({ + // method: CTPayment.paymentMethodInfo.method, + // amount: { + // currency: mollieAmount.currency, + // value: mollieAmount.value, + // }, + // webhookUrl: extensionUrl, + // lines: [], + // }); + // }); - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: PaymentMethod.paypal, - }, - custom: { - type: { - typeId: 'type', - id: 'sctm_payment', - }, - fields: { - sctm_create_payment_request: JSON.stringify(customFieldObject), - }, - }, - }; - const extensionUrl = 'https://example.com/webhook'; + // it('should able to create a mollie payment params from CommerceTools payment object for with method as creditcard and surcharge amount is not 0', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; - const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - expect(mollieCreatePaymentParams).toEqual({ - method: PaymentMethod.paypal, - amount: { - currency: 'EUR', - value: '10.00', - }, - locale: customFieldObject.locale, - redirectUrl: customFieldObject.redirectUrl, - webhookUrl: extensionUrl, - description: customFieldObject.description, - sessionId: customFieldObject.sessionId, - digitalGoods: customFieldObject.digitalGoods, - lines: [], - }); - }); + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: 'creditcard', + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; - it('should able to create a mollie payment params from CommerceTools payment object with method as giftcard', async () => { - const customFieldObject = { - description: 'Test payment', - locale: 'en_GB', - redirectUrl: 'https://example.com/success', - webhookUrl: 'https://example.com/webhook', - voucherNumber: '12345', - voucherPin: '9999', - }; + // const surchargeAmountInCent = 1000; - const CTPayment: Payment = { - id: '5c8b0375-305a-4f19-ae8e-07806b101999', - version: 1, - createdAt: '2024-07-04T14:07:35.625Z', - lastModifiedAt: '2024-07-04T14:07:35.625Z', - amountPlanned: { - type: 'centPrecision', - currencyCode: 'EUR', - centAmount: 1000, - fractionDigits: 2, - }, - paymentStatus: {}, - transactions: [], - interfaceInteractions: [], - paymentMethodInfo: { - method: PaymentMethod.giftcard, - }, - custom: { - type: { - typeId: 'type', - id: 'sctm_payment', - }, - fields: { - sctm_create_payment_request: JSON.stringify(customFieldObject), - }, - }, - }; - const extensionUrl = 'https://example.com/webhook'; + // const mollieCreatePaymentParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, surchargeAmountInCent, cart); + // const mollieAmount = { + // currency: CTPayment.amountPlanned.currencyCode, + // value: '20.00', + // }; - const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); - expect(mollieCreatePaymentParams).toEqual({ - method: PaymentMethod.giftcard, - amount: { - currency: 'EUR', - value: '10.00', + // expect(mollieCreatePaymentParams).toEqual({ + // method: CTPayment.paymentMethodInfo.method, + // amount: mollieAmount, + // webhookUrl: extensionUrl, + // lines: [ + // { + // description: MOLLIE_SURCHARGE_LINE_DESCRIPTION, + // quantity: 1, + // quantityUnit: 'pcs', + // unitPrice: { + // currency: CTPayment.amountPlanned.currencyCode, + // value: '10.00', + // }, + // totalAmount: { + // currency: CTPayment.amountPlanned.currencyCode, + // value: '10.00', + // }, + // }, + // ], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object with method as creditcard which has custom field', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // webhookUrl: 'https://example.com/webhook', + // cardToken: 'card_token_12345', + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: 'creditcard', + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; + + // const mollieCreatePaymentParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + + // expect(mollieCreatePaymentParams).toEqual({ + // method: 'creditcard', + // amount: { + // currency: 'EUR', + // value: '10.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: extensionUrl, // Always use our default webhook endpoint + // description: customFieldObject.description, + // cardToken: customFieldObject.cardToken, + // lines: [], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object with method as ideal', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // include: { + // 'details.qrCode': { + // width: 100, + // height: 100, + // src: 'qr_code_url', + // }, + // }, + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: PaymentMethod.ideal + ',ideal_TEST', + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; + + // const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + // expect(mollieCreatePaymentParams).toEqual({ + // method: PaymentMethod.ideal, + // amount: { + // currency: 'EUR', + // value: '10.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: extensionUrl, + // description: customFieldObject.description, + // issuer: 'ideal_TEST', + // include: customFieldObject.include, + // lines: [], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object with method as bancontact', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // webhookUrl: 'https://example.com/webhook', + // include: { + // 'details.qrCode': { + // width: 100, + // height: 100, + // src: 'qr_code_url', + // }, + // }, + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: PaymentMethod.bancontact, + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; + + // const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + // expect(mollieCreatePaymentParams).toEqual({ + // method: PaymentMethod.bancontact, + // amount: { + // currency: 'EUR', + // value: '10.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: extensionUrl, + // description: customFieldObject.description, + // include: customFieldObject.include, + // lines: [], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object with method as banktransfer', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // webhookUrl: 'https://example.com/webhook', + // billingAddress: { + // email: 'test@mollie.com', + // }, + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: PaymentMethod.banktransfer, + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; + + // const dueDate = '2024-01-01'; + // (calculateDueDate as jest.Mock).mockReturnValueOnce(dueDate); + + // const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + + // expect(mollieCreatePaymentParams).toEqual({ + // method: PaymentMethod.banktransfer, + // amount: { + // currency: 'EUR', + // value: '10.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: extensionUrl, + // description: customFieldObject.description, + // billingAddress: customFieldObject.billingAddress, + // dueDate, + // lines: [], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object with method as przelewy24', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // webhookUrl: 'https://example.com/webhook', + // billingEmail: 'test@mollie.com', + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: PaymentMethod.przelewy24, + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; + + // const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + // expect(mollieCreatePaymentParams).toEqual({ + // method: PaymentMethod.przelewy24, + // amount: { + // currency: 'EUR', + // value: '10.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: extensionUrl, + // description: customFieldObject.description, + // billingEmail: customFieldObject.billingEmail, + // lines: [], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object with method as kbc', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // webhookUrl: 'https://example.com/webhook', + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: PaymentMethod.kbc, + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; + + // const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + // expect(mollieCreatePaymentParams).toEqual({ + // method: PaymentMethod.kbc, + // amount: { + // currency: 'EUR', + // value: '10.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: extensionUrl, + // description: customFieldObject.description, + // lines: [], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object with method as blik', () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // webhookUrl: 'https://example.com/webhook', + // billingEmail: 'n.tran@shopmacher.de', + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: CustomPaymentMethod.blik, + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + + // const extensionUrl = 'https://example.com/webhook'; + + // const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + // expect(mollieCreatePaymentParams).toEqual({ + // method: CustomPaymentMethod.blik, + // amount: { + // currency: 'EUR', + // value: '10.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: customFieldObject.webhookUrl, + // description: customFieldObject.description, + // billingEmail: customFieldObject.billingEmail, + // lines: [], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object with method as applepay', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // webhookUrl: 'https://example.com/webhook', + // applePayPaymentToken: '{"paymentData": {"version": "EC_v1", "data": "vK3BbrCbI/...."}}', + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: PaymentMethod.applepay, + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; + + // const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + // expect(mollieCreatePaymentParams).toEqual({ + // method: PaymentMethod.applepay, + // amount: { + // currency: 'EUR', + // value: '10.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: extensionUrl, + // description: customFieldObject.description, + // applePayPaymentToken: JSON.stringify(customFieldObject.applePayPaymentToken), + // lines: [], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object with method as paypal', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // webhookUrl: 'https://example.com/webhook', + // sessionId: '12345', + // digitalGoods: true, + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: PaymentMethod.paypal, + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; + + // const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + // expect(mollieCreatePaymentParams).toEqual({ + // method: PaymentMethod.paypal, + // amount: { + // currency: 'EUR', + // value: '10.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: extensionUrl, + // description: customFieldObject.description, + // sessionId: customFieldObject.sessionId, + // digitalGoods: customFieldObject.digitalGoods, + // lines: [], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object with method as giftcard', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // webhookUrl: 'https://example.com/webhook', + // voucherNumber: '12345', + // voucherPin: '9999', + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 1000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: PaymentMethod.giftcard, + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; + + // const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + // expect(mollieCreatePaymentParams).toEqual({ + // method: PaymentMethod.giftcard, + // amount: { + // currency: 'EUR', + // value: '10.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: extensionUrl, + // description: customFieldObject.description, + // voucherNumber: customFieldObject.voucherNumber, + // voucherPin: customFieldObject.voucherPin, + // lines: [], + // }); + // }); + + // it('should able to create a mollie payment params from CommerceTools payment object including lineItems', async () => { + // const cart = { + // id: 'cart-test-id' + // } as Cart; + + // const customFieldObject = { + // description: 'Test payment', + // locale: 'en_GB', + // redirectUrl: 'https://example.com/success', + // webhookUrl: 'https://example.com/webhook', + // lines: [ + // { + // description: 'Item 1', + // quantity: 1, + // quantityUnit: 'pcs', + // unitPrice: { currency: 'EUR', value: '10.00' }, + // totalAmount: { currency: 'EUR', value: '10.00' }, + // sku: 'TEST1', + // imageUrl: 'https://example.com/image1.jpg', + // productUrl: 'https://example.com/product1', + // }, + // { + // description: 'Item 2', + // quantity: 1, + // quantityUnit: 'pcs', + // unitPrice: { currency: 'EUR', value: '10.00' }, + // totalAmount: { currency: 'EUR', value: '10.00' }, + // sku: 'TEST2', + // imageUrl: 'https://example.com/image2.jpg', + // productUrl: 'https://example.com/product2', + // }, + // ], + // }; + + // const CTPayment: Payment = { + // id: '5c8b0375-305a-4f19-ae8e-07806b101999', + // version: 1, + // createdAt: '2024-07-04T14:07:35.625Z', + // lastModifiedAt: '2024-07-04T14:07:35.625Z', + // amountPlanned: { + // type: 'centPrecision', + // currencyCode: 'EUR', + // centAmount: 2000, + // fractionDigits: 2, + // }, + // paymentStatus: {}, + // transactions: [], + // interfaceInteractions: [], + // paymentMethodInfo: { + // method: PaymentMethod.paypal, + // }, + // custom: { + // type: { + // typeId: 'type', + // id: 'sctm_payment', + // }, + // fields: { + // sctm_create_payment_request: JSON.stringify(customFieldObject), + // }, + // }, + // }; + // const extensionUrl = 'https://example.com/webhook'; + + // const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0, cart); + // expect(mollieCreatePaymentParams).toEqual({ + // method: PaymentMethod.paypal, + // amount: { + // currency: 'EUR', + // value: '20.00', + // }, + // locale: customFieldObject.locale, + // redirectUrl: customFieldObject.redirectUrl, + // webhookUrl: extensionUrl, + // description: customFieldObject.description, + // lines: customFieldObject.lines, + // }); + // }); + + it('should able to create a mollie payment params from CommerceTools payment object including a line item for shipping amount', async () => { + const cart = { + id: 'cart-test-id', + shippingInfo: { + price: { + type: 'centPrecision', + currencyCode: 'EUR', + centAmount: 5000, + fractionDigits: 2, + }, }, - locale: customFieldObject.locale, - redirectUrl: customFieldObject.redirectUrl, - webhookUrl: extensionUrl, - description: customFieldObject.description, - voucherNumber: customFieldObject.voucherNumber, - voucherPin: customFieldObject.voucherPin, - lines: [], - }); - }); + } as Cart; - it('should able to create a mollie payment params from CommerceTools payment object including lineItems', async () => { const customFieldObject = { description: 'Test payment', locale: 'en_GB', @@ -744,6 +884,21 @@ describe('createMollieCreatePaymentParams', () => { ], }; + const mollieLines = Object.assign([], customFieldObject.lines as Array); + mollieLines.push({ + description: MOLLIE_SHIPPING_LINE_DESCRIPTION, + quantity: 1, + quantityUnit: 'pcs', + unitPrice: { + currency: 'EUR', + value: '50.00', + }, + totalAmount: { + currency: 'EUR', + value: '50.00', + }, + }); + const CTPayment: Payment = { id: '5c8b0375-305a-4f19-ae8e-07806b101999', version: 1, @@ -771,9 +926,15 @@ describe('createMollieCreatePaymentParams', () => { }, }, }; + const extensionUrl = 'https://example.com/webhook'; - const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams(CTPayment, extensionUrl, 0); + const mollieCreatePaymentParams: PaymentCreateParams = createMollieCreatePaymentParams( + CTPayment, + extensionUrl, + 0, + cart, + ); expect(mollieCreatePaymentParams).toEqual({ method: PaymentMethod.paypal, amount: { @@ -784,7 +945,7 @@ describe('createMollieCreatePaymentParams', () => { redirectUrl: customFieldObject.redirectUrl, webhookUrl: extensionUrl, description: customFieldObject.description, - lines: customFieldObject.lines, + lines: mollieLines, }); }); }); @@ -881,7 +1042,7 @@ describe('Test createCartUpdateActions', () => { }); }); -describe('Test createMollieLineForSurchargeAmount', () => { +describe('Test createMollieLineForAdditionalAmount', () => { it('should return a Mollie line for the surcharge amount', () => { const surchargeAmountInCent = 1020; const fractionDigits = 2; @@ -901,6 +1062,13 @@ describe('Test createMollieLineForSurchargeAmount', () => { }, }; - expect(createMollieLineForSurchargeAmount(surchargeAmountInCent, fractionDigits, currency)).toStrictEqual(expected); + expect( + createMollieLineForAdditionalAmount( + MOLLIE_SURCHARGE_LINE_DESCRIPTION, + surchargeAmountInCent, + fractionDigits, + currency, + ), + ).toStrictEqual(expected); }); });