Currently, as I work on creating an app using parse.com and stripe as the payment provider for subscriptions, I am faced with a challenge. My goal is to set up a method that allows users to update their subscription plan. Following the guidelines provided in the stripe documentation, here is what my cloud code function looks like:
Parse.Cloud.define("stripeChangeSub", function(request, response) {
var currentUser = Parse.User.current();
var customer = currentUser.get('stripeCustomerId');
var subscriptionId = currentUser.get('stripeSubscriptionId');
var newPlan = request.params.plan;
var userProrate = request.params.prorate;
var stripeToken = request.params.token;
Stripe.Customers.updateSubscription(
customer,
subscriptionId,
{ plan: newPlan,
prorate: userProrate,
source: stripeToken})
.then(null, function(error) {
response.error(error.message);
}).then(function(subscription) {
// All tasks completed successfully!
response.success(subscription);
});
});
However, upon running this function, I encountered the following error message:
P…e.Error {code: 141, message: "Received unknown parameter: sub_XXXXXX"}
The issue seems to be related to the correct subscription id stored in my user table as 'sub_XXXX.' Despite spending hours trying to resolve it and even conducting online research, I have not been able to find a solution...
Has anyone else faced a similar problem? Any suggestions or examples of working cloud code for this scenario would be greatly appreciated!
Thank you in advance for any assistance!
Best regards, Seb