How to keep in sync your customers details with Stripe in Laravel

There is a handy syncStripeCustomerDetails method available on Laravel Cashier for Stripe that lets you keep in sync your customers details.

So, when a customer updates their email or name details, it gets updated on Stripe too.

1// App/Models/User.php
2 
3namespace App\Models;
4 
5use function Illuminate\Events\queueable;
6 
7class User extends Authenticatable
8{
9 // ...
10 
11 // listen for the updated User model event and invoke `syncStripeCustomerDetails`
12 
13 protected static function booted()
14 {
15 static::updated(queueable(function ($customer) {
16 $customer->syncStripeCustomerDetails();
17 }));
18 }
19}

Code in action:

You can overwrite the attributes used to sync the information by adding the following methods stripeName, stripeEmail, stripePhone, and stripeAddress methods.