You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: artisan.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,6 +158,12 @@ To assign a shortcut when defining an option, you may specify it before the opti
158
158
159
159
email:send {user} {--Q|queue}
160
160
161
+
If you would like to define arguments or options to expect array inputs, you may use the `*` character:
162
+
163
+
email:send {user*}
164
+
165
+
email:send {user} {--id=*}
166
+
161
167
#### Input Descriptions
162
168
163
169
You may assign descriptions to input arguments and options by separating the parameter from the description using a colon:
@@ -176,8 +182,6 @@ You may assign descriptions to input arguments and options by separating the par
176
182
177
183
While your command is executing, you will obviously need to access the values for the arguments and options accepted by your command. To do so, you may use the `argument` and `option` methods:
178
184
179
-
To retrieve the value of an argument, use the `argument` method:
180
-
181
185
/**
182
186
* Execute the console command.
183
187
*
@@ -233,13 +237,13 @@ If you need to ask the user for a simple confirmation, you may use the `confirm`
233
237
234
238
#### Giving The User A Choice
235
239
236
-
The `anticipate` method can be used to provided autocompletion for possible choices. The user can still choose any answer, regardless of the choices.
240
+
The `anticipate` method can be used to provide autocompletion for possible choices. The user can still choose any answer, regardless of the auto-completion hints:
237
241
238
242
$name = $this->anticipate('What is your name?', ['Taylor', 'Dayle']);
239
243
240
244
If you need to give the user a predefined set of choices, you may use the `choice` method. The user chooses the index of the answer, but the value of the answer will be returned to you. You may set the default value to be returned if nothing is chosen:
241
245
242
-
$name = $this->choice('What is your name?', ['Taylor', 'Dayle'], false);
246
+
$name = $this->choice('What is your name?', ['Taylor', 'Dayle'], $default);
Copy file name to clipboardExpand all lines: authorization.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,8 +18,6 @@
18
18
19
19
In addition to providing [authentication](/docs/{{version}}/authentication) services out of the box, Laravel also provides a simple way to organize authorization logic and control access to resources. There are a variety of methods and helpers to assist you in organizing your authorization logic, and we'll cover each of them in this document.
20
20
21
-
> **Note:** Authorization was added in Laravel 5.1.11, please refer to the [upgrade guide](/docs/{{version}}/upgrade) before integrating these features into your application.
Copy file name to clipboardExpand all lines: billing.md
+64-56Lines changed: 64 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,42 +28,53 @@ Laravel Cashier provides an expressive, fluent interface to [Stripe's](https://s
28
28
29
29
First, add the Cashier package to your `composer.json` file and run the `composer update` command:
30
30
31
-
"laravel/cashier": "~5.0" (For Stripe SDK ~2.0, and Stripe APIs on 2015-02-18 version and later)
32
-
"laravel/cashier": "~4.0" (For Stripe APIs on 2015-02-18 version and later)
33
-
"laravel/cashier": "~3.0" (For Stripe APIs up to and including 2015-02-16 version)
31
+
"laravel/cashier": "~6.0"
34
32
35
33
#### Service Provider
36
34
37
35
Next, register the `Laravel\Cashier\CashierServiceProvider`[service provider](/docs/{{version}}/providers) in your `app` configuration file.
38
36
39
37
#### Migration
40
38
41
-
Before using Cashier, we'll need to add several columns to your database. Don't worry, you can use the `cashier:table` Artisan command to create a migration to add the necessary column. For example, to add the column to the users table run the command: `php artisan cashier:table users`.
39
+
Before using Cashier, we'll need to prepare the database. We need to add several columns to your `users` table and create a new `subscriptions` table to hold all of our customer's subscriptions:
42
40
43
-
Once the migration has been created, simply run the `migrate` command.
41
+
Schema::table('users', function ($table) {
42
+
$table->string('stripe_id')->nullable();
43
+
$table->string('card_brand')->nullable();
44
+
$table->string('card_last_four')->nullable();
45
+
});
46
+
47
+
Schema::create('subscriptions', function ($table) {
48
+
$table->increments('id');
49
+
$table->integer('user_id');
50
+
$table->string('name');
51
+
$table->string('stripe_id');
52
+
$table->string('stripe_plan');
53
+
$table->integer('quantity');
54
+
$table->timestamp('trial_ends_at')->nullable();
55
+
$table->timestamp('ends_at')->nullable();
56
+
$table->timestamps();
57
+
});
58
+
59
+
Once the migrations have been created, simply run the `migrate` command.
44
60
45
61
#### Model Setup
46
62
47
-
Next, add the `Billable` trait and appropriate date mutators to your model definition:
63
+
Next, add the `Billable` trait to your model definition:
48
64
49
65
use Laravel\Cashier\Billable;
50
-
use Laravel\Cashier\Contracts\Billable as BillableContract;
51
66
52
-
class User extends Model implements BillableContract
Adding the columns to your model's `$dates` property will instruct Eloquent to return the columns as Carbon / DateTime instances instead of raw strings.
60
-
61
72
#### Stripe Key
62
73
63
74
Finally, set your Stripe key in your `services.php` configuration file:
64
75
65
76
'stripe' => [
66
-
'model' => 'User',
77
+
'model' => App\User::class,
67
78
'secret' => env('STRIPE_API_SECRET'),
68
79
],
69
80
@@ -73,25 +84,21 @@ Finally, set your Stripe key in your `services.php` configuration file:
73
84
<aname="creating-subscriptions"></a>
74
85
### Creating Subscriptions
75
86
76
-
To create a subscription, first retrieve an instance of your billable model, which typically will be an instance of `App\User`. Once you have retrieved the model instance, you may use the `subscription` method to manage the model's subscription:
87
+
To create a subscription, first retrieve an instance of your billable model, which typically will be an instance of `App\User`. Once you have retrieved the model instance, you may use the `newSubscription` method to create the model's subscription:
The `create` method will automatically create the Stripe subscription, as well as update your database with Stripe customer ID and other relevant billing information. If your plan has a trial configured in Stripe, the trial end date will also automatically be set on the user record.
83
-
84
-
If you want to implement trial periods, but are managing the trials entirely within your application instead of defining them within Stripe, you must manually set the trial end date:
The first argument passed to the `newSubscription` method should be the name of the subscription. If your application only offers a single subscription, you might call this `main` or `primary`. The second argument is the specific Stripe plan the user is subscribing to. This value should correspond to the plan's identifier in Stripe.
87
94
88
-
$user->save();
95
+
The `create` method will automatically create the Stripe subscription, as well as update your database with Stripe customer ID and other relevant billing information. If your plan has a trial configured in Stripe, the trial end date will also automatically be set on the user record.
89
96
90
97
#### Additional User Details
91
98
92
99
If you would like to specify additional customer details, you may do so by passing them as the second argument to the `create` method:
'email' => $email, 'description' => 'Our First Customer'
96
103
]);
97
104
@@ -101,7 +108,7 @@ To learn more about the additional fields supported by Stripe, check out Stripe'
101
108
102
109
If you would like to apply a coupon when creating the subscription, you may use the `withCoupon` method:
103
110
104
-
$user->subscription('monthly')
111
+
$user->newSubscription('main', 'monthly')
105
112
->withCoupon('code')
106
113
->create($creditCardToken);
107
114
@@ -110,15 +117,15 @@ If you would like to apply a coupon when creating the subscription, you may use
110
117
111
118
Once a user is subscribed to your application, you may easily check their subscription status using a variety of convenient methods. First, the `subscribed` method returns `true` if the user has an active subscription, even if the subscription is currently within its trial period:
112
119
113
-
if ($user->subscribed()) {
120
+
if ($user->subscribed('main')) {
114
121
//
115
122
}
116
123
117
124
The `subscribed` method also makes a great candidate for a [route middleware](/docs/{{version}}/middleware), allowing you to filter access to routes and controllers based on the user's subscription status:
118
125
119
126
public function handle($request, Closure $next)
120
127
{
121
-
if ($request->user() && ! $request->user()->subscribed()) {
128
+
if ($request->user() && ! $request->user()->subscribed('main')) {
122
129
// This user is not a paying customer...
123
130
return redirect('billing');
124
131
}
@@ -128,7 +135,7 @@ The `subscribed` method also makes a great candidate for a [route middleware](/d
128
135
129
136
If you would like to determine if a user is still within their trial period, you may use the `onTrial` method. This method can be useful for displaying a warning to the user that they are still on their trial period:
130
137
131
-
if ($user->onTrial()) {
138
+
if ($user->subscription('main')->onTrial()) {
132
139
//
133
140
}
134
141
@@ -142,19 +149,13 @@ The `onPlan` method may be used to determine if the user is subscribed to a give
142
149
143
150
To determine if the user was once an active subscriber, but has cancelled their subscription, you may use the `cancelled` method:
144
151
145
-
if ($user->cancelled()) {
152
+
if ($user->subscription('main')->cancelled()) {
146
153
//
147
154
}
148
155
149
156
You may also determine if a user has cancelled 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 `subscribed` method still returns `true` during this time.
150
157
151
-
if ($user->onGracePeriod()) {
152
-
//
153
-
}
154
-
155
-
The `everSubscribed` method may be used to determine if the user has ever subscribed to a plan in your application:
156
-
157
-
if ($user->everSubscribed()) {
158
+
if ($user->subscription('main')->onGracePeriod()) {
158
159
//
159
160
}
160
161
@@ -165,43 +166,43 @@ After a user is subscribed to your application, they may occasionally want to ch
If the user is on trial, the trial period will be maintained. Also, if a "quantity" exists for the subscription, that quantity will also be maintained. If you would like to invoice the customer immediately after swapping plans, use the `invoice` method:
169
172
170
-
If the user is on trial, the trial period will be maintained. Also, if a "quantity" exists for the subscription, that quantity will also be maintained. When swapping plans, you may also use the `prorate` method to indicate that the charges should be pro-rated. In addition, you may use the `swapAndInvoice` method to immediately invoice the user for the plan change:
Sometimes subscriptions are affected by "quantity". For example, your application might charge $10 per month **per user** on an account. To easily increment or decrement your subscription quantity, use the `increment` and `decrement` methods:
180
+
Sometimes subscriptions are affected by "quantity". For example, your application might charge $10 per month **per user** on an account. To easily increment or decrement your subscription quantity, use the `incrementQuantity` and `decrementQuantity` methods:
180
181
181
182
$user = User::find(1);
182
183
183
-
$user->subscription()->increment();
184
+
$user->subscription('main')->incrementQuantity();
184
185
185
186
// Add five to the subscription's current quantity...
Alternatively, you may set a specific quantity using the `updateQuantity` method:
194
195
195
-
$user->subscription()->updateQuantity(10);
196
+
$user->subscription('main')->updateQuantity(10);
196
197
197
198
For more information on subscription quantities, consult the [Stripe documentation](https://stripe.com/docs/guides/subscriptions#setting-quantities).
198
199
199
200
<aname="subscription-taxes"></a>
200
201
### Subscription Taxes
201
202
202
-
With Cashier, it's easy to provide the `tax_percent` value sent to Stripe. To specify the tax percentage a user pays on a subscription, implement the `getTaxPercent` method on your billable model, and return a numeric value between 0 and 100, with no more than 2 decimal places.
203
+
With Cashier, it's easy to provide the `tax_percent` value sent to Stripe. To specify the tax percentage a user pays on a subscription, implement the `taxPercentage` method on your billable model, and return a numeric value between 0 and 100, with no more than 2 decimal places.
203
204
204
-
public function getTaxPercent() {
205
+
public function taxPercentage() {
205
206
return 20;
206
207
}
207
208
@@ -212,22 +213,22 @@ This enables you to apply a tax rate on a model-by-model basis, which may be hel
212
213
213
214
To cancel a subscription, simply call the `cancel` method on the user's subscription:
214
215
215
-
$user->subscription()->cancel();
216
+
$user->subscription('main')->cancel();
216
217
217
-
When a subscription is cancelled, Cashier will automatically set the `subscription_ends_at` column in your database. This column is used to know when the `subscribed` method should begin returning `false`. For example, if a customer cancels a subscription on March 1st, but the subscription was not scheduled to end until March 5th, the `subscribed` method will continue to return `true` until March 5th.
218
+
When a subscription is cancelled, Cashier will automatically set the `ends_at` column in your database. This column is used to know when the `subscribed` method should begin returning `false`. For example, if a customer cancels a subscription on March 1st, but the subscription was not scheduled to end until March 5th, the `subscribed` method will continue to return `true` until March 5th.
218
219
219
220
You may determine if a user has cancelled their subscription but are still on their "grace period" using the `onGracePeriod` method:
220
221
221
-
if ($user->onGracePeriod()) {
222
+
if ($user->subscription('main')->onGracePeriod()) {
222
223
//
223
224
}
224
225
225
226
<aname="resuming-subscriptions"></a>
226
227
### Resuming Subscriptions
227
228
228
-
If a user has cancelled their subscription and you wish to resume it, use the `resume` method:
229
+
If a user has cancelled their subscription and you wish to resume it, use the `resume` method. The user **must** still be on their grace period in order to resume a subscription:
If the user cancels a subscription and then resumes that subscription before the subscription has fully expired, they will not be billed immediately. Instead, their subscription will simply be re-activated, and they will be billed on the original billing cycle.
233
234
@@ -239,7 +240,10 @@ If the user cancels a subscription and then resumes that subscription before the
239
240
240
241
What if a customer's credit card expires? No worries - Cashier includes a Webhook controller that can easily cancel the customer's subscription for you. Just point a route to the controller:
That's it! Failed payments will be captured and handled by the controller. The controller will cancel the customer's subscription when Stripe determines the subscription has failed (normally after three failed payment attempts). Don't forget: you will need to configure the webhook URI in your Stripe control panel settings.
245
249
@@ -258,7 +262,7 @@ If you have additional Stripe webhook events you would like to handle, simply ex
258
262
259
263
namespace App\Http\Controllers;
260
264
261
-
use Laravel\Cashier\WebhookController as BaseController;
265
+
use Laravel\Cashier\Http\Controllers\WebhookController as BaseController;
262
266
263
267
class WebhookController extends BaseController
264
268
{
@@ -308,8 +312,8 @@ When listing the invoices for the customer, you may use the invoice's helper met
@@ -318,6 +322,10 @@ When listing the invoices for the customer, you may use the invoice's helper met
318
322
<aname="generating-invoice-pdfs"></a>
319
323
#### Generating Invoice PDFs
320
324
325
+
Before generating invoice PDFs, you need to install the `dompdf` PHP library:
326
+
327
+
composer require dompdf/dompdf
328
+
321
329
From within a route or controller, use the `downloadInvoice` method to generate a PDF download of the invoice. This method will automatically generate the proper HTTP response to send the download to the browser:
322
330
323
331
Route::get('user/invoice/{invoice}', function ($invoiceId) {
0 commit comments