Search code examples
curloauthparse-cloud-codestripe-connectstripe.net

How to Connect Standalone Stripe account to platform after user authorizes access


When connecting a Stand alone account to a platform in Stripe Connect, there is one more small step to be taken after the user authorizes access. Stripe offeres this code example:

 curl https://connect.stripe.com/oauth/token \
    -d client_secret=sk_test_xxxxxxxxxxxxxxxx \
    -d code=AUTHORIZATION_CODE \
    -d grant_type=authorization_code

However, my application runs on Cloud Code, and I would like to make the request from a cloud code function on my parse-server. How can I do this?


Solution

  • Here is the solution. Hope it helps someone, as it took me a while to get the syntax right from a Cloud Code Function perspective.

     Parse.Cloud.define("postRequest", function(request, response){
    
    
    
     Parse.Cloud.httpRequest({
         method: 'POST',
         url: 'https://connect.stripe.com/oauth/token',
         headers: {
           'Authorization': 'Bearer sk_test_xxxxxxxxxxxxx'
         },
         body: {
        'code': request.params.code, //the authorization code passed back through the redirect_uri after user authorizes platform
        'grant_type': 'authorization_code',
        'client_secret': 'sk_test_xxxxxxxxxxxxx'
         },
       }).then(function(httpResponse) {
         console.log(httpResponse);
         response.success(httpResponse.text);
       }, function(err) {
         console.log(err);
         response.error(err);
       });
    
    
    
    
    });