@@ -12,8 +12,10 @@ import {
12
12
checkValidRefundTransactionForCreate ,
13
13
checkValidRefundTransactionForCancel ,
14
14
checkValidSuccessAuthorizationTransaction ,
15
+ validateBanktransfer ,
16
+ paymentMethodRequiredExtraParameters ,
15
17
} 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' ;
17
19
import CustomError from '../../src/errors/custom.error' ;
18
20
import SkipError from '../../src/errors/skip.error' ;
19
21
import { logger } from '../../src/utils/logger.utils' ;
@@ -281,6 +283,62 @@ describe('checkPaymentMethodInput', () => {
281
283
282
284
expect ( checkPaymentMethodSpecificParameters ) . toBeCalledTimes ( 1 ) ;
283
285
} ) ;
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
+ } ) ;
284
342
} ) ;
285
343
286
344
describe ( 'checkPaymentMethodSpecificParameters' , ( ) => {
@@ -1354,3 +1412,30 @@ describe('validateCommerceToolsPaymentPayload', () => {
1354
1412
expect ( checkValidSuccessAuthorizationTransaction ) . toReturnWith ( true ) ;
1355
1413
} ) ;
1356
1414
} ) ;
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