hey guys today we have a very exciting tutorial and it is about stripe subscription so as you know natively flut flow doesn't have a strap subscription built in they just have normal stripe payments um and the only native piece built in within flutter flow related to subscription is called Revenue cat however stripe is a very big platform across the world and I would love to show you now how you can set up stripe subscription in your flut Flow app similar to to my previous uh tutorial on stripe connect we will we will cover stripe subscription
which will involve making API course to create the customer allowing the customer to choose a product they want to subscribe to and then having and listening uh V web hook whether the customer has successfully started subscription in addition the retrieving the statuses of the subscription so you know when the customer has you know not paid their um subscription therefore terminate access or to continue allowing them to access the app or whatever feature you want so this is what you'll be building firstly we're able to set up a strap customer by pressing this button you really
don't need to press a button to um set up the strap Customer because that technically should be on your on boarding flow I'm just showing you here manually um how to do it so once the customer is created they have a customer key and here they can subsequently select a product they want to subscribe to so let's just say they want to subscribe to the basic $19 per month plan we would do this and they can go through the checkout of the subscription flow let's press subscribe next Once you subscribed we will also receive webhook
information about the customer that and the subscription plan So the plan is ending in month time and description status is active which means they've successfully paid for it in addition what is the subscription ID price ID and the product if subscribe to lastly we're able to manage the subscription so here we will allow the user to um manage and upgrade um their subscription so for example from $19 per month plan I would upgrade to an annual one of n per year this will you charge the remaining payments and then update the end date of the
subscription to March 20 March 12 2025 you can also allow the user to um manage your subscription um VI your app fre API course uh but ultimately that's up to you I've decided to use Stripes inbuilt management because it was the easiest to set up so let's get started so this is what you'll build so the first thing we're going to do is there is I'm like to point out that there is a documentation on stripe on how to um set up stripe subscription um and you can read it extensively to understand all kinds of
customization for example stting a trialing period um what happens at the end of the uh do you require payment on sign up do you not um all these customization can be done by reading documentation I'll just show you the most basic and you can build on top to suit your individual needs so let's get started so the first thing we're going to do similar to strip connect is set up the API course so let's firstly uh create API Group let's call this strap subscription and the URL we need is the common one so HP SL
this one which is in the documentation and we need to add some headers so the two major headers we need are content type content type applic location next do uh URL included I'm just typing in of copying from stripe and lastly you also need your key so you can get the key here in your developer dashboard um so you can easily get the key you know developer dashboard and stripe so I'll just write that here so it'll write bar and press add grip let's add the API CES we need so they are in essence two
big API two major API cords you need to set up and the first one is creating a customer and the second one is um the checkout session allowing the customer to select a subscription and subsequently pay for that subscription so as always remember to make your API call Private you can do it yourself I won't do it here um just to reduce the time um but always make API call private so people don't see this authorization key when you finally deploy it so first thing we're going to do add the API call in this group
so the call we need is create customer call so basically what we need here is to create a strap customer think of strap customer is what stripe is associating uh with your users so when you create a customer the response would come back with a customer ID and this a stripe customer ID and let's save this strip customer ID into our database um so this allows our out to speak to stripe and tell them this is the customer that is uh using the app right now in order to create the subscription later on so let's
quickly go back and change our database um a little so here the app is very simple right we have a page called create customer ultimately you should create the customer on on boarding so they don't need to manually press create customer but I'm just doing it here so you can man we see what's happening so let's quickly add in the user a field cor St cus key or C ID it's going to be off string so let's set up that API core uh you can of course read all about it what you want but let's
just hypothetically say we only want the we'll only pass the email so let's go back to the API call um where is it so add API call create customer the endpoint is called customers and what we need is a post requests because we're sending data across the stripe and the body is going to be ex Euro encoded and the parameter we pass in based on documentation you can just pass in um an email because the email is a unique identifier to your user so I'm going to set as a variable email email it's going to
be a string let's add this call uh let's test to see if this works so let's write an email of it's It's gmail.com and see if this works perfect you can see here we got a response from stripe and this is the customer key so we need to save this custom key somewhere maybe just call a strip C Key C ID and save perfect so the next API call we need is the checkout sessions API key so but before we start this uh we need to create some products within stripe to understand what subscription are
available so you can read a lot about it on the documentation on strip products so TR product catalog you can read a lot about it um the documentation is also here um in essence you have products so what are you selling and then you have prices underneath so for example if you have most basic sense a company might have only one product like notion you're selling notion um access to notion and they would have different prices so you might have a monthly price a basic tier or premium tier and so on uh so let's quickly
set something up similarly so let's just say we're only selling one product let's call it access to app and then the product you're adding you can write it description you want you can write image you know whatever you want right and let's just say it's basic access and let's amount maybe $19 and it's going to be building monthly let's add this product and you can see here that we added a new product and also let's add another price now uh let's this could be a more premium tier and let's call this a flat price um
let's call this uh maybe $30 for premium it's billing monthly so let's add this up so you can see here there are now two price product keys uh for this access to the app so we can see here that access to the app we now have two tiers 19 per month for the basic tier and the pricing for and $30 per month for the premium tier you need will need to use these price IDs to determine during checkout what the user has selected now that we set up stripe in terms of our product setup let's
copy these Keys into the app so because we need to use it later your checkout flow can be different I'm just using drop down for Simplicity sake you can put you know contain coners and users select one product and then you know whatever design you want I'm making it easy so you know the whole goal of this tutorial is about strap subscription not really about design of checkouts so here I have option label for basic $19 per month and premium $30 per month and I'm just going to copy the keys here the price key that
we just configured from stripe so that's $19 and this is $30 per month so what I want to achieve here is that when a user selects $19 per month we will now be passing to stripe this uh price ID and if the selected $30 per month will pass in stripe pass it stripe this price ID where we make that checkout session call so let's go back to our subscription um for the checkout session so the checkout session um what we need is like if you just read the checkout session document ation which is here checkout
session you can see you know what kind of information is required um but in most basic sense I'll just cover it in this call and explain why we need it so similarly to the CR customer let's call this API call create check checkout session and this is going to be a post request the endpoint will be check out/ sessions and then what we need is going to be a XML Ur encoded and what we need are quite a few parameters I'll just add it quickly so the first parameter we need is mode it's going to
be a specific value um if you recall the stripe connect it's the value was I believe was payments but today we're going to be using subscription so we're telling stripe we want to check out uh in a subscription model we need a success URL um it's going to be it's I'm going to make this a variable I'll create a variable later uh I need to cancel URL so this is basically what what does the page direct to when they press when they're successful in checking out and canceling in checking out um what we also need
is align items 0. price so this is the price ID we'll create variable for the E later we also need is line items zero quantity and we can just hide code this to one and as a string this is because there's only one subscription we signing up to you can do it to two buying subscription but subscription models don't work like that anyway next we need the customer so this is the customer key um we'll create a variable for later and that's the most basic uh requirement to make a stripe subscription checkout um if you
read more about the documentation you can uh set up heat of lot of things so I believe you can set up trials um how long's the trial for when is it trial for you can set up whether the payment is required at um at subscription or payment is not required and strap will send an email to them based on your settings to remind them to add a payment ultimately that's your choice but here these are the bare minimum we need to set up for a subscription now let's add these variables I want to let's add
these variables success URL that's good let's add create a variable cancel URL and whatever we call maybe just call this price it's easier to understand and that's going to be all type string add call so let's quickly test this so the customer key we create it I don't know we just bring it back again so this is the customer key response and let's go to test and response write this maybe I just write HPS Google maybe I should just copy this link copy paste price this is the price ID let's just say we want to
initiate um the $9 per month subscription check out uh let's copy this ID right here and let's test this to see if it works uh okay that didn't work because I totally forgot to set this variable here here you go save it again um test it voila a session has been created and then what we need is the URL response so to launch it so let's add Jason path here let's call this URL let's preview it and see we can copy this and see what it looks like so here you can say that the user
this is the email the customer email that is linked to that customer ID see here that we can do a checkout right checkout flow of $19 per month access to app right now let's save this API call just did I'm going to stop here in the next lesson we'll cover setting up the front end to make the API call remember to comment like or subscribe to keep updated on the series