Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOL-440/MOL-542 + MOL-440/MOL-545: fix name in CA changeable + card c… #88

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions application/src/components/method-details/method-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<TabularModalPage
title={methodName}
title={formProps.values.technicalName || ''}
isOpen
onClose={() => props.onClose()}
tabControls={
Expand Down Expand Up @@ -235,7 +224,11 @@ const MethodDetails = (props: TMethodDetailsProps) => {
</Text.Body>
</ContentNotification>
)}
{method && <ApplicationPageTitle additionalParts={[methodName]} />}
{method && (
<ApplicationPageTitle
additionalParts={[formProps.values.technicalName]}
/>
)}
{method === null && <PageNotFound />}
<Switch>
<Route path={`${match.path}/general`}>
Expand Down
14 changes: 1 addition & 13 deletions application/src/components/welcome/welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,7 @@ const Welcome = () => {
<CheckInactiveIcon color="neutral60"></CheckInactiveIcon>
);
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 (
<IconButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const convertMollieMethodToCustomMethod = (
);
return availableMethods.map((method: MollieMethod) => ({
id: method.id,
technicalName: method.description,
name: projectLanguages.reduce((acc, lang) => {
acc[lang] = method.description;
return acc;
Expand Down
1 change: 1 addition & 0 deletions application/src/types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type MollieMethod = {

export type CustomMethodObject = {
id: string;
technicalName: string;
name: Record<string, string>;
description?: Record<string, string>;
imageUrl: string;
Expand Down
18 changes: 7 additions & 11 deletions processor/src/service/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down Expand Up @@ -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);
}
Expand Down
68 changes: 45 additions & 23 deletions processor/tests/service/payment.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,6 @@ describe('Test listPaymentMethodsByPayment', () => {
},
]);

(getCartFromPayment as jest.Mock).mockReturnValueOnce({
id: 'cart-id',
country: 'DE',
} as Cart);

mockResource = {
id: 'RANDOMID_12345',
paymentMethodInfo: {
Expand All @@ -314,6 +309,7 @@ describe('Test listPaymentMethodsByPayment', () => {
fields: {
sctm_payment_methods_request: JSON.stringify({
locale: 'de_DE',
billingCountry: 'DE',
}),
},
} as unknown as CustomFields,
Expand All @@ -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: {
Expand Down Expand Up @@ -468,11 +453,6 @@ describe('Test listPaymentMethodsByPayment', () => {
},
]);

(getCartFromPayment as jest.Mock).mockReturnValueOnce({
id: 'cart-id',
country: 'DE',
} as Cart);

mockResource = {
typeId: 'payment',
paymentMethodInfo: {
Expand All @@ -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);
Expand Down Expand Up @@ -512,6 +500,7 @@ describe('Test listPaymentMethodsByPayment', () => {
fields: {
sctm_payment_methods_request: JSON.stringify({
locale: 'de_DE',
billingCountry: 'DE',
}),
},
} as unknown as CustomFields,
Expand All @@ -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([
{
Expand Down Expand Up @@ -688,6 +708,7 @@ describe('Test listPaymentMethodsByPayment', () => {
fields: {
sctm_payment_methods_request: JSON.stringify({
locale: 'de_DE',
billingCountry: 'DE',
}),
},
} as unknown as CustomFields,
Expand Down Expand Up @@ -868,6 +889,7 @@ describe('Test listPaymentMethodsByPayment', () => {
fields: {
sctm_payment_methods_request: JSON.stringify({
locale: 'de_DE',
billingCountry: 'DE',
}),
},
} as unknown as CustomFields,
Expand All @@ -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');
});
});

Expand Down