Repository navigation
fix(ad-hoc): Support redirect result in nAPM tokenization flow #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrii-vysotskyi-cko
wants to merge
8
commits into
master
Choose a base branch
from
fix/napm-tokenization-customer-token-request
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9005b86
fix(ad-hoc): Extend customer token creation request
andrii-vysotskyi-cko 0865158
fix(ad-hoc): Verify customer token in native APM example
andrii-vysotskyi-cko dde0790
fix(ad-hoc): Support redirect result URL in nAPM redirect confirmation
andrii-vysotskyi-cko cbd59f4
fix(ad-hoc): Send tokenization deep link result to tokenize endpoint
andrii-vysotskyi-cko 82b4830
fix(ad-hoc): Ignore unexpected redirect results in nAPM deep link han…
andrii-vysotskyi-cko 68274fa
fix(ad-hoc): Keep binary compatibility and single return URL
andrii-vysotskyi-cko 3f602e0
fix(ad-hoc): Log ignored redirect results while waiting for next step
andrii-vysotskyi-cko 6df939c
fix(ad-hoc): Correct capture polling note for ignored redirect results
andrii-vysotskyi-cko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,70 @@ 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) { | ||
| // Redirect result is either unrelated to this payment or no longer needed, so payment continues as is. | ||
| // 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, | ||
| ValidationCode.unexpectedRedirectResult, | ||
| ValidationCode.unexpectedRedirectResultForStep | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| ) | ||
| 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) } | ||
| } | ||
|
|
||
| private fun PONativeAlternativePaymentInvoice.map() = Invoice( | ||
| id = id, | ||
| amount = amount, | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.