Skip to content
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

STPPaymentHandler.shared().handleNextAction can return status == .failed but no handleActionError #1769

Closed
mvarie opened this issue Mar 3, 2021 · 4 comments
Assignees
Labels
triaged Issue has been reviewed by Stripe and is being tracked internally

Comments

@mvarie
Copy link

mvarie commented Mar 3, 2021

Summary

Sometimes, when using STPPaymentHandler.shared().handleNextAction with test card 4000 0000 0000 3063 which requires 3DS, the completion block is called with a seemingly inconsistent set of parameters:

  • status == .failed
  • paymentIntent == populated and seemingly normal
  • handleActionError == nil

It is unclear at this stage why the status is .failed, as no error object is offered.

Code to reproduce

I have been unable to identify a situation where this can be consistently reproduced.

My best guess is that cases that return an empty error handleActionError == nil, but a seemingly valid and populated paymentIntent, and a .failurestatus, pass by this line:

completion(status, resultPaymentIntent, error)

.. but it's kind of a wild guess.

iOS version

14.4 , on physical device (iPhone 8)

Installation method

Swift Package Manager

SDK version

21.3.1

Other information

I wish I had more information to offer - I'll keep on monitoring these calls and see if I can find out more.

@csabol-stripe csabol-stripe added the triaged Issue has been reviewed by Stripe and is being tracked internally label Mar 4, 2021
@csabol-stripe csabol-stripe self-assigned this Mar 4, 2021
@csabol-stripe
Copy link
Contributor

@mvarie thanks for the report, I'll see if I can find anything that looks suspicious here. If you manage to reproduce, could you look at the status of the returned PaymentIntent?

@mvarie
Copy link
Author

mvarie commented Mar 8, 2021

@csabol-stripe the issue originates where your code checks if authenticationPresentingViewController can be presented on – in the two cases where it can't, you set canPresent = false, and then set an error message string, errorMessage = "error message...".

However, you then check if !canPresent && error != nil { .. and unfortunately error is nil; the errorMessage string never makes it to the caller and it's lost.

I was sometimes asking your sdk to present on a controller that was already presenting (my bad) but I never got the error message - that's why I was confused and trying to find a problem with the payment flow.

/// Checks if authenticationContext.authenticationPresentingViewController can be presented on.
/// @note Call this method after `prepareAuthenticationContextForPresentation:`
func _canPresent(with authenticationContext: STPAuthenticationContext, error: inout NSError?)
-> Bool
{
// Always allow in tests:
if NSClassFromString("XCTest") != nil {
return true
}
let presentingViewController = authenticationContext.authenticationPresentingViewController()
var canPresent = true
var errorMessage: String?
// Is it in the window hierarchy?
if presentingViewController.viewIfLoaded?.window == nil {
canPresent = false
errorMessage =
"authenticationPresentingViewController is not in the window hierarchy. You should probably return the top-most view controller instead."
}
// Is it already presenting something?
if presentingViewController.presentedViewController != nil {
canPresent = false
errorMessage =
"authenticationPresentingViewController is already presenting. You should probably dismiss the presented view controller in `prepareAuthenticationContextForPresentation`."
}
if !canPresent && error != nil {
error = _error(
for: .requiresAuthenticationContextErrorCode,
userInfo: errorMessage != nil
? [
STPError.errorMessageKey: errorMessage ?? ""
] : nil)
}
return canPresent
}

Thanks!

@csabol-stripe
Copy link
Contributor

Thanks for the followup @mvarie! I've got a fix that we'll include in the next release so these errors are reported

@davidme-stripe
Copy link
Contributor

This should be fixed in 21.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Issue has been reviewed by Stripe and is being tracked internally
Projects
None yet
Development

No branches or pull requests

3 participants