Looking to hire Laravel developers? Try LaraJobs

laravel-stripe maintained by freelancernishad

Description
Stripe Payment Gateway integration for Laravel
Last update
2026/05/06 11:12 (dev-main)
License
Links
Downloads
0

Comments
comments powered by Disqus

Laravel Stripe Payment Gateway

A reusable and extensible Laravel package for integrating Stripe Payment Gateway. Supports Checkout Sessions, Payment Intents, and Subscriptions.

Features

  • Flexible Models: Link payments to any project entity using polymorphic relations.
  • Configurable: Easily swap log models and table names.
  • Robust Webhooks: Pre-configured webhook handlers for common Stripe events.
  • Metadata Support: Store arbitrary JSON data with every transaction.

Installation

  1. Install the package via composer:
composer require freelancernishad/laravel-stripe
  1. Publish the config and migrations:
php artisan vendor:publish --tag=stripe-config
php artisan vendor:publish --tag=stripe-migrations
  1. Run the migrations:
php artisan migrate

Configuration

Add your Stripe credentials to your .env file:

STRIPE_KEY=pk_test_...
STRIPE_SECRET=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...

Basic Usage

Checkout Session Example

use FreelancerNishad\Stripe\Services\StripeService;

public function checkout(StripeService $stripe) {
    $session = $stripe->createCheckoutSession(auth()->user(), [
        [
            'price_data' => [
                'currency' => 'usd',
                'product_data' => ['name' => 'T-shirt'],
                'unit_amount' => 2000,
            ],
            'quantity' => 1,
        ]
    ], url('/success'), url('/cancel'));

    return redirect()->to($session->url);
}

Customization

Adding Extra Fields

Use the meta_data parameter to store additional info:

$stripe->createCheckoutSession($user, $items, $successUrl, $cancelUrl, false, [
    'order_id' => 123,
    'referral' => 'friend'
]);

Overriding the Log Model

  1. Extend FreelancerNishad\Stripe\Models\StripeLog.
  2. Map your model in config/stripe.php:
'models' => [
    'log' => \App\Models\MyStripeLog::class,
],

Webhooks

The package includes a default webhook handler. Point your Stripe Webhook URL to: https://your-domain.com/v1/payments/stripe/webhook

License

The MIT License (MIT).