celtyvsk/cashier-connect

Laravel Cashier Connect add support for Stripe Connect to Laravel Cashier.


Keywords
stripe, laravel, billing
License
MIT

Documentation

Introduction

Laravel Cashier Connect add support for Stripe Connect Subscription to laravel Cashier (based on v10.7.1).

Documentation

  1. Install the package
composer require "oixan/cashier-connect"
  1. Follow the instructions of cashier in the official guide The installations process is the same.

  2. Add the Trait to User model use Billable from use Laravel\CashierConnect\Billable

Create your .env file

You will need to set the Stripe Testing Secret env variable before your vendor/bin/phpunit call in order to run the Cashier Connect tests:

STRIPE_SECRET=<your Stripe secret>

Please note that due to the fact that actual API requests against Stripe are being made, these tests take a few minutes to run.

How this package work.

All the default cashier methods remain the same if not direct support by CashierConnect.

This package assume you created yours Stripe Accounts directly or through API then assign the Account id to user->stripe_account_id.

Every user can be a customers or an Stripe Account.

Basic Method Added to User model

$user = user from db or wathever;
$user->getStripeAccount(); // Check if every cashier call will go to Stripe Account
$user->setStripeAccount($userAccount); // Pass a User instance then every cashier call will go to Stripe Account
$user->unsetStripeAccount; // Remove the userAccount, cashier will work with default setting.
$user->pauseStripeAccount // Pause the userAccount, cashier will work with default setting.
$user->resumeStripeAccount  // Resume the previous userAccount, cashier call will go to Stripe Account

*** IMPORTANT *** any further call after setStripeAccount() will be direct to Stripe Account so remember to call unsetStripeAccount() if needed.

Methods Supported (Version 0.3.0).

The setStripeAccount($userAccount) method make every subsequent call goes from your Platform to Stripe Account passed like parameter. If you need to change the userAccount or pause the StripeAccount call see the previous section.

Creating Subscriptions

   $user->setStripeAccount($userAccount)->newSubscription('main', 'plan_id')->create("pm_card_visa");

Add user detail

$user->newSubscription('main', 'monthly')->create($token, [
  'email' => $email,
]);

Checking Subscription Status

if ($user->subscribed('main')) {
   //
}

Subscribe to plan

if ($user->subscribedToPlan('monthly', 'main')) {
  //
}

Reccuring check

if ($user->subscription('main')->recurring()) {
  //
}

Cancelled Subscription Status

if ($user->subscription('main')->cancelled()) {
  //
}

if ($user->subscription('main')->onGracePeriod()) {
  //
}

if ($user->subscription('main')->ended()) {
  //
}

Changing Plans

$user->subscription('main')->swap('provider-plan-id');

Subscription Quantity

$user->subscription('main')->incrementQuantity();

// Add five to the subscription's current quantity...
$user->subscription('main')->incrementQuantity(5);

$user->subscription('main')->decrementQuantity();

// Subtract five to the subscription's current quantity...
$user->subscription('main')->decrementQuantity(5);

Subscription Ancor Date

$user->newSubscription('main', 'premium')
     ->anchorBillingCycleOn( Carbon::parse('first day of next month'))
     ->create($token);

Subscription Trials

$user->newSubscription('main', 'monthly')
            ->trialDays(10)
            ->create($token);

$user->newSubscription('main', 'monthly')
        ->trialUntil(Carbon::now()->addDays(10))
        ->create($token);

$user->onTrial('main')

$user->subscription('main')->onTrial()

Cancelling Subscriptions

$user->subscription('main')->cancel();

if ($user->subscription('main')->onGracePeriod()) {
    //
}

$user->subscription('main')->cancelNow();

Resume Subscriptions

$user->subscription('main')->resume();

*All cashier methods not in list are not tested to work with Stripe Account

More.

If you want set an application fee set on user model

public function applicationFeePercent()
{
    return 40;
}

The Web hook from stripe connect have different secret key. Set

services.stripe.webhook.connect_secret

to allow cashier connect to accept webhook from stripe connect.

License

Laravel Cashier Connect is open-sourced software licensed under the MIT license.