我正在尝试在我的应用中使用Apple Pay。它可以很好地呈现PKPaymentAuthorizationViewController。但是,在我填写了信用卡和结算信息之后,它只显示了一个旋转轮和“处理”信息。如图所示。
Apple Pay视图控制器的呈现代码如下:
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)
}
func paymentAuthorizationViewController(controller: PKPaymentAuthorizationViewController!, didAuthorizePayment payment: PKPayment!, completion: ((PKPaymentAuthorizationStatus) -> Void)!)
委托永远不会被调用。
证书状态看起来很好。我在这里想念什么才能让它发挥作用?
答案 0 :(得分:7)
应该有一个需要调用的完成块。它应该在PKPaymentAuthorizationViewController上的委托方法 didAuthorizePayment 中,您需要使用此完成块并将成功或失败消息传递给它。它应该看起来像这样
console.log(JSON.parse(xmlHttp.responseText));
在完成块中,您应该传递PKPaymentAuthorizationStatus.Success或 PKPaymentAuthorizationStatus.Failure取决于您是否能够处理付款。
另外,您可以在这里参考Ray Wenderlich教程。 http://www.raywenderlich.com/87300/apple-pay-tutorial
答案 1 :(得分:4)
我的问题是有这种委托方法:
func paymentAuthorizationViewController(controller: PKPaymentAuthorizationViewController, didSelectPaymentMethod paymentMethod: PKPaymentMethod, completion: ([PKPaymentSummaryItem]) -> Void) {
}
取下它,它应该停止无休止的旋转。