Skip to content
Coderity Wallet extends Laravel Cashier allowing users to have multiple credit cards with multiple subscriptions.
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.

Coderity Wallet


Coderity Wallet extends Laravel Cashier allowing users to have multiple credit cards with multiple subscriptions, along with the ability to charge different cards as needed.

Coderity Wallet still contains all the features of Laravel Cashier, with extra methods available!

Coderity Wallet currently only works with Stripe.


Wallet follows closely with the Laravel Cashier Installation Guide - with some subtle differences.


First, add the Wallet package for Stripe to your dependencies:

composer require "coderity/wallet":"~1.0"

Service Provider

If your version of Laravel is version 5.5 or greater, you can skip the following step.

Next, register the Coderity\Wallet\WalletServiceProvider ervice provider in your config/app.php configuration file.

Database Migrations

Before using Wallet, we'll also need to prepare the database. We need to add several columns to your users table and create a new subscriptions table to hold all of our customer's subscriptions:

Schema::table('users', function ($table) {

Schema::create('subscriptions', function ($table) {

Once the migrations have been created, run the migrate Artisan command.

Billable Model

Next, add the Billable trait to your model definition. This trait provides various methods to allow you to perform common billing tasks, such as creating subscriptions, applying coupons, and updating credit card information:

use Coderity\Wallet\Billable;

class User extends Authenticatable
    use Billable;

API Keys

Finally, you should configure your Stripe key in your services.php configuration file. You can retrieve your Stripe API keys from the Stripe control panel:

'stripe' => [
    'model'  => App\User::class,
    'key' => env('STRIPE_KEY'),
    'secret' => env('STRIPE_SECRET'),


You should be familiar with Laravel Cashier Installation Guide to see all of the methods and features available.

The following highlights the specific methods of Coderity Wallet.

Adding a Credit Card

You can add a credit card easily for a user by passing the addCard() method:

$user = User::find(1);

    'cardNumber' => 4242424242424242,
    'expiryMonth' => 12,
    'expiryYear' => 2021,
    'cvc' => 123

If you would like to set the new card as the default card, you can pass true as the second parameter:

    'cardNumber' => 4242424242424242,
    'expiryMonth' => 12,
    'expiryYear' => 2021,
    'cvc' => 123
], true);

If you already have a token generated, you can also pass a token as the first parameter:


Generate a Token

If you need to generate a token or even validate a credit card, use the generateToken() method:

$result = $user->generateToken([
    'cardNumber' => 4242424242424242,
    'expiryMonth' => 12,
    'expiryYear' => 2021,
    'cvc' => 123

$token = $result['token'];

Get all Cards

You can see all the cards for a user by passing the cards() method:


An array of cards will be returned. Note, the card ID ($card->id) will be a prefixed with card_, e.g. card_1BGBDfLBsAc3LtzZbIEQ8xpF. This is the ID you will need to use the card in other methods.

Get a Card

To get a specific card, you can pass the card ID to the getCard() method:


Charging with a Specific Card

The charge() method works the same Laravel Cashier with the following additional parameter:

$this->user->charge(100, [
     'cardId' => $cardId

This parameter will charge the specific card with $100 in this case.

Charging without a Subscription

Coderity Wallet also makes doing simple charging very easy. By passing two methods, you can easily make a one off charge (without needing the user to have signed up for a subscription):

$card = $user->addCard([
    'cardNumber' => 4242424242424242,
    'expiryMonth' => 12,
    'expiryYear' => 2021,
    'cvc' => 123

$this->user->charge(100, [
     'cardId' => $card['cardId']

Creating a Subscription with a Specific Card

You can create a subscription with a specific card, by including the useCard() method, before calling create() when adding a subscription.

$this->user->newSubscription('main', 'monthly-10-1')

Note that the currently functionality will actually set this card as the default card for all the user's subscriptions - this is how Stripe currently handles multiple subscriptions for a customer.

Update Default Card

Of course, you can update the default card at any stage by using the updateDefaultCard() method:


Get Default Card

If you want to get the users default card, simple use the getDefaultCard() method:

$card = $user->getDefaultCard();

Delete a Specific Card

You can delete a specific card by passing the card ID to the deleteCard() method:


For more use cases, please refer to the Unit Tests.

Running Wallet's Tests Locally

You will need to set the following details locally and on your Stripe account in order to run the Wallet unit tests:






* monthly-10-1 ($10)


Please read the Contributing Guide if you would like to make any suggestions for improvements to Coderity Wallet.


Coderity Wallet is open-sourced software licensed under the MIT license

You can’t perform that action at this time.