简体   繁体   中英

PKPaymentAuthorizationViewController not calling delegate

I've set up a PKPaymentAuthorizationViewController with a valid PKPaymentRequest, logged in an account from the Sandbox with a valid test card and shipping address . I've changed the region to USA, but nothing changed. The app has all the valid certificates and entitilements.

func getApplePayController(request: PKPaymentRequest) -> PKPaymentAuthorizationViewController? {
            guard let vc = PKPaymentAuthorizationViewController(paymentRequest: request) else {
                return nil
            }

            //Set ourselves as delegate to get callbacks on the transaction status
            vc.delegate = self

            //we keep a weak reference to the controller to be able to dismiss it if necessary
            self.applePayViewController = vc//This is weak

            return vc
        }

And to present:

//Show Apple Pay screen with configured PKPaymentRequest object
        guard let vc = getApplePayController(request: paymentRequest) else {
            dLog("Error instantiating Apple Pay screen")
            handleEventType(.status(.failed))
            return
        }

        assert(delegate != nil)
        assert(applePay.didAuthorize == false)
        assert(vc.delegate != nil)

        //disable swipe to dismiss
        if #available(iOS 13.0, *) {
            vc.isModalInPresentation = true
        }

        if var topController = UIApplication.shared.keyWindow?.rootViewController {
            while let presentedViewController = topController.presentedViewController {
                topController = presentedViewController
            }

            // topController should now be your topmost view controller
            topController.present(vc, animated: true, completion: nil)
        }

The screen shows up, if I click on cancel everything freezes. If I click on the background the screen gets automatically dismissed, but the rest of the view is not interactive (PKPaymentAuthorizationViewController is not dismissed, but its ui is hidden). If I click on Pay it asks for the pin and it's stuck processing. No delegate is called in either case.

My implementation:

public func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
print("Dismiss")
}

public func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
                                 didAuthorizePayment payment: PKPayment,
                                                  completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
           completion(.success)
           return;
}

@available(iOS 11.0, *)
        public func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
                                 didAuthorizePayment payment: PKPayment,
                                                     handler: @escaping (PKPaymentAuthorizationResult) -> Void) {
            handler(PKPaymentAuthorizationResult(status: .success, errors: nil))
           return;
}

Not one of the three methods is ever called, no matter what I do. I've checked and the delegate is set up correctly.

Any idea?

I now implemented also PKPaymentAuthorizationControllerDelegate even though I' not using it and it works...

    public func paymentAuthorizationControllerDidFinish(_ controller: PKPaymentAuthorizationController) {
    return
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM