我目前正在使用 PKPaymentAuthorizationViewController 并展示它以验证我的应用程序中的付款。我可以展示控制器,但收到一条错误消息,指出“应用内付款请求无效。PKPaymentRequest 必须包含类型为 'NSString' 的属性 'countryCode'”。我已经为付款请求设置了国家代码,但仍然收到此错误。如果我用来创建付款请求并显示控制器的代码,请附在下面。出于发布的目的,我已经删除了我的商家 ID。任何帮助,将不胜感激。
var applePayController = PKPaymentAuthorizationViewController()
applePayController.delegate = self
let request = PKPaymentRequest()
let supportedPaymentNetworks = [PKPaymentNetwork.visa, PKPaymentNetwork.masterCard, PKPaymentNetwork.amex, PKPaymentNetwork.discover]
let applePayMerchantID = "merchant.com.xxxxxxxxxx.XXXXXXXXXXX"
request.countryCode = "US"
request.currencyCode = "USD"
request.merchantIdentifier = applePayMerchantID
request.supportedNetworks = supportedPaymentNetworks
request.merchantCapabilities = PKMerchantCapability.capability3DS
let price = Decimal(self.creditsPrice[index])
let priceDecimal = NSDecimalNumber(decimal: price)
request.paymentSummaryItems.append(PKPaymentSummaryItem(label: "for \(self.credits[index]) Credits", amount: priceDecimal))
applePayController = PKPaymentAuthorizationViewController(paymentRequest: request)
self.paymentName = self.credits[index]
self.paymentValue = self.creditsPrice[index]
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: supportedPaymentNetworks) {
self.present(applePayController, animated: true, completion: nil)
} else {
self.displayAlert(title: "Error", message: "Please setup Apple Pay before trying to purchase credits")
}