flutter-plugin icon indicating copy to clipboard operation
flutter-plugin copied to clipboard

[pay_ios] Add more logging to `paymentFailed` error.

Open asaarnak opened this issue 2 years ago • 8 comments

We are not able to reproduce or understand why some users get this error. PlatformException(paymentFailed, Failed to complete the payment, null, null) What may be the reasons?

asaarnak avatar Jan 16 '23 10:01 asaarnak

Have you inspected the error included in the onError callback?

JlUgia avatar Jan 24 '23 13:01 JlUgia

We are using showPaymentSelector directly there is no onError callback parameter.

await payClient.showPaymentSelector(
    provider: pay.PayProvider.apple_pay,
    paymentItems: paymentItems,
  );

We think the exception comes from here. It says payment failed, but we can't understand why. It fails only for very small number of users. https://github.com/google-pay/flutter-plugin/blob/e2069bf10a7418856bd22d15e03bbeac8e44ae1d/pay_ios/ios/Classes/PaymentHandler.swift#L205

asaarnak avatar Jan 24 '23 13:01 asaarnak

Correct, this error occurs when the payment fails during the payment authorization stage. Can you confirm that the card you are using can complete a payment? Can you verify other cards? If the issue is confirmed we can confirm the error to be more explicit about the authorization attempt.

JlUgia avatar Jan 24 '23 13:01 JlUgia

Unfortunately we haven't been able to reproduce this ourself. We only see it in crashlytics for a few users.

asaarnak avatar Jan 24 '23 13:01 asaarnak

This error surfaces when the following happens:

  1. The payment selector is presented
  2. An authorization of the payment was attempted.
  3. The payment intent finished without receiving an authorization.

In other words, this seems like a payment attempt that failed during authorization. A fraction of your payments should be expected not to authorize successfully. That said, the error code could be updated to be more useful. Something like authorizationFailed, or paymentAuthorizationFailed.

Do you think that's consistent with your data?

JlUgia avatar Jan 30 '23 09:01 JlUgia

authorizationFailed seems better. If we could get error code why the authorization failed it would be even better. It would allow us to understand the reason why authorization failed and we could give user hints how to fix the authorization failed error on their phone.

asaarnak avatar Jan 30 '23 11:01 asaarnak

The Apple Pay library does not seem to return any error or additional information at runtime (it simply does not call didAuthorizePayment). Some Apple Pay docs and SO comments allude to a window of 30s for the payment to be confirmed before timing out on its own.

Are you able to gather additional telemetry when the error shows up to confirm the above?

JlUgia avatar Jan 30 '23 12:01 JlUgia

I tried multiple times and ways to get the timeout but i couldn't reproduce it. For one user it happened on iOS 16.0.0 with iPhone 13 Pro Max. It's very rare exception, this has happened only once for this one user.

asaarnak avatar Jan 31 '23 13:01 asaarnak

Feel free to reopen this issue if you have additional information on the issue.

JlUgia avatar May 09 '24 12:05 JlUgia