I am trying to create a subscription plan on a stripe connect managed account. I tried the following code:
Parse.Cloud.define("createSubscription", function (request, response) {
Parse.Cloud.httpRequest({
method:"POST",
url: "https://" + "sk_test_****************" + ':@' + "api.stripe.com/v1" + "/accounts/" + 'acct_**********' + "/plans/",
headers: {
'Authorization': 'Basic ********************'
},
body: {
'amount': 2000,
'interval': 'month',
'name': 'JPGB Plan',
'currency': 'usd',
'id':'first Plan',
},
success: function(httpResponse) {
response.success(httpResponse.text);
},
error: function(httpResponse) {
response.error('Request failed with response code' + httpResponse.status);
}
});
});
But this failed with a 404 (the requested resource doesn't exist) error.
This is how I did it.
Parse.Cloud.define("createAccountPlan", function (request, response) {
Parse.Cloud.httpRequest({
method:"POST",
url: "https://" + "sk_test_****************" + ':@' + "api.stripe.com/v1/plans",
headers: {
'Stripe-Account': request.params.accountId
},
body: {
'amount': request.params.amount,
'interval': 'day',
'interval_count':request.params.intervalCount,
'name': request.params.planName,
'currency': 'usd',
'id':request.params.planId,
},
success: function(httpResponse) {
response.success(httpResponse.text);
},
error: function(httpResponse) {
response.error('Request failed with response code' + httpResponse.status);
}
});
});
What i think you should do is not to execute a direct http request to stripe REST API but to use strip node-js SDK that will do it and more for you.
In order to achieve it in parse server you need to do the following steps:
this will install stripe into your parse-server project
Then if you need additional service call to stripe you can do it in the same way.
All the services that you can run with stripe can be found in here
From the Stripe connect docs:
Authentication via the Stripe-Account header
(demo showing making a customer)
Stripe docs are a little subtle here, but this means you can use the same technique to make a subscription for a customer on a connected account. You can also use it to make the products and plans for that connected account too. and anything else you want to do on behalf of the connected customer: