@adamhholmes Forgive me for the long message, I felt my progress may be beneficial to others if documented step-by-step.
I have saved the Stripe Customer ID in a similar way to your screenshot above but still experiencing multiple issues. If you can spot any areas I am going wrong I would be most grateful.
Database set up
Most tutorials recommend adding fields in the User’s Data type for Stripe’s payment activity (such as SubscriptionEnd etc) but my User’s Data type has a lot of info and is at risk of being messy! So, I have created a new ‘Subscription’ Data type.
Here is how I am set up:
The User Data type refers to Subscription [Subscription] and I also have a Plan data type which has the default settings for a subscription plan so that I can refer to Plan’s first item.
Datatype: Plan
- Fields: Description [Text]
- Frequency [Text]
- Name [Text]
- Price [Number]
- Stripe Price ID [Text]
I’m not sure if I should also have a Subscription field in the Plan Data type?
Stripe setup
I created a new product in Stripe and copied the API ID.
Then I added a ’ Pay now’ button on my website and opened it’s workflow:
Workflow step 1. “Subscribe the user to [API ID]”
Workflow step 2. “Make changes to a thing… Thing to change is Current User’s Subscription
(see below)
Error: When a new user signs up, I want their Subscription Status to be predefined as ‘not_activated’. I have added the words ‘not_activated’ as a default in the SubscriptionStatus field, but when a User signs up the ‘SubscriptionStatus’ field is empty?
Displaying user information
New users to my site will see ‘You are on the free plan’ and I have conditions in place so that they see different messages after subscribing/cancelling.
Stripe customer portal
Now I want to give users the ability to cancel/edit their subscription. I’ve added a button to my website called ‘Manage Plan’ and in it’s workflow I add ‘Self Service Portal - Stripe Portal w/ dynamic return url’.
Customize customer portal
Note to newbies. You need to go to Stripe > Settings (cog icon) > Customer portal and make sure you have filled everything in. Be aware that the page layout is not great and whilst it looks like there are only two things to fill out, you need to scroll down to see more. Importantly, here is where you choose how to allow customers to end their billing. I have chosen ‘Cancel immediately’ so I can test cancellations easier.
Test signup
Error: When I checkout, Stripe says that a payment has been made but my database is empty?
Create Webhook
I set up a New API workflow…
I clicked on ‘Detect data’ and copied the data URL.
Note to newbies, DO NOT CLOSE THE DATA POPUP until you have completed the next steps.
Go to Stripe > Developers > Webhooks. Then Add endpoint and paste the data URL. I am listening for customer.subscription.deleted
.
How to ‘sync’ Bubble and Stripe
Note to newbies, at this point you will see the new Webhook is 'Waiting for events …". To make it work you have to create a new user, pay for a subscription and then cancel it manually via Stripe’s interface by going to Customer > Click on customer and cancel immediately. Then check the webhook worked by going to Stripe > Developers > Events and you’ll see recent Webhook attempts. Also, go back to Bubble and you’ll see the data payload which has been sent (change object start_date to Date (UNIX).
My webhook appears to be active and set up correctly.
Make changes to a Thing based on the webhook data received.
In the API workflow, I make changes to a user’s subscription, I get the Customer ID and update the Status.
Note to newbies: If you’re wonder why I do a Search for
instead of refering to the current user, it’s because a backend workflow can’t refer to Current User directly.
Note to newbies: Go to Stripe > Developers > Webhooks and remove ‘/initialize’ from the end of the webhook URL or it will not work again.
Test new user
I created a new user and signed up to a plan
I went to Stripe > Developers > Webhooks and refreshed the page, I see ‘Waiting for events …’ has cleared and “The endpoint test_webhook1 was successfully initialized”.
Error 1: Even though Stripe registered the new users payment, the fields in my ‘Subscription’ Data type are empty with no new payment info saved. Also, if I click the ‘Manage Plan’ button on my website I see an error preventing me from going to the customer portal (see below).
