braintree / braintree_ios

Braintree SDK for iOS
https://developer.paypal.com/braintree/docs/start/hello-client/ios/v5
MIT License
560 stars 294 forks source link

Callback for BTAppSwitchDelegate and BTViewControllerPresentingDelegate are never called #549

Closed xujiali08 closed 3 years ago

xujiali08 commented 3 years ago

General information

Using cocoapod SDK 4.36.1

Issue description

When using these code and delegates :


- (void)tappedCustomPayPal {
    BTPayPalDriver *payPalDriver = [[BTPayPalDriver alloc] initWithAPIClient:self.apiClient];
    payPalDriver.viewControllerPresentingDelegate = self;
    [payPalDriver authorizeAccountWithCompletion:^(BTPayPalAccountNonce * _Nullable tokenizedPayPalAccount, NSError * _Nullable error) {
        if (tokenizedPayPalAccount) {
            self.progressBlock(@"Got a nonce 💎!");
            NSLog(@"%@", [tokenizedPayPalAccount debugDescription]);
            self.completionBlock(tokenizedPayPalAccount);
        } else if (error) {
            self.progressBlock(error.localizedDescription);
        } else {
            self.progressBlock(@"Canceled 🔰");
        }
    }];
}

- (void)paymentDriver:(__unused id)driver requestsPresentationOfViewController:(UIViewController *)viewController {
    [self presentViewController:viewController animated:YES completion:nil];
}

- (void)paymentDriver:(__unused id)driver requestsDismissalOfViewController:(UIViewController *)viewController {
    [viewController dismissViewControllerAnimated:YES completion:nil];
}

Then, we get no callback: no requestsPresentationOfViewController and no requestsDismissalOfViewController

Others

I can't get callbacks even with your demo.

sestevens commented 3 years ago

Hi @xujiali08, the PayPal flow only uses BTViewControllerPresentingDelegate on iOS 10 and earlier. On iOS 11+, we use SFAuthenticationSession, which can be presented without a call to presentViewController, so calling the BTViewControllerPresentingDelegate methods isn't necessary.

On iOS 10 and earlier, SFAuthenticationSession is not available, so we use SFSafariViewController, which must be presented and dismissed by the merchant in the BTViewControllerPresentingDelegate methods.

This is a bit confusing right now, but we're planning to drop support for iOS 11 and below when we do our next major version bump of the SDK, at which point we'll remove the viewControllerPresentingDelegate property from BTPayPalDriver.

sestevens commented 3 years ago

If your app doesn't support iOS 10 or below, you don't need to implement BTViewControllerPresentingDelegate for the PayPal flow. (It may still be required for other payment methods.)

sestevens commented 3 years ago

I'm closing this issue, but let us know if you need any additional help!

xujiali08 commented 3 years ago

If your app doesn't support iOS 10 or below, you don't need to implement BTViewControllerPresentingDelegate for the PayPal flow. (It may still be required for other payment methods.)

Okay, I see, my problem now is that after the payment page dismissed, it took me two seconds to get paymentMethodNonce, during which time I couldn't find the right place to add loding to let the user know that we were waiting for the payment result.

scannillo commented 3 years ago

Hi @xujiali08 - you can conform to the BTAppSwitchDelegate protocol which receives messages when switching to the PayPal checkout flow. Please see our docs about it here.

siddarth-byte commented 2 years ago

Hi @xujiali08 - you can conform to the BTAppSwitchDelegate protocol which receives messages when switching to the PayPal checkout flow. Please see our docs about it here.

@scannillo BTAppSwitchDelegate has been removed in v5. As mentioned above, it takes a few seconds between calling requestBillingAgreement and then showing the PayPal web page. If we want to show a loader during that time, is there another alternative for BTAppSwitchDelegate now? https://github.com/braintree/braintree_ios/blob/master/V5_MIGRATION.md