fix: prefill APM fields by canonical key and parse E.164 phone numbers - #277
Draft
roshan-gorasia-cko wants to merge 1 commit into
Draft
fix: prefill APM fields by canonical key and parse E.164 phone numbers#277roshan-gorasia-cko wants to merge 1 commit into
roshan-gorasia-cko wants to merge 1 commit into
Conversation
roshan-gorasia-cko
force-pushed
the
fix/apm-initial-data-prefill
branch
2 times, most recently
from
August 6, 2026 10:47
282832c to
3cc9902
Compare
Prefilling an APM form via `initialData` had two problems. Values were matched only against the payment method's own parameter key, so the documented `initialData.phone_number` silently did nothing whenever a payment method named the field something else (for example `customerPhone`), leaving merchants to discover each one's internal parameter names. `email` and `phone_number` now also match on the parameter's type, so the canonical keys prefill on every payment method. An exact parameter-key match still wins, so a specific field can be targeted or a canonical value overridden. A phone number passed as an E.164 string was dropped into the national number input whole, with the dialing code set to the first entry in the available list. That selected the wrong country, left `+CC` inside the number box and submitted a malformed value. The string is now split on a longest-prefix match against the available dialing codes, falling back to the browser-locale default when the country isn't offered. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
roshan-gorasia-cko
force-pushed
the
fix/apm-initial-data-prefill
branch
from
August 6, 2026 10:48
3cc9902 to
89b6b96
Compare
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.
Problem
Two issues with
initialDataprefilling on the APM form.1. Prefill only matched the payment method's own parameter key.
NextStepslooked upinitialData[param.key], so the documentedinitialData.phone_numbersilently no-op'd whenever a payment method named the field something else (for examplecustomerPhone). In practice a merchant had to discover each payment method's internal parameter names to prefill anything.2. An E.164 phone string wasn't parsed. A
phone_numberpassed as"+48123123123"went into the national-number input whole, with the dialing code set to the first entry in the available list. That selected the wrong country, left+CCinside the number box, and submitted a malformed value. The+-prefix splitting logic only existed in the phone field's paste/typing handler, so it never ran for seeded state.Changes
resolvePrefilledValue(src/apm/utils.ts) resolves a parameter's prefill value: an exact parameter-key match wins, otherwise the canonical key for that parameter's type (email→ typeemail,phone_number→ typephone). Canonical keys now work on every payment method, and a specific parameter can still be targeted directly or used to override a canonical value.normalizePhoneValue(src/apm/utils.ts) coerces a prefilled phone into the{ dialing_code, value }shape the field renders. An E.164 string is split on a longest-prefix match against the available dialing codes (so+1242beats+1), separators are ignored, and the browser-locale default is used when the country isn't offered. The object form is still accepted, keyed ondialing_code, including thenumberkey the field emits on input.InitialData(src/apm/types.ts) typesphone_numberasstring | { dialing_code?, value? }and allows payment-method-specific keys.Notes
The prefilling docs present
email/phone_numberas universal keys and document the phone value as a bare E.164 string. Both are now true of the SDK; the docs should be extended to cover the object form and to note that a specific parameter key can also be passed and takes precedence.Tests
test/apm/prefill.test.ts— 15 cases covering key/type resolution precedence and E.164 splitting.yarn test,yarn buildandyarn lintall pass.