0

I am using Laravel Cashier with Stripe checkout (to avoid need for compliance). I cannot fathom how to allow customer to change their card details. I know the cashier syntax is

$customer->updateCard($stripeToken)

but how do we get there? Anyone able to offer me the steps please?

Jonathan Hyams
  • 121
  • 1
  • 2
  • 14

2 Answers2

0

Cashier expects a token to be created client side using stripe.js/elements or checkout. You then submit this token to your server route where you call:

// grab the token from the request like this
// $stripeToken = request()->input('stripe_token');

$customer->updateCard($stripeToken);

The Stripe API is itself really well put together and easy to use, so you can use it directly, as well:

\Stripe\Stripe::setApiKey("stripe_secret_test_key");

$customer = \Stripe\Customer::retrieve("cus_CFdeffeSfeefe");
$card = $customer->sources->retrieve("card_1sdafjkfsdD32f");
$card->name = "Joseph Jones";
$card->save();
0

Here's a good starting point to understand what Stripe expects tp update a customers card. Even though this is targeted towards vanilla PHP, it gives you a fair bit of detail as to what is required and what goes on behind the scenes. https://stripe.com/docs/recipes/updating-customer-cards

This explains further the inner working of updateCard https://github.com/laravel/cashier/blob/7.0/src/Billable.php#389

In your case, you need a view with a form for new card details. The view should implement Stripe's JS Checkout library which in turn generates the stripe token. In your controller you can pass that token to updateCard method on an instance of your user/customer model.

Sam
  • 139
  • 1