@@ -138,7 +138,8 @@ export const handlePaymentWebhook = async (paymentId: string): Promise<boolean>
138
138
139
139
if (
140
140
molliePayment . status === PaymentStatus . canceled &&
141
- ( ! pendingChargeTransaction || ! initialCancelAuthorizationTransaction )
141
+ ! pendingChargeTransaction &&
142
+ ! initialCancelAuthorizationTransaction
142
143
) {
143
144
logger . warn (
144
145
`SCTM - handlePaymentWebhook - Pending Charge transaction or Initial CancelAuthorization transaction is not found, CommerceTools Payment ID: ${ ctPayment . id } ` ,
@@ -424,24 +425,36 @@ export const handlePaymentCancelRefund = async (ctPayment: Payment): Promise<Con
424
425
* @param triggerTransaction
425
426
*/
426
427
export const getPaymentCancelActions = ( targetTransaction : Transaction , triggerTransaction : Transaction ) => {
427
- const transactionCustomFieldName = CustomFields . paymentCancelReason ;
428
+ const transactionCustomFieldName = CustomFields ? .paymentCancelReason ;
428
429
429
430
const newTransactionCustomFieldValue = {
430
- reasonText : triggerTransaction . custom ?. fields ?. reasonText ,
431
+ reasonText : triggerTransaction ? .custom ?. fields ?. reasonText ,
431
432
statusText : CancelStatusText ,
432
433
} ;
433
434
434
- return [
435
- // Update transaction state to failure
436
- // For cancelling payment, it will be the pendingChargeTransaction
437
- // For cancelling refund, it will be the pendingRefundTransaction
438
- changeTransactionState ( targetTransaction . id , CTTransactionState . Failure ) ,
439
- // Update transaction state to success
440
- // For both cancelling payment and cancelling refund, it will be the InitialCancelAuthorization
441
- changeTransactionState ( triggerTransaction . id , CTTransactionState . Success ) ,
442
- // Set transaction custom field value
443
- setTransactionCustomType ( targetTransaction . id , transactionCustomFieldName , newTransactionCustomFieldValue ) ,
444
- ] ;
435
+ // Update transaction state to failure
436
+ // For cancelling payment, it will be the pendingChargeTransaction
437
+ // For cancelling refund, it will be the pendingRefundTransaction
438
+ const actions : UpdateAction [ ] = [ ] ;
439
+
440
+ if ( targetTransaction ?. id ) {
441
+ actions . push ( changeTransactionState ( targetTransaction ?. id , CTTransactionState . Failure ) ) ;
442
+ }
443
+
444
+ // Update transaction state to success
445
+ // For both cancelling payment and cancelling refund, it will be the InitialCancelAuthorization
446
+ if ( triggerTransaction ?. id ) {
447
+ actions . push ( changeTransactionState ( triggerTransaction ?. id , CTTransactionState . Success ) ) ;
448
+ }
449
+
450
+ // Set transaction custom field value
451
+ if ( transactionCustomFieldName ) {
452
+ actions . push (
453
+ setTransactionCustomType ( targetTransaction ?. id , transactionCustomFieldName , newTransactionCustomFieldValue ) ,
454
+ ) ;
455
+ }
456
+
457
+ return actions ;
445
458
} ;
446
459
447
460
/**
0 commit comments