Paypal payout using Firebase Functions

Hey friends.
I have an app where there are two types of users, User A makes payments to Paypal and User B who gets paid by Paypal.
This app uses Firebase Functions.
The problem i am having is the payoutRequest - posting a url request so that i can pay User B. Below is the code i am using but it isn’t working in IOS.
I am also including the code i use for Android that does work (for those who know both IOS and Android). I tried to take the code that works and try to do the same in IOS but not working.

PayoutRequest: IOS:

let email = txtPayoutEmail.text!

    let url = "https://us-central1-ryyde-sj.cloudfunctions.net/payout"

    let params : Parameters = [
        "uid": self.uid! as String,
        "email": email
    ]
    
    let headers : HTTPHeaders = [
        "Content-Type": "application/json",
        "Authorization": "Your Token",
        "cache-control": "no-cache"
    ]

    let myData = try? JSONSerialization.data(withJSONObject: params, options: [])
    //print("data: \(String(describing: myData))")

    Alamofire.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers)
        .validate(statusCode: 200..<300)
        .validate(contentType: ["application/json"])
        .responseData(completionHandler: { (response) in

            switch response.result {
            case .success:
                let parsedObject = try! JSONSerialization.jsonObject(with: myData!, options: .allowFragments)
                NSLog("parsed: \(parsedObject)")

            case .failure(let error):
                print(error)
            }
    })

Below is the code I used for the same function, but in Android:

PayoutRequest: Android

public static final MediaType MEDIA_TYPE = MediaType.parse("application/json");
ProgressDialog progress;

private void payoutRequest() {

    progress = new ProgressDialog(this);
    progress.setTitle("Processing your payout ...");
    progress.setMessage("Please Wait .....");
    progress.setCancelable(false);
    progress.show();

    // HTTP Request ....
    final OkHttpClient client = new OkHttpClient();

    // in json - we need variables for the hardcoded uid and Email
    JSONObject postData = new JSONObject();

    try {
        postData.put("uid", FirebaseAuth.getInstance().getCurrentUser().getUid());
        postData.put("email", mPayoutEmail.getText().toString());

    } catch (JSONException e) {
        e.printStackTrace();
    }

    // Request body ...
    RequestBody body = RequestBody.create(MEDIA_TYPE, postData.toString());

    // Build Request ...
    final Request request = new Request.Builder()
            .url("https://us-central1-ryyde-sj.cloudfunctions.net/payout")
            .post(body)
            .addHeader("Content-Type", "application/json")
            .addHeader("cache-control", "no-cache")
            .addHeader("Authorization", "Your Token")
            .build();

    client.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Call call, IOException e) {
            // something went wrong right off the bat
            progress.dismiss();
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            // response successful ....
            // refers to response.status('200') or ('500')
            int responseCode = response.code();
            if (response.isSuccessful()) {
                switch(responseCode) {
                    case 200:
                        Snackbar.make(findViewById(R.id.layout),
                                "Payout Successful!", Snackbar.LENGTH_LONG)
                                .show();
                        break;

                    case 500:
                        Snackbar.make(findViewById(R.id.layout),
                                "Error: no payout available", Snackbar
                                        .LENGTH_LONG).show();
                        break;

                    default:
                        Snackbar.make(findViewById(R.id.layout),
                                "Error: couldn't complete the transaction",
                                Snackbar.LENGTH_LONG).show();
                        break;
                }

            } else {
                Snackbar.make(findViewById(R.id.layout),
                        "Error: couldn't complete the transaction",
                        Snackbar.LENGTH_LONG).show();
            }

            progress.dismiss();
        }
    });
}

Please help if you can. I have been working on this for over a year and i am stumped. This is my first time working with Firebase Functions and Paypal, not to mention url requests of any kind.

Thank you in advance :slight_smile:

~ Liz ~