diff --git a/application/src/components/method-details/method-details.tsx b/application/src/components/method-details/method-details.tsx index bdb7bfe..2eb2adc 100644 --- a/application/src/components/method-details/method-details.tsx +++ b/application/src/components/method-details/method-details.tsx @@ -145,20 +145,9 @@ const MethodDetails = (props: TMethodDetailsProps) => { dataLocale={dataLocale} > {(formProps) => { - const methodName = formatLocalizedString( - { - name: formProps.values?.name, - }, - { - key: 'name', - locale: dataLocale, - fallbackOrder: projectLanguages, - fallback: NO_VALUE_FALLBACK, - } - ); return ( props.onClose()} tabControls={ @@ -235,7 +224,11 @@ const MethodDetails = (props: TMethodDetailsProps) => { )} - {method && } + {method && ( + + )} {method === null && } diff --git a/application/src/components/welcome/welcome.tsx b/application/src/components/welcome/welcome.tsx index d27cc16..bb00482 100644 --- a/application/src/components/welcome/welcome.tsx +++ b/application/src/components/welcome/welcome.tsx @@ -179,19 +179,7 @@ const Welcome = () => { ); case 'name': - return item.name - ? formatLocalizedString( - { - name: item.name, - }, - { - key: 'name', - locale: dataLocale, - fallbackOrder: projectLanguages, - fallback: NO_VALUE_FALLBACK, - } - ) - : item.description; + return item.technicalName; case 'image': return ( ({ id: method.id, + technicalName: method.description, name: projectLanguages.reduce((acc, lang) => { acc[lang] = method.description; return acc; diff --git a/application/src/types/app.ts b/application/src/types/app.ts index a2cb326..83d7cf1 100644 --- a/application/src/types/app.ts +++ b/application/src/types/app.ts @@ -30,6 +30,7 @@ export type MollieMethod = { export type CustomMethodObject = { id: string; + technicalName: string; name: Record; description?: Record; imageUrl: string; diff --git a/processor/src/service/payment.service.ts b/processor/src/service/payment.service.ts index ccfb7d6..d01e2ed 100644 --- a/processor/src/service/payment.service.ts +++ b/processor/src/service/payment.service.ts @@ -157,13 +157,6 @@ const getBillingCountry = (ctPayment: Payment): string | undefined => { return requestField ? JSON.parse(requestField).billingCountry : undefined; }; -const removeCreditCardMethod = (methods: CustomMethod[]) => { - const index = methods.findIndex((method) => method.id === PaymentMethod.creditcard); - if (index !== -1) { - methods.splice(index, 1); - } -}; - const filterMethodsByPricingConstraints = ( methods: CustomMethod[], configObjects: CustomObject[], @@ -207,16 +200,19 @@ export const handleListPaymentMethodsByPayment = async (ctPayment: Payment): Pro const billingCountry = getBillingCountry(ctPayment); + if (!billingCountry) { + logger.error(`SCTM - listPaymentMethodsByPayment - billingCountry is not provided.`, { + commerceToolsPaymentId: ctPayment.id, + }); + throw new CustomError(400, 'billingCountry is not provided.'); + } + const customMethods = methods.map(mapMollieMethodToCustomMethod); const validatedMethods = validateAndSortMethods(customMethods, configObjects); const enableCardComponent = shouldEnableCardComponent(validatedMethods); - if (enableCardComponent) { - removeCreditCardMethod(validatedMethods); - } - if (billingCountry) { filterMethodsByPricingConstraints(validatedMethods, configObjects, ctPayment, billingCountry); } diff --git a/processor/tests/service/payment.service.spec.ts b/processor/tests/service/payment.service.spec.ts index 8de0ec2..7ff8185 100644 --- a/processor/tests/service/payment.service.spec.ts +++ b/processor/tests/service/payment.service.spec.ts @@ -293,11 +293,6 @@ describe('Test listPaymentMethodsByPayment', () => { }, ]); - (getCartFromPayment as jest.Mock).mockReturnValueOnce({ - id: 'cart-id', - country: 'DE', - } as Cart); - mockResource = { id: 'RANDOMID_12345', paymentMethodInfo: { @@ -314,6 +309,7 @@ describe('Test listPaymentMethodsByPayment', () => { fields: { sctm_payment_methods_request: JSON.stringify({ locale: 'de_DE', + billingCountry: 'DE', }), }, } as unknown as CustomFields, @@ -326,19 +322,8 @@ describe('Test listPaymentMethodsByPayment', () => { expect(response?.actions?.[0]?.action).toBe('setCustomField'); expect((response?.actions?.[1] as any)?.value).toBe( JSON.stringify({ - count: 3, + count: 2, methods: [ - { - id: 'paypal', - name: { - 'en-GB': 'PayPal', - }, - description: { - 'en-GB': '', - }, - image: 'https://www.mollie.com/external/icons/payment-methods/applepay.svg', - order: 0, - }, { id: 'bancontact', name: { @@ -468,11 +453,6 @@ describe('Test listPaymentMethodsByPayment', () => { }, ]); - (getCartFromPayment as jest.Mock).mockReturnValueOnce({ - id: 'cart-id', - country: 'DE', - } as Cart); - mockResource = { typeId: 'payment', paymentMethodInfo: { @@ -485,6 +465,14 @@ describe('Test listPaymentMethodsByPayment', () => { centAmount: 1000, fractionDigits: 2, }, + custom: { + fields: { + sctm_payment_methods_request: JSON.stringify({ + locale: 'de_DE', + billingCountry: 'DE', + }), + }, + } as unknown as CustomFields, } as unknown as Payment; const response: ControllerResponseType = await handleListPaymentMethodsByPayment(mockResource); @@ -512,6 +500,7 @@ describe('Test listPaymentMethodsByPayment', () => { fields: { sctm_payment_methods_request: JSON.stringify({ locale: 'de_DE', + billingCountry: 'DE', }), }, } as unknown as CustomFields, @@ -526,6 +515,37 @@ describe('Test listPaymentMethodsByPayment', () => { expect(JSON.stringify(response)).not.toContain('count'); }); + test('call listPaymentMethodsByPayment with billingCountry', async () => { + mockResource = { + id: 'RANDOMID_12345', + paymentMethodInfo: { + paymentInterface: 'mollie', + method: 'card', + }, + amountPlanned: { + type: 'centPrecision', + currencyCode: 'VND', + centAmount: 1000, + fractionDigits: 2, + }, + custom: { + fields: { + sctm_payment_methods_request: JSON.stringify({ + locale: 'de_DE', + }), + }, + } as unknown as CustomFields, + } as unknown as Payment; + + try { + await handleListPaymentMethodsByPayment(mockResource); + } catch (error: unknown) { + expect(error).toBeInstanceOf(CustomError); + expect((error as CustomError).message).toBe('billingCountry is not provided.'); + expect((error as CustomError).statusCode).toBe(400); + } + }); + test('call listPaymentMethodsByPayment with cardComponent deactivated', async () => { (listPaymentMethods as jest.Mock).mockReturnValueOnce([ { @@ -688,6 +708,7 @@ describe('Test listPaymentMethodsByPayment', () => { fields: { sctm_payment_methods_request: JSON.stringify({ locale: 'de_DE', + billingCountry: 'DE', }), }, } as unknown as CustomFields, @@ -868,6 +889,7 @@ describe('Test listPaymentMethodsByPayment', () => { fields: { sctm_payment_methods_request: JSON.stringify({ locale: 'de_DE', + billingCountry: 'DE', }), }, } as unknown as CustomFields, @@ -885,7 +907,7 @@ describe('Test listPaymentMethodsByPayment', () => { name: 'sctm_mollie_profile_id', value: process.env.MOLLIE_PROFILE_ID, }); - expect(JSON.stringify(response)).not.toContain('creditcard'); + expect(JSON.stringify(response)).toContain('creditcard'); }); });