Need help - Stripe.js Subscription Update - Changing Plan or Billing Interval

Hi all,

I need help regarding changing and updating customer plan/price id subscription using Stripe.js plugin.

What is the best way to implement this. Currently what I am doing is when customer wants to change plan or billing interval and [if customer already has existing subscription], I will Cancel current subscription and Create a new Subscription? Since I am cancelling subscription (potentially unused one as well], do I need to refund the amount paid (with proration=yes)?

Stripe.js have Subscription Update workflow but there is nothing in it for me to change any plan or price id.

Thank you.

Hi @faisalkarimstubapp
Have you got anywhere with stripe.js subscriptions, I am having the same issue.
Best regards,
Pawel

Hi @pawelodr

I havenā€™t check the recent update of Stripe.js plugin, but from a glance at the version update, none mentioned about the Subscription Updateā€™s plan/price id.

Please share with me if you have any solution for this.

@faisalkarimstubapp
Once I get this figured out I will post a solution.
Cheers,

Cheer mate, appreciate it.

Hi @faisalkarimstubapp,

So I got this figured out at least for my purposes, and for argumentā€™s sake I used bubbleā€™s-stripe plugin rather than Stripe.js - but you can use either one.

So this is what you need:

  1. Under Settings/API ā†’ Enable Workflow API and backend workflows needs to be checked

    2 Create a table to capture charges - Include fields: Invoice_ID, Charge_ID, Subscription_ID, Customer_ID
  2. In Your Stripe account you need to create a couple of webhooks ā†’ This is found under the developerā€™s menu item
    Screen Shot 2020-09-07 at 6.32.27 AM
  3. In Bubble your last item where you expend the search for pages will be backend workflows
    Screen Shot 2020-09-07 at 6.37.07 AM
    Screen Shot 2020-09-07 at 6.37.50 AM
    From here you have to create a new API workflow - Create one for subscription update
    Screen Shot 2020-09-07 at 6.39.12 AM
    Screen Shot 2020-09-07 at 6.41.10 AM
    Click on ā€œDetect Dataā€ button
  • Bubble will now display a url with ā€œInitiate at the endā€ - copy this URL
  1. In Stripe Create a webhook for when subscription is updated
  2. Paste previously copied URL (from bubble) and paste in ā€œEnd point URLā€
    Click on Add Endpoint and Send Test webhook
  3. Go back to bubble. Bubble and Stripe now will make a connection where stripe will send a whole bunch of data to bubble - make sure you create a record in your newly created table and capture the Invoice_ID, Subscription_ID and Customer_ID
  4. You also need to create a webhook for when a charge is succeeded - from there you need to update your charge table record (where ā€œinvoice idā€ from subscription update = ā€œinvoice idā€ from charge succeeded) capture charge amount and charge_id.
    Now you should have all the data you need to process a refund on a subscription.
  5. In order to process a refund, there might be another way, but I used an API Connector plugin - where you have to connect to Stripe
  6. Create a Call to process a refund:

    Once you initialize the call (proving that bubble can communicate with stripe) you will be able to use it in your workflow
    I hope this helps. Cheers
1 Like

Thank you so so so much for taking the time to write the step by step guide for me. The process that you explained means you are canceling userā€™s current subscription (with refund) and create a new subscription, is it?

I am using Stripeā€™s Subscription feature thus I am not using Charge.

I will take time to fully digest what you have mentioned above.

Cheers mate.

Iā€™m sure @pawelodrā€™s way of doing it works, and Using the Bubble Stripe plugin for this is definitely a good idea.

To update the subscription without cancelling and starting a new one (therefore letting Stripe deal with the proration calculation), here is what I did on an app I built:

  • store the SubscriptionID in the Userā€™s DB when subscribing to a plan for the first time
  • use the Subscribe the user to a plan action (Bubble plugin) when you want to update the subscription
  • check both boxes (ā€˜Apply this action to the current userā€™ and ā€˜Update existing subscriptionā€™)
  • inform the Userā€™s SubscriptionID and specify the new plan_id

Let me know if that works for you too
Ambroise

Need extra help?

Book a free 15 minutes call - happy to help if I can

2 Likes

Thank you so much @ambroisedlg for contributing in your knowledge. I didnā€™t use Bubbleā€™s Stripe plugin, only Stripe.js plugin due to its features and I read it somewhere that Bubble is not updating/maintaining the stripe plugin anymore hence I am using Stripe.js .

Can I use both plugin at the same time, probably will use Bubbleā€™ Stripe plugin for ā€œupdatingā€ existing subscription? I will give it a try soon.

For the scenario of a User has already paid and subscribed to more expensive plan and moving to cheaper plan in the middle, using Bubbleā€™ Stripe [ ā€˜Update existing subscriptionā€™)] , I still need to do the refund workflow or it is automated by Stripe?

Iā€™m also using Stripe.js + API Connector for everything else - Iā€™m just using Bubbleā€™s plugin for the Update Subscription, so yes you can definitely use both together

Each Customer in Stripe has a balance, and Stripe calculates the proration automatically. Iā€™m not sure they refund automatically, but I think they charge less on the following billing period. Iā€™m not entirely sure though so I would suggest you do some tests in Stripe first!

Hope that helps
Ambroise

Need extra help?

Book a free 15 minutes call - happy to help if I can

From what I have read in stripe documentation, stripe does not refund automatically, and does charge less the following billing period. This did not necessarily work for me, as my two subscriptions have different time periods - one is annual and the other monthly, which means that if a user switches from monthly to annual subscription, the user would initially have to pay the whole amount for the new subscription and would have to wait a year in order to have the prorated amount credited to the next payment - at least this is how I understand the process.
https://stripe.com/docs/api/subscriptions/cancel#cancel_subscription-prorate
Hence the additional refund process in bubble.
I hope this helps.

By the way, every time your customer is charged, you might not see it, but you are using Charge.
When subscribing, Stripe creates a subscription and an invoice, when you collect money (which might happen instantly), stripe references the invoice and assigns a charge to it to reference the payment. You can capture the charge through a stripe webhook and use it to process a refund.

Hey @pawelodr

Thanks for confirming that for us

In my experience this isnā€™t true though - if a User pays a $50USD monthly subscription, and then switches to a $500USD annual, the prorated amount spent for the current month will be deducted from the $500USD.
However the problem lies where the User wants to switch from annual to monthly, in that case youā€™re right, a manual refund is required.

Cheers
Ambroise

1 Like

Hi @ambroisedlg,

Do you mind clarifying the way you work with API Connector when integrating Stripe? I decided to use this thread and not create a new one since I think itā€™s relevant to the discussion.

Iā€™ve successfully integrated Stripe using similar approach, it was mostly manual API calls and in testing environment it worked nicely. Now it must be deployed to live. What I 've done for other things with manual calls before was creating duplicates for every API call, changing keys to live version and checking ā€œIsnā€™t live versionā€ condition in workflows to run dev or live API call version. Is there a simpler (more maintainable) way to handle dev/live versions?

Thanks,
Andrey

(Btw, I updated subscriptions without the plugin, as I understand Stripe should handle proration even when switching from billing period to another, itā€™ll change invoicing date but other things should be the same. I believe you donā€™t have to manually refund in this case - never tested though)