Paypal mobile SDKs are deprecated, people suggested to use braintree. I'm creating a demo iOS app. This the error message i'm getting from server side: "The currency of this PayPal transaction must match the currency of the merchant account". The currency code i'm passing is PHP. Paypal automatically converts some currencies and PHP is not one of them. Is there any additional setup i need to do for this currency conversion?
Here is the code on client side:
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()
}
}
This is the code on server side:
$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);