In this episode, we get our Laravel app ready to work with Stripe by setting up the Stripe PHP library (or SDK). First things first, you’ll need a Stripe account—so if you don’t already have one, you’ll want to sign up. We talk about operating in test mode for safe experimentation and grab the necessary API keys from the Stripe dashboard.
Next, we install the library using Composer, and then instead of just throwing the Stripe client directly into our controllers, we do things the "Laravel way". That means setting up a Stripe service provider. This makes sure the Stripe client is available app-wide via Laravel’s service container, making it super easy to access it wherever we need.
To keep things organized and secure, we create a stripe.php
config file to store our Stripe keys, and we pull those keys in from the environment file (.env
). This approach means your test and production API keys are kept separate, and you won’t accidentally commit secret info to your codebase.
Lastly, we register our new service provider and quickly test things out by doing a dd
on the app container to check our Stripe client is working. With this setup complete, we’re ready to start creating payment intents in the next episode!