来自paypal沙箱的消息:“此PayPal交易的货币必须与商户账户的货币匹配”
Posted
技术标签:
【中文标题】来自paypal沙箱的消息:“此PayPal交易的货币必须与商户账户的货币匹配”【英文标题】:Message from paypal sandbox: "The currency of this PayPal transaction must match the currency of the merchant account" 【发布时间】:2021-02-24 03:33:14 【问题描述】:Paypal 移动 SDK 已弃用,人们建议使用 Braintree。我正在创建一个演示 ios 应用程序。 这是我从服务器端收到的错误消息:“此 PayPal 交易的货币必须与商家帐户的货币匹配”。 我传递的货币代码是 php。 Paypal 会自动转换一些货币,而 PHP 不是其中之一。 对于这种货币转换,我需要做任何额外的设置吗?
这是客户端的代码:
class ViewController: UIViewController
var btClient: BTAPIClient?
var dataCollector: BTDataCollector?
override func viewDidLoad()
super.viewDidLoad()
self.btClient = BTAPIClient(authorization: tokenizationKey)
self.dataCollector = BTDataCollector(apiClient: btClient!)
@IBAction func buttonTouchUpInside(_ sender: Any)
startCheckout()
@objc func startCheckout()
let payPalDriver = BTPayPalDriver(apiClient: self.btClient!)
payPalDriver.viewControllerPresentingDelegate = self
payPalDriver.appSwitchDelegate = self
let payPalRequest = BTPayPalRequest(amount: "1000.00")
payPalRequest.currencyCode = "PHP"
payPalRequest.lineItems = [.init(quantity: "1", unitAmount: "1000", name: "Item name", kind: .debit)]
payPalRequest.isShippingAddressEditable = true
payPalRequest.isShippingAddressRequired = true
//Shipping address
let postalAddress = BTPostalAddress()
postalAddress.streetAddress = "1234 Main St."
postalAddress.countryCodeAlpha2 = "PH"
postalAddress.extendedAddress = "Unit 1"
postalAddress.locality = "Chicago"
postalAddress.postalCode = "60652"
postalAddress.recipientName = "Jhon doe"
postalAddress.region = "IL"
payPalRequest.shippingAddressOverride = postalAddress
payPalDriver.requestOneTimePayment(payPalRequest) (tokenizedPayPalAccount, error) -> Void in
if let tokenizedPayPalAccount = tokenizedPayPalAccount
print("nonce: \(tokenizedPayPalAccount.nonce)")
self.dataCollector?.collectDeviceData() deviceData in
self.sendRequestPaymentToServer(nonce: tokenizedPayPalAccount.nonce, amount: "1000.00", deviceData: deviceData)
else if let error = error
print(error.localizedDescription)
else
print("cancelled")
func sendRequestPaymentToServer(nonce: String, amount: String, deviceData: String)
print("payment_method_nonce=\(nonce)&amount=\(amount)&deviceData=\(deviceData)")
let paymentURL = URL(string: "http://localhost/newServer/pay.php")!
var request = URLRequest(url: paymentURL)
request.httpBody = "payment_method_nonce=\(nonce)&amount=\(amount)&deviceData=\(deviceData)".data(using: String.Encoding.utf8)
request.httpMethod = "POST"
URLSession.shared.dataTask(with: request) [weak self] (data, response, error) -> Void in
guard let data = data else
print(error!.localizedDescription)
return
print(String(decoding: data, as: UTF8.self))
guard let result = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let success = result["success"] as? Bool, success == true else
print("Transaction failed. Please try again.")
return
print("Successfully charged. Thanks So Much :)")
.resume()
这是服务器端的代码:
$paymentMethodNonce = $_POST['payment_method_nonce'];
$amount = $_POST['amount'];
$deviceData = $_POST['deviceData'];
$result = $gateway->transaction()->sale([
'amount' => $amount,
'paymentMethodNonce' => $paymentMethodNonce,
'options' => [
'submitForSettlement' => true
],
'deviceData' => $deviceData
]);
echo json_encode($result);
【问题讨论】:
【参考方案1】:self.btClient = BTAPIClient(authorization: tokenizationKey)
令牌化密钥只能用于完整的 Braintree 网关集成。这种集成需要在网关沙箱和您用于处理的后续生产帐户上设置新货币 PHP。如果您想在生产中使用 Braintree 网关,您的企业需要为此申请并获得批准。
所以基本上,如果您要通过上述集成方法使用新货币,则需要在网关界面中设置 PHP。
要更直接地将 Braintree SDK 与 PayPal 一起使用(无网关帐户),您首先需要用于身份验证的凭据是访问令牌。使用您服务器上的访问令牌获取客户端令牌,您的客户端将根据需要获取该令牌:https://developers.braintreepayments.com/guides/authorization/client-token
沙盒 PayPal Braintree 访问令牌可以从底部获取:https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Fapplication(对于直播模式,通过https://www.paypal.com/api)
【讨论】:
以上是关于来自paypal沙箱的消息:“此PayPal交易的货币必须与商户账户的货币匹配”的主要内容,如果未能解决你的问题,请参考以下文章