@@ -195,7 +195,7 @@ const filterMethodsByPricingConstraints = (
195
195
196
196
const isCaptureFromMollie = (
197
197
manualCapture : boolean ,
198
- ctTransactions : CTTransaction [ ] ,
198
+ ctTransactions : Transaction [ ] ,
199
199
molliePayment : MPayment ,
200
200
) : DoCapturePaymentFromMollie => {
201
201
const hasSuccessAuthorizedTransaction = ctTransactions . some ( ( transaction ) => {
@@ -232,8 +232,13 @@ const isCaptureFromMollie = (
232
232
transaction . interactionId === molliePayment . id ,
233
233
) ;
234
234
235
+ const hasSurchargeCost =
236
+ pendingChargeTransaction ?. custom ?. fields ?. [ CustomFields . surchargeAndCapture . fields . surchargeCode . name ] !==
237
+ undefined ;
238
+
235
239
return {
236
240
answer,
241
+ hasSurchargeCost,
237
242
id : pendingChargeTransaction ?. id ,
238
243
} ;
239
244
} ;
@@ -333,13 +338,7 @@ export const handlePaymentWebhook = async (paymentId: string): Promise<boolean>
333
338
return false ;
334
339
}
335
340
336
- logger . debug ( 'SCTM - handlePaymentWebhook - debugging' , {
337
- mollieStatus : molliePayment . status ,
338
- ctPaymentId : ctPayment . id ,
339
- ctPaymentTransactions : JSON . stringify ( ctPayment . transactions ) ,
340
- } ) ;
341
-
342
- const action = getPaymentStatusUpdateAction ( ctPayment . transactions as CTTransaction [ ] , molliePayment ) ;
341
+ const action = getPaymentStatusUpdateAction ( ctPayment . transactions as Transaction [ ] , molliePayment ) ;
343
342
344
343
// If refunds are present, update their status
345
344
const refunds = molliePayment . _embedded ?. refunds ;
@@ -366,7 +365,7 @@ export const handlePaymentWebhook = async (paymentId: string): Promise<boolean>
366
365
} ;
367
366
368
367
export const getPaymentStatusUpdateAction = (
369
- ctTransactions : CTTransaction [ ] ,
368
+ ctTransactions : Transaction [ ] ,
370
369
molliePayment : MPayment ,
371
370
) : UpdateAction [ ] => {
372
371
const updateActions : UpdateAction [ ] = [ ] ;
@@ -444,23 +443,34 @@ export const getPaymentStatusUpdateAction = (
444
443
logger . debug (
445
444
`SCTM - getPaymentStatusUpdateAction - Capture payment triggered from Mollie paymentID: ${ molliePaymentId } ` ,
446
445
) ;
447
- updateActions . push (
448
- setTransactionCustomField (
449
- CustomFields . surchargeAndCapture . fields . shouldCapture . name ,
450
- true ,
451
- doCaptureInMollie . id as string ,
452
- ) ,
453
- setTransactionCustomField (
454
- CustomFields . surchargeAndCapture . fields . descriptionCapture . name ,
455
- 'Payment is captured from Mollie.' ,
456
- doCaptureInMollie . id as string ,
457
- ) ,
458
- setTransactionCustomField (
459
- CustomFields . surchargeAndCapture . fields . captureErrors . name ,
460
- '' ,
461
- doCaptureInMollie . id as string ,
462
- ) ,
463
- ) ;
446
+
447
+ if ( doCaptureInMollie . hasSurchargeCost ) {
448
+ updateActions . push (
449
+ setTransactionCustomField (
450
+ CustomFields . surchargeAndCapture . fields . shouldCapture . name ,
451
+ true ,
452
+ doCaptureInMollie . id as string ,
453
+ ) ,
454
+ setTransactionCustomField (
455
+ CustomFields . surchargeAndCapture . fields . descriptionCapture . name ,
456
+ 'Payment is captured from Mollie.' ,
457
+ doCaptureInMollie . id as string ,
458
+ ) ,
459
+ setTransactionCustomField (
460
+ CustomFields . surchargeAndCapture . fields . captureErrors . name ,
461
+ '' ,
462
+ doCaptureInMollie . id as string ,
463
+ ) ,
464
+ ) ;
465
+ } else {
466
+ updateActions . push (
467
+ setTransactionCustomType ( doCaptureInMollie . id as string , CustomFields . surchargeAndCapture . typeKey , {
468
+ [ CustomFields . surchargeAndCapture . fields . shouldCapture . name ] : true ,
469
+ [ CustomFields . surchargeAndCapture . fields . descriptionCapture . name ] : 'Payment is captured from Mollie.' ,
470
+ [ CustomFields . surchargeAndCapture . fields . captureErrors . name ] : '' ,
471
+ } ) ,
472
+ ) ;
473
+ }
464
474
}
465
475
466
476
return updateActions ;
0 commit comments