PHPackages                             encoredigitalgroup/stripe - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. encoredigitalgroup/stripe

ActiveLibrary

encoredigitalgroup/stripe
=========================

v0.3.1(3mo ago)01.6k↓46.2%[4 PRs](https://github.com/EncoreDigitalGroup/laravel-stripe/pulls)BSD-3-ClausePHPPHP ^8.4CI passing

Since Oct 16Pushed 2mo agoCompare

[ Source](https://github.com/EncoreDigitalGroup/laravel-stripe)[ Packagist](https://packagist.org/packages/encoredigitalgroup/stripe)[ RSS](/packages/encoredigitalgroup-stripe/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (20)Used By (0)

Stripe for Laravel
==================

[](#stripe-for-laravel)

A clean, type-safe PHP interface for the Stripe API designed specifically for Laravel applications. This library wraps the Stripe PHP SDK with strongly-typed objects, service classes, and enums while maintaining full compatibility with Laravel 11-12.

Why This Library?
-----------------

[](#why-this-library)

The official Stripe PHP SDK, while powerful, returns dynamic objects and arrays that lack type safety and IDE support. This library bridges that gap by providing:

- **Type Safety**: All Stripe objects are represented as strongly-typed PHP classes with full PHPStan Level 8 compliance
- **Laravel Integration**: Seamless integration with Laravel's service container and testing infrastructure
- **Developer Experience**: Rich IDE autocompletion, type hints, and inline documentation
- **Consistent API**: Clean, predictable methods that follow Laravel conventions
- **Comprehensive Testing**: Built-in testing utilities that fake Stripe API calls without network requests
- **Stripe SDK Escape Hatch**: Direct access to the Stripe SDK for when you need to do something super custom, that this SDK does not directly support.

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 11 or 12
- Stripe PHP SDK ^18.0

Installation
------------

[](#installation)

Install via Composer:

```
composer require encoredigitalgroup/stripe
```

The package will automatically register its service provider with Laravel's auto-discovery feature.

Quick Start
-----------

[](#quick-start)

Configure your Stripe secret key in `.env`:

```
STRIPE_PUBLIC_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...
```

Then add the following to your `services.php` config file:

```
[
    "stripe" => [
        "public_key" => env("STRIPE_PUBLIC_KEY"),
        "secret_key" => env("STRIPE_SECRET_KEY"),
    ]
]
```

You may also configure the public and secret keys directly if you wish:

```
use EncoreDigitalGroup\Stripe\Stripe;
use Illuminate\Support\Facades\Config;

Stripe::config()->authentication->publicKey = Config::get("your.custom.config.key.public")
Stripe::config()->authentication->private = Config::get("your.custom.config.key.secret")
```

Start using the library:

```
use EncoreDigitalGroup\Stripe\Stripe;

// Create a customer
$customer = Stripe::customer()
    ->withEmail('customer@example.com')
    ->withName('John Doe')
    ->save();

echo $customer->id(); // cus_...
```

Core Features
-------------

[](#core-features)

### Type-Safe Objects with Fluent API

[](#type-safe-objects-with-fluent-api)

All objects use a fluent API pattern with private properties and chainable `withXXX()` methods. Access DTOs through the `Stripe` facade:

```
use EncoreDigitalGroup\Stripe\Stripe;
use EncoreDigitalGroup\Stripe\Objects\Product\{StripeProduct, StripePrice, StripeRecurring};
use EncoreDigitalGroup\Stripe\Objects\Support\StripeAddress;
use EncoreDigitalGroup\Stripe\Objects\Customer\StripeShipping;

// Customer with full details
$customer = Stripe::customer()
    ->withEmail('customer@example.com')
    ->withName('John Doe')
    ->withPhone('+1-555-123-4567')
    ->withAddress(
        StripeAddress::make()
            ->withLine1('123 Main St')
            ->withCity('San Francisco')
            ->withState('CA')
            ->withPostalCode('94105')
            ->withCountry('US')
    );

// Subscription with trial
$subscription = Stripe::subscription()
    ->withCustomer('cus_123')
    ->withItems(collect([
        StripeSubscriptionItem::make()
            ->withPrice('price_monthly')
            ->withQuantity(1)
    ]))
    ->withTrialEnd(now()->addDays(14));

// Webhook endpoint
$endpoint = Stripe::webhook()
    ->withUrl('https://myapp.com/webhooks/stripe')
    ->withEnabledEvents(['customer.created', 'invoice.paid'])
    ->withDescription('Production webhook');
```

### Enums for Type Safety

[](#enums-for-type-safety)

String-backed enums prevent typos and provide IDE autocompletion:

```
use EncoreDigitalGroup\Stripe\Enums\{
    RecurringInterval,
    PriceType,
    SubscriptionStatus,
    CollectionMethod,
    ProrationBehavior
};

// All enum cases use PascalCase
RecurringInterval::Month
RecurringInterval::Year
PriceType::Recurring
SubscriptionStatus::Active
```

### Comprehensive Testing Infrastructure

[](#comprehensive-testing-infrastructure)

Test your Stripe integration without making real API calls:

```
use EncoreDigitalGroup\Stripe\Stripe;
use EncoreDigitalGroup\Stripe\Support\Testing\{StripeFixtures, StripeMethod};

test('can create a customer', function () {
    // Set up fake responses
    $fake = Stripe::fake([
        StripeMethod::CustomersCreate->value => StripeFixtures::customer([
            'id' => 'cus_test123',
            'email' => 'test@example.com'
        ])
    ]);

    // Execute code under test
    $customer = Stripe::customer()
        ->withEmail('test@example.com')
        ->withName('Test Customer')
        ->save();

    // Assert results
    expect($customer->id())->toBe('cus_test123')
        ->and($fake)->toHaveCalledStripeMethod(StripeMethod::CustomersCreate);
});
```

Common Use Cases
----------------

[](#common-use-cases)

### Customer Management

[](#customer-management)

```
use EncoreDigitalGroup\Stripe\Stripe;

// Create customer
$customer = Stripe::customer()
    ->withEmail('customer@example.com')
    ->withName('Jane Smith')
    ->withMetadata(['user_id' => '12345'])
    ->save();

// Retrieve customer
$customer = Stripe::customer()->get('cus_123');

// Update customer
$updated = Stripe::customer()
    ->get('cus_123')
    ->withName('Jane Doe')
    ->save();
```

### Payment Method Management

[](#payment-method-management)

```
use EncoreDigitalGroup\Stripe\Stripe;
use EncoreDigitalGroup\Stripe\Enums\PaymentMethodType;
use EncoreDigitalGroup\Stripe\Objects\Payment\StripePaymentMethod;

// Create and attach payment method to customer
$customer = Stripe::customer()->get('cus_123');
$paymentMethod = StripePaymentMethod::make()
    ->withType(PaymentMethodType::Card);

$customer->addPaymentMethod($paymentMethod);

// List customer's payment methods
$paymentMethods = $customer->paymentMethods();

// Access individual payment method
$paymentMethod = $paymentMethods->first();
echo $paymentMethod->type()?->value; // "card"
```

### Product &amp; Price Management

[](#product--price-management)

```
use EncoreDigitalGroup\Stripe\Stripe;
use EncoreDigitalGroup\Stripe\Enums\{PriceType, RecurringInterval};

// Create product
$product = Stripe::product()
    ->withName('Premium Subscription')
    ->withDescription('Access to all premium features')
    ->save();

// Create recurring price with strongly-typed recurring object
$price = Stripe::price()
    ->withProduct($product->id())
    ->withCurrency('usd')
    ->withUnitAmount(2999) // $29.99
    ->withType(PriceType::Recurring)
    ->withRecurring(
        StripeRecurring::make()
            ->withInterval(RecurringInterval::Month)
            ->withIntervalCount(1)
    )
    ->save();
```

### Subscription Management

[](#subscription-management)

```
use EncoreDigitalGroup\Stripe\Stripe;
use EncoreDigitalGroup\Stripe\Enums\ProrationBehavior;
use EncoreDigitalGroup\Stripe\Objects\Subscription\StripeSubscriptionItem;

// Create subscription
$subscription = Stripe::subscription()
    ->withCustomer('cus_123')
    ->withItems(collect([
        StripeSubscriptionItem::make()
            ->withPrice('price_monthly')
            ->withQuantity(1)
    ]))
    ->withMetadata(['plan' => 'professional'])
    ->save();

// Update subscription (upgrade/downgrade)
$updated = Stripe::subscription()
    ->get('sub_123')
    ->withItems(collect([
        StripeSubscriptionItem::make()->withPrice('price_premium')
    ]))
    ->withProrationBehavior(ProrationBehavior::CreateProrations)
    ->save();

// Cancel subscription at period end
$canceled = Stripe::subscription()
    ->get('sub_123')
    ->cancelAtPeriodEnd()
    ->save();

// Cancel immediately
$canceled = Stripe::subscription()
    ->get('sub_123')
    ->cancelImmediately()
    ->save();

// Resume canceled subscription
$resumed = Stripe::subscription()
    ->get('sub_123')
    ->resume()
    ->save();
```

### Subscription Schedules

[](#subscription-schedules)

Plan complex subscription changes over time:

```
use EncoreDigitalGroup\Stripe\Stripe;
use EncoreDigitalGroup\Stripe\Objects\Subscription\Schedules\{StripeSubscriptionSchedule, StripePhaseItem};

// Access schedule from subscription and add phases
$subscription = Stripe::subscription()->get('sub_123');

$subscription->schedule()
    ->get()
    ->addPhase(
        StripePhaseItem::make()
            ->withPrice('price_intro')
            ->withQuantity(1)
    )
    ->addPhase(
        StripePhaseItem::make()
            ->withPrice('price_regular')
            ->withQuantity(1)
    )
    ->save();

// Or create a standalone schedule
$schedule = StripeSubscriptionSchedule::make()
    ->withCustomer('cus_123')
    ->withStartDate(now()->addDay())
    ->save();
```

### Webhook Management

[](#webhook-management)

```
use EncoreDigitalGroup\Stripe\Stripe;

// Create webhook endpoint
$endpoint = Stripe::webhook()
    ->withUrl(route('stripe.webhook'))
    ->withEnabledEvents([
        'customer.created',
        'customer.updated',
        'invoice.paid',
        'invoice.payment_failed',
        'customer.subscription.created',
        'customer.subscription.updated',
        'customer.subscription.deleted'
    ])
    ->withDescription('Production webhook')
    ->save();

// Store the webhook secret (IMPORTANT!)
$webhookSecret = $endpoint->secret();
```

### Webhook Processing

[](#webhook-processing)

#### Example Webhook Controller

[](#example-webhook-controller)

```
use EncoreDigitalGroup\Stripe\Support\StripeWebhookHelper;
use EncoreDigitalGroup\Stripe\Objects\Customer\StripeCustomer;
use Illuminate\Http\Request;

class StripeWebhookController extends Controller
{
    public function handleWebhook(Request $request)
    {
        try {
            // Verify and construct event
            $event = StripeWebhookHelper::constructEvent(
                $request->getContent(),
                StripeWebhookHelper::getSignatureHeader(),
                config('services.stripe.webhook_secret')
            );

            // Process event
            match ($event->type) {
                'customer.created' => $this->handleCustomerCreated($event),
                'invoice.paid' => $this->handleInvoicePaid($event),
                default => logger()->info('Unhandled event', ['type' => $event->type])
            };

            return response()->json(['status' => 'success']);

        } catch (\Exception $e) {
            return response()->json(['error' => 'Invalid signature'], 400);
        }
    }

    protected function handleCustomerCreated($event): void
    {
        $customer = StripeCustomer::fromStripeObject($event->data->object);

        User::updateOrCreate(
            ['stripe_customer_id' => $customer->id()],
            ['email' => $customer->email(), 'name' => $customer->name()]
        );
    }
}
```

Testing
-------

[](#testing)

Run the test suite:

```
# All tests
./vendor/bin/pest

# Specific suite
./vendor/bin/pest tests/Feature/
./vendor/bin/pest tests/Unit/

# With coverage
./vendor/bin/pest --coverage --min=80

# Stop on first failure
./vendor/bin/pest --stop-on-failure
```

Code Quality
------------

[](#code-quality)

```
# Static analysis (Level 8)
./vendor/bin/phpstan analyse

# Code style fixing
./vendor/bin/duster fix

# Refactoring
./vendor/bin/rector process
```

Contributing
------------

[](#contributing)

Contributions to this repository are governed by the Encore Digital Group [Contribution Terms](https://docs.encoredigitalgroup.com/Contributing/Terms/).

Additional details on how to contribute are available [here](https://docs.encoredigitalgroup.com/Contributing/).

License
-------

[](#license)

This repository is licensed using a modified version of the BSD 3-Clause License.

The license is available for review [here](https://docs.encoredigitalgroup.com/LicenseTerms/).

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance81

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 74.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Recently: every ~20 days

Total

12

Last Release

119d ago

PHP version history (2 changes)v0.1.0PHP ^8.3

v0.3.1PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c78c232b40f1006e496164f8cdbf70e91f945b5962b0d13aae14d076fda21e6?d=identicon)[onairmarc](/maintainers/onairmarc)

---

Top Contributors

[![onairmarc](https://avatars.githubusercontent.com/u/50760632?v=4)](https://github.com/onairmarc "onairmarc (50 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (17 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/encoredigitalgroup-stripe/health.svg)

```
[![Health](https://phpackages.com/badges/encoredigitalgroup-stripe/health.svg)](https://phpackages.com/packages/encoredigitalgroup-stripe)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
