ApplePay PKPaymentAuthorizationViewController always shows processing

℡╲_俬逩灬. 提交于 2019-12-24 05:18:06

问题


I am trying to use Apple Pay in my app. It works fine to present PKPaymentAuthorizationViewController. However, after I filled up with credit card and billing information, it just shows a spinning wheel and 'processing' as shown in the picture.

The code for presenting Apple Pay view controller is as follows:

let request = Stripe.paymentRequestWithMerchantIdentifier(DH_APPLEPAY_ID)
request.paymentSummaryItems = [PKPaymentSummaryItem(label: label, amount: amountDecimal)]

request.requiredBillingAddressFields = PKAddressField.All
request.requiredShippingAddressFields = PKAddressField.PostalAddress | PKAddressField.Email
request.countryCode = "US"
request.currencyCode = "USD"
request.merchantCapabilities = PKMerchantCapability.CapabilityEMV | PKMerchantCapability.Capability3DS
request.supportedNetworks = [PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa]

if Stripe.canSubmitPaymentRequest(request) {

    let paymentController = PKPaymentAuthorizationViewController(paymentRequest: request)

    paymentController.delegate = self

    self.navigationController?.presentViewController(paymentController, animated: true, completion: nil)
} else {
    //popup
    DHUtils.alert("Apple Pay", message: "Please add your credit card to Passbook.", inViewController: self)
}

The func paymentAuthorizationViewController(controller: PKPaymentAuthorizationViewController!, didAuthorizePayment payment: PKPayment!, completion: ((PKPaymentAuthorizationStatus) -> Void)!) delegate never get called.

The certificate status looks all right. What do I miss here to make it work?


回答1:


There should be a completion block that you need to call. It should be in the delegate method didAuthorizePayment on the PKPaymentAuthorizationViewController, you need to use this completion block and pass the success or failure message to it. It should look somewhat like this

extension BuySwagViewController: PKPaymentAuthorizationViewControllerDelegate {
  func paymentAuthorizationViewController(controller: PKPaymentAuthorizationViewController!, didAuthorizePayment payment: PKPayment!, completion: ((PKPaymentAuthorizationStatus) -> Void)!) {
    completion(PKPaymentAuthorizationStatus.Success)
  }

  func paymentAuthorizationViewControllerDidFinish(controller: PKPaymentAuthorizationViewController!) {
    controller.dismissViewControllerAnimated(true, completion: nil)
  }
}

Here in completion block you should pass PKPaymentAuthorizationStatus.Success or PKPaymentAuthorizationStatus.Failure depending on whether you were able to process the payment.

Also, you can refer the Ray Wenderlich tutorial here. http://www.raywenderlich.com/87300/apple-pay-tutorial




回答2:


My issue was having this delegate method:

func paymentAuthorizationViewController(controller: PKPaymentAuthorizationViewController, didSelectPaymentMethod paymentMethod: PKPaymentMethod, completion: ([PKPaymentSummaryItem]) -> Void) {

}

Remove it and it should stop the endless spinning.



来源:https://stackoverflow.com/questions/28239635/applepay-pkpaymentauthorizationviewcontroller-always-shows-processing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!