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
05. Automatically creating Stripe accounts for your users

Episodes

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

Transcript

00:00
The Stripe Connect flow requires that we have an account for each of the users that are using our
00:05
app, so we can start this flow that we see here. So what we're going to do, because we got rid of our logout link, which we could add back later, we're just going to clear out the cookies here so we can head over to the register page. Also bear in mind that the onboarding controller just here, good catch, this doesn't require authentication. So I'm just going to go ahead
00:24
and update that really quickly. So if we head over to our Stripe onboarding controller, we just want to make sure that of course we add in the middleware there that the user has to be authenticated. So let's go ahead and add in our auth middleware, and of course when we give that a refresh we're back to login. So when we register an account, this is the point where we want to go
00:43
ahead and create a Stripe account for this user in the background, so we can use that account to start the onboarding flow. So how do we do this? Well within Laravel we have an event service provider which already contains a registered listener, so this event that's fired will then perform any of these actions which are registered as listeners. At the moment we only have one which
01:05
is sending an email verification notification if we have email verification enabled, which we don't at the moment. So what we can do is very easily whenever anyone registers an account on this platform, we can go ahead and behind the scenes create out a Stripe account. So we'll go ahead and create a listener for this, so let's go over once again to Artisan, make out a listener, and
01:26
let's call this create Stripe account, and we can go ahead and add that directly in here. Create Stripe account, and just give the full class name to that. So if we head over to this listener now when we register an account what we can do is under handle actually hit the Stripe API to create that user out. So let's assign this a response, remember we just in the last episode added
01:50
Stripe to our container, so like we saw before we can just use app and Stripe to access the Stripe client. We can then access the accounts section of the API, and we can go ahead and create out an account. Now we don't need to give too much information in here, we just need to pass a type in here, and that's just going to be a standard account. Now from this response we get back that
02:11
will give us the Stripe account id, which we know that we can put into this column for that particular user. So now what all we need to do is from the event that we get passed into this listener, the registered event will contain the user, an event will contain all of that data, we can just grab the user who's just registered, and we can go ahead and update that user. So we can pass in the Stripe
02:33
account id, and from the response we get back we grab back the id, and that is it. So we're going to go over to the database and just test this. I'm going to delete this user that I already created because we want to see all of that data roll in, including the listener that we've just added. So if we head over to the register section here, I'm just going to go ahead and register out a new
02:54
account, enter all the details I normally would, and we're going to go ahead and hit register. Okay so we're registered, it didn't look like anything happened, but of course behind the scenes we're now creating out that Stripe account, and you can see here sure enough that has been filled with the Stripe account id.
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.