Repository navigation
feat(POINT-3672)(dc): add payment_method_selected event - #299
Draft
jakub-binczyk-cko wants to merge 3 commits into
Draft
jakub-binczyk-cko wants to merge 3 commits into
jakub-binczyk-cko wants to merge 3 commits into
Conversation
…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.
Contributor
There was a problem hiding this comment.
🟡 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Jira: https://checkout.atlassian.net/browse/POINT-3672
Adds a new Dynamic Checkout event,
processout_dynamic_checkout_payment_method_selected, dispatched onwindowevery 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
change, or click / focus inside its form), only when the selection changedpayment_submittedand the payment / redirectSelection tracking
Each checkout instance keeps the last selection it reported (keyed by type, name and customer token), shared by all its payment methods:
changeand any click /focusininside their element while their radio is checked, but only when the selection differs from the last one reported. So:changefires) reportscardagain on the first click or focus in its form;It is not dispatched from the saved payment methods manager (delete mode).
Payload
No card data is included.
null/undefinedfields are stripped, like in the other DC events.Changes
DynamicCheckoutEventsUtils.dispatchPaymentMethodSelectedEventand the new event constant.dispatchPaymentMethodSelectedEvent(paymentConfig, paymentMethod, { onlyIfChanged })fills ininvoice_id/return_urland keeps the last selection inDynamicCheckoutPaymentConfig.lastSelectedPaymentMethodKey(runtime state, per checkout instance).PaymentMethodButton.onPaymentMethodInteractionhooks radiochangeplusclick/focusinon the method element while its radio is checked; card, APM and native APM use it withonlyIfChanged.handleButtonClickbefore opening the wallet.examples/dynamic-checkoutevents list.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
yarn test,yarn lint,yarn build.examples/dynamic-checkout/index.htmlagainst an invoice with card, a redirect APM (e.g. PayPal), a native APM, a saved card/APM and Google Pay / Apple Pay.processout_dynamic_checkout_payment_method_selectedwith the matchingpayment_method_name, once per switch, and typing in the selected form logs nothing more;card,google_pay,card;payment_method_selectedthenpayment_submitted;payment_method_selectedbefore the wallet sheet shows.