Skip to content

fix(ad-hoc): Support redirect result in nAPM tokenization flow - #406

Open
andrii-vysotskyi-cko wants to merge 8 commits into
masterfrom
fix/napm-tokenization-customer-token-request
Open

andrii-vysotskyi-cko wants to merge 8 commits into
masterfrom
fix/napm-tokenization-customer-token-request

Conversation

@andrii-vysotskyi-cko

Copy link
Copy Markdown
Collaborator

Description

In Flow.Tokenization, the return URL from a web redirect was resolved via POST /apm-payments, which only supports invoice payments. Tokenization return URLs carry no invoice_id/processout_token, so the flow failed with resource.invoice.not-found (e.g. Revolut Pay, PayPal REST).

Solution

  • handleDeepLink branches on the flow: authorization keeps /apm-payments, tokenization posts redirect: { success: true, result: { url } } to /tokenize, matching iOS.
  • PONativeAlternativePaymentRedirectConfirmation gets an internal result.url (@ProcessOutInternalApi, like iOS @_spi(PO)).
  • Deep link handling also ignores redirect-result-unexpected and redirect-result-unexpected-for-step (new ValidationCodes), matching iOS.
  • Customer token creation request supports return_url, invoice_id, manual_invoice_cancellation and sends device data; the example creates the token with verify: true and the deep link return URL.

andrii-vysotskyi-cko and others added 5 commits November 27, 2026 13:59
Add return_url, invoice_id and manual_invoice_cancellation to the create
customer token request and attach device data, matching iOS. The existing
returnUrl field is now sent as return_url; invoice_return_url moves to the
new invoiceReturnUrl field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Create the customer token with verify enabled and the deep link return
URL so the native APM tokenization flow can be tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add an internal `result.url` to the redirect confirmation so the return URL
can be sent along with `success`, matching iOS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deep links were always resolved via `/apm-payments`, which only supports
invoice payments, so tokenization flows failed with invoice not found after
a web redirect. Tokenization now posts the full return URL as the redirect
result to `/tokenize`; authorization keeps resolving via `/apm-payments`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dling

Add `redirect-result-unexpected` and `redirect-result-unexpected-for-step`
validation codes and ignore them alongside `redirect-result-invalid` when
handling deep links, matching iOS. The payment continues and polling picks
up the latest state instead of failing the flow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andrii-vysotskyi-cko
andrii-vysotskyi-cko marked this pull request as draft November 27, 2026 14:19
andrii-vysotskyi-cko and others added 2 commits November 27, 2026 15:31
Restore the `(Boolean)` constructor of `PONativeAlternativePaymentRedirectConfirmation`
so code compiled against previous versions keeps working, and send the customer
token `returnUrl` as both `return_url` and `invoice_return_url`, matching iOS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Report a warning to telemetry when a redirect result error is ignored while
the native alternative payment is in the next step state, since nothing else
advances the payment there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The WebView fallback fails to deliver its return URI to tokenization, while ignored redirect-step errors can leave required follow-up steps undisplayed until polling times out.

2 open issues
What changed in this PR

This PR routes native alternative payment tokenization redirects to /tokenize instead of the invoice-only /apm-payments endpoint, while preserving authorization routing.

Changes:

  • Adds flow-specific redirect handling and recognition of additional redirect validation errors.
  • Extends token creation with verification options, return URLs, invoice settings, and device data.
  • Updates the example to request token verification with a deep-link return URL.
File Description
ui/​src/​main/​kotlin/​com/​processout/​sdk/​ui/​napm/​NativeAlternativePaymentInteractor.kt Routes redirects by flow and centralizes redirect failure handling.
sdk/​src/​main/​kotlin/​com/​processout/​sdk/​core/​POFailure.kt Adds two redirect validation codes.
sdk/​src/​main/​kotlin/​com/​processout/​sdk/​api/​repository/​DefaultCustomerTokensRepository.kt Adds device data and maps token creation fields.
sdk/​src/​main/​kotlin/​com/​processout/​sdk/​api/​network/​CustomerTokensApi.kt Uses the device-enriched token creation body.
sdk/​src/​main/​kotlin/​com/​processout/​sdk/​api/​model/​request/​POCreateCustomerTokenRequest.kt Extends token creation options and defines the network payload.
sdk/​src/​main/​kotlin/​com/​processout/​sdk/​api/​model/​request/​napm/​v2/​PONativeAlternativePaymentRedirectConfirmation.kt Adds an internal redirect result URL.
example/​src/​main/​kotlin/​com/​processout/​example/​ui/​screen/​nativeapm/​NativeApmViewModel.kt Enables verification and supplies the deep-link return URL.

Review effort: Balanced

Comment on lines +595 to +597
when (val flow = configuration.flow) {
is Authorization -> handleAuthorizationDeepLink(uri)
is Tokenization -> handleTokenizationDeepLink(flow, uri)

@andrii-vysotskyi-cko andrii-vysotskyi-cko Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid. This gap already exists on master for both the authorization and tokenization flows: the WebView fallback returns the URI only via the activity result, which the interactor ignores on success. It touches the launcher and WebView result plumbing, so it will be addressed in a separate PR.

is Validation -> code.validationCode in listOf(
ValidationCode.invalidRedirectResult,
ValidationCode.unexpectedRedirectResult,
ValidationCode.unexpectedRedirectResultForStep

@andrii-vysotskyi-cko andrii-vysotskyi-cko Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid. The capture poller only stops on SUCCESS, which predates this PR, so a payment that advanced to another step isn't shown until polling times out. The misleading comment is corrected in this PR; the poller and next-step handling will be fixed in a separate PR.

Capture polling only stops on success, so a payment that advanced to another
step is not shown until polling times out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andrii-vysotskyi-cko
andrii-vysotskyi-cko marked this pull request as ready for review November 27, 2026 15:00
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