Skip to content

feat(apm)(POCP-1407): support buy and tokenize on APM sessions - #295

Draft
lukasz-k-bieszczad-cko wants to merge 1 commit into
masterfrom
feat/apm-sessions-buy-and-tokenize
Draft

lukasz-k-bieszczad-cko wants to merge 1 commit into
masterfrom
feat/apm-sessions-buy-and-tokenize

Conversation

@lukasz-k-bieszczad-cko

@lukasz-k-bieszczad-cko lukasz-k-bieszczad-cko commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

The api is moving APM payments to a new backend flow, APM sessions, behind the routes src/apm already calls (POST /invoices/{id}/apm-payment, POST /customers/{cid}/apm-tokens/{tok}/tokenize). The goal is web parity for client.apm.authorization and client.apm.tokenization: every offering the mobile SDKs get on sessions also works from processout.js.

Buy and tokenize was missing: src/apm sent no save_source and 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

  • New authorization-only options on client.apm.authorization: saveSource?: boolean and clientSecret?: string. client.apm.tokenization can't take them (?: never).
  • save_source: true is sent only on the first apm-payment POST, and resent if that POST is retried after a network error. Polling, form submits and the post-redirect POST never send it.
  • The invoice client secret goes as x-processout-client-secret on every authorization-flow request, through the existing apiRequest option. isLegacy keeps its default, so routing doesn't change. Without clientSecret, the calls are the same as today.
  • There is no client-side check when saveSource is set without clientSecret: the api decides.
  • The created token (customer_token.id in the response) reaches the merchant as customerTokenId on the success event, for all 3 triggers. The key is left out when there is no token.
  • The first API-level tests for src/apm (test/apm/api.test.ts), with a loader that evaluates the real Context, Storage, API and Success sources.
  • The migration guide documents the options. examples/apm gets 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/apm because of a tessel9 proto pin mismatch. The automatic redirect flow worked against the local api.

Checklist

  • I bumped the version of the project using yarn bump-version
  • I have checked the code for any potential issues
  • I tested my changes in the browser

Notes

  • The api creates a token only when the invoice has a customer. With a customer-token source (pay with token), the api ignores save_source (module/apmsessions/internal/routing/routing.go).
  • customerTokenId is set only for payments that run on APM sessions. The older module/apm path ignores save_source.
  • Depends on api work in the same release: the client secret check for save_source on apm-payment.
  • X-ProcessOut-JS-Version is already sent on every src/apm call in published builds.

Jira Issue

POCP-1407

🤖 Generated with Claude Code

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>

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.

🔵 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 saveSource and clientSecret options.
  • 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

@lukasz-k-bieszczad-cko lukasz-k-bieszczad-cko changed the title feat(apm): support buy and tokenize on APM sessions feat(apm)(POCP-1407): support buy and tokenize on APM sessions Dec 3, 2026
@lukasz-k-bieszczad-cko
lukasz-k-bieszczad-cko requested a balanced review from Copilot December 3, 2026 14:45

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.

🟢 Approval recommended

No active review issues are blocking approval.

No open issues 🎉

Review effort: Balanced

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