Cara menggunakan php install numberformatter

Pada kesempatan kali ini, saya akan share sedikit tips bagi kalian yang pusing dengan bagaimana cara membuat format angka dalam rupiah? maksudnya misal kita punya sebuah angka 1000000, kalau tiadak ada titiknya kan pusing juga bacanya? maka dari itu tutorial ini saya buat agar bisa membuat sebuah format uang standar.

Sebenarnya PHP sudah menyediakan sebuah fungsi yang benar-benar bisa memecahkan masalah ini hanya dengan 1 baris skrip saja. fungsi tersebut antara lain :

<?php
$angka = 1000000;

echo number_format($angka, 0, '', '.');
?>

Dari skrip diatas terlihat kita akan mengubah angka 1000000 menjadi 1.000.000. Pasti pada bingung dengan fungsi number_format() tersebut? berikut ini penjelasan parameter apa saja yang dibutuhkan pada fungsi tersebut :

number_format(param1, param2, param3, param4)

  1. Parameter pertama (param1) diisi dengan angka yang ingin kita ubah formatnya. Pada skrip diatas saya set dengan angka 1000000.
  2. Parameter kedua (param2) diisi dengan jumlah angka desimal (angka 0) pada akhir angka. contoh dari angka 1.000.000,00 (angka yang saya beri merah itulah angka desimal). Pada skrip kita diatas, saya set angka desimalnya 0, jadi otomatis tidak ada angka desimalnya.
  3. Parameter ketiga (param3) diisi dengan tanda pemisah dengan angka desimal. Untuk tanda pemisah ini, jika dalam rupiah biasanya berupa tanda koma (,). Contoh dari angka 1.000.000,00 (koma (warna merah) itulah yang dimaksud dengna pemisah disini)
  4. Parameter keempat (param4) diisi dengan tanda pemisah angka ribuan (angka yang diset pada param1). Dalam pecahan rupiah, tanda pemisahnya adalah titik (.). Contoh 1.000.000 (titik merah itulah yang saya maksud disini)

Oke sebagai contoh biar lebih jelas soal penjelasan mengenai parameter-parameter diatas. Kita akan coba berbagai kustom parameternya. Silakan buat sebuah folder dengan nama latihan_php, lalu simpan pada folder xampp/htdocs. Kemudian buat sebuah file dengan nama format_uang.php, lalu simpan pada folder xampp/htdocs/latihan_php/. Berikut ini kodenya :

<?php
$angka = 1000000;

echo "<b>Contoh 1</b> (tanpa angka desimal dan tanda pemisah angka ribuan adalah titik)<br>";
echo "<h2>Rp. ".number_format($angka, 0, '', '.')."</h2>";

echo "<br>";
echo "<b>Contoh 2</b> (dengan 2 angka desimal, tanda pemisah angka desimal adalah koma, tanda pemisah angka ribuan adalah titik)<br>";
echo "<h2>Rp. ".number_format($angka, 2, ',', '.')."</h2>";

echo "<br>";
echo "<b>Contoh 3</b> (tanpa angka desimal dan tanda pemisah angka ribuan adalah koma)<br>";
echo "<h2>Rp. ".number_format($angka, 0, '', ',')."</h2>";
?>

Kemudian save file tadi. Lalu buka browser dan ketik localhost/latihan_php/format_uang.php. Berikut ini tampilan dari hasil kode diatas :

Cara menggunakan php install numberformatter

Sudah cukup mengerti dengan maksud dari penjelasan saya? dari 3 contoh diatas seharusnya sudah bisa lebih paham dan mengerti bagaimana cara menggunakan fungsi number_format yang disediakan PHP.

Baca Juga:

  • Tutorial Codeigniter Bahasa Indonesia Lengkap Plus Source Code
  • Tutorial PHP Bahasa Indonesia Lengkap Plus Source Code
  • Cara Mudah Membuat Form Login dengan Session PHP
  • Cara Membuat Multiple Upload Gambar dengan PHP AJAX Bootstrap


Mungkin sekian untuk catatan kali ini. Semoga bisa bermanfaat. Jika ada yang kurang dipahami, langsung tanyakan pada form komentar dibawah ini. Jangan lupa LIKE dan SHARE nya, Terimakasih banyak.

Laravel Cashier Stripe provides an expressive, fluent interface to Stripe's subscription billing services. It handles almost all of the boilerplate subscription billing code you are dreading writing. In addition to basic subscription management, Cashier can handle coupons, swapping subscription, subscription "quantities", cancellation grace periods, and even generate invoice PDFs.

Upgrading Cashier

When upgrading to a new version of Cashier, it's important that you carefully review the upgrade guide.

Warning
To prevent breaking changes, Cashier uses a fixed Stripe API version. Cashier 14 utilizes Stripe API version

php artisan vendor:publish --tag="cashier-migrations"

84. The Stripe API version will be updated on minor releases in order to make use of new Stripe features and improvements.

Installation

First, install the Cashier package for Stripe using the Composer package manager:

composer require laravel/cashier

Warning
To ensure Cashier properly handles all Stripe events, remember to .

Database Migrations

Cashier's service provider registers its own database migration directory, so remember to migrate your database after installing the package. The Cashier migrations will add several columns to your

php artisan vendor:publish --tag="cashier-migrations"

85 table as well as create a new

php artisan vendor:publish --tag="cashier-migrations"

86 table to hold all of your customer's subscriptions:

If you need to overwrite the migrations that ship with Cashier, you can publish them using the

php artisan vendor:publish --tag="cashier-migrations"

87 Artisan command:

php artisan vendor:publish --tag="cashier-migrations"

If you would like to prevent Cashier's migrations from running entirely, you may use the

php artisan vendor:publish --tag="cashier-migrations"

88 method provided by Cashier. Typically, this method should be called in the

php artisan vendor:publish --tag="cashier-migrations"

89 method of your

php artisan vendor:publish --tag="cashier-migrations"

90:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

Warning
Stripe recommends that any column used for storing Stripe identifiers should be case-sensitive. Therefore, you should ensure the column collation for the

php artisan vendor:publish --tag="cashier-migrations"

91 column is set to

php artisan vendor:publish --tag="cashier-migrations"

92 when using MySQL. More information regarding this can be found in the .

Configuration

Billable Model

Before using Cashier, add the

php artisan vendor:publish --tag="cashier-migrations"

93 trait to your billable model definition. Typically, this will be the

php artisan vendor:publish --tag="cashier-migrations"

94 model. This trait provides various methods to allow you to perform common billing tasks, such as creating subscriptions, applying coupons, and updating payment method information:

use Laravel\Cashier\Billable;

class User extends Authenticatable

Cashier assumes your billable model will be the

php artisan vendor:publish --tag="cashier-migrations"

94 class that ships with Laravel. If you wish to change this you may specify a different model via the

php artisan vendor:publish --tag="cashier-migrations"

96 method. This method should typically be called in the

php artisan vendor:publish --tag="cashier-migrations"

97 method of your

php artisan vendor:publish --tag="cashier-migrations"

90 class:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

Warning
If you're using a model other than Laravel's supplied

php artisan vendor:publish --tag="cashier-migrations"

94 model, you'll need to publish and alter the provided to match your alternative model's table name.

API Keys

Next, you should configure your Stripe API keys in your application's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

00 file. You can retrieve your Stripe API keys from the Stripe control panel:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

Warning
You should ensure that the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

01 environment variable is defined in your application's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

00 file, as this variable is used to ensure that incoming webhooks are actually from Stripe.

Currency Configuration

The default Cashier currency is United States Dollars (USD). You can change the default currency by setting the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

03 environment variable within your application's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

00 file:

In addition to configuring Cashier's currency, you may also specify a locale to be used when formatting money values for display on invoices. Internally, Cashier utilizes PHP's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

05 class to set the currency locale:

CASHIER_CURRENCY_LOCALE=nl_BE

Warning
In order to use locales other than

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

06, ensure the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

07 PHP extension is installed and configured on your server.

Tax Configuration

Thanks to Stripe Tax, it's possible to automatically calculate taxes for all invoices generated by Stripe. You can enable automatic tax calculation by invoking the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

08 method in the

php artisan vendor:publish --tag="cashier-migrations"

97 method of your application's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

10 class:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

Once tax calculation has been enabled, any new subscriptions and any one-off invoices that are generated will receive automatic tax calculation.

For this feature to work properly, your customer's billing details, such as the customer's name, address, and tax ID, need to be synced to Stripe. You may use the and methods offered by Cashier to accomplish this.

Warning
No tax is calculated for or .

Logging

Cashier allows you to specify the log channel to be used when logging fatal Stripe errors. You may specify the log channel by defining the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

11 environment variable within your application's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

00 file:

Exceptions that are generated by API calls to Stripe will be logged through your application's default log channel.

Using Custom Models

You are free to extend the models used internally by Cashier by defining your own model and extending the corresponding Cashier model:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

After defining your model, you may instruct Cashier to use your custom model via the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

13 class. Typically, you should inform Cashier about your custom models in the

php artisan vendor:publish --tag="cashier-migrations"

97 method of your application's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

10 class:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

Customers

Retrieving Customers

You can retrieve a customer by their Stripe ID using the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

16 method. This method will return an instance of the billable model:

php artisan vendor:publish --tag="cashier-migrations"

0

Creating Customers

Occasionally, you may wish to create a Stripe customer without beginning a subscription. You may accomplish this using the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

17 method:

php artisan vendor:publish --tag="cashier-migrations"

1

Once the customer has been created in Stripe, you may begin a subscription at a later date. You may provide an optional

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

18 array to pass in any additional customer creation parameters that are supported by the Stripe API:

php artisan vendor:publish --tag="cashier-migrations"

2

You may use the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

19 method if you want to return the Stripe customer object for a billable model:

php artisan vendor:publish --tag="cashier-migrations"

3

The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

20 method may be used if you would like to retrieve the Stripe customer object for a given billable model but are not sure whether the billable model is already a customer within Stripe. This method will create a new customer in Stripe if one does not already exist:

php artisan vendor:publish --tag="cashier-migrations"

4

Updating Customers

Occasionally, you may wish to update the Stripe customer directly with additional information. You may accomplish this using the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

21 method. This method accepts an array of customer update options supported by the Stripe API:

php artisan vendor:publish --tag="cashier-migrations"

5

Balances

Stripe allows you to credit or debit a customer's "balance". Later, this balance will be credited or debited on new invoices. To check the customer's total balance you may use the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

22 method that is available on your billable model. The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

22 method will return a formatted string representation of the balance in the customer's currency:

php artisan vendor:publish --tag="cashier-migrations"

6

To credit a customer's balance, you may provide a value to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

24 method. If you wish, you may also provide a description:

php artisan vendor:publish --tag="cashier-migrations"

7

Providing a value to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

25 method will debit the customer's balance:

php artisan vendor:publish --tag="cashier-migrations"

8

The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

26 method will create new customer balance transactions for the customer. You may retrieve these transaction records using the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

27 method, which may be useful in order to provide a log of credits and debits for the customer to review:

php artisan vendor:publish --tag="cashier-migrations"

9

Tax IDs

Cashier offers an easy way to manage a customer's tax IDs. For example, the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

28 method may be used to retrieve all of the tax IDs that are assigned to a customer as a collection:

You can also retrieve a specific tax ID for a customer by its identifier:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

0

You may create a new Tax ID by providing a valid and value to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

29 method:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

1

The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

29 method will immediately add the VAT ID to the customer's account. ; however, this is an asynchronous process. You can be notified of verification updates by subscribing to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

31 webhook event and inspecting . For more information on handling webhooks, please consult the .

You may delete a tax ID using the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

33 method:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

2

Syncing Customer Data With Stripe

Typically, when your application's users update their name, email address, or other information that is also stored by Stripe, you should inform Stripe of the updates. By doing so, Stripe's copy of the information will be in sync with your application's.

To automate this, you may define an event listener on your billable model that reacts to the model's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

34 event. Then, within your event listener, you may invoke the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

35 method on the model:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

3

Now, every time your customer model is updated, its information will be synced with Stripe. For convenience, Cashier will automatically sync your customer's information with Stripe on the initial creation of the customer.

You may customize the columns used for syncing customer information to Stripe by overriding a variety of methods provided by Cashier. For example, you may override the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

36 method to customize the attribute that should be considered the customer's "name" when Cashier syncs customer information to Stripe:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

4

Similarly, you may override the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

37,

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

38,

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

39, and

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

40 methods. These methods will sync information to their corresponding customer parameters when updating the Stripe customer object. If you wish to take total control over the customer information sync process, you may override the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

35 method.

Billing Portal

Stripe offers an easy way to set up a billing portal so that your customer can manage their subscription, payment methods, and view their billing history. You can redirect your users to the billing portal by invoking the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

42 method on the billable model from a controller or route:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

5

By default, when the user is finished managing their subscription, they will be able to return to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

43 route of your application via a link within the Stripe billing portal. You may provide a custom URL that the user should return to by passing the URL as an argument to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

42 method:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

6

If you would like to generate the URL to the billing portal without generating an HTTP redirect response, you may invoke the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

45 method:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

7

Payment Methods

Storing Payment Methods

In order to create subscriptions or perform "one-off" charges with Stripe, you will need to store a payment method and retrieve its identifier from Stripe. The approach used to accomplish this differs based on whether you plan to use the payment method for subscriptions or single charges, so we will examine both below.

Payment Methods For Subscriptions

When storing a customer's credit card information for future use by a subscription, the Stripe "Setup Intents" API must be used to securely gather the customer's payment method details. A "Setup Intent" indicates to Stripe the intention to charge a customer's payment method. Cashier's

php artisan vendor:publish --tag="cashier-migrations"

93 trait includes the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

47 method to easily create a new Setup Intent. You should invoke this method from the route or controller that will render the form which gathers your customer's payment method details:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

8

After you have created the Setup Intent and passed it to the view, you should attach its secret to the element that will gather the payment method. For example, consider this "update payment method" form:

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

9

Next, the Stripe.js library may be used to attach a Stripe Element to the form and securely gather the customer's payment details:

use Laravel\Cashier\Billable;

class User extends Authenticatable

0

Next, the card can be verified and a secure "payment method identifier" can be retrieved from Stripe using Stripe's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

48 method:

use Laravel\Cashier\Billable;

class User extends Authenticatable

1

After the card has been verified by Stripe, you may pass the resulting

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

49 identifier to your Laravel application, where it can be attached to the customer. The payment method can either be or . You can also immediately use the payment method identifier to .

Note
If you would like more information about Setup Intents and gathering customer payment details please .

Payment Methods For Single Charges

Of course, when making a single charge against a customer's payment method, we will only need to use a payment method identifier once. Due to Stripe limitations, you may not use the stored default payment method of a customer for single charges. You must allow the customer to enter their payment method details using the Stripe.js library. For example, consider the following form:

use Laravel\Cashier\Billable;

class User extends Authenticatable

2

After defining such a form, the Stripe.js library may be used to attach a Stripe Element to the form and securely gather the customer's payment details:

use Laravel\Cashier\Billable;

class User extends Authenticatable

0

Next, the card can be verified and a secure "payment method identifier" can be retrieved from Stripe using :

use Laravel\Cashier\Billable;

class User extends Authenticatable

4

If the card is verified successfully, you may pass the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

51 to your Laravel application and process a .

Retrieving Payment Methods

The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

52 method on the billable model instance returns a collection of

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

53 instances:

use Laravel\Cashier\Billable;

class User extends Authenticatable

5

By default, this method will return payment methods of the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

54 type. To retrieve payment methods of a different type, you may pass the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

55 as an argument to the method:

use Laravel\Cashier\Billable;

class User extends Authenticatable

6

To retrieve the customer's default payment method, the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

56 method may be used:

use Laravel\Cashier\Billable;

class User extends Authenticatable

7

You can retrieve a specific payment method that is attached to the billable model using the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

57 method:

use Laravel\Cashier\Billable;

class User extends Authenticatable

8

Determining If A User Has A Payment Method

To determine if a billable model has a default payment method attached to their account, invoke the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

58 method:

use Laravel\Cashier\Billable;

class User extends Authenticatable

9

You may use the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

59 method to determine if a billable model has at least one payment method attached to their account:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

0

This method will determine if the billable model has payment methods of the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

54 type. To determine if a payment method of another type exists for the model, you may pass the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

55 as an argument to the method:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

1

Updating The Default Payment Method

The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

62 method may be used to update a customer's default payment method information. This method accepts a Stripe payment method identifier and will assign the new payment method as the default billing payment method:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

2

To sync your default payment method information with the customer's default payment method information in Stripe, you may use the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

63 method:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

3

Warning
The default payment method on a customer can only be used for invoicing and creating new subscriptions. Due to limitations imposed by Stripe, it may not be used for single charges.

Adding Payment Methods

To add a new payment method, you may call the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

64 method on the billable model, passing the payment method identifier:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

4

Note
To learn how to retrieve payment method identifiers please review the .

Deleting Payment Methods

To delete a payment method, you may call the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

65 method on the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

53 instance you wish to delete:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

5

The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

67 method will delete a specific payment method from the billable model:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

6

The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

68 method will delete all of the payment method information for the billable model:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

7

By default, this method will delete payment methods of the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

54 type. To delete payment methods of a different type you can pass the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

55 as an argument to the method:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

8

Warning
If a user has an active subscription, your application should not allow them to delete their default payment method.

Subscriptions

Subscriptions provide a way to set up recurring payments for your customers. Stripe subscriptions managed by Cashier provide support for multiple subscription prices, subscription quantities, trials, and more.

Creating Subscriptions

To create a subscription, first retrieve an instance of your billable model, which typically will be an instance of

php artisan vendor:publish --tag="cashier-migrations"

94. Once you have retrieved the model instance, you may use the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

72 method to create the model's subscription:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

9

The first argument passed to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

72 method should be the internal name of the subscription. If your application only offers a single subscription, you might call this

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

74 or

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

75. This subscription name is only for internal application usage and is not meant to be shown to users. In addition, it should not contain spaces and it should never be changed after creating the subscription. The second argument is the specific price the user is subscribing to. This value should correspond to the price's identifier in Stripe.

The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

76 method, which accepts or Stripe

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

77 object, will begin the subscription as well as update your database with the billable model's Stripe customer ID and other relevant billing information.

Warning
Passing a payment method identifier directly to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

76 subscription method will also automatically add it to the user's stored payment methods.

Collecting Recurring Payments Via Invoice Emails

Instead of collecting a customer's recurring payments automatically, you may instruct Stripe to email an invoice to the customer each time their recurring payment is due. Then, the customer may manually pay the invoice once they receive it. The customer does not need to provide a payment method up front when collecting recurring payments via invoices:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

0

The amount of time a customer has to pay their invoice before their subscription is cancelled is determined by the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

79 option. By default, this is 30 days; however, you may provide a specific value for this option if you wish:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

1

Quantities

If you would like to set a specific quantity for the price when creating the subscription, you should invoke the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

80 method on the subscription builder before creating the subscription:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

2

Additional Details

If you would like to specify additional customer or subscription options supported by Stripe, you may do so by passing them as the second and third arguments to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

76 method:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

3

Coupons

If you would like to apply a coupon when creating the subscription, you may use the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

82 method:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

2

Or, if you would like to apply a Stripe promotion code, you may use the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

83 method:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

5

The given promotion code ID should be the Stripe API ID assigned to the promotion code and not the customer facing promotion code. If you need to find a promotion code ID based on a given customer facing promotion code, you may use the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

84 method:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

6

In the example above, the returned

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

85 object is an instance of

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

86. This class decorates an underlying

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

87 object. You can retrieve the coupon related to the promotion code by invoking the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

88 method:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

7

The coupon instance allows you to determine the discount amount and whether the coupon represents a fixed discount or percentage based discount:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

8

You can also retrieve the discounts that are currently applied to a customer or subscription:

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

9

The returned

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

89 instances decorate an underlying

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

90 object instance. You may retrieve the coupon related to this discount by invoking the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

88 method:

CASHIER_CURRENCY_LOCALE=nl_BE

0

If you would like to apply a new coupon or promotion code to a customer or subscription, you may do so via the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

92 or

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

93 methods:

CASHIER_CURRENCY_LOCALE=nl_BE

1

Remember, you should use the Stripe API ID assigned to the promotion code and not the customer facing promotion code. Only one coupon or promotion code can be applied to a customer or subscription at a given time.

For more info on this subject, please consult the Stripe documentation regarding coupons and promotion codes.

Adding Subscriptions

If you would like to add a subscription to a customer who already has a default payment method you may invoke the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

94 method on the subscription builder:

CASHIER_CURRENCY_LOCALE=nl_BE

2

Creating Subscriptions From The Stripe Dashboard

You may also create subscriptions from the Stripe dashboard itself. When doing so, Cashier will sync newly added subscriptions and assign them a name of

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

74. To customize the subscription name that is assigned to dashboard created subscriptions, and overwrite the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

97 method.

In addition, you may only create one type of subscription via the Stripe dashboard. If your application offers multiple subscriptions that use different names, only one type of subscription may be added through the Stripe dashboard.

Finally, you should always make sure to only add one active subscription per type of subscription offered by your application. If a customer has two

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

74 subscriptions, only the most recently added subscription will be used by Cashier even though both would be synced with your application's database.

Checking Subscription Status

Once a customer is subscribed to your application, you may easily check their subscription status using a variety of convenient methods. First, the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

99 method returns

use Laravel\Cashier\Billable;

class User extends Authenticatable

00 if the customer has an active subscription, even if the subscription is currently within its trial period. The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

99 method accepts the name of the subscription as its first argument:

CASHIER_CURRENCY_LOCALE=nl_BE

3

The

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

99 method also makes a great candidate for a route middleware, allowing you to filter access to routes and controllers based on the user's subscription status:

CASHIER_CURRENCY_LOCALE=nl_BE

4

If you would like to determine if a user is still within their trial period, you may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

03 method. This method can be useful for determining if you should display a warning to the user that they are still on their trial period:

CASHIER_CURRENCY_LOCALE=nl_BE

5

The

use Laravel\Cashier\Billable;

class User extends Authenticatable

04 method may be used to determine if the user is subscribed to a given product based on a given Stripe product's identifier. In Stripe, products are collections of prices. In this example, we will determine if the user's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

74 subscription is actively subscribed to the application's "premium" product. The given Stripe product identifier should correspond to one of your product's identifiers in the Stripe dashboard:

CASHIER_CURRENCY_LOCALE=nl_BE

6

By passing an array to the

use Laravel\Cashier\Billable;

class User extends Authenticatable

04 method, you may determine if the user's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

74 subscription is actively subscribed to the application's "basic" or "premium" product:

CASHIER_CURRENCY_LOCALE=nl_BE

7

The

use Laravel\Cashier\Billable;

class User extends Authenticatable

08 method may be used to determine if a customer's subscription corresponds to a given price ID:

CASHIER_CURRENCY_LOCALE=nl_BE

8

The

use Laravel\Cashier\Billable;

class User extends Authenticatable

09 method may be used to determine if the user is currently subscribed and is no longer within their trial period:

CASHIER_CURRENCY_LOCALE=nl_BE

9

Warning
If a user has two subscriptions with the same name, the most recent subscription will always be returned by the

use Laravel\Cashier\Billable;

class User extends Authenticatable

10 method. For example, a user might have two subscription records named

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

74; however, one of the subscriptions may be an old, expired subscription, while the other is the current, active subscription. The most recent subscription will always be returned while older subscriptions are kept in the database for historical review.

Canceled Subscription Status

To determine if the user was once an active subscriber but has canceled their subscription, you may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

12 method:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

0

You may also determine if a user has canceled their subscription but are still on their "grace period" until the subscription fully expires. For example, if a user cancels a subscription on March 5th that was originally scheduled to expire on March 10th, the user is on their "grace period" until March 10th. Note that the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

99 method still returns

use Laravel\Cashier\Billable;

class User extends Authenticatable

00 during this time:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

1

To determine if the user has canceled their subscription and is no longer within their "grace period", you may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

15 method:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

2

Incomplete and Past Due Status

If a subscription requires a secondary payment action after creation the subscription will be marked as

use Laravel\Cashier\Billable;

class User extends Authenticatable

16. Subscription statuses are stored in the

use Laravel\Cashier\Billable;

class User extends Authenticatable

17 column of Cashier's

php artisan vendor:publish --tag="cashier-migrations"

86 database table.

Similarly, if a secondary payment action is required when swapping prices the subscription will be marked as

use Laravel\Cashier\Billable;

class User extends Authenticatable

19. When your subscription is in either of these states it will not be active until the customer has confirmed their payment. Determining if a subscription has an incomplete payment may be accomplished using the

use Laravel\Cashier\Billable;

class User extends Authenticatable

20 method on the billable model or a subscription instance:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

3

When a subscription has an incomplete payment, you should direct the user to Cashier's payment confirmation page, passing the

use Laravel\Cashier\Billable;

class User extends Authenticatable

21 identifier. You may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

21 method available on subscription instance to retrieve this identifier:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

4

If you would like the subscription to still be considered active when it's in a

use Laravel\Cashier\Billable;

class User extends Authenticatable

19 or

use Laravel\Cashier\Billable;

class User extends Authenticatable

16 state, you may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

25 and

use Laravel\Cashier\Billable;

class User extends Authenticatable

26 methods provided by Cashier. Typically, these methods should be called in the

php artisan vendor:publish --tag="cashier-migrations"

89 method of your

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

10:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

5

Warning
When a subscription is in an

use Laravel\Cashier\Billable;

class User extends Authenticatable

16 state it cannot be changed until the payment is confirmed. Therefore, the

use Laravel\Cashier\Billable;

class User extends Authenticatable

30 and

use Laravel\Cashier\Billable;

class User extends Authenticatable

31 methods will throw an exception when the subscription is in an

use Laravel\Cashier\Billable;

class User extends Authenticatable

16 state.

Subscription Scopes

Most subscription states are also available as query scopes so that you may easily query your database for subscriptions that are in a given state:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

6

A complete list of available scopes is available below:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

7

Changing Prices

After a customer is subscribed to your application, they may occasionally want to change to a new subscription price. To swap a customer to a new price, pass the Stripe price's identifier to the

use Laravel\Cashier\Billable;

class User extends Authenticatable

30 method. When swapping prices, it is assumed that the user would like to re-activate their subscription if it was previously canceled. The given price identifier should correspond to a Stripe price identifier available in the Stripe dashboard:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

8

If the customer is on trial, the trial period will be maintained. Additionally, if a "quantity" exists for the subscription, that quantity will also be maintained.

If you would like to swap prices and cancel any trial period the customer is currently on, you may invoke the

use Laravel\Cashier\Billable;

class User extends Authenticatable

34 method:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

9

If you would like to swap prices and immediately invoice the customer instead of waiting for their next billing cycle, you may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

35 method:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

0

Prorations

By default, Stripe prorates charges when swapping between prices. The

use Laravel\Cashier\Billable;

class User extends Authenticatable

36 method may be used to update the subscription's price without prorating the charges:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

1

For more information on subscription proration, consult the Stripe documentation.

Warning
Executing the

use Laravel\Cashier\Billable;

class User extends Authenticatable

36 method before the

use Laravel\Cashier\Billable;

class User extends Authenticatable

35 method will have no effect on proration. An invoice will always be issued.

Subscription Quantity

Sometimes subscriptions are affected by "quantity". For example, a project management application might charge $10 per month per project. You may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

39 and

use Laravel\Cashier\Billable;

class User extends Authenticatable

40 methods to easily increment or decrement your subscription quantity:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

2

Alternatively, you may set a specific quantity using the

use Laravel\Cashier\Billable;

class User extends Authenticatable

31 method:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

3

The

use Laravel\Cashier\Billable;

class User extends Authenticatable

36 method may be used to update the subscription's quantity without prorating the charges:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

4

For more information on subscription quantities, consult the Stripe documentation.

Quantities For Subscriptions With Multiple Products

If your subscription is a , you should pass the ID of the price whose quantity you wish to increment or decrement as the second argument to the increment / decrement methods:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

5

Subscriptions With Multiple Products

Subscription with multiple products allow you to assign multiple billing products to a single subscription. For example, imagine you are building a customer service "helpdesk" application that has a base subscription price of $10 per month but offers a live chat add-on product for an additional $15 per month. Information for subscriptions with multiple products is stored in Cashier's

use Laravel\Cashier\Billable;

class User extends Authenticatable

43 database table.

You may specify multiple products for a given subscription by passing an array of prices as the second argument to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

72 method:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

6

In the example above, the customer will have two prices attached to their

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

74 subscription. Both prices will be charged on their respective billing intervals. If necessary, you may use the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

80 method to indicate a specific quantity for each price:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

7

If you would like to add another price to an existing subscription, you may invoke the subscription's

use Laravel\Cashier\Billable;

class User extends Authenticatable

47 method:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

8

The example above will add the new price and the customer will be billed for it on their next billing cycle. If you would like to bill the customer immediately you may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

48 method:

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription

9

If you would like to add a price with a specific quantity, you can pass the quantity as the second argument of the

use Laravel\Cashier\Billable;

class User extends Authenticatable

47 or

use Laravel\Cashier\Billable;

class User extends Authenticatable

48 methods:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

0

You may remove prices from subscriptions using the

use Laravel\Cashier\Billable;

class User extends Authenticatable

51 method:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

1

Warning
You may not remove the last price on a subscription. Instead, you should simply cancel the subscription.

Swapping Prices

You may also change the prices attached to a subscription with multiple products. For example, imagine a customer has a

use Laravel\Cashier\Billable;

class User extends Authenticatable

52 subscription with a

use Laravel\Cashier\Billable;

class User extends Authenticatable

53 add-on product and you want to upgrade the customer from the

use Laravel\Cashier\Billable;

class User extends Authenticatable

52 to the

use Laravel\Cashier\Billable;

class User extends Authenticatable

55 price:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

2

When executing the example above, the underlying subscription item with the

use Laravel\Cashier\Billable;

class User extends Authenticatable

52 is deleted and the one with the

use Laravel\Cashier\Billable;

class User extends Authenticatable

53 is preserved. Additionally, a new subscription item for the

use Laravel\Cashier\Billable;

class User extends Authenticatable

55 is created.

You can also specify subscription item options by passing an array of key / value pairs to the

use Laravel\Cashier\Billable;

class User extends Authenticatable

30 method. For example, you may need to specify the subscription price quantities:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

3

If you want to swap a single price on a subscription, you may do so using the

use Laravel\Cashier\Billable;

class User extends Authenticatable

30 method on the subscription item itself. This approach is particularly useful if you would like to preserve all of the existing metadata on the subscription's other prices:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

4

Proration

By default, Stripe will prorate charges when adding or removing prices from a subscription with multiple products. If you would like to make a price adjustment without proration, you should chain the

use Laravel\Cashier\Billable;

class User extends Authenticatable

36 method onto your price operation:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

5

Quantities

If you would like to update quantities on individual subscription prices, you may do so using the by passing the name of the price as an additional argument to the method:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

6

Warning
When a subscription has multiple prices the

use Laravel\Cashier\Billable;

class User extends Authenticatable

62 and

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

80 attributes on the

use Laravel\Cashier\Billable;

class User extends Authenticatable

64 model will be

use Laravel\Cashier\Billable;

class User extends Authenticatable

65. To access the individual price attributes, you should use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

66 relationship available on the

use Laravel\Cashier\Billable;

class User extends Authenticatable

64 model.

Subscription Items

When a subscription has multiple prices, it will have multiple subscription "items" stored in your database's

use Laravel\Cashier\Billable;

class User extends Authenticatable

43 table. You may access these via the

use Laravel\Cashier\Billable;

class User extends Authenticatable

66 relationship on the subscription:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

7

You can also retrieve a specific price using the

use Laravel\Cashier\Billable;

class User extends Authenticatable

70 method:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

8

Multiple Subscriptions

Stripe allows your customers to have multiple subscriptions simultaneously. For example, you may run a gym that offers a swimming subscription and a weight-lifting subscription, and each subscription may have different pricing. Of course, customers should be able to subscribe to either or both plans.

When your application creates subscriptions, you may provide the name of the subscription to the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

72 method. The name may be any string that represents the type of subscription the user is initiating:

use App\Models\Cashier\Subscription;

use App\Models\Cashier\SubscriptionItem;

* Bootstrap any application services.

Cashier::useSubscriptionModel(Subscription::class);

Cashier::useSubscriptionItemModel(SubscriptionItem::class);

9

In this example, we initiated a monthly swimming subscription for the customer. However, they may want to swap to a yearly subscription at a later time. When adjusting the customer's subscription, we can simply swap the price on the

use Laravel\Cashier\Billable;

class User extends Authenticatable

72 subscription:

php artisan vendor:publish --tag="cashier-migrations"

00

Of course, you may also cancel the subscription entirely:

php artisan vendor:publish --tag="cashier-migrations"

01

Metered Billing

Metered billing allows you to charge customers based on their product usage during a billing cycle. For example, you may charge customers based on the number of text messages or emails they send per month.

To start using metered billing, you will first need to create a new product in your Stripe dashboard with a metered price. Then, use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

73 to add the metered price ID to a customer subscription:

php artisan vendor:publish --tag="cashier-migrations"

02

You may also start a metered subscription via :

php artisan vendor:publish --tag="cashier-migrations"

03

Reporting Usage

As your customer uses your application, you will report their usage to Stripe so that they can be billed accurately. To increment the usage of a metered subscription, you may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

74 method:

php artisan vendor:publish --tag="cashier-migrations"

04

By default, a "usage quantity" of 1 is added to the billing period. Alternatively, you may pass a specific amount of "usage" to add to the customer's usage for the billing period:

php artisan vendor:publish --tag="cashier-migrations"

05

If your application offers multiple prices on a single subscription, you will need to use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

75 method to specify the metered price you want to report usage for:

php artisan vendor:publish --tag="cashier-migrations"

06

Sometimes, you may need to update usage which you have previously reported. To accomplish this, you may pass a timestamp or a

use Laravel\Cashier\Billable;

class User extends Authenticatable

76 instance as the second parameter to

use Laravel\Cashier\Billable;

class User extends Authenticatable

74. When doing so, Stripe will update the usage that was reported at that given time. You can continue to update previous usage records as the given date and time is still within the current billing period:

php artisan vendor:publish --tag="cashier-migrations"

07

Retrieving Usage Records

To retrieve a customer's past usage, you may use a subscription instance's

use Laravel\Cashier\Billable;

class User extends Authenticatable

78 method:

php artisan vendor:publish --tag="cashier-migrations"

08

If your application offers multiple prices on a single subscription, you may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

79 method to specify the metered price that you wish to retrieve usage records for:

php artisan vendor:publish --tag="cashier-migrations"

09

The

use Laravel\Cashier\Billable;

class User extends Authenticatable

78 and

use Laravel\Cashier\Billable;

class User extends Authenticatable

79 methods return a Collection instance containing an associative array of usage records. You may iterate over this array to display a customer's total usage:

php artisan vendor:publish --tag="cashier-migrations"

10

For a full reference of all usage data returned and how to use Stripe's cursor based pagination, please consult the official Stripe API documentation.

Subscription Taxes

Warning
Instead of calculating Tax Rates manually, you can

To specify the tax rates a user pays on a subscription, you should implement the

use Laravel\Cashier\Billable;

class User extends Authenticatable

82 method on your billable model and return an array containing the Stripe tax rate IDs. You can define these tax rates in your Stripe dashboard:

php artisan vendor:publish --tag="cashier-migrations"

11

The

use Laravel\Cashier\Billable;

class User extends Authenticatable

82 method enables you to apply a tax rate on a customer-by-customer basis, which may be helpful for a user base that spans multiple countries and tax rates.

If you're offering subscriptions with multiple products, you may define different tax rates for each price by implementing a

use Laravel\Cashier\Billable;

class User extends Authenticatable

84 method on your billable model:

php artisan vendor:publish --tag="cashier-migrations"

12

Warning
The

use Laravel\Cashier\Billable;

class User extends Authenticatable

82 method only applies to subscription charges. If you use Cashier to make "one-off" charges, you will need to manually specify the tax rate at that time.

Syncing Tax Rates

When changing the hard-coded tax rate IDs returned by the

use Laravel\Cashier\Billable;

class User extends Authenticatable

82 method, the tax settings on any existing subscriptions for the user will remain the same. If you wish to update the tax value for existing subscriptions with the new

use Laravel\Cashier\Billable;

class User extends Authenticatable

82 values, you should call the

use Laravel\Cashier\Billable;

class User extends Authenticatable

88 method on the user's subscription instance:

php artisan vendor:publish --tag="cashier-migrations"

13

This will also sync any item tax rates for a subscription with multiple products. If your application is offering subscriptions with multiple products, you should ensure that your billable model implements the

use Laravel\Cashier\Billable;

class User extends Authenticatable

84 method .

Tax Exemption

Cashier also offers the

use Laravel\Cashier\Billable;

class User extends Authenticatable

90,

use Laravel\Cashier\Billable;

class User extends Authenticatable

91, and

use Laravel\Cashier\Billable;

class User extends Authenticatable

92 methods to determine if the customer is tax exempt. These methods will call the Stripe API to determine a customer's tax exemption status:

php artisan vendor:publish --tag="cashier-migrations"

14

Warning
These methods are also available on any

use Laravel\Cashier\Billable;

class User extends Authenticatable

93 object. However, when invoked on an

use Laravel\Cashier\Billable;

class User extends Authenticatable

94 object, the methods will determine the exemption status at the time the invoice was created.

Subscription Anchor Date

By default, the billing cycle anchor is the date the subscription was created or, if a trial period is used, the date that the trial ends. If you would like to modify the billing anchor date, you may use the

use Laravel\Cashier\Billable;

class User extends Authenticatable

95 method:

php artisan vendor:publish --tag="cashier-migrations"

15

For more information on managing subscription billing cycles, consult the Stripe billing cycle documentation

Cancelling Subscriptions

To cancel a subscription, call the

use Laravel\Cashier\Billable;

class User extends Authenticatable

96 method on the user's subscription:

php artisan vendor:publish --tag="cashier-migrations"

16

When a subscription is canceled, Cashier will automatically set the

use Laravel\Cashier\Billable;

class User extends Authenticatable

97 column in your

php artisan vendor:publish --tag="cashier-migrations"

86 database table. This column is used to know when the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

99 method should begin returning

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

00.

For example, if a customer cancels a subscription on March 1st, but the subscription was not scheduled to end until March 5th, the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

99 method will continue to return

use Laravel\Cashier\Billable;

class User extends Authenticatable

00 until March 5th. This is done because a user is typically allowed to continue using an application until the end of their billing cycle.

You may determine if a user has canceled their subscription but are still on their "grace period" using the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

03 method:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

1

If you wish to cancel a subscription immediately, call the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

04 method on the user's subscription:

php artisan vendor:publish --tag="cashier-migrations"

18

If you wish to cancel a subscription immediately and invoice any remaining un-invoiced metered usage or new / pending proration invoice items, call the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

05 method on the user's subscription:

php artisan vendor:publish --tag="cashier-migrations"

19

You may also choose to cancel the subscription at a specific moment in time:

php artisan vendor:publish --tag="cashier-migrations"

20

Resuming Subscriptions

If a customer has canceled their subscription and you wish to resume it, you may invoke the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

06 method on the subscription. The customer must still be within their "grace period" in order to resume a subscription:

php artisan vendor:publish --tag="cashier-migrations"

21

If the customer cancels a subscription and then resumes that subscription before the subscription has fully expired the customer will not be billed immediately. Instead, their subscription will be re-activated and they will be billed on the original billing cycle.

Subscription Trials

With Payment Method Up Front

If you would like to offer trial periods to your customers while still collecting payment method information up front, you should use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

07 method when creating your subscriptions:

php artisan vendor:publish --tag="cashier-migrations"

22

This method will set the trial period ending date on the subscription record within the database and instruct Stripe to not begin billing the customer until after this date. When using the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

07 method, Cashier will overwrite any default trial period configured for the price in Stripe.

Warning
If the customer's subscription is not canceled before the trial ending date they will be charged as soon as the trial expires, so you should be sure to notify your users of their trial ending date.

The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

09 method allows you to provide a

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

10 instance that specifies when the trial period should end:

php artisan vendor:publish --tag="cashier-migrations"

23

You may determine if a user is within their trial period using either the

use Laravel\Cashier\Billable;

class User extends Authenticatable

03 method of the user instance or the

use Laravel\Cashier\Billable;

class User extends Authenticatable

03 method of the subscription instance. The two examples below are equivalent:

php artisan vendor:publish --tag="cashier-migrations"

24

You may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

13 method to immediately end a subscription trial:

php artisan vendor:publish --tag="cashier-migrations"

25

To determine if an existing trial has expired, you may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

14 methods:

php artisan vendor:publish --tag="cashier-migrations"

26

Defining Trial Days In Stripe / Cashier

You may choose to define how many trial days your price's receive in the Stripe dashboard or always pass them explicitly using Cashier. If you choose to define your price's trial days in Stripe you should be aware that new subscriptions, including new subscriptions for a customer that had a subscription in the past, will always receive a trial period unless you explicitly call the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

15 method.

Without Payment Method Up Front

If you would like to offer trial periods without collecting the user's payment method information up front, you may set the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

16 column on the user record to your desired trial ending date. This is typically done during user registration:

php artisan vendor:publish --tag="cashier-migrations"

27

Warning
Be sure to add a for the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

16 attribute within your billable model's class definition.

Cashier refers to this type of trial as a "generic trial", since it is not attached to any existing subscription. The

use Laravel\Cashier\Billable;

class User extends Authenticatable

03 method on the billable model instance will return

use Laravel\Cashier\Billable;

class User extends Authenticatable

00 if the current date is not past the value of

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

16:

php artisan vendor:publish --tag="cashier-migrations"

28

Once you are ready to create an actual subscription for the user, you may use the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

72 method as usual:

php artisan vendor:publish --tag="cashier-migrations"

29

To retrieve the user's trial ending date, you may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

22 method. This method will return a Carbon date instance if a user is on a trial or

use Laravel\Cashier\Billable;

class User extends Authenticatable

65 if they aren't. You may also pass an optional subscription name parameter if you would like to get the trial ending date for a specific subscription other than the default one:

php artisan vendor:publish --tag="cashier-migrations"

30

You may also use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

24 method if you wish to know specifically that the user is within their "generic" trial period and has not yet created an actual subscription:

php artisan vendor:publish --tag="cashier-migrations"

31

Extending Trials

The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

25 method allows you to extend the trial period of a subscription after the subscription has been created. If the trial has already expired and the customer is already being billed for the subscription, you can still offer them an extended trial. The time spent within the trial period will be deducted from the customer's next invoice:

php artisan vendor:publish --tag="cashier-migrations"

32

Handling Stripe Webhooks

Note
You may use the Stripe CLI to help test webhooks during local development.

Stripe can notify your application of a variety of events via webhooks. By default, a route that points to Cashier's webhook controller is automatically registered by the Cashier service provider. This controller will handle all incoming webhook requests.

By default, the Cashier webhook controller will automatically handle cancelling subscriptions that have too many failed charges (as defined by your Stripe settings), customer updates, customer deletions, subscription updates, and payment method changes; however, as we'll soon discover, you can extend this controller to handle any Stripe webhook event you like.

To ensure your application can handle Stripe webhooks, be sure to configure the webhook URL in the Stripe control panel. By default, Cashier's webhook controller responds to the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

26 URL path. The full list of all webhooks you should enable in the Stripe control panel are:

  • use App\Models\Cashier\User;

    use Laravel\Cashier\Cashier;

    * Bootstrap any application services.

    Cashier::useCustomerModel(User::class);

    27
  • use App\Models\Cashier\User;

    use Laravel\Cashier\Cashier;

    * Bootstrap any application services.

    Cashier::useCustomerModel(User::class);

    28
  • use App\Models\Cashier\User;

    use Laravel\Cashier\Cashier;

    * Bootstrap any application services.

    Cashier::useCustomerModel(User::class);

    29
  • use App\Models\Cashier\User;

    use Laravel\Cashier\Cashier;

    * Bootstrap any application services.

    Cashier::useCustomerModel(User::class);

    30
  • use App\Models\Cashier\User;

    use Laravel\Cashier\Cashier;

    * Bootstrap any application services.

    Cashier::useCustomerModel(User::class);

    31
  • use App\Models\Cashier\User;

    use Laravel\Cashier\Cashier;

    * Bootstrap any application services.

    Cashier::useCustomerModel(User::class);

    32
  • use App\Models\Cashier\User;

    use Laravel\Cashier\Cashier;

    * Bootstrap any application services.

    Cashier::useCustomerModel(User::class);

    33

For convenience, Cashier includes a

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

34 Artisan command. This command will create a webhook in Stripe that listens to all of the events required by Cashier:

php artisan vendor:publish --tag="cashier-migrations"

33

By default, the created webhook will point to the URL defined by the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

35 environment variable and the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

36 route that is included with Cashier. You may provide the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

37 option when invoking the command if you would like to use a different URL:

php artisan vendor:publish --tag="cashier-migrations"

34

The webhook that is created will use the Stripe API version that your version of Cashier is compatible with. If you would like to use a different Stripe version, you may provide the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

38 option:

php artisan vendor:publish --tag="cashier-migrations"

35

After creation, the webhook will be immediately active. If you wish to create the webhook but have it disabled until you're ready, you may provide the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

39 option when invoking the command:

php artisan vendor:publish --tag="cashier-migrations"

36

Warning
Make sure you protect incoming Stripe webhook requests with Cashier's included middleware.

Webhooks & CSRF Protection

Since Stripe webhooks need to bypass Laravel's CSRF protection, be sure to list the URI as an exception in your application's

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

40 middleware or list the route outside of the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

41 middleware group:

Defining Webhook Event Handlers

Cashier automatically handles subscription cancellations for failed charges and other common Stripe webhook events. However, if you have additional webhook events you would like to handle, you may do so by listening to the following events that are dispatched by Cashier:

  • use App\Models\Cashier\User;

    use Laravel\Cashier\Cashier;

    * Bootstrap any application services.

    Cashier::useCustomerModel(User::class);

    42
  • use App\Models\Cashier\User;

    use Laravel\Cashier\Cashier;

    * Bootstrap any application services.

    Cashier::useCustomerModel(User::class);

    43

Both events contain the full payload of the Stripe webhook. For example, if you wish to handle the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

32 webhook, you may register a that will handle the event:

php artisan vendor:publish --tag="cashier-migrations"

37

Once your listener has been defined, you may register it within your application's

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

45:

php artisan vendor:publish --tag="cashier-migrations"

38

Verifying Webhook Signatures

To secure your webhooks, you may use Stripe's webhook signatures. For convenience, Cashier automatically includes a middleware which validates that the incoming Stripe webhook request is valid.

To enable webhook verification, ensure that the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

01 environment variable is set in your application's

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

00 file. The webhook

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

48 may be retrieved from your Stripe account dashboard.

Single Charges

Simple Charge

If you would like to make a one-time charge against a customer, you may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

49 method on a billable model instance. You will need to as the second argument to the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

49 method:

php artisan vendor:publish --tag="cashier-migrations"

39

The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

49 method accepts an array as its third argument, allowing you to pass any options you wish to the underlying Stripe charge creation. More information regarding the options available to you when creating charges may be found in the Stripe documentation:

php artisan vendor:publish --tag="cashier-migrations"

40

You may also use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

49 method without an underlying customer or user. To accomplish this, invoke the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

49 method on a new instance of your application's billable model:

php artisan vendor:publish --tag="cashier-migrations"

41

The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

49 method will throw an exception if the charge fails. If the charge is successful, an instance of

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

55 will be returned from the method:

php artisan vendor:publish --tag="cashier-migrations"

42

Warning
The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

49 method accepts the payment amount in the lowest denominator of the currency used by your application. For example, if customers are paying in United States Dollars, amounts should be specified in pennies.

Charge With Invoice

Sometimes you may need to make a one-time charge and offer a PDF receipt to your customer. The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

57 method lets you do just that. For example, let's invoice a customer for five new shirts:

php artisan vendor:publish --tag="cashier-migrations"

43

The invoice will be immediately charged against the user's default payment method. The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

57 method also accepts an array as its third argument. This array contains the billing options for the invoice item. The fourth argument accepted by the method is also an array which should contain the billing options for the invoice itself:

php artisan vendor:publish --tag="cashier-migrations"

44

Similarly to

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

57, you may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

60 method to create a one-time charge for multiple items (up to 250 items per invoice) by adding them to the customer's "tab" and then invoicing the customer. For example, we may invoice a customer for five shirts and two mugs:

php artisan vendor:publish --tag="cashier-migrations"

45

Alternatively, you may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

61 method to make a "one-off" charge against the customer's default payment method:

php artisan vendor:publish --tag="cashier-migrations"

46

Although the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

61 method is available for you to use, it is recommended that you use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

57 and

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

60 methods with pre-defined prices. By doing so, you will have access to better analytics and data within your Stripe dashboard regarding your sales on a per-product basis.

Warning
The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

65,

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

57, and

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

61 methods will create a Stripe invoice which will retry failed billing attempts. If you do not want invoices to retry failed charges, you will need to close them using the Stripe API after the first failed charge.

Creating Payment Intents

You can create a new Stripe payment intent by invoking the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

68 method on a billable model instance. Calling this method will create a payment intent that is wrapped in a

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

55 instance:

php artisan vendor:publish --tag="cashier-migrations"

47

After creating the payment intent, you can return the client secret to your application's frontend so that the user can complete the payment in their browser. To read more about building entire payment flows using Stripe payment intents, please consult the Stripe documentation.

When using the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

68 method, the default payment methods that are enabled within your Stripe dashboard will be available to the customer. Alternatively, if you only want to allow for some specific payment methods to be used, you may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

71 method:

php artisan vendor:publish --tag="cashier-migrations"

48

Warning
The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

68 and

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

71 methods accept the payment amount in the lowest denominator of the currency used by your application. For example, if customers are paying in United States Dollars, amounts should be specified in pennies.

Refunding Charges

If you need to refund a Stripe charge, you may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

74 method. This method accepts the Stripe as its first argument:

php artisan vendor:publish --tag="cashier-migrations"

49

Invoices

Retrieving Invoices

You may easily retrieve an array of a billable model's invoices using the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

75 method. The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

75 method returns a collection of

use Laravel\Cashier\Billable;

class User extends Authenticatable

93 instances:

php artisan vendor:publish --tag="cashier-migrations"

50

If you would like to include pending invoices in the results, you may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

78 method:

php artisan vendor:publish --tag="cashier-migrations"

51

You may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

79 method to retrieve a specific invoice by its ID:

php artisan vendor:publish --tag="cashier-migrations"

52

Displaying Invoice Information

When listing the invoices for the customer, you may use the invoice's methods to display the relevant invoice information. For example, you may wish to list every invoice in a table, allowing the user to easily download any of them:

php artisan vendor:publish --tag="cashier-migrations"

53

Upcoming Invoices

To retrieve the upcoming invoice for a customer, you may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

80 method:

php artisan vendor:publish --tag="cashier-migrations"

54

Similarly, if the customer has multiple subscriptions, you can also retrieve the upcoming invoice for a specific subscription:

php artisan vendor:publish --tag="cashier-migrations"

55

Previewing Subscription Invoices

Using the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

81 method, you can preview an invoice before making price changes. This will allow you to determine what your customer's invoice will look like when a given price change is made:

php artisan vendor:publish --tag="cashier-migrations"

56

You may pass an array of prices to the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

81 method in order to preview invoices with multiple new prices:

php artisan vendor:publish --tag="cashier-migrations"

57

Generating Invoice PDFs

Before generating invoice PDFs, you should use Composer to install the Dompdf library, which is the default invoice renderer for Cashier:

php artisan vendor:publish --tag="cashier-migrations"

58

From within a route or controller, you may use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

83 method to generate a PDF download of a given invoice. This method will automatically generate the proper HTTP response needed to download the invoice:

php artisan vendor:publish --tag="cashier-migrations"

59

By default, all data on the invoice is derived from the customer and invoice data stored in Stripe. The filename is based on your

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

84 config value. However, you can customize some of this data by providing an array as the second argument to the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

83 method. This array allows you to customize information such as your company and product details:

php artisan vendor:publish --tag="cashier-migrations"

60

The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

83 method also allows for a custom filename via its third argument. This filename will automatically be suffixed with

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

87:

php artisan vendor:publish --tag="cashier-migrations"

61

Custom Invoice Renderer

Cashier also makes it possible to use a custom invoice renderer. By default, Cashier uses the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

88 implementation, which utilizes the dompdf PHP library to generate Cashier's invoices. However, you may use any renderer you wish by implementing the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

89 interface. For example, you may wish to render an invoice PDF using an API call to a third-party PDF rendering service:

php artisan vendor:publish --tag="cashier-migrations"

62

Once you have implemented the invoice renderer contract, you should update the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

90 configuration value in your application's

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

91 configuration file. This configuration value should be set to the class name of your custom renderer implementation.

Checkout

Cashier Stripe also provides support for Stripe Checkout. Stripe Checkout takes the pain out of implementing custom pages to accept payments by providing a pre-built, hosted payment page.

The following documentation contains information on how to get started using Stripe Checkout with Cashier. To learn more about Stripe Checkout, you should also consider reviewing Stripe's own documentation on Checkout.

Product Checkouts

You may perform a checkout for an existing product that has been created within your Stripe dashboard using the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

92 method on a billable model. The

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

92 method will initiate a new Stripe Checkout session. By default, you're required to pass a Stripe Price ID:

php artisan vendor:publish --tag="cashier-migrations"

63

If needed, you may also specify a product quantity:

php artisan vendor:publish --tag="cashier-migrations"

64

When a customer visits this route they will be redirected to Stripe's Checkout page. By default, when a user successfully completes or cancels a purchase they will be redirected to your

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

43 route location, but you may specify custom callback URLs using the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

95 and

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

96 options:

php artisan vendor:publish --tag="cashier-migrations"

65

When defining your

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

95 checkout option, you may instruct Stripe to add the checkout session ID as a query string parameter when invoking your URL. To do so, add the literal string

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

98 to your

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

95 query string. Stripe will replace this placeholder with the actual checkout session ID:

php artisan vendor:publish --tag="cashier-migrations"

66

Promotion Codes

By default, Stripe Checkout does not allow user redeemable promotion codes. Luckily, there's an easy way to enable these for your Checkout page. To do so, you may invoke the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

00 method:

php artisan vendor:publish --tag="cashier-migrations"

67

Single Charge Checkouts

You can also perform a simple charge for an ad-hoc product that has not been created in your Stripe dashboard. To do so you may use the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

01 method on a billable model and pass it a chargeable amount, a product name, and an optional quantity. When a customer visits this route they will be redirected to Stripe's Checkout page:

php artisan vendor:publish --tag="cashier-migrations"

68

Warning
When using the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

01 method, Stripe will always create a new product and price in your Stripe dashboard. Therefore, we recommend that you create the products up front in your Stripe dashboard and use the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

92 method instead.

Subscription Checkouts

Warning
Using Stripe Checkout for subscriptions requires you to enable the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

27 webhook in your Stripe dashboard. This webhook will create the subscription record in your database and store all of the relevant subscription items.

You may also use Stripe Checkout to initiate subscriptions. After defining your subscription with Cashier's subscription builder methods, you may call the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

92method. When a customer visits this route they will be redirected to Stripe's Checkout page:

php artisan vendor:publish --tag="cashier-migrations"

69

Just as with product checkouts, you may customize the success and cancellation URLs:

php artisan vendor:publish --tag="cashier-migrations"

70

Of course, you can also enable promotion codes for subscription checkouts:

php artisan vendor:publish --tag="cashier-migrations"

69

Warning
Unfortunately Stripe Checkout does not support all subscription billing options when starting subscriptions. Using the

use Laravel\Cashier\Billable;

class User extends Authenticatable

95 method on the subscription builder, setting proration behavior, or setting payment behavior will not have any effect during Stripe Checkout sessions. Please consult the Stripe Checkout Session API documentation to review which parameters are available.

Stripe Checkout & Trial Periods

Of course, you can define a trial period when building a subscription that will be completed using Stripe Checkout:

php artisan vendor:publish --tag="cashier-migrations"

72

However, the trial period must be at least 48 hours, which is the minimum amount of trial time supported by Stripe Checkout.

Subscriptions & Webhooks

Remember, Stripe and Cashier update subscription statuses via webhooks, so there's a possibility a subscription might not yet be active when the customer returns to the application after entering their payment information. To handle this scenario, you may wish to display a message informing the user that their payment or subscription is pending.

Collecting Tax IDs

Checkout also supports collecting a customer's Tax ID. To enable this on a checkout session, invoke the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

07 method when creating the session:

php artisan vendor:publish --tag="cashier-migrations"

73

When this method is invoked, a new checkbox will be available to the customer that allows them to indicate if they're purchasing as a company. If so, they will have the opportunity to provide their Tax ID number.

Warning
If you have already configured in your application's service provider then this feature will be enabled automatically and there is no need to invoke the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

07 method.

Guest Checkouts

Using the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

09 method, you may initiate checkout sessions for guests of your application that do not have an "account":

php artisan vendor:publish --tag="cashier-migrations"

74

Similarly to when creating checkout sessions for existing users, you may utilize additional methods available on the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

10 instance to customize the guest checkout session:

php artisan vendor:publish --tag="cashier-migrations"

75

After a guest checkout has been completed, Stripe can dispatch a

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

11 webhook event, so make sure to configure your Stripe webhook to actually send this event to your application. Once the webhook has been enabled within the Stripe dashboard, you may . The object contained in the webhook payload will be a

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

92 object that you may inspect in order to fulfill your customer's order.

Handling Failed Payments

Sometimes, payments for subscriptions or single charges can fail. When this happens, Cashier will throw an

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

13 exception that informs you that this happened. After catching this exception, you have two options on how to proceed.

First, you could redirect your customer to the dedicated payment confirmation page which is included with Cashier. This page already has an associated named route that is registered via Cashier's service provider. So, you may catch the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

14 exception and redirect the user to the payment confirmation page:

php artisan vendor:publish --tag="cashier-migrations"

76

On the payment confirmation page, the customer will be prompted to enter their credit card information again and perform any additional actions required by Stripe, such as "3D Secure" confirmation. After confirming their payment, the user will be redirected to the URL provided by the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

15 parameter specified above. Upon redirection,

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

16 (string) and

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

17 (integer) query string variables will be added to the URL. The payment page currently supports the following payment method types:

  • Credit Cards
  • Alipay
  • Bancontact
  • BECS Direct Debit
  • EPS
  • Giropay
  • iDEAL
  • SEPA Direct Debit

Alternatively, you could allow Stripe to handle the payment confirmation for you. In this case, instead of redirecting to the payment confirmation page, you may setup Stripe's automatic billing emails in your Stripe dashboard. However, if an

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

14 exception is caught, you should still inform the user they will receive an email with further payment confirmation instructions.

Payment exceptions may be thrown for the following methods:

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

49,

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

61, and

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

65 on models using the

php artisan vendor:publish --tag="cashier-migrations"

93 trait. When interacting with subscriptions, the

use Laravel\Cashier\Cashier;

* Register any application services.

Cashier::ignoreMigrations();

76 method on the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

24, and the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

25 and

use Laravel\Cashier\Billable;

class User extends Authenticatable

35 methods on the

use Laravel\Cashier\Billable;

class User extends Authenticatable

64 and

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

28 models may throw incomplete payment exceptions.

Determining if an existing subscription has an incomplete payment may be accomplished using the

use Laravel\Cashier\Billable;

class User extends Authenticatable

20 method on the billable model or a subscription instance:

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::calculateTaxes();

3

You can derive the specific status of an incomplete payment by inspecting the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

30 property on the exception instance:

php artisan vendor:publish --tag="cashier-migrations"

78

Strong Customer Authentication

If your business or one of your customers is based in Europe you will need to abide by the EU's Strong Customer Authentication (SCA) regulations. These regulations were imposed in September 2019 by the European Union to prevent payment fraud. Luckily, Stripe and Cashier are prepared for building SCA compliant applications.

Warning
Before getting started, review Stripe's guide on PSD2 and SCA as well as their documentation on the new SCA APIs.

Payments Requiring Additional Confirmation

SCA regulations often require extra verification in order to confirm and process a payment. When this happens, Cashier will throw a

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

13 exception that informs you that extra verification is needed. More information on how to handle these exceptions be found can be found in the documentation on .

Payment confirmation screens presented by Stripe or Cashier may be tailored to a specific bank or card issuer's payment flow and can include additional card confirmation, a temporary small charge, separate device authentication, or other forms of verification.

Incomplete and Past Due State

When a payment needs additional confirmation, the subscription will remain in an

use Laravel\Cashier\Billable;

class User extends Authenticatable

16 or

use Laravel\Cashier\Billable;

class User extends Authenticatable

19 state as indicated by its

use Laravel\Cashier\Billable;

class User extends Authenticatable

17 database column. Cashier will automatically activate the customer's subscription as soon as payment confirmation is complete and your application is notified by Stripe via webhook of its completion.

For more information on

use Laravel\Cashier\Billable;

class User extends Authenticatable

16 and

use Laravel\Cashier\Billable;

class User extends Authenticatable

19 states, please refer to .

Off-Session Payment Notifications

Since SCA regulations require customers to occasionally verify their payment details even while their subscription is active, Cashier can send a notification to the customer when off-session payment confirmation is required. For example, this may occur when a subscription is renewing. Cashier's payment notification can be enabled by setting the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

37 environment variable to a notification class. By default, this notification is disabled. Of course, Cashier includes a notification class you may use for this purpose, but you are free to provide your own notification class if desired:

php artisan vendor:publish --tag="cashier-migrations"

79

To ensure that off-session payment confirmation notifications are delivered, verify that for your application and the

use App\Models\Cashier\User;

use Laravel\Cashier\Cashier;

* Bootstrap any application services.

Cashier::useCustomerModel(User::class);

33 webhook is enabled in your Stripe dashboard. In addition, your

php artisan vendor:publish --tag="cashier-migrations"

93 model should also use Laravel's

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

40 trait.

Warning
Notifications will be sent even when customers are manually making a payment that requires additional confirmation. Unfortunately, there is no way for Stripe to know that the payment was done manually or "off-session". But, a customer will simply see a "Payment Successful" message if they visit the payment page after already confirming their payment. The customer will not be allowed to accidentally confirm the same payment twice and incur an accidental second charge.

Stripe SDK

Many of Cashier's objects are wrappers around Stripe SDK objects. If you would like to interact with the Stripe objects directly, you may conveniently retrieve them using the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

41 method:

php artisan vendor:publish --tag="cashier-migrations"

80

You may also use the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

42 method to update a Stripe subscription directly:

php artisan vendor:publish --tag="cashier-migrations"

81

You may invoke the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

43 method on the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

44 class if you would like to use the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

45 client directly. For example, you could use this method to access the

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

46 instance and retrieve a list of prices from your Stripe account:

php artisan vendor:publish --tag="cashier-migrations"

82

Testing

When testing an application that uses Cashier, you may mock the actual HTTP requests to the Stripe API; however, this requires you to partially re-implement Cashier's own behavior. Therefore, we recommend allowing your tests to hit the actual Stripe API. While this is slower, it provides more confidence that your application is working as expected and any slow tests may be placed within their own PHPUnit testing group.

When testing, remember that Cashier itself already has a great test suite, so you should only focus on testing the subscription and payment flow of your own application and not every underlying Cashier behavior.

To get started, add the testing version of your Stripe secret to your

STRIPE_KEY=your-stripe-key

STRIPE_SECRET=your-stripe-secret

STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

47 file:

use Laravel\Cashier\Billable;

class User extends Authenticatable

2

Now, whenever you interact with Cashier while testing, it will send actual API requests to your Stripe testing environment. For convenience, you should pre-fill your Stripe testing account with subscriptions / prices that you may use during testing.