This episode is for members only

Sign up to access "Build a File Marketplace with Laravel" right now.

Get started
Already a member? Sign in to continue
Playing
03. The onboarding screen

Episodes

0%
Your progress
  • Total: 3h 32m
  • Played: 0m
  • Remaining: 3h 32m
Join or sign in to track your progress

Transcript

00:00
When a user registers for the first time in our app,
00:02
we don't actually want them to be sent over to the dashboard. We want them to only be able to access an onboarding screen until they've successfully gone through the Stripe onboarding process. So in this episode, what we're going to do is build out the onboarding screen,
00:17
add some columns to our user model, and then implement some middleware to redirect the user if they haven't authorized or gone through the Stripe onboarding flow. So the first thing that we'll do is build out this onboarding controller.
00:30
So let's go ahead and make a controller in here called Stripe onboarding controller, and we'll use this to control pretty much everything. So if we head over to routes and web,
00:39
let's go ahead and just define this out as a get route, and we're going to say onboarding. That's pretty much it. We're going to use that Stripe onboarding controller,
00:49
and we're actually going to go ahead and use an index method on this. So we'll have multiple methods on this for each part of the flow, like so, and we can go ahead and give this a name here so we can reference it a little bit more easily.
01:03
We'll just call this onboarding. So over in here, let's go ahead and create out that index method, and we're going to go ahead and return a view here, and let's just call this onboarding.
01:16
Okay, so let's go ahead and create out this view. We'll make it really, really simple as we've seen. So let's go ahead and just create out an onboarding.blade.php file. We could, of course, put that in a different directory if we wanted to,
01:27
and we're pretty much going to grab the same structure as the home here. We just want to keep this really simple, and inside of here, we are going to create an anchor, which is going to go through.
01:36
So let's just do that properly, and that's going to go through to authorize with Stripe. So we're going to say connect with Stripe to get started, and of course, you can add more instructions here,
01:48
make this a little bit better. So we're actually going to forward this over to an onboarding slash redirect page on our app. What that's going to do is take the user's details
02:00
and create the onboarding flow through Stripe Connect, and we'll get to that in a minute. We're going to need to hit the Stripe API for that, but at least we've got our page now,
02:09
which is going to allow us to see this. So if we just head over to slash onboarding, we see the following, and of course, we could just add some styles in here
02:16
just to make this a little bit more clear. So let's say indigo and 500. That should give us this color just here. Great.
02:23
OK, so now that we've got this, we need to make sure that the user can't access certain parts of the app. So we're going to apply middleware to the dashboard,
02:30
the products page when we build it, any other page where the user needs to be connected to Stripe for this to work. So for that, we need some way of determining
02:40
whether the user has actually successfully gone through the onboarding process, and that's going to be through a migration to add some columns to our user model.
02:48
So let's go ahead and make a migration here and just say add Stripe columns to users table, and let's create that migration out. Let's go ahead and open that up.
02:58
So add Stripe columns to users table, and we only need two things in here. We need the ID of the Stripe user that we're going to create,
03:06
and we're going to do that in a separate episode. We're going to automatically create a user's account when they register, a Stripe account when they register,
03:13
and that's going to be a string, and we'll just call this Stripe account ID, and we're going to make that nullable because it's not always going to be there
03:20
when we first register an account, and the second thing is just going to be a boolean, and that's going to be whether they have an account enabled basically.
03:29
So once they go through the onboarding flow, what's going to happen is we're going to go through the flow that we saw in the introduction,
03:36
and then when we come back to the site, we're going to verify that they have entered all of their details correctly, payment information, all that kind of stuff,
03:43
so they're ready to actually start selling and receiving money through their account, so we're going to set a default on this to false because they won't be enabled by default.
03:53
Okay, so we can go ahead and migrate these changes now. That's of course not going to do much, but we're now going to create that middleware. Just before we do that,
04:01
let's head over to the user model, and let's go to the fillable section and make sure we fill in both of these columns, so Stripe account ID and Stripe account enabled,
04:10
and we'll be able to fill them in that model. Okay, so now that we've done this, we are going to create some middleware, so let's go ahead and make out some middleware with Artisan,
04:18
and let's call this redirect if user has not enabled Stripe. Now, that's quite a long name for a piece of middleware, but it tells us exactly what this does,
04:30
so we're going to go ahead and open that up, redirect if user has not enabled Stripe. That's on the app HTTP middleware, and we're going to come down here
04:38
and basically just redirect if the user doesn't have the column that we just added, Stripe account enabled in there. So very, very simply,
04:47
we can just add a little if statement into the handle method here, and we can say if the currently authenticated user does not have the Stripe account enabled,
04:59
so we're checking if this is false, or you could just strictly compare it, then we're going to go ahead and redirect the user, and we're going to redirect them to the onboarding flow
05:11
that we named in our route, and that's all we need to do. So now what we can do is start to apply this middleware anywhere where a user can't access
05:18
unless they have gone through Stripe onboarding. That might include the dashboard. I'm going to add it in here anyway. You might want to show something on the dashboard if not,
05:26
but I'm going to sort of always forward the user over to this onboarding flow. So if we head over to our web routes, let's take a look at what we've got so far.
05:35
We've got the home controller, which we don't need to apply this to, but we do want to apply this to the dashboard. Now, while we do this,
05:41
I'm going to actually move the dashboard over to a controller because by default it's just a route with a closure in here. So let's go ahead and very quickly create out a dashboard controller in here.
05:53
Dashboard controller, and we can sort of start to move this away. So we're going to still return the dashboard view. We're still going to keep that middleware in there.
06:02
So let's head over to the dashboard controller, and let's go ahead and just create out an invoke magic method in here. Return what we removed from that closure.
06:11
And then I always tend to define my middleware within the constructing controllers, although you could do it at the root level if you wanted to. So we want both of these pieces of middleware.
06:20
We're not looking at account verification in this case, but you can, of course, add that later. So over in the dashboard controller, we're just going to say this middleware,
06:30
and we're just going to apply the same middleware to this. And then we can just get rid of this closure, and we can just swap that out for the dashboard controller, fully qualified class name.
06:39
And that's it. So we should still be able to access our dashboard in the same way, but now that's just moved over to a controller,
06:46
which makes it a little bit easier. So now all we need to do is just apply that middleware that we just created. So redirect if user has not enabled Stripe,
06:56
and that's pretty much it. So now when a user lands on their dashboard, we know that they're authenticated, but if they don't have Stripe enabled,
07:03
we're going to redirect them back over to the onboarding flow. And you can see here, sure enough, that has happened.
07:08
We cannot access the dashboard or any other pages that we apply this to if the user has not gone through the Stripe connect process.
34 episodes3 hrs 32 mins

Overview

Build a marketplace where sellers can list and sell files, while we take a cut of each sale using Stripe Connect.

We'll cover onboarding users with Stripe Connect, creating products and uploading files, payments, and delivering purchased files to your customers.

Here's everything we'll cover:

  • The Stripe Connect onboarding flow
  • Effortlessly creating products (and uploading files) with Livewire forms
  • Subdomains for your user's marketplace
  • Stripe Checkout for a beautiful, secure payment flow
  • Securely delivering files with Signed URLs in Laravel
  • Showing sales stats on a dashboard
Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

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