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
04. Registering the Stripe PHP library

Episodes

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

Transcript

00:00
From here on, we're going to start to make a bunch of requests the Stripe API to actually go through that onboarding process. So we need to put in the Stripe PHP library, get it into our application so we can use it really easily.
00:12
So the first thing that we're going to do is head over to the Stripe PHP library, and we're just going to go ahead and pull that in with Composer. We're going to close this off now because most of it now is pretty straightforward, but we're going to have to keep our Stripe account open and head over to this developer section where we can grab our API keys. So we're going to need our API keys under this test mode.
00:34
We obviously don't want to do this on production or live mode, and we can grab these and put these into our app. So this is usually where I start because it's the most boring part. We're going to go over and pull these into an EMV value just over here. So we're going to go ahead and say Stripe secret, or in this case, that's the publishable key.
00:52
I don't actually think we need the publishable key because we have no checkout on our page. So I'm going to go ahead and log in here and just grab the secret key. OK, so let's grab this secret here, and we're just going to add this to a EMV value called Stripe secret, and that's it. Now we're going to build out some config for this because we don't want to read these values directly from our EMV.
01:12
So let's go ahead and do that now while we're here. If we just head over to the config folder over in Laravel, let's go ahead and create our Stripe.php file. This is just going to return to us an array. So this is just how we build our config.
01:25
And we're just going to say secret in here and we're going to reference that Stripe secret value inside of our EMV. If you are new to Laravel, the reason that we do this is because in a different environment like production, this Stripe secret is going to be different. It's going to be your live version of the key. So this is just a really easy way to switch this out.
01:43
But we want to keep this in config so within Laravel we can access it a little bit more easily. OK, so now that we've done that, what we want to do is build out a service provider for Stripe. So again, we can do that with Artisan. So let's go ahead and make out a provider and we're going to call this Stripe service provider.
02:02
We're going to go ahead and register that under config and app. So if we just come down to our provider section here, we should find down here a package service providers. Or you can put this on the applications service providers. So let's just copy one of these down here.
02:19
Switch this out to Stripe service provider and we're done. So we can open up our Stripe service provider and under register we can bind Stripe to the container. Now we're going to do this in the most basic way possible because we're only going to be making a few API calls to Stripe. We're not going to get that advanced in this case, but you might want to change this around if you grow this app any bigger.
02:40
So we're going to go ahead and bind in just a string value in our container called Stripe. This just means that later on, what we can do is resolve this out of the container using app and Stripe. And then we can start to make API calls like this. We could say customers and create, for example.
02:57
This just makes it super easy to have this within our app so we don't have to pull it in in every single controller or action that we need to do. So to bind this to our container, we're going to create our closure here. Anything that we return from here is now going to be put into our container under this Stripe key that we can access anywhere in our app. So we're going to return a new instance of the Stripe client.
03:18
So let's go ahead and pull in the Stripe client. We might just need to re-index our workspace. And there it is. And then in here, all we need to do for our purposes right now is just pull in our secret key, which we know we added to Stripe config file under secret.
03:33
So we can just use the config helper here and say Stripe.secret. And that's pretty much it. That's all we need to do. We now have this in our app that we can start to use.
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.