Skip to content

feat: add reason to payment cancelled for dc#245

Merged
jakubjasinsky merged 3 commits intomasterfrom
add-reason-to-payment-canceled
Mar 16, 2026
Merged

feat: add reason to payment cancelled for dc#245
jakubjasinsky merged 3 commits intomasterfrom
add-reason-to-payment-canceled

Conversation

@jakubjasinsky
Copy link
Collaborator

Summary

Adds a tab_closed reason to the payment cancelled event in Dynamic Checkout. When a customer closes the APM payment tab, the cancellation event now includes metadata indicating the tab was closed, allowing consumers to distinguish between different cancellation reasons.

Changes

  • src/processout/exception.ts: Extended Exception class with an optional metadata property (ExceptionMetadata interface) to carry additional context alongside error codes
  • src/processout/actionhandler.ts: Pass { reason: "tab_closed" } metadata when creating the customer.canceled exception upon payment window closure
  • src/dynamic-checkout/payment-methods/apm.ts: Read error.metadata?.reason and include tab_closed: true/false in the payment cancelled event payload
  • src/dynamic-checkout/utils/events.ts: Added optional tab_closed boolean to the PAYMENT_CANCELLED event type definition

Impact

  • Non-breaking change — metadata is optional on Exception and tab_closed is optional on the event payload
  • Downstream consumers of the PAYMENT_CANCELLED event can now react differently when the user explicitly closed the payment tab vs other cancellation scenarios

Testing Plan

  1. Open Dynamic Checkout and select an APM payment method that opens in a new tab/window
  2. Close the payment tab before completing the payment
  3. Verify the PAYMENT_CANCELLED event payload includes tab_closed: true
  4. Complete a payment flow that gets cancelled for a non-tab-close reason and verify tab_closed is false or absent
  5. Verify existing APM error handling (non-cancelled errors) still renders the error message correctly

Additional Context

  • The ExceptionMetadata interface uses an index signature ([key: string]: any) to keep it flexible for future use cases beyond reason
  • This builds on existing telemetry work in actionhandler.ts that was added to investigate payment window closure issues

@jakubjasinsky jakubjasinsky requested review from a team and mateusz-walesiak-cko and removed request for a team March 13, 2026 08:58
@jakubjasinsky jakubjasinsky merged commit 30bd527 into master Mar 16, 2026
5 checks passed
@jakubjasinsky jakubjasinsky deleted the add-reason-to-payment-canceled branch March 16, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants