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
@@ -41,6 +46,11 @@ Laravel Cashier provides an expressive, fluent interface to [Stripe's](https://s
41
46
42
47
> {note} If you're only performing "one-off" charges and do not offer subscriptions, you should not use Cashier. Instead, use the Stripe and Braintree SDKs directly.
43
48
49
+
<aname="upgrading-cashier"></a>
50
+
## Upgrading Cashier
51
+
52
+
When upgrading to a new major version of the Cashier, it's important that you carefully review [the upgrade guide](https://github.com/laravel/cashier/blob/master/UPGRADE.md).
53
+
44
54
<aname="configuration"></a>
45
55
## Configuration
46
56
@@ -389,13 +399,6 @@ If a user has cancelled their subscription and you wish to resume it, use the `r
389
399
390
400
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 be re-activated, and they will be billed on the original billing cycle.
391
401
392
-
<aname="updating-credit-cards"></a>
393
-
### Updating Credit Cards
394
-
395
-
The `updateCard` method may be used to update a customer's credit card information. This method accepts a Stripe token and will assign the new credit card as the default billing source:
396
-
397
-
$user->updateCard($stripeToken);
398
-
399
402
<aname="subscription-trials"></a>
400
403
## Subscription Trials
401
404
@@ -470,12 +473,63 @@ Once you are ready to create an actual subscription for the user, you may use th
470
473
471
474
Occasionally, you may wish to create a Stripe customer without beginning a subscription. You may accomplish this using the `createAsStripeCustomer` method:
472
475
473
-
$user->createAsStripeCustomer($stripeToken);
476
+
$user->createAsStripeCustomer();
474
477
475
478
Of course, once the customer has been created in Stripe, you may begin a subscription at a later date.
476
479
477
480
> {tip} The Braintree equivalent of this method is the `createAsBraintreeCustomer` method.
478
481
482
+
<aname="cards"></a>
483
+
## Cards
484
+
485
+
<aname="retrieving-credit-cards"></a>
486
+
### Retrieving Credit Cards
487
+
488
+
The `cards` method on the billable model instance returns a collection of `Laravel\Cashier\Card` instances:
489
+
490
+
$cards = $user->cards();
491
+
492
+
To retrieve the default card, the `defaultCard` method may be used;
493
+
494
+
$card = $user->defaultCard();
495
+
496
+
<aname="determining-if-a-card-is-on-file"></a>
497
+
### Determining If A Card Is On File
498
+
499
+
You may check if a customer has a credit card attached to their account using the `hasCardOnFile` method:
500
+
501
+
if ($user->hasCardOnFile()) {
502
+
//
503
+
}
504
+
505
+
<aname="updating-credit-cards"></a>
506
+
### Updating Credit Cards
507
+
508
+
The `updateCard` method may be used to update a customer's credit card information. This method accepts a Stripe token and will assign the new credit card as the default billing source:
509
+
510
+
$user->updateCard($stripeToken);
511
+
512
+
To sync your card information with the customer's default card information in Stripe, you may use the `updateCardFromStripe` method:
513
+
514
+
$user->updateCardFromStripe();
515
+
516
+
<aname="deleting-credit-cards"></a>
517
+
### Deleting Credit Cards
518
+
519
+
To delete a card, you should first retrieve the customer's cards with the `cards` method. Then, you may call the `delete` method on the card instance you wish to delete:
520
+
521
+
foreach ($user->cards() as $card) {
522
+
$card->delete();
523
+
}
524
+
525
+
> {note} If you delete the default card, please make sure that you sync the new default card with your database using the `updateCardFromStripe` method.
526
+
527
+
The `deleteCards` method will delete all of the card information stored by your application:
528
+
529
+
$user->deleteCards();
530
+
531
+
> {note} If the user has an active subscription, you should consider preventing them from deleting the last remaining payment source.
532
+
479
533
<aname="handling-stripe-webhooks"></a>
480
534
## Handling Stripe Webhooks
481
535
@@ -490,6 +544,8 @@ Both Stripe and Braintree can notify your application of a variety of events via
490
544
491
545
By default, this 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 credit card changes; however, as we'll soon discover, you can extend this controller to handle any webhook event you like.
492
546
547
+
> {note} Make sure you protect incoming requests with Cashier's included [webhook signature verification](/docs/{{version}}/billing#verifying-webhook-signatures) middleware.
548
+
493
549
#### Webhooks & CSRF Protection
494
550
495
551
Since Stripe webhooks need to bypass Laravel's [CSRF protection](/docs/{{version}}/csrf), be sure to list the URI as an exception in your `VerifyCsrfToken` middleware or list the route outside of the `web` middleware group:
@@ -512,10 +568,10 @@ Cashier automatically handles subscription cancellation on failed charges, but i
public function handleInvoicePaymentSucceeded($payload)
521
577
{
@@ -545,16 +601,9 @@ That's it! Failed payments will be captured and handled by the controller. The c
545
601
<aname="verifying-webhook-signatures"></a>
546
602
### Verifying Webhook Signatures
547
603
548
-
To secure your webhooks, you may use [Stripe's webhook signatures](https://stripe.com/docs/webhooks/signatures). For convenience, Cashier includes a middleware that validates the incoming Stripe webhook request is valid.
549
-
550
-
To get started, ensure that the `stripe.webhook.secret` configuration value is set in your `services` configuration file. Once you have configured your webhook secret, you may attach the `VerifyWebhookSignature` middleware to the route:
551
-
552
-
use Laravel\Cashier\Http\Middleware\VerifyWebhookSignature;
604
+
To secure your webhooks, you may use [Stripe's webhook signatures](https://stripe.com/docs/webhooks/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 `stripe.webhook.secret` configuration value is set in your `services` configuration file. The webhook `secret` may be retrieved from your Stripe account dashboard.
558
607
559
608
<aname="handling-braintree-webhooks"></a>
560
609
## Handling Braintree Webhooks
@@ -593,14 +642,14 @@ Cashier automatically handles subscription cancellation on failed charges, but i
public function handleDisputeOpened(WebhookNotification $notification)
650
+
public function handleDisputeOpened(WebhookNotification $webhook)
602
651
{
603
-
// Handle The Event
652
+
// Handle The Webhook...
604
653
}
605
654
}
606
655
@@ -657,10 +706,12 @@ Sometimes you may need to make a one-time charge but also generate an invoice fo
657
706
// Braintree Accepts Charges In Dollars...
658
707
$user->invoiceFor('One Time Fee', 5);
659
708
660
-
The invoice will be charged immediately against the user's credit card. The `invoiceFor` method also accepts an array as its third argument, allowing you to pass any options you wish to the underlying Stripe / Braintree charge creation:
709
+
The invoice will be charged immediately against the user's credit card. The `invoiceFor` 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. This final argument accepts the billing options for the invoice itself:
661
710
662
-
$user->invoiceFor('One Time Fee', 500, [
663
-
'custom-option' => $value,
711
+
$user->invoiceFor('Stickers', 500, [
712
+
'quantity' => 50,
713
+
], [
714
+
'tax_percent' => 21,
664
715
]);
665
716
666
717
If you are using Braintree as your billing provider, you must include a `description` option when calling the `invoiceFor` method:
@@ -669,7 +720,6 @@ If you are using Braintree as your billing provider, you must include a `descrip
669
720
'description' => 'your invoice description here',
670
721
]);
671
722
672
-
673
723
> {note} The `invoiceFor` method 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.
Copy file name to clipboardExpand all lines: blade.md
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -167,12 +167,13 @@ You may display the contents of the `name` variable like so:
167
167
168
168
Hello, {{ $name }}.
169
169
170
+
171
+
> {tip} Blade `{{ }}` statements are automatically sent through PHP's `htmlspecialchars` function to prevent XSS attacks.
172
+
170
173
Of course, you are not limited to displaying the contents of the variables passed to the view. You may also echo the results of any PHP function. In fact, you can put any PHP code you wish inside of a Blade echo statement:
171
174
172
175
The current UNIX timestamp is {{ time() }}.
173
176
174
-
> {tip} Blade `{{ }}` statements are automatically sent through PHP's `htmlspecialchars` function to prevent XSS attacks.
175
-
176
177
#### Displaying Unescaped Data
177
178
178
179
By default, Blade `{{ }}` statements are automatically sent through PHP's `htmlspecialchars` function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:
0 commit comments