Initiating a firebase-function with PayPal

只谈情不闲聊 提交于 2019-12-20 05:58:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!