Stripe Integration - Backend Workflow Only Works With Root Workflow API URL (Good or bad?)

I built a very simple app just to test out the stripe integration. The app has 4 buttons: Purchase plan, start free trial, manage billing, and cancel plan.

Everything works, except for the “cancel plan” bit. For some reason, it’s returning the wrong “current_period_end” date (it’s showing today’s date instead of next month, when the subscription expires).

The way the backend workflow that updates the user data is configured is exactly like this: https://youtu.be/GE2fYHFWahw?t=694 (included the timestamp in the link) only in my case, I’m canceling using a button in my app, instead of using the customer portal to do so. And I’m canceling the subscription at the end of the current billing period, instead of canceling it immediately.

What happens is:

  • I have a backend workflow called “update_subscription” that updates the current user with data received from the Stripe webhook (such as subscription id, status, start and end date, etc.)
  • In the bubble app, I click the red “Cancel plan button” which triggers a workflow that cancels the user’s subscription, and then shows me this text: “Your subscription expires on: Thursday, June 15, 2023” (it gets the date from stripe via the backend workflow I mentioned above)
  • The backend workflow works fine when I first initialize it using this webhook url in stripe: https://mybubbleapp.bubbleapps.io/version-test/api/1.1/wf/update_subscription/initialize
  • So since it worked, I then removed the “/initialize” bit from the endpoint url in stripe and tried canceling the plan again, in the bubble app. For some reason, it now shows today’s date as the subscription expiration date, instead of June 15, 2023.
  • So instead of the backend workflow url of “https://mybubbleapp.bubbleapps.io/version-test/api/1.1/wf/update_subscription/”, I tried using the root workflow api URL of “https://mybubbleapp.bubbleapps.io/version-test/api/1.1/wf” in my Stripe webhook. I then canceled the plan again in bubble and it now shows the correct expiration date.

My question is: Should I just continue using the bubble workflow API root URL in my stripe webhook? Would that cause any issues going forward, especially if I have multiple backend stripe workflows with different names, but in Stripe I only have one webhook that uses the root URL?

And why is the workflow URL not working after I remove the “/initialize” bit from it? I thought that’s what you’re supposed to do after you successfully initialized the request.

Thanks

Can you share some screenshots of your worklfows?

The backend workflow:



The “Cancel plan” workflow:


The API Call used in the “Cancel plan” workflow:

Firstly, why are you setting the same field twice (with different values) in your workflow?

Doing this will only store the last value set, so the Subscription_End is being stored in the DB as the request data’s current_period_start

Secondly, why are you changing the Current User’s Subscription End in the ‘cancel plan’ workflow?

That date isn’t changing, and besides, the webhook workflow will change that once it triggers.

And it looks like that is what’s happening…

So to summarize:

When a User clicks the cancel button, your workflow is setting the Subscription_End to the API call’s current period end (that’s fine, although there’s no need for as you’re not changing the current period end date). For example, it sets the Subscription End to 15th June

In any case, that action then triggers the webhook.

The webhook workflow updates the User’s Subscription_End again, but this time it changes it it to the request data’s current_period_start which, presumably, is 1 month prior to the end date… i.e. 16th May (or “Today’s” date on the date you wrote this post.)

So that’s what’s happening here.

2 Likes

Can’t believe I didn’t notice that :sweat_smile: Thanks, it’s working now. And you’re right about the changing the Current User’s Subscription End in the ‘cancel plan’ workflow, I just deleted it.

1 Like