Skip to content

feat(POINT-3672)(dc): add payment_method_selected event - #299

Draft
jakub-binczyk-cko wants to merge 3 commits into
masterfrom
feat/POINT-3672/dc-payment-method-selected
Draft

jakub-binczyk-cko wants to merge 3 commits into
masterfrom
feat/POINT-3672/dc-payment-method-selected

Conversation

@jakub-binczyk-cko

@jakub-binczyk-cko jakub-binczyk-cko commented Dec 2, 2026 •

Copy link
Copy Markdown

Summary

Jira: https://checkout.atlassian.net/browse/POINT-3672

Adds a new Dynamic Checkout event, processout_dynamic_checkout_payment_method_selected, dispatched on window every time the buyer picks a payment method, before any form submission or wallet/APM popup, and again on every switch. Merchants driving their own UI from DC events can now tell which method was chosen upfront (e.g. to size a wait timer per method).

The name matches what the internal complete-test-tool already listens for.

When it fires

Payment method Trigger
Card interaction with the method while its radio is checked (radio change, or click / focus inside its form), only when the selection changed
APM (redirect and native) same as card
Saved card / saved APM every click on the saved method button, before payment_submitted and the payment / redirect
Google Pay every click on the Google Pay button, before the payment sheet opens
Apple Pay every click on the Apple Pay button, synchronously before the session is created (the sheet still opens within the user gesture)

Selection tracking

Each checkout instance keeps the last selection it reported (keyed by type, name and customer token), shared by all its payment methods:

  • Express methods (wallets, saved methods) report every click, since each click starts a payment or opens a popup.
  • Regular methods (card, APMs) report a radio change and any click / focusin inside their element while their radio is checked, but only when the selection differs from the last one reported. So:
    • switching between regular methods reports each switch;
    • coming back to the card after dismissing the Google Pay / Apple Pay sheet (the card radio stays checked, so no change fires) reports card again on the first click or focus in its form;
    • the sole regular method, pre-checked and hidden on render, is reported on the first interaction with its form;
    • further interactions with an already selected form don't re-fire it, and a label click or tabbing onto an unchecked radio doesn't fire it either.

It is not dispatched from the saved payment methods manager (delete mode).

Payload

No card data is included. null/undefined fields are stripped, like in the other DC events.

{
  payment_method_name: string          // "card", "google_pay", "apple_pay" or the APM gateway name (e.g. "paypal")
  payment_method_display_name: string  // display name from the invoice
  payment_method_type: string          // API type: "card", "card_customer_token", "apm", "apm_customer_token", "googlepay", "applepay"
  invoice_id: string
  return_url?: string
  customer_token_id?: string           // saved card / saved APM only
}

Changes

  • DynamicCheckoutEventsUtils.dispatchPaymentMethodSelectedEvent and the new event constant.
  • dispatchPaymentMethodSelectedEvent(paymentConfig, paymentMethod, { onlyIfChanged }) fills in invoice_id / return_url and keeps the last selection in DynamicCheckoutPaymentConfig.lastSelectedPaymentMethodKey (runtime state, per checkout instance).
  • PaymentMethodButton.onPaymentMethodInteraction hooks radio change plus click / focusin on the method element while its radio is checked; card, APM and native APM use it with onlyIfChanged.
  • Saved card / saved APM dispatch at the start of their click handler; the Google Pay / Apple Pay clients dispatch in a new handleButtonClick before opening the wallet.
  • Event added to the examples/dynamic-checkout events list.
  • Version bumped to 1.9.22.
  • Tests: test/dynamic-checkout/payment-method-selected.test.ts, plus a minimal fake DOM (test/support/fakeDom.ts) and a loader for the payment method components.

How to test

  1. yarn test, yarn lint, yarn build.
  2. Open examples/dynamic-checkout/index.html against an invoice with card, a redirect APM (e.g. PayPal), a native APM, a saved card/APM and Google Pay / Apple Pay.
  3. Watch the console. Each event is logged:
    • selecting card / APM radios logs processout_dynamic_checkout_payment_method_selected with the matching payment_method_name, once per switch, and typing in the selected form logs nothing more;
    • selecting the card, clicking Google Pay, dismissing the sheet and clicking the card form logs card, google_pay, card;
    • with a single regular method, the first click / focus in its form logs it once;
    • clicking a saved method logs payment_method_selected then payment_submitted;
    • clicking Google Pay / Apple Pay logs payment_method_selected before the wallet sheet shows.

…nt method selection

Fire processout_dynamic_checkout_payment_method_selected whenever the buyer picks a payment method (card, redirect/native APM, saved card, saved APM, Google Pay, Apple Pay), before any form submission or wallet/APM popup, and again on every switch.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Returning to Card after dismissing Google Pay emits no selection event, leaving merchants with a stale Google Pay selection, including when Card is the sole regular method.

1 open issue
What changed in this PR

Adds a Dynamic Checkout payment-method selection event so merchants can identify the buyer’s choice before submission or wallet launch.

Changes:

  • Defines the event and payload, with hooks for regular methods, saved methods, and wallets.
  • Adds selection-event tests and supporting test utilities.
  • Logs the new event in the checkout example.
File Description
test/​support/​loadNamespace.ts Loads payment-method components for tests.
test/​support/​fakeDom.ts Adds a minimal DOM test helper.
test/​dynamic-checkout/​payment-method-selected.test.ts Tests payloads, selection triggers, and event ordering.
src/​dynamic-checkout/​utils/​events.ts Defines the event, payload, and dispatcher.
src/​dynamic-checkout/​payment-methods/​saved-card.ts Emits selection before saved-card payment.
src/​dynamic-checkout/​payment-methods/​saved-apm.ts Emits selection before saved-APM execution.
src/​dynamic-checkout/​payment-methods/​native-apm.ts Hooks native APM radio selection.
src/​dynamic-checkout/​payment-methods/​card.ts Hooks card radio selection.
src/​dynamic-checkout/​payment-methods/​apm.ts Hooks redirect APM radio selection.
src/​dynamic-checkout/​elements/​payment-method-button.ts Adds a shared radio-change callback.
src/​dynamic-checkout/​clients/​google-pay.ts Emits selection before opening Google Pay.
src/​dynamic-checkout/​clients/​apple-pay.ts Emits selection synchronously before session creation.
examples/​dynamic-checkout/​index.html Adds the event to example logging.

Review effort: Balanced

return
}

this.radioButton.addEventListener("change", () => {
…o a checked method

Track the last reported selection per checkout instance. Express methods (wallets, saved methods) report every click; card and APMs also report a click or focus inside their form, but only when the selection changed, so coming back to the card after dismissing a wallet sheet and the sole pre-checked method are reported too.
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