triniwiz / nativescript-plugins

Apache License 2.0
80 stars 50 forks source link

[nativescript-stripe] SCA shows a blank page when confirming an intent #112

Open sebj54 opened 2 years ago

sebj54 commented 2 years ago

Hi there,

I have an issue with iOS and SCA with the Stripe plugin. I have tested it with latest 7 and 8 versions and the same problem occurs. I'm using latest NativeScript-Vue (+ {N} 8.2).

When confirming a setup intent or a payment intent with a 3DS2 test card (for instance: 4000002760003184), the SCA page is blank.

I opened Safari DevTools to check the page URL and it is about:blank. I added a breakpoint in the Stripe pod's code and the URL is correct in the SDK when SFSafariViewController is presented.

There is no error, just a warning:

[Presentation] Presenting view controller <SFSafariViewController: 0x108875000> from detached view controller <UIViewControllerImpl: 0x119791260> is discouraged.

Do you have any idea I can try to debug this?

If you think it can help, I can produce a sample project (which I don't have yet).

sebj54 commented 2 years ago

The problem seems to be caused by SFSafariViewController called in the background. Therefore, iOS prevent page loading to avoid apps tracking users with background webviews (see https://blog.rizwan.dev/blog/blank_safari_viewcontroller).

If I understand correctly, UIViewControllerImpl is considered background?

It seems I have to do something like this to return the rootViewController:

extension PaymentGatewayController: STPAuthenticationContext {
    func authenticationPresentingViewController() -> UIViewController {
          return self
      }
}

(code from https://github.com/OBaller/NQB8Task/blob/c4e11c9b3a2eafe84aeb8865938c4d2c21a429b5/NQB8/PaymentGatewayController.swift)

The problem is I don't know how to do it with NativeScript :/

EDIT

It turns out the plugin already does this part: https://github.com/triniwiz/nativescript-plugins/blob/12f13aeb7361cb9c28554bcb90974587e5527084/packages/nativescript-stripe/index.ios.ts#L351-L366

sebj54 commented 2 years ago

I finally find a fix (at least in my case)!

Replace this line: https://github.com/triniwiz/nativescript-plugins/blob/12f13aeb7361cb9c28554bcb90974587e5527084/packages/nativescript-stripe/index.ios.ts#L339

by

const rootVC = UIApplication.sharedApplication.keyWindow.rootViewController;

I would be happy to make a PR for this fix, but I think we should discuss it before to avoid breaking other users' apps. What do you think @triniwiz?