Repository navigation
fix(ad-hoc): Support redirect result in nAPM tokenization flow - #406
andrii-vysotskyi-cko wants to merge 8 commits into
Conversation
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>
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>
There was a problem hiding this comment.
🟡 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
| when (val flow = configuration.flow) { | ||
| is Authorization -> handleAuthorizationDeepLink(uri) | ||
| is Tokenization -> handleTokenizationDeepLink(flow, uri) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>

Description
In
Flow.Tokenization, the return URL from a web redirect was resolved viaPOST /apm-payments, which only supports invoice payments. Tokenization return URLs carry noinvoice_id/processout_token, so the flow failed withresource.invoice.not-found(e.g. Revolut Pay, PayPal REST).Solution
handleDeepLinkbranches on the flow: authorization keeps/apm-payments, tokenization postsredirect: { success: true, result: { url } }to/tokenize, matching iOS.PONativeAlternativePaymentRedirectConfirmationgets an internalresult.url(@ProcessOutInternalApi, like iOS@_spi(PO)).redirect-result-unexpectedandredirect-result-unexpected-for-step(newValidationCodes), matching iOS.return_url,invoice_id,manual_invoice_cancellationand sends device data; the example creates the token withverify: trueand the deep link return URL.