问题
I am having a problem passing my data from my firebase-function to PayPal.
When I run the following code, the logs in firebase-functions receives it but it is not getting to PayPal:
let url = NSURL(string: "https://us-central1-ryyde-sj.cloudfunctions.net/payout")
let postParams: [String : Any] = ["uid": FIRAuth.auth()?.currentUser?.uid as Any, "email": txtPayoutEmail.text as Any]
let request = NSMutableURLRequest(url: url! as URL)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("Your Token", forHTTPHeaderField: "Authorization")
request.addValue("no-cache", forHTTPHeaderField: "cache-control")
do
{
request.httpBody = try JSONSerialization.data(withJSONObject: postParams, options: [])
print("My paramaters: \(postParams)")
}
catch
{
print("Caught an error: \(error)")
}
let task = URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error) in
if let realResponse = response as? HTTPURLResponse {
if realResponse.statusCode != 200 {
print("Not a 200 response")
} else {
let parsedObject = try! JSONSerialization.jsonObject(with: request.httpBody!, options: .allowFragments)
print("parsedObject: \(parsedObject)")
}
}
}
task.resume()
Once it is execute in my iOS app, the data is received in the logs in firebase-function but then comes back as an error after 4 hours - next day.
Any reason why PayPal is not accepting the data? Is the iOS code wrong?
来源:https://stackoverflow.com/questions/53925577/initiating-a-firebase-function-with-paypal