PHPackages                             showapp/laravel-chargebee - 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. showapp/laravel-chargebee

ActiveLibrary[Payment Processing](/categories/payments)

showapp/laravel-chargebee
=========================

A Laravel package which provides an easy way to handle billing and subscriptions.

v0.4(6y ago)0631MITPHPPHP ~7.3

Since Jul 11Pushed 3y agoCompare

[ Source](https://github.com/ShowappSoftware/LaravelChargebee)[ Packagist](https://packagist.org/packages/showapp/laravel-chargebee)[ Docs](https://github.com/TijmenWierenga/LaravelChargebee)[ RSS](/packages/showapp-laravel-chargebee/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

LaravelChargebee
================

[](#laravelchargebee)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a92b6544be6919ace68c022fccd6b2a478bbbec7558a9af223b6c14077f4559d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74696a6d656e2d77696572656e67612f6c61726176656c2d6368617267656265652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tijmen-wierenga/laravel-chargebee)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/12df67b3b7a79de522f395e53845a5ecab4ade1efc2adb33aee9b5b4328bc1c1/68747470733a2f2f7472617669732d63692e6f72672f54696a6d656e57696572656e67612f4c61726176656c4368617267656265652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/TijmenWierenga/LaravelChargebee)[![Total Downloads](https://camo.githubusercontent.com/fd3fc4b73d216de28140da86fc6eb74ae9fc7e723082eff3f5da9ed8dc9b042c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74696a6d656e2d77696572656e67612f6c61726176656c2d6368617267656265652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tijmen-wierenga/laravel-chargebee)

A Laravel package which provides an easy way to handle billing and subscriptions by making use of [Chargebee](https://www.chargebee.com)'s subscription software.

Introduction
------------

[](#introduction)

LaravelChargebee (LC) is a membership management tool which handles your billing and recurring subscriptions with minimal effort. This easy-to-install package will cover the most important features for a successful subscription system:

- Create recurring subscriptions in a very flexible way:
    - Add add-ons, coupons or even one-time charges
- Change existing subscriptions
- Cancel subscriptions
- All of this through a fluent API or by using Chargebee's secure hosted pages.

Install
-------

[](#install)

If you haven't got an account on Chargebee, create one [here](https://www.chargebee.com/trial-signup.html).

Then require the package into your project via Composer:

```
$ composer require tijmen-wierenga/laravel-chargebee
```

Next, register the service provider in `config/app.php`:

```
['providers'] => [
    TijmenWierenga\LaravelChargebee\ChargebeeServiceProvider::class
]
```

Add the LaravelChargebee traits to your [model](https://laravel.com/docs/master/eloquent#defining-models):

```
use TijmenWierenga\LaravelChargebee\Billable;
use TijmenWierenga\LaravelChargebee\HandlesWebhooks;

class User extends Eloquent {

    use Billable, HandlesWebhooks;

}
```

If you want to use the package's routes for handling webhooks, make sure you place the service provider before the Route Service Prodiver (`App\Providers\RouteServiceProvider::class`).

Next, run the following command in your terminal:

```
php artisan chargebee:install
```

This will copy and run the migrations necessary for the package to work. It also copies the configuration file to your config path.

There are also a few environment variables that need to be added to the `.env`-file:

```
CHARGEBEE_SITE=your-chargebee-site
CHARGEBEE_KEY=your-chargebee-token

```

If you want to use a different payment gateway, define your payment gateway details in the `.env`-file:

```
CHARGEBEE_GATEWAY=stripe

```

Usage
-----

[](#usage)

### Creating a new subscription:

[](#creating-a-new-subscription)

You can create subscriptions in multiple ways:

- Through [Chargebee's Hosted Page](https://www.chargebee.com/docs/hp_overview.html)
- Through [Stripe](https://www.chargebee.com/docs/stripe.html)/[Braintree](https://www.chargebee.com/docs/braintree.html)'s Javascript library

#### Create a subscription with Chargebee's Hosted Page

[](#create-a-subscription-with-chargebees-hosted-page)

Retrieve a hosted page URL:

```
$url = $user->subscription($planId)->withAddon($addonId)->getCheckoutUrl($embed);
```

The `$embed` variable is a boolean value which describes whether or not you want to embed the hosted page as an i-frame.

You can now choose between redirecting the user to the hosted page, or send it to a view where you can render it:

**Redirect**

```
return redirect($url);
```

**Return it as a variable in your view**

```
return view('subscribe')->with(compact($url));
```

Next, render it in your view:

```

```

You can fully customize your hosted page on Chargebee, an example is shown below:

[![Chargebee's Hosted Page example](https://camo.githubusercontent.com/d8c166bd869100cf86cd0f018466bf186664d5f920796211f7ce073dedbb2c9f/68747470733a2f2f7333322e706f7374696d672e6f72672f34626b3030786d66702f53637265656e5f53686f745f323031365f30375f31375f61745f31325f33375f33342e706e67)](https://camo.githubusercontent.com/d8c166bd869100cf86cd0f018466bf186664d5f920796211f7ce073dedbb2c9f/68747470733a2f2f7333322e706f7374696d672e6f72672f34626b3030786d66702f53637265656e5f53686f745f323031365f30375f31375f61745f31325f33375f33342e706e67)

On success, Chargebee will redirect to their own success page by default, but to register the subscription in our own application, we need to redirect back to our application. To define this redirect, setup a callback route:

```
    // Define your callback URI's here
    'redirect' => [
        'success' => 'http://chargebee.app/success',
        'cancelled' => null,
    ],
```

Add the route and make a call to the `registerFromHostedPage` method from the controller:

```
$user->subscription()->registerFromHostedPage($request->id);
```

The subscription is now registered in both Chargebee and your own application. I coulnd't be easier!

#### Example

[](#example)

##### Subscription Controller

[](#subscription-controller)

```
