Getting Started
Installation
Install and configure the package using the following command :
Migrations
Shopkeeper comes with a set of migrations to add serveral columns to your users
table, a new subscriptions
table to hold all of your customer's subscriptions and a subscription_items
table for subscriptions with multiple prices.
You can run the migration with:
Lastly, to ensure Shopkeeper properly handles all Stripe events, remember to configure Shopkeeper's webhook handling.
Configuration
Billable Model
Before using Shopkeeper, add the Billable
mixin to your billable model definition. Typically, this will be the User
model. This trait provides various methods to allow you to perform common billing tasks, such as creating subscriptions, applying coupons, and updating payment method information:
In your Shopkeeper configuration file, define your User as the Customer model:
When using a model with a different name than User
, make sure to change the table name in the generated migration.
API Keys
Next, you should configure your Stripe API keys in your application's .env
file. You can retrieve your Stripe API keys from the Stripe control panel:
In production environment the STRIPE_WEBHOOK_SECRET
environment variable is mandatory as it secures the Stripe webhook endpoint.
Your first Checkout
The easiest way to get started with Stripe is by using the [https://stripe.com/payments/checkout](Stripe Checkout) feature.
Create a price
To start selling you must create a new price in Stripe. want to try the implementation
If you have the Stripe CLI you can simply run the following command.
Redirect to the Checkout
Let's now create a route to redirect our user to the Stripe Checkout page for the price we just created.
Handle redirect
When a customer visits this route they will be redirected to Stripe's Checkout page. By default, when a user successfully completes or cancels a purchase they will be redirected to your home
route location, but you may specify custom callback URLs using the success_url
and cancel_url
options:
Congratulation, you can now accept money and get your first customers!