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
-[Handling Other Stripe Webhooks](#handling-other-stripe-webhooks)
13
14
-[Invoices](#invoices)
14
15
15
16
<aname="introduction"></a>
16
17
## Introduction
17
18
18
-
Laravel Cashier provides an expressive, fluent interface to [Stripe's](https://stripe.com) 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 "quantites", cancellation grace periods, and even generate invoice PDFs.
19
+
Laravel Cashier provides an expressive, fluent interface to [Stripe's](https://stripe.com) 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.
19
20
20
21
<aname="configuration"></a>
21
22
## Configuration
@@ -32,7 +33,7 @@ Next, register the `Laravel\Cashier\CashierServiceProvider` in your `app` config
32
33
33
34
#### Migration
34
35
35
-
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. Once the migration has been created, simply run the `migrate` command.
36
+
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 use `php artisan cashier:table users`. Once the migration has been created, simply run the `migrate` command.
36
37
37
38
#### Model Setup
38
39
@@ -70,14 +71,24 @@ If you would like to apply a coupon when creating the subscription, you may use
70
71
->withCoupon('code')
71
72
->create($creditCardToken);
72
73
73
-
The `subscription` method will automatically create the Stripe subscription, as well as update your database with Stripe customer ID and other relevant billing information.
74
+
The `subscription` 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.
74
75
75
-
If your plan has a trial period, make sure to set the trial end date on your model after subscribing:
76
+
If your plan has a trial period that is **not** configured in Stripe, you must set the trial end date manually after subscribing:
'email' => $email, 'description' => 'Our First Customer'
88
+
]);
89
+
90
+
To learn more about the additional fields supported by Stripe, check out Stripe's [documentation on customer creation](https://stripe.com/docs/api#create_customer).
91
+
81
92
<aname="no-card-up-front"></a>
82
93
## No Card Up Front
83
94
@@ -110,12 +121,12 @@ Sometimes subscriptions are affected by "quantity". For example, your applicatio
110
121
$user->subscription()->increment();
111
122
112
123
// Add five to the subscription's current quantity...
113
-
$user->subscription()->increment(5)
124
+
$user->subscription()->increment(5);
114
125
115
126
$user->subscription->decrement();
116
127
117
128
// Subtract five to the subscription's current quantity...
118
-
$user->subscription()->decrement(5)
129
+
$user->subscription()->decrement(5);
119
130
120
131
<aname="cancelling-a-subscription"></a>
121
132
## Cancelling A Subscription
@@ -183,6 +194,13 @@ The `everSubscribed` method may be used to determine if the user has ever subscr
183
194
//
184
195
}
185
196
197
+
The `onPlan` method may be used to determine if the user is subscribed to a given plan based on its ID:
198
+
199
+
if ($user->onPlan('monthly'))
200
+
{
201
+
//
202
+
}
203
+
186
204
<aname="handling-failed-payments"></a>
187
205
## Handling Failed Payments
188
206
@@ -192,16 +210,16 @@ What if a customer's credit card expires? No worries - Cashier includes a Webhoo
192
210
193
211
That's it! Failed payments will be captured and handled by the controller. The controller will cancel the customer's subscription after three failed payment attempts. The `stripe/webhook` URI in this example is just for example. You will need to configure the URI in your Stripe settings.
194
212
195
-
If you have additional Stripe webhook events you would like to handle, simply extend the Webhook controller:
213
+
<aname="handling-other-stripe-webhooks"></a>
214
+
## Handling Other Stripe Webhooks
215
+
216
+
If you have additional Stripe webhook events you would like to handle, simply extend the Webhook controller. Your method names should correspond to Cashier's expected convention, specifically, methods should be prefixed with `handle` and the name of the Stripe webhook you wish to handle. For example, if you wish to handle the `invoice.payment_succeeded` webhook, you should add a `handleInvoicePaymentSucceeded` method to the controller.
196
217
197
218
class WebhookController extends Laravel\Cashier\WebhookController {
198
219
199
-
public function handleWebhook()
220
+
public function handleInvoicePaymentSucceeded($payload)
Copy file name to clipboardExpand all lines: cn/quick.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,13 @@
1
1
# Laravel 快速入门
2
2
3
3
-[安装](#installation)
4
+
-[本地开发环境](#local-development-environment)
4
5
-[路由](#routing)
5
6
-[创建视图](#creating-a-view)
6
7
-[创建迁移](#creating-a-migration)
7
8
-[Eloquent ORM](#eloquent-orm)
8
9
-[显示数据](#displaying-data)
10
+
-[部署应用](#deploying-your-application)
9
11
10
12
<aname="installation"></a>
11
13
## 安装
@@ -42,6 +44,20 @@ Typically, you may use a web server such as Apache or Nginx to serve your Larave
42
44
43
45
After installing the framework, take a glance around the project to familiarize yourself with the directory structure. The `app` directory contains folders such as `views`, `controllers`, and `models`. Most of your application's code will reside somewhere in this directory. You may also wish to explore the `app/config` directory and the configuration options that are available to you.
44
46
47
+
<aname="local-development-environment"></a>
48
+
## Local Development Environment
49
+
50
+
In the past, configuring a local PHP development environment on your machine was a headache. Installing the proper version of PHP, required extensions, and other needed components is time consuming and confusing. Instead, consider using [Laravel Homestead](/docs/homestead). Homestead is a simple virtual machine designed for Laravel and [Vagrant](http://vagrantup.com). Since the Homestead Vagrant box is pre-packaged with all of the software you need to build robust PHP applications, you can create a virtualized, isolated development environment in seconds. Here is a list of some of the goodies included with Homestead:
51
+
52
+
- Nginx
53
+
- PHP 5.5
54
+
- MySQL
55
+
- Redis
56
+
- Memcached
57
+
- Beanstalk
58
+
59
+
Don't worry, even though "virtualized" sounds complicated, it's painless. VirtualBox and Vagrant, which are Homestead's two dependencies, both include simple, graphical installers for all popular operating systems. Check out the [Homestead documentation](/docs/homestead) to get started.
60
+
45
61
<aname="routing"></a>
46
62
## Routing
47
63
@@ -171,3 +187,10 @@ Now that we have made the `users` available to our view, we can display them lik
171
187
You may be wondering where to find our `echo` statements. When using Blade, you may echo data by surrounding it with double curly braces. It's a cinch. Now, you should be able to hit the `/users` route and see the names of your users displayed in the response.
172
188
173
189
This is just the beginning. In this tutorial, you've seen the very basics of Laravel, but there are so many more exciting things to learn. Keep reading through the documentation and dig deeper into the powerful features available to you in [Eloquent](/docs/eloquent) and [Blade](/docs/templates). Or, maybe you're more interested in [Queues](/docs/queues) and [Unit Testing](/docs/testing). Then again, maybe you want to flex your architecture muscles with the [IoC Container](/docs/ioc). The choice is yours!
190
+
191
+
<aname="deploying-your-application"></a>
192
+
## Deploying Your Application
193
+
194
+
One of Laravel's goals is to make PHP application development enjoyable from download to deploy, and [Laravel Forge](https://forge.laravel.com) provides a simple way to deploy your Laravel applications onto blazing fast servers. Forge can configure and provision servers on DigitalOcean, Linode, Rackspace, and Amazon EC2. Like Homestead, all of the latest goodes are included: Nginx, PHP 5.5, MySQL, Postgres, Redis, Memcached, and more. Forge "Quick Deploy" can even deploy your code for you each time you push changes out to Github or Bitbucket!
195
+
196
+
On top of that, Forge can help you configure queue workers, SSL, Cron jobs, sub-domains, and more. For more information, visit the [Forge website](https://forge.laravel.com).
0 commit comments