Overview
Laravel Cashier (Stripe) is Laravel’s official package for Stripe billing. You can use it to create and manage subscriptions, run one-time charges, retrieve invoices, and handle Stripe webhooks through a fluent API.Installation and configuration
Install Cashier and run its database migrations.Billable trait to your billable model.
.env.
Customer management
UsecreateOrGetStripeCustomer() when you want to safely fetch or create the Stripe customer record.
createAsStripeCustomer() when you explicitly want to create a customer first.
Subscriptions
Create a subscription
Create a subscription withnewSubscription() and create().
Pass a Payment Method ID (for example, from Stripe.js) as $paymentMethodId.
price_monthly is an example. Use the actual Stripe Price ID from your Stripe dashboard.
Check status
Usesubscribed() to check whether a user currently has an active subscription.
Cancel and resume
One-time charges
Usecharge() for one-time billing. Pass the amount in the lowest currency denomination (for example, 100 means $1.00 in USD). Use a Stripe Payment Method ID as $paymentMethodId.
charge() throws an exception.
Payment Element
Stripe’s Payment Element supports multiple payment methods in a single UI component, including cards, Apple Pay, Google Pay, and iDEAL.Payment Element for Subscriptions
Create a Setup Intent and pass it to your view.client_secret.
return_url, use the setup_intent query string parameter to retrieve the payment method and create the subscription.
Payment Element for Single Charges
For one-off payments, create a Payment Intent with thepay() method. Store the Payment Intent ID on an order model so you can retrieve it after Stripe redirects back. The example below assumes an Order model with user_id, amount, status, and stripe_payment_intent_id columns.
payment_intent query parameter. Always verify that the Payment Intent belongs to the authenticated customer and that its status is succeeded before fulfilling the order.
Invoices
Retrieve invoices withinvoices().
dompdf/dompdf and call downloadInvoice(). Pass an invoice ID from the invoices() collection as $invoiceId.
Webhook setup
Cashier automatically registers a Stripe webhook route and uses/stripe/webhook by default. Configure this URL in your Stripe dashboard.
You can create the webhook through Artisan.
stripe/* from CSRF protection.
STRIPE_WEBHOOK_SECRET in .env so Cashier can validate webhook signatures.