Skip to content

Commit 6f45600

Browse files
NghiaDTrTung-Huynh-Shopmacher
authored andcommitted
MOL-475: Connector should verify if mailaddress for banktransfer is set, as it is mandatory
1 parent d176d0e commit 6f45600

File tree

2 files changed

+91
-4
lines changed

2 files changed

+91
-4
lines changed

processor/src/validators/payment.validators.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const validateCardToken = (cardToken: string | undefined, ctPayment: CTPayment):
3838
}
3939
};
4040

41-
const validateBanktransfer = (paymentCustomFields: any, ctPayment: CTPayment): void => {
41+
export const validateBanktransfer = (paymentCustomFields: any, ctPayment: CTPayment): void => {
4242
if (!paymentCustomFields?.billingAddress || !paymentCustomFields?.billingAddress?.email) {
4343
throwError(
4444
'validateBanktransfer',
@@ -66,8 +66,10 @@ const validateBlik = (paymentCustomFields: any, ctPayment: CTPayment): void => {
6666
}
6767
};
6868

69-
const paymentMethodRequiredExtraParameters = (method: string): method is MolliePaymentMethods | CustomPaymentMethod => {
70-
return [MolliePaymentMethods.creditcard, CustomPaymentMethod.blik].includes(
69+
export const paymentMethodRequiredExtraParameters = (
70+
method: string,
71+
): method is MolliePaymentMethods | CustomPaymentMethod => {
72+
return [MolliePaymentMethods.creditcard, CustomPaymentMethod.blik, MolliePaymentMethods.banktransfer].includes(
7173
method as MolliePaymentMethods | CustomPaymentMethod,
7274
);
7375
};

processor/tests/validators/payment.validators.spec.ts

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import {
1212
checkValidRefundTransactionForCreate,
1313
checkValidRefundTransactionForCancel,
1414
checkValidSuccessAuthorizationTransaction,
15+
validateBanktransfer,
16+
paymentMethodRequiredExtraParameters,
1517
} from './../../src/validators/payment.validators';
16-
import { describe, it, expect, jest, afterEach } from '@jest/globals';
18+
import { describe, it, expect, jest, afterEach, test } from '@jest/globals';
1719
import CustomError from '../../src/errors/custom.error';
1820
import SkipError from '../../src/errors/skip.error';
1921
import { logger } from '../../src/utils/logger.utils';
@@ -281,6 +283,62 @@ describe('checkPaymentMethodInput', () => {
281283

282284
expect(checkPaymentMethodSpecificParameters).toBeCalledTimes(1);
283285
});
286+
287+
it('should validate the billing email for banktransfer method', () => {
288+
const paymentValidators = require('../../src/validators/payment.validators');
289+
290+
jest.spyOn(paymentValidators, 'checkPaymentMethodSpecificParameters');
291+
jest.spyOn(paymentValidators, 'validateBanktransfer');
292+
293+
const CTPayment: Payment = {
294+
id: '5c8b0375-305a-4f19-ae8e-07806b101999',
295+
version: 1,
296+
createdAt: '2024-07-04T14:07:35.625Z',
297+
lastModifiedAt: '2024-07-04T14:07:35.625Z',
298+
amountPlanned: {
299+
type: 'centPrecision',
300+
currencyCode: 'EUR',
301+
centAmount: 1000,
302+
fractionDigits: 2,
303+
},
304+
paymentStatus: {},
305+
transactions: [],
306+
interfaceInteractions: [],
307+
paymentMethodInfo: {
308+
method: 'banktransfer',
309+
},
310+
custom: {
311+
type: {
312+
typeId: 'type',
313+
id: 'sctm-payment-custom-fields',
314+
},
315+
fields: {
316+
sctm_create_payment_request:
317+
'{"description":"Test","locale":"en_GB","redirectUrl":"https://www.google.com/","cardToken":"token_12345"}',
318+
},
319+
},
320+
};
321+
322+
try {
323+
checkPaymentMethodInput(ConnectorActions.CreatePayment, CTPayment);
324+
} catch (error) {
325+
expect(checkPaymentMethodSpecificParameters).toBeCalledTimes(1);
326+
expect(checkPaymentMethodSpecificParameters).toBeCalledWith(
327+
CTPayment,
328+
CTPayment.paymentMethodInfo.method as string,
329+
);
330+
331+
expect(validateBanktransfer).toBeCalledTimes(1);
332+
333+
expect(logger.error).toBeCalledTimes(1);
334+
expect(logger.error).toBeCalledWith(
335+
'SCTM - validateBanktransfer - email is required for payment method banktransfer. Please make sure you have sent it in billingAddress.email of the custom field.',
336+
{
337+
commerceToolsPayment: CTPayment,
338+
},
339+
);
340+
}
341+
});
284342
});
285343

286344
describe('checkPaymentMethodSpecificParameters', () => {
@@ -1354,3 +1412,30 @@ describe('validateCommerceToolsPaymentPayload', () => {
13541412
expect(checkValidSuccessAuthorizationTransaction).toReturnWith(true);
13551413
});
13561414
});
1415+
1416+
describe('paymentMethodRequiredExtraParameters', () => {
1417+
test.each([
1418+
{
1419+
method: 'creditcard',
1420+
result: true,
1421+
},
1422+
{
1423+
method: 'banktransfer',
1424+
result: true,
1425+
},
1426+
{
1427+
method: 'blik',
1428+
result: true,
1429+
},
1430+
{
1431+
method: 'applepay',
1432+
result: false,
1433+
},
1434+
{
1435+
method: 'ideal',
1436+
result: false,
1437+
},
1438+
])('should return $result for method $method', ({ method, result }) => {
1439+
expect(paymentMethodRequiredExtraParameters(method)).toBe(result);
1440+
});
1441+
});

0 commit comments

Comments
 (0)