Skip to content

feat: add apm additional data to dc#244

Open
jakubjasinsky wants to merge 2 commits intomasterfrom
apm-additional-data
Open

feat: add apm additional data to dc#244
jakubjasinsky wants to merge 2 commits intomasterfrom
apm-additional-data

Conversation

@jakubjasinsky
Copy link
Collaborator

Summary

Add support for passing additionalData through the Dynamic Checkout widget to APM redirect URLs. This enables use cases like preselecting an issuing bank for iDEAL on Adyen. Also extracts and reuses the additional data query-building logic from processout.ts, and fixes encodeURIencodeURIComponent for proper URL encoding.

Changes

Config (payment-config.ts)

  • Add additionalData?: Record<string, string> to DynamicCheckoutPublicConfigType
  • Add corresponding field to DynamicCheckoutPaymentConfig class (defaults to {})
  • Include additionalData in getConfig() return and setInitialConfig()

Core (processout.ts)

  • Extract buildAdditionalDataQuery() — converts an object into ?additional_data[key]=value&... query string
  • Add appendAdditionalDataToUrl() — appends additional data to an existing URL, handling ? vs & separator
  • Fix encodeURIencodeURIComponent for proper encoding of special characters in keys and values
  • Deduplicate query-building logic in getConfigurableInvoiceActionURL and getCustomerTokenActionURL

APM payment methods

  • apm.ts: Append additionalData to apm.redirect_url before calling handleAction (non-save-for-future flow only)
  • saved-apm.ts: Append additionalData to apm_customer_token.redirect_url before calling handleAction

Example

  • Add additionalData usage to examples/dynamic-checkout/index.html

Impact

  • New optional config field — no breaking changes for existing consumers
  • encodeURIComponent fix affects all callers of buildAdditionalDataQuery (invoice action URLs and customer token action URLs) — values with special characters (&, =, #) are now properly encoded
  • APM redirect URLs in Dynamic Checkout will now include additional data query params when provided

Testing Plan

  1. Initialize Dynamic Checkout without additionalData — verify APM redirect URLs are unchanged
  2. Initialize with additionalData: { issuer_id: "1234" } — verify the redirect URL includes additional_data[issuer_id]=1234
  3. Test with special characters in values (e.g., { key: "a&b=c" }) — verify proper encoding
  4. Test save-for-future APM flow — verify data.customer_action.value URL is not modified
  5. Test saved APM token flow with redirect_url — verify additional data is appended

Additional Context

  • additionalData is only appended to pre-known redirect URLs (apm.redirect_url, apm_customer_token.redirect_url), not to URLs returned from API responses (data.customer_action.value)
  • The buildAdditionalDataQuery function was extracted from inline duplicated code in getConfigurableInvoiceActionURL and getCustomerTokenActionURL

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.

1 participant