This episode is for members only

Sign up to access "Build a Referral System with Laravel" right now.

Get started
Already a member? Sign in to continue
Playing
12. Setting up Cashier

Transcript

00:00
All right, so let's go through all the steps
00:01
that we need to get subscriptions working within our application. Because when we build our referral functionality, we want this to tie into the subscriptions that
00:09
have been created. Laravel Cache works really nicely for this. You might be using something else, but for the rest of the course, as we are receiving payments
00:17
in and attaching them up and calculating stuff, you can pretty much use any solution. OK, so Laravel Cache is basically just a package that hooks up and creates subscriptions for you,
00:27
allows you to create checkout links. All of that good stuff, we'll go through it in a second. Let's get it installed and just get this working. So we'll obviously go ahead and pull this in with Composer.
00:37
And let's take a look at the database migrations, because these are really important for what we're doing. So we'll go ahead and run phps and migrate. And you can see that's created a Customers column,
00:48
or added Customers columns to the Users table. It's created a Subscriptions table and a Subscriptions Items table. Now, the thing that we're most interested in
00:57
is this Subscriptions table. So what's basically going to happen is when someone creates a subscription, this is going to fill in with all of the details from Stripe.
01:06
Now, what we want to do when a subscription gets created is we want to hook up the subscription that just got created to the referral code. That means that on our dashboard,
01:17
based on the referral code we've got, we know which subscriptions are responsible or have been created from our referral code. So that's really important.
01:27
So we're not going to worry too much about subscription items. That's useful for Laravel Cachier, but we're really interested in this Subscriptions table. OK, let's go through and see if we need to do anything else.
01:38
We'll go ahead and publish all of the assets for this, which is going to be our migrations, which we've already done. And we don't want to ignore the migrations.
01:47
OK, so the next thing is the billable model. We need the user to be a billable entity. So let's go straight over to the user model. And up here, we will go ahead and use the billable trait.
01:57
This contains everything that we need to create subscriptions, generate links, all of that kind of stuff. So let's go down here. The next most important thing are the API keys from Stripe,
02:08
or this just isn't going to work. So we'll head over to our EMV file. We'll paste these at the bottom, and then we'll just copy these over.
02:15
We're not going to worry about the webhook secret just yet. We'll add that in later when we get to receiving webhooks. But we at least want our Stripe key and our Stripe secret. So we're going to go over to the Developers section over in
02:26
Stripe, head over to API keys. And we just need these two keys. So we're going to grab the publishable key, which is for the client side.
02:34
And we're going to grab the test key, which is for the back end. So let's go ahead and enter our password and just wait for that to finish so we can reveal this key.
02:42
And there it is. Great. So let's go ahead and pop that directly into there. And we're pretty much done.
02:48
Just check if we need to set anything else up on here. Currency configuration if you need to. Tax configuration. I think we're just about done.
02:55
So that is Stripe now set up. And what we can do from this is when the user clicks on here, we can go through to another controller. And we can generate out a checkout link
03:04
for that specific plan or price. Because we have that price stored in our database now, we can forward the user over properly. So let's head over and do that next.
24 episodes2 hrs 39 mins

Overview

Let's build a feature complete Laravel referral system, completely from scratch.

We’ll cover generating referral codes, setting a cookie to track the referral process, hooking up referrals to subscriptions and displaying detailed referral stats in a dashboard, so your users can see how they're doing.

On the admin side, we'll set up a job to automatically generate a CSV with all the amounts you need to pay out each month, automatically mark referrals as paid, and display historical referral payments for users.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

No comments, yet. Be the first to leave a comment.