错误:Apple支付未完成 [英] Error: Apple pay not completed
问题描述
我已经使用Passkit框架在我的iOS应用程序中实现了Apple Pay.我完全完成了这些事情设置苹果工资. 我正在使用沙盒帐户.我在电子钱包应用程序中添加了卡,这些卡是测试卡,是从此链接.我正在使用的代码:
I have implemented apple pay in my iOS application using Passkit framework. I did all of these things fully to set up apple pay. I am using sandbox account. I added cards in Wallet application and these cards are testing cards which I copied from this link. This code I am using:
print("\(((self.grandTotalLabel.text!).replacingOccurrences(of: "$", with: "")))")
let paymentNetworks = [PKPaymentNetwork.amex]
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks){
paymentRequest.supportedNetworks = paymentNetworks
paymentRequest.merchantCapabilities = .capability3DS
paymentRequest.requiredShippingAddressFields = [.all]
paymentRequest.paymentSummaryItems = self.itemToSell(shipping: 10.0)
let sameDayShipping = PKShippingMethod(label: "Same day divilery", amount: 12.99)
sameDayShipping.detail = "Same day divilery Detail"
sameDayShipping.identifier = "sameDay"
let twDaysShipping = PKShippingMethod(label: "Two days divilery", amount: 4.99)
twDaysShipping.detail = "Two days divilery Detail"
twDaysShipping.identifier = "twoDays"
let freeShipping = PKShippingMethod(label: "Free shipping divilery", amount: 0.0)
freeShipping.detail = "Free shipping divilery Detail"
freeShipping.identifier = "freeShipping"
// paymentRequest.shippingMethods = [sameDayShipping,twDaysShipping, freeShipping]
let applePayVC = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest)
applePayVC?.delegate = self
self.present(applePayVC!, animated: true) {
print("ApplePayViewcontroller")
}
}
else{
print("Please set up for apple pay")
}
func itemToSell(shipping:Float) -> [PKPaymentSummaryItem]{
print(Double("\(((self.grandTotalLabel.text!).replacingOccurrences(of: "$", with: "")))") as Any)
let dishItems = PKPaymentSummaryItem(label: "FoodKonnect", amount: NSDecimalNumber(string: "21.00"))
let discount = PKPaymentSummaryItem(label: "Discount", amount: 1.0)
let shipping = PKPaymentSummaryItem(label: "Shipping", amount: NSDecimalNumber(string: "\(shipping)"))
let totalAmount = dishItems.amount.adding(discount.amount)
let totalPrice = PKPaymentSummaryItem(label: "FoodKonnect application", amount: totalAmount)
return [dishItems, discount,shipping, totalPrice]
}
这些我正在使用的所有代表 PKPaymentAuthorizationViewControllerDelegate
:
extension CartViewController:PKPaymentAuthorizationViewControllerDelegate{
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
controller.dismiss(animated: true, completion: nil)
}
// @available(iOS 11.0, *)
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didSelectShippingContact contact: PKContact, completion: @escaping (PKPaymentAuthorizationStatus, [PKShippingMethod], [PKPaymentSummaryItem]) -> Void) {
print("\(#function)")
}
@available(iOS 11.0, *)
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didSelect shippingMethod: PKShippingMethod, handler completion: @escaping (PKPaymentRequestShippingMethodUpdate) -> Void) {
print("\(#function)")
}
@available(iOS 11.0, *)
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
print("\(#function)")
}
}
正在显示Apple pay viewcontroller,并且此屏幕显示的是正在处理的圆圈视图.
Apple pay viewcontroller is showing and this screen is showing with a processing circle view.
但是几秒钟后,我收到以下错误消息:
我无法弄清楚我到底在做什么错.
I am not able to figure what exactly I am doing wrong.
推荐答案
在PKPaymentAuthorizationViewControllerDelegate
的每个具有completion
/handler
的已实现委托函数中,必须使用适当的参数(最重要的是使用适当的状态)调用该块.
In each implemented delegate function of PKPaymentAuthorizationViewControllerDelegate
that have completion
/handler
you must call that block with the appropriate parameters and most importantly with appropriate status.
在iOS 11上(大约)15到20秒内未调用该区块,iOS终止了您所看到的错误的付款.在iOS 10上,它将使您无限期地旋转Processing
,直到调用completion
块.
On iOS 11 not calling the block within (approximately) 15-20s, the iOS is killing the Payment with the error you are seeing. On iOS 10, it will let you spin on Processing
indefinitely until the completion
blocks are called.
我遇到了同样的问题,结果是在一种极端情况下我根本没有调用handler
块.
I had the same issue and it turned out that I was not calling the handler
block at all in one of the edge cases.
这篇关于错误:Apple支付未完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!