Repository navigation
feat(apm)(POCP-1407): support buy and tokenize on APM sessions - #295
Draft
lukasz-k-bieszczad-cko wants to merge 1 commit into
Draft
lukasz-k-bieszczad-cko wants to merge 1 commit into
lukasz-k-bieszczad-cko wants to merge 1 commit into
Conversation
Add the authorization-only options `saveSource` and `clientSecret` to `client.apm.authorization`. - `save_source: true` is sent only on the first `apm-payment` POST, and resent if that POST is retried after a network error. - The invoice client secret is sent as `x-processout-client-secret` on every authorization-flow request; `isLegacy` is unchanged. - The created customer token (`customer_token.id`) is passed to the merchant as `customerTokenId` on the `success` event, on all triggers. Adds the first API-level tests for `src/apm` and documents the options in the migration guide. The example page gets a client secret field and a working "Buy & Tokenize" flow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Browser testing against the coordinated APM-sessions backend is still needed to verify whether customer_token is repeated on final SUCCESS after polling or redirects.
No open issues 🎉
What changed in this PR
Adds buy-and-tokenize support to APM authorization sessions, allowing merchants to save a payment method during payment and receive its token ID on success.
Changes:
- Adds authorization-only
saveSourceandclientSecretoptions. - Includes returned customer token IDs in all three success-event triggers.
- Adds API tests and updates the example and migration guide.
| File | Description |
|---|---|
test/support/loadNamespace.ts |
Adds an APM source loader for tests. |
test/apm/api.test.ts |
Tests request options, retries, and success payloads. |
src/apm/views/Success.ts |
Includes token IDs in user- and timeout-triggered success events. |
src/apm/events/APMEventListener.ts |
Types the optional success-event token ID. |
src/apm/Context.ts |
Defines authorization-only save and secret options. |
src/apm/API.ts |
Sends save instructions and credentials; propagates token metadata. |
examples/apm/index.html |
Implements buy-and-tokenize configuration and secret input. |
docs/migration-guide-native-apm-to-apm.md |
Documents options, prerequisites, and token delivery. |
Review effort: Balanced
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.
Description
The api is moving APM payments to a new backend flow, APM sessions, behind the routes
src/apmalready calls (POST /invoices/{id}/apm-payment,POST /customers/{cid}/apm-tokens/{tok}/tokenize). The goal is web parity forclient.apm.authorizationandclient.apm.tokenization: every offering the mobile SDKs get on sessions also works from processout.js.Buy and tokenize was missing:
src/apmsent nosave_sourceand no client secret, so the merchant could not save the payment method on the first payment.This is the first PR of a stack. The next one handles the manual finalization states.
Solution
client.apm.authorization:saveSource?: booleanandclientSecret?: string.client.apm.tokenizationcan't take them (?: never).save_source: trueis sent only on the firstapm-paymentPOST, and resent if that POST is retried after a network error. Polling, form submits and the post-redirect POST never send it.x-processout-client-secreton every authorization-flow request, through the existingapiRequestoption.isLegacykeeps its default, so routing doesn't change. WithoutclientSecret, the calls are the same as today.saveSourceis set withoutclientSecret: the api decides.customer_token.idin the response) reaches the merchant ascustomerTokenIdon thesuccessevent, for all 3 triggers. The key is left out when there is no token.src/apm(test/apm/api.test.ts), with a loader that evaluates the realContext,Storage,APIandSuccesssources.examples/apmgets a client secret field and a real "Buy & Tokenize" flow (it was sending pay with token before).Demo
Not tested end to end yet. Local runs against localstack found that the api branch then in use routed payments to
module/apmbecause of a tessel9 proto pin mismatch. The automatic redirect flow worked against the local api.Checklist
yarn bump-versionNotes
source(pay with token), the api ignoressave_source(module/apmsessions/internal/routing/routing.go).customerTokenIdis set only for payments that run on APM sessions. The oldermodule/apmpath ignoressave_source.save_sourceonapm-payment.X-ProcessOut-JS-Versionis already sent on everysrc/apmcall in published builds.Jira Issue
POCP-1407
🤖 Generated with Claude Code