Apple Pay令牌包含错误的transactionAmount信息。例如,如果交易金额为$ 1.10,则在iOS设备上,Apple Pay屏幕仍显示正确的金额,但PaymentToken解密后返回110
我使用这个库通过我自己的公钥-私钥对解密Apple Pay令牌
https://github.com/sidimansourjs/applepay-token
我的示例代码
class ViewController: UIViewController {
...
@IBAction func payBtn(_ sender: UIButton) {
do {
let paymentItem = PKPaymentSummaryItem.init(label: "Test item", amount: NSDecimalNumber(value: 1.10))
let paymentNetworks = [PKPaymentNetwork.amex, .discover, .masterCard, .visa]
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) {
let request = PKPaymentRequest()
request.currencyCode = "SGD" // 1
request.countryCode = "SG" // 2
request.merchantIdentifier = "merchant.com.xxxxx" // 3
request.merchantCapabilities = PKMerchantCapability.capability3DS // 4
request.supportedNetworks = paymentNetworks // 5
request.paymentSummaryItems = [paymentItem] // 6
guard let paymentVC = PKPaymentAuthorizationViewController(paymentRequest: request) else {
displayDefaultAlert(title: "Error", message: "Unable to present Apple Pay authorization.")
return
}
paymentVC.delegate = self
self.present(paymentVC, animated: true, completion: nil)
} else {
displayDefaultAlert(title: "Error", message: "Unable to make Apple Pay transaction.")
}
} catch {
print(error.localizedDescription)
}
}
}
extension ViewController: PKPaymentAuthorizationViewControllerDelegate {
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
dismiss(animated: true, completion: nil)
}
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
let token = String(data: payment.token.paymentData, encoding: .utf8)
let utf8str = token!.data(using: .utf8)
if let base64Encoded = utf8str?.base64EncodedString()
{
print("Encoded: \(base64Encoded)")
//Send token to backend server to decrypt
}
}
}
当我尝试向Adyen(付款网关)提出付款请求时,我发现了这一点。请求必须同时包含amount
字段和paymentToken
字段,但是由于amount
和paymentToken
中的金额不匹配,因此从未成功。然后,我尝试使用amount
而不是1.10,然后请求成功了,但具有讽刺意味的是,在Adyen仪表板中,它仍然以某种方式仍认为交易金额为$ 1.10
我期望Apple Pay令牌中的transactionAmount
为1.10
请帮助解释为什么设备和令牌上显示的Apple Pay金额存在差异