0

As always, thanks in advance. You're all awesome, just for reading this.

I use Parse as my backend, and am using Stripe as my payment API. Parse has some stripe integration, but not the full API, so to access parts of the API that aren't built in to Parse, you have to use http requests.

I'm adding coupon functionality to my app, and therefore, sometimes will need to generate a transfer directly to my Stripe managed accounts, since the customer may have paid less than the recipient needs to receive. here is the cURL code, found in Stripe's API documentation, that I need to convert to an http request:

    curl https://api.stripe.com/v1/transfers \
   -u [secret api key]: \
   -d amount=400 \
   -d destination=[account id] 

"Transfer to test@example.com"

Here is the Parse.Cloud.httpRequest I am using in my code:

Parse.Cloud.httpRequest
(
    {
        method:"POST",
        url: "https://" + STRIPE_SECRET_KEY + ':@' + STRIPE_API_BASE_URL + "/transfers?amount=" + amountOwedProvider.toString() + "&destination=" + recipient_id
    }
);

STRIPE_API_BASE_URL is 'api.stripe.com/v1'

amountOwedProvider is the number, in cents, that I still need to send the provider

recipient_id is a properly formatted stripe recipient id. I also use it when generating the initial charges.

When I make this request, the following error appears in my Stripe log:

"Unrecognized request URL (POST: /v1/transfers)

I have tried using both transfer and transfers, even though the documentation calls for transfers. I have also tried using transfers/?amount... rather than transfers?amount, but received the same error.

Any tips on how to properly create this http request? I'd really appreciate any guidance.

Thanks, Jake

Jake T.
  • 4,308
  • 2
  • 20
  • 48

1 Answers1

0

I'm an idiot. I started from the cURL request found here: https://stripe.com/docs/connect/special-case-transfers

You may notice that it does not have the currency parameter found in the actual code from the api documentation link I posted in my question. Turns out, it's a required parameter. I figured since it wasn't in this link, which I found first, that it was an optional parameter, and that if it wasn't specified, the default currency would be used. WRONG. i just had to add currency=usd into my request url. My final request looks like this:

Parse.Cloud.httpRequest
(
    {
        method:"POST",
        url: "https://" + STRIPE_SECRET_KEY + ':@' + STRIPE_API_BASE_URL + "/transfers?currency=usd&amount=" + amountOwedProvider.toString() + "&destination=" + recipient_id
    }
);
Jake T.
  • 4,308
  • 2
  • 20
  • 48