From 9005b8638619ffb726b609a709eef71974309c3e Mon Sep 17 00:00:00 2001 From: Andrii Vysotskyi Date: Fri, 27 Nov 2026 13:59:54 +0100 Subject: [PATCH 1/8] fix(ad-hoc): Extend customer token creation request 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 --- .../request/POCreateCustomerTokenRequest.kt | 30 +++++++++++++++++-- .../sdk/api/network/CustomerTokensApi.kt | 4 +-- .../DefaultCustomerTokensRepository.kt | 17 ++++++++++- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/sdk/src/main/kotlin/com/processout/sdk/api/model/request/POCreateCustomerTokenRequest.kt b/sdk/src/main/kotlin/com/processout/sdk/api/model/request/POCreateCustomerTokenRequest.kt index 827128559..3337f2e90 100644 --- a/sdk/src/main/kotlin/com/processout/sdk/api/model/request/POCreateCustomerTokenRequest.kt +++ b/sdk/src/main/kotlin/com/processout/sdk/api/model/request/POCreateCustomerTokenRequest.kt @@ -11,11 +11,35 @@ data class POCreateCustomerTokenRequest( val body: POCreateCustomerTokenRequestBody ) -/** @suppress */ +/** + * @suppress + * + * @param verify Whether to verify the customer token. Required when [invoiceId] or [manualInvoiceCancellation] is set. + * @param returnUrl For APMs, the URL to return to the app after the customer completes the redirect. + * @param invoiceReturnUrl The URL set on the invoice created for verification. + * @param invoiceId Invoice to associate with the token (buy and tokenize). + * @param manualInvoiceCancellation Whether you cancel the associated invoice yourself. + */ @ProcessOutInternalApi -@JsonClass(generateAdapter = true) data class POCreateCustomerTokenRequestBody( val verify: Boolean = false, + val returnUrl: String? = null, + val invoiceReturnUrl: String? = null, + val invoiceId: String? = null, + val manualInvoiceCancellation: Boolean? = null +) + +@JsonClass(generateAdapter = true) +internal data class CreateCustomerTokenRequestWithDeviceData( + val verify: Boolean, + @Json(name = "return_url") + val returnUrl: String?, @Json(name = "invoice_return_url") - val returnUrl: String? = null + val invoiceReturnUrl: String?, + @Json(name = "invoice_id") + val invoiceId: String?, + @Json(name = "manual_invoice_cancellation") + val manualInvoiceCancellation: Boolean?, + @Json(name = "device") + val deviceData: DeviceData ) diff --git a/sdk/src/main/kotlin/com/processout/sdk/api/network/CustomerTokensApi.kt b/sdk/src/main/kotlin/com/processout/sdk/api/network/CustomerTokensApi.kt index 058683caa..a07ce8510 100644 --- a/sdk/src/main/kotlin/com/processout/sdk/api/network/CustomerTokensApi.kt +++ b/sdk/src/main/kotlin/com/processout/sdk/api/network/CustomerTokensApi.kt @@ -1,8 +1,8 @@ package com.processout.sdk.api.network import com.processout.sdk.api.model.request.AssignCustomerTokenRequestWithDeviceData +import com.processout.sdk.api.model.request.CreateCustomerTokenRequestWithDeviceData import com.processout.sdk.api.model.request.POCreateCustomerRequest -import com.processout.sdk.api.model.request.POCreateCustomerTokenRequestBody import com.processout.sdk.api.model.request.napm.v2.NativeAlternativePaymentRequestBody import com.processout.sdk.api.model.response.CustomerResponse import com.processout.sdk.api.model.response.CustomerTokenResponse @@ -37,7 +37,7 @@ internal interface CustomerTokensApi { @POST("/customers/{customer_id}/tokens") suspend fun createCustomerToken( @Path("customer_id") customerId: String, - @Body request: POCreateCustomerTokenRequestBody + @Body request: CreateCustomerTokenRequestWithDeviceData ): Response @POST("/customers") diff --git a/sdk/src/main/kotlin/com/processout/sdk/api/repository/DefaultCustomerTokensRepository.kt b/sdk/src/main/kotlin/com/processout/sdk/api/repository/DefaultCustomerTokensRepository.kt index 753fbe976..7b56de203 100644 --- a/sdk/src/main/kotlin/com/processout/sdk/api/repository/DefaultCustomerTokensRepository.kt +++ b/sdk/src/main/kotlin/com/processout/sdk/api/repository/DefaultCustomerTokensRepository.kt @@ -54,7 +54,12 @@ internal class DefaultCustomerTokensRepository( } override suspend fun createCustomerToken(request: POCreateCustomerTokenRequest) = - apiCall { api.createCustomerToken(request.customerId, request.body) }.let { result -> + apiCall { + api.createCustomerToken( + customerId = request.customerId, + request = request.body.withDeviceData() + ) + }.let { result -> when (result) { is ProcessOutResult.Success -> result.value.token?.let { token -> ProcessOutResult.Success(token) @@ -66,6 +71,16 @@ internal class DefaultCustomerTokensRepository( override suspend fun createCustomer(request: POCreateCustomerRequest) = apiCall { api.createCustomer(request) }.map { it.customer } + private fun POCreateCustomerTokenRequestBody.withDeviceData() = + CreateCustomerTokenRequestWithDeviceData( + verify = verify, + returnUrl = returnUrl, + invoiceReturnUrl = invoiceReturnUrl, + invoiceId = invoiceId, + manualInvoiceCancellation = manualInvoiceCancellation, + deviceData = contextGraph.deviceData + ) + private fun POAssignCustomerTokenRequest.withDeviceData() = AssignCustomerTokenRequestWithDeviceData( source = source, From 08651582da2f26373a1c43712392d064b694ea34 Mon Sep 17 00:00:00 2001 From: Andrii Vysotskyi Date: Fri, 27 Nov 2026 14:07:55 +0100 Subject: [PATCH 2/8] fix(ad-hoc): Verify customer token in native APM example 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 --- .../example/ui/screen/nativeapm/NativeApmViewModel.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmViewModel.kt b/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmViewModel.kt index af2903fac..9fedcea19 100644 --- a/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmViewModel.kt +++ b/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmViewModel.kt @@ -98,7 +98,11 @@ class NativeApmViewModel( customerTokens.createCustomerToken( POCreateCustomerTokenRequest( customerId = customerId, - body = POCreateCustomerTokenRequestBody() + body = POCreateCustomerTokenRequestBody( + verify = true, + returnUrl = Constants.RETURN_URL_DEEP_LINK, + invoiceReturnUrl = Constants.RETURN_URL_DEEP_LINK + ) ) ).getOrNull() From dde0790f841719f4edc52181af319d23189165ad Mon Sep 17 00:00:00 2001 From: Andrii Vysotskyi Date: Fri, 27 Nov 2026 14:35:33 +0100 Subject: [PATCH 3/8] fix(ad-hoc): Support redirect result URL in nAPM redirect confirmation 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 --- ...eAlternativePaymentRedirectConfirmation.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/sdk/src/main/kotlin/com/processout/sdk/api/model/request/napm/v2/PONativeAlternativePaymentRedirectConfirmation.kt b/sdk/src/main/kotlin/com/processout/sdk/api/model/request/napm/v2/PONativeAlternativePaymentRedirectConfirmation.kt index 32084346a..c96c08e79 100644 --- a/sdk/src/main/kotlin/com/processout/sdk/api/model/request/napm/v2/PONativeAlternativePaymentRedirectConfirmation.kt +++ b/sdk/src/main/kotlin/com/processout/sdk/api/model/request/napm/v2/PONativeAlternativePaymentRedirectConfirmation.kt @@ -1,5 +1,6 @@ package com.processout.sdk.api.model.request.napm.v2 +import com.processout.sdk.core.annotation.ProcessOutInternalApi import com.squareup.moshi.JsonClass /** @@ -9,5 +10,19 @@ import com.squareup.moshi.JsonClass */ @JsonClass(generateAdapter = true) data class PONativeAlternativePaymentRedirectConfirmation( - val success: Boolean -) + val success: Boolean, + @property:ProcessOutInternalApi + val result: Result? = null +) { + + /** + * Redirect result. + * + * @param[url] Return URL that customer was redirected to. + */ + @ProcessOutInternalApi + @JsonClass(generateAdapter = true) + data class Result( + val url: String + ) +} From cbd59f40349cf7353549a6a637677a0346f8d2cd Mon Sep 17 00:00:00 2001 From: Andrii Vysotskyi Date: Fri, 27 Nov 2026 14:42:19 +0100 Subject: [PATCH 4/8] fix(ad-hoc): Send tokenization deep link result to tokenize endpoint 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 --- .../NativeAlternativePaymentInteractor.kt | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt index c73f744d4..867db3cf5 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt @@ -592,6 +592,13 @@ internal class NativeAlternativePaymentInteractor( } private fun handleDeepLink(uri: Uri) { + when (val flow = configuration.flow) { + is Authorization -> handleAuthorizationDeepLink(uri) + is Tokenization -> handleTokenizationDeepLink(flow, uri) + } + } + + private fun handleAuthorizationDeepLink(uri: Uri) { interactorScope.launch { val request = PONativeAlternativePaymentUrlResolutionRequest( redirect = PONativeAlternativePaymentUrlResolutionRequest.Redirect( @@ -615,18 +622,56 @@ internal class NativeAlternativePaymentInteractor( redirect = response.redirect ) }.onFailure { failure -> - val isInvalidRedirectResult = when (val code = failure.code) { - is Validation -> code.validationCode == ValidationCode.invalidRedirectResult - else -> false - } - if (isInvalidRedirectResult) { - return@onFailure + handleDeepLinkFailure(failure) + } + } + } + + private fun handleTokenizationDeepLink(flow: Tokenization, uri: Uri) { + interactorScope.launch { + val request = PONativeAlternativePaymentTokenizationRequest( + customerId = flow.customerId, + customerTokenId = flow.customerTokenId, + gatewayConfigurationId = flow.gatewayConfigurationId, + configuration = flow.configuration, + redirectConfirmation = PONativeAlternativePaymentRedirectConfirmation( + success = true, + result = PONativeAlternativePaymentRedirectConfirmation.Result( + url = uri.toString() + ) + ) + ) + customerTokensService.tokenize(request) + .onSuccess { response -> + if (response.state == PENDING && _state.value is Pending) { + return@onSuccess } - _completion.update { Failure(failure) } + handlePaymentState( + stateValue = initNextStepStateValue( + paymentMethod = response.paymentMethod, + invoice = null + ), + paymentState = response.state, + elements = response.elements, + redirect = response.redirect + ) + }.onFailure { failure -> + handleDeepLinkFailure(failure) } } } + private fun handleDeepLinkFailure(failure: ProcessOutResult.Failure) { + val isInvalidRedirectResult = when (val code = failure.code) { + is Validation -> code.validationCode == ValidationCode.invalidRedirectResult + else -> false + } + if (isInvalidRedirectResult) { + return + } + _completion.update { Failure(failure) } + } + private fun PONativeAlternativePaymentInvoice.map() = Invoice( id = id, amount = amount, From 82b483003cb39e789036d2bae6fb02c936964ae7 Mon Sep 17 00:00:00 2001 From: Andrii Vysotskyi Date: Fri, 27 Nov 2026 14:46:42 +0100 Subject: [PATCH 5/8] fix(ad-hoc): Ignore unexpected redirect results in nAPM deep link handling 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 --- .../kotlin/com/processout/sdk/core/POFailure.kt | 2 ++ .../ui/napm/NativeAlternativePaymentInteractor.kt | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sdk/src/main/kotlin/com/processout/sdk/core/POFailure.kt b/sdk/src/main/kotlin/com/processout/sdk/core/POFailure.kt index 0651d78f2..26fd3aca0 100644 --- a/sdk/src/main/kotlin/com/processout/sdk/core/POFailure.kt +++ b/sdk/src/main/kotlin/com/processout/sdk/core/POFailure.kt @@ -149,6 +149,8 @@ class POFailure private constructor() { invalidUrl("request.validation.invalid-url"), invalidUser("request.validation.invalid-user"), invalidRedirectResult("request.validation.redirect-result-invalid"), + unexpectedRedirectResult("request.validation.redirect-result-unexpected"), + unexpectedRedirectResultForStep("request.validation.redirect-result-unexpected-for-step"), missingCurrency("request.validation.missing-currency"), missingCustomerInput("gateway.missing-customer-input"), missingDescription("request.validation.missing-description"), diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt index 867db3cf5..009b82756 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt @@ -662,11 +662,18 @@ internal class NativeAlternativePaymentInteractor( } private fun handleDeepLinkFailure(failure: ProcessOutResult.Failure) { - val isInvalidRedirectResult = when (val code = failure.code) { - is Validation -> code.validationCode == ValidationCode.invalidRedirectResult + // Redirect result is either unrelated to this payment or no longer needed, so payment continues as is. + // When payment has advanced to another step, polling picks it up because it stops once payment + // is no longer pending. + val isIgnoredRedirectResult = when (val code = failure.code) { + is Validation -> code.validationCode in listOf( + ValidationCode.invalidRedirectResult, + ValidationCode.unexpectedRedirectResult, + ValidationCode.unexpectedRedirectResultForStep + ) else -> false } - if (isInvalidRedirectResult) { + if (isIgnoredRedirectResult) { return } _completion.update { Failure(failure) } From 68274fa19dedb405ef1524c7d133a627fd35d8e9 Mon Sep 17 00:00:00 2001 From: Andrii Vysotskyi Date: Fri, 27 Nov 2026 15:31:51 +0100 Subject: [PATCH 6/8] fix(ad-hoc): Keep binary compatibility and single return URL 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 --- .../example/ui/screen/nativeapm/NativeApmViewModel.kt | 3 +-- .../sdk/api/model/request/POCreateCustomerTokenRequest.kt | 5 ++--- .../v2/PONativeAlternativePaymentRedirectConfirmation.kt | 4 +++- .../sdk/api/repository/DefaultCustomerTokensRepository.kt | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmViewModel.kt b/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmViewModel.kt index 9fedcea19..dcfae1a7c 100644 --- a/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmViewModel.kt +++ b/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmViewModel.kt @@ -100,8 +100,7 @@ class NativeApmViewModel( customerId = customerId, body = POCreateCustomerTokenRequestBody( verify = true, - returnUrl = Constants.RETURN_URL_DEEP_LINK, - invoiceReturnUrl = Constants.RETURN_URL_DEEP_LINK + returnUrl = Constants.RETURN_URL_DEEP_LINK ) ) ).getOrNull() diff --git a/sdk/src/main/kotlin/com/processout/sdk/api/model/request/POCreateCustomerTokenRequest.kt b/sdk/src/main/kotlin/com/processout/sdk/api/model/request/POCreateCustomerTokenRequest.kt index 3337f2e90..a86e6d147 100644 --- a/sdk/src/main/kotlin/com/processout/sdk/api/model/request/POCreateCustomerTokenRequest.kt +++ b/sdk/src/main/kotlin/com/processout/sdk/api/model/request/POCreateCustomerTokenRequest.kt @@ -15,8 +15,8 @@ data class POCreateCustomerTokenRequest( * @suppress * * @param verify Whether to verify the customer token. Required when [invoiceId] or [manualInvoiceCancellation] is set. - * @param returnUrl For APMs, the URL to return to the app after the customer completes the redirect. - * @param invoiceReturnUrl The URL set on the invoice created for verification. + * @param returnUrl URL to return to the app after the customer completes the redirect. + * Also used as the return URL of the invoice created for verification. * @param invoiceId Invoice to associate with the token (buy and tokenize). * @param manualInvoiceCancellation Whether you cancel the associated invoice yourself. */ @@ -24,7 +24,6 @@ data class POCreateCustomerTokenRequest( data class POCreateCustomerTokenRequestBody( val verify: Boolean = false, val returnUrl: String? = null, - val invoiceReturnUrl: String? = null, val invoiceId: String? = null, val manualInvoiceCancellation: Boolean? = null ) diff --git a/sdk/src/main/kotlin/com/processout/sdk/api/model/request/napm/v2/PONativeAlternativePaymentRedirectConfirmation.kt b/sdk/src/main/kotlin/com/processout/sdk/api/model/request/napm/v2/PONativeAlternativePaymentRedirectConfirmation.kt index c96c08e79..947fe43e2 100644 --- a/sdk/src/main/kotlin/com/processout/sdk/api/model/request/napm/v2/PONativeAlternativePaymentRedirectConfirmation.kt +++ b/sdk/src/main/kotlin/com/processout/sdk/api/model/request/napm/v2/PONativeAlternativePaymentRedirectConfirmation.kt @@ -12,9 +12,11 @@ import com.squareup.moshi.JsonClass data class PONativeAlternativePaymentRedirectConfirmation( val success: Boolean, @property:ProcessOutInternalApi - val result: Result? = null + val result: Result? ) { + constructor(success: Boolean) : this(success = success, result = null) + /** * Redirect result. * diff --git a/sdk/src/main/kotlin/com/processout/sdk/api/repository/DefaultCustomerTokensRepository.kt b/sdk/src/main/kotlin/com/processout/sdk/api/repository/DefaultCustomerTokensRepository.kt index 7b56de203..1b3b1e6b4 100644 --- a/sdk/src/main/kotlin/com/processout/sdk/api/repository/DefaultCustomerTokensRepository.kt +++ b/sdk/src/main/kotlin/com/processout/sdk/api/repository/DefaultCustomerTokensRepository.kt @@ -75,7 +75,7 @@ internal class DefaultCustomerTokensRepository( CreateCustomerTokenRequestWithDeviceData( verify = verify, returnUrl = returnUrl, - invoiceReturnUrl = invoiceReturnUrl, + invoiceReturnUrl = returnUrl, invoiceId = invoiceId, manualInvoiceCancellation = manualInvoiceCancellation, deviceData = contextGraph.deviceData From 3f602e086bbe360b9040e8be78578f1a64c71277 Mon Sep 17 00:00:00 2001 From: Andrii Vysotskyi Date: Fri, 27 Nov 2026 15:44:04 +0100 Subject: [PATCH 7/8] fix(ad-hoc): Log ignored redirect results while waiting for next step 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 --- .../sdk/ui/napm/NativeAlternativePaymentInteractor.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt index 009b82756..45fa6c723 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt @@ -674,6 +674,13 @@ internal class NativeAlternativePaymentInteractor( else -> false } if (isIgnoredRedirectResult) { + if (_state.value is NextStep) { + // Nothing else advances the next step after the redirect, so payment may not progress. + POLogger.warn( + message = "Ignored redirect result while waiting for next step: %s", failure, + attributes = configuration.logAttributes + ) + } return } _completion.update { Failure(failure) } From 6df939caaf7015f486fe39ab5ad32adecb59fb18 Mon Sep 17 00:00:00 2001 From: Andrii Vysotskyi Date: Fri, 27 Nov 2026 15:59:06 +0100 Subject: [PATCH 8/8] fix(ad-hoc): Correct capture polling note for ignored redirect results 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 --- .../sdk/ui/napm/NativeAlternativePaymentInteractor.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt index 45fa6c723..f97d96350 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt @@ -663,8 +663,8 @@ internal class NativeAlternativePaymentInteractor( private fun handleDeepLinkFailure(failure: ProcessOutResult.Failure) { // Redirect result is either unrelated to this payment or no longer needed, so payment continues as is. - // When payment has advanced to another step, polling picks it up because it stops once payment - // is no longer pending. + // Note that capture polling only stops on success, so if payment has advanced to another step + // it is not shown until polling times out. val isIgnoredRedirectResult = when (val code = failure.code) { is Validation -> code.validationCode in listOf( ValidationCode.invalidRedirectResult,