在生产中,ApplePay 不会从真实卡中扣除金额,应用程序已上线,仍然像沙箱一样工作,我们应该如何进行生产?
let request = PKPaymentRequest()
request.merchantIdentifier = MerchantIdentifier
request.supportedNetworks = [PKPaymentNetwork.visa, PKPaymentNetwork.masterCard, PKPaymentNetwork.amex]
request.merchantCapabilities = PKMerchantCapability.capability3DS
request.countryCode = "SA"
request.currencyCode = "SAR"
request.paymentSummaryItems = [
PKPaymentSummaryItem(label: "Wallet", amount: NSDecimalNumber(value: amount))
]
let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request)
applePayController?.delegate = self
self.present(applePayController!, animated: true, completion: nil)
extension WalletAmountTopupVC: PKPaymentAuthorizationViewControllerDelegate {
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: (@escaping (PKPaymentAuthorizationStatus) -> Void)) {
let pkPaymentToken = payment.token
//pkPaymentToken.paymentData //base64 encoded, applepay.data
print(pkPaymentToken)
let json = try? JSONSerialization.jsonObject(with: pkPaymentToken.paymentData, options: JSONSerialization.ReadingOptions.allowFragments) as? [String:AnyObject]
print(json)
paymentStatus = .success
completion(paymentStatus)
if paymentStatus == .success {
}
//TODO: Handle error condition
completion(PKPaymentAuthorizationStatus.success)
}
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
// controller.dismiss(animated: true, completion: nil)
controller.dismiss(animated: true) {
DispatchQueue.main.async {
if self.paymentStatus == .success {
// self.completionHandler!(true)
Alerts.createAutoHideAlert(title: "", message: "Success")
} else {
// self.completionHandler!(false)
}
}
}
}
}
Apple 仅生成令牌,之后您需要将解密的令牌传递给支付处理器以生成对您的银行的信贷操作