PHPackages                             tmyers273/laravel-stripe-billing - 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. [Payment Processing](/categories/payments)
4. /
5. tmyers273/laravel-stripe-billing

ActiveLibrary[Payment Processing](/categories/payments)

tmyers273/laravel-stripe-billing
================================

Laravel Stripe Billing

2.0.4(5y ago)3804[7 issues](https://github.com/tmyers273/laravel-stripe-billing/issues)MITPHPPHP &gt;=7.0CI failing

Since Oct 31Pushed 4y ago2 watchersCompare

[ Source](https://github.com/tmyers273/laravel-stripe-billing)[ Packagist](https://packagist.org/packages/tmyers273/laravel-stripe-billing)[ RSS](/packages/tmyers273-laravel-stripe-billing/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (8)Versions (17)Used By (0)

Laravel Stripe Billing
======================

[](#laravel-stripe-billing)

Versions
--------

[](#versions)

- 1.x - Laravel 5.1 -&gt; 5.7
- 2.x - Laravel 5.8+

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

[](#installation)

Via composer:

`composer require tmyers273/laravel-stripe-billing`

After package is installed via composer, run the following command: `php artisan vendor:publish`and then pick ` Provider: TMyers\StripeBilling\StripeBillingServiceProvider` from the displayed list. This will copy migrations files and config into your app.

Afterwards run the migrations: `php artisan migrate`

Usage
-----

[](#usage)

Add `Billable` trait to the User model.

### Stripe Secret

[](#stripe-secret)

In order to use this package you must posses a **Stripe Secret Key**. It must be stored as an environment variable `STRIPE_SECRET` and/or set in `config/services.php` under `stripe.secret`

### Models

[](#models)

- Product (this is the parent product used to control access rights - e.g. Pro, Gold, Basic, Team etc.)
- Price (this defines price and trial period e.g. pro\_monthly\_10, gold\_yearly\_9999 etc.)
- Subscription
- Card

Product model represents product access/privileges parameters Price model optionally belongs to Product model and represents price parameters

Public API
----------

[](#public-api)

### StripeBilling static helper

[](#stripebilling-static-helper)

```
StripeBilling::createTestToken();
StripeBilling::setApiKey($apiKey);
StripeBilling::setCurrency($currency);
```

#### Stripe customer

[](#stripe-customer)

```
// Create a customer from token (new default card will be created)
$user->retrieveOrCreateStripeCustomer($token);
$user->retrieveStripeCustomer($token);
```

### Subscriptions

[](#subscriptions)

By default users can have multiple subscriptions. But this can be changed by setting `unique_active_subscription` to `true` in `config/stripe-billing.php`

##### Check subscription

[](#check-subscription)

```
// Check if user is already subscribed to product
// Accepts Price object, Product object, string (name of Product or Price) e.g. basic, basic_yearly_90
$user->isSubscribedTo($product);

// Check if user is subscribed to a specific $price
$user->isSubscribedStrictlyTo($price);

// true or false
$user->hasActiveSubscriptions();

// or for subscription
// accepts Price|Product|string (name of Product or Price)
$subscription->isFor($product);
```

##### Retrieve subscriptions and chain methods

[](#retrieve-subscriptions-and-chain-methods)

```
$user->getSubscriptionFor($product)->isActive();
$user->getSubscriptionFor('basic-monthly-10')->cancelNow();

// in the vast majority of cases your users will be only allowed
// to have one active subscription, so use this method when applicable
$user->getFirstActiveSubscription();
```

##### Create products and subscriptions

[](#create-products-and-subscriptions)

```
// Create the plans
$bronzePlan= Plan::create([
    'description' => 'Bronze Plan',
    'name' => 'bronze',
]);

// Create the Price
$bronzeMonthly = Price::create([
    'product_id' => $bronzePlan->id, // parent plan id
    'description' => 'Monthly Bronze Plan',
    'name' => 'bronze_monthly_50.00',
    'interval' => 'month',
    'stripe_product_id' => 'bronze_monthly', // this needs to be created in Stripe first
    'price' => 5000,
    'active' => true,
]);

// Accepts Plan object or string representing Plan name e.g. bronze_monthly_50.00
$user->subscribeTo($bronzeMonthly); // for already existing stripe customer
$user->subscribeTo($bronzeMonthly, $token); // for user without created customer
```

##### List subscriptions

[](#list-subscriptions)

```
$user->subscriptions;
$user->activeSubscriptions;
```

##### Cancel subscriptions

[](#cancel-subscriptions)

```
$subscription->cancelAtPeriodEnd();
$subscription->cancelNow();
```

##### Resuming subscription

[](#resuming-subscription)

Resuming subscription is possible only as long as it is on grace period

```
$subscription->resume();
```

##### Extend trial

[](#extend-trial)

Extending the trial is done in two ways.

```
$subscription->trialEndAt($unixTimestamp);
```

```
$days = 10;
$subscription->addDaysToTrial($days);
```

**This will default prorate to false**

#### Changing plan

[](#changing-plan)

```
// Accepts Plan object
$subscription->changeTo($basicMonthlyPlan);
```

#### Subscription scopes

[](#subscription-scopes)

```
Subscription::active()->get(); // get all active subscriptions
Subscription::canceledAndArchived()->get(); // get all canceled and non active subscriptions
```

Charges and credit cards
------------------------

[](#charges-and-credit-cards)

#### Default card

[](#default-card)

```
$user->defaultCard;
```

#### Add card from token

[](#add-card-from-token)

```
$card = $user->addCardFromToken($token);
```

This will create a stripe customer if user does not have one assigned yet. The default source of the new Stripe customer will be used to create the default credit card for the user, which will be used by default for future transactions.

If Stripe customer already exists for the user and the user already has a default card, the new card will be added as a new source for the users's Stripe Customer and a new Card record will be created in the local database.

#### Set another card as default

[](#set-another-card-as-default)

```
$user->setCardAsDefault($card);
```

That method by default takes `\TMyers\StripeBilling\Models\Card::class` as an argument and makes the card the default card for that user. User's corresponding Stripe Customer's default source also gets updated.

#### Check if user already has a default card assigned

[](#check-if-user-already-has-a-default-card-assigned)

```
$user->hasDefaultCard(); //true or false
```

Or you can pass an instance of `\TMyers\StripeBilling\Models\Card::class` to verify if that particular card is the default one for the user:

```
$user->hasDefaultCard($card); //true or false
```

#### Remove card

[](#remove-card)

```
$user->removeCard($card);
```

#### Card helper methods

[](#card-helper-methods)

```
$card->isOwnedBy($user); // true or false
$card->isDefault(); // true or false
```

### Single charges

[](#single-charges)

When user already has a default card assigned:

```
$user->charge(2500); // Charge 25$
```

#### Charge by token

[](#charge-by-token)

```
$user->chargeByToken(1799, 'some token from stripe.js'); // Charge 17.99$
```

#### Charge via non-default card

[](#charge-via-non-default-card)

```
/**
* @param int $amount
* @param Card $card
* @param array $params
* @return mixed
*/
$user->chargeCard(1799, $card); // Charge 17.99$
```

### Coupons

[](#coupons)

Coupon can be either a Stripe/Coupon or a string coupon ID of an existing coupon

```
$user->applyCoupon($coupon);
```

### Middleware

[](#middleware)

Register in HTTP `Kernel.php`

```
'subscription' => \TMyers\StripeBilling\Middleware\SubscriptionMiddleware::class,
```

The middleware can take parameters like so: `subscription:basic,pro` - that means that users with any of these subscriptions can pass the middleware. When used *without parameters* it will just look for any active including `onTrial` or `OnGracePeriod` subscriptions

### Blade directives

[](#blade-directives)

**subscribed** directive determines if user is logged in and subscribed

```
@subscribed
// do something
@endsubscribed
```

**unless\_subscribed** directive determines if user is logged in and not subscribed

```
@unless_subscribed
// do something
@endunless_subscribed
```

### Config

[](#config)

```
'models' => [
        'owner' => 'App\User',
        'subscription' => \TMyers\StripeBilling\Models\Subscription::class,
        'pricing_plan' => \TMyers\StripeBilling\Models\Price::class,
        'plan' => \TMyers\StripeBilling\Models\Plan::class,
        'card' => \TMyers\StripeBilling\Models\Card::class,
    ],

    'tables' => [
        'owner' => 'users',
        'subscriptions' => 'subscriptions',
        'pricing_plans' => 'pricing_plans',
        'plans' => 'plans',
        'cards' => 'cards',
    ],

    'unique_active_subscription' => false,
];
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 71% 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 ~73 days

Recently: every ~103 days

Total

15

Last Release

1729d ago

Major Versions

1.8 → 2.02020-06-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d1e0537d67c9c029b807bd76d4abd3818ebcd7ca84101b106f914fecd5510bd?d=identicon)[tmyers273](/maintainers/tmyers273)

---

Top Contributors

[![denismitr](https://avatars.githubusercontent.com/u/16356446?v=4)](https://github.com/denismitr "denismitr (93 commits)")[![tmyers273](https://avatars.githubusercontent.com/u/10467493?v=4)](https://github.com/tmyers273 "tmyers273 (38 commits)")

---

Tags

laravelstripebillingpayments

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tmyers273-laravel-stripe-billing/health.svg)

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

###  Alternatives

[laravel/cashier

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

2.5k25.9M107](/packages/laravel-cashier)[lanos/laravel-cashier-stripe-connect

Adds Stripe Connect functionality to Laravel's main billing package, Cashier.

84138.9k](/packages/lanos-laravel-cashier-stripe-connect)[simonhamp/laravel-stripe-connect

1343.1k](/packages/simonhamp-laravel-stripe-connect)[mmanos/laravel-billing

A billing package for Laravel 4.

451.3k](/packages/mmanos-laravel-billing)[asciisd/knet

Knet package is provides an expressive, fluent interface to KNet's payment services.

141.1k](/packages/asciisd-knet)

PHPackages © 2026

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