Stripe API updating credit card stored in Stripe

David Carr

Stripe API Nova Framework Tutorials

There will be times customers need to update their stored credit card, this post goes over how to enable that.

I’m using Nova Framework not setup with Nova? please read Getting Stripe API setup with Nova Framework

first get the customers information, if you don’t have this method please read Stripe API get customer information

$customer = $this->getCustomer();

Next using checkout prefix a Stripe button, notice the use of $ustomer->default_source->last4 this displayed the last 4 digits of the card. It’s not required but is useful.

<form action="{{ site_url('account/updatecard') }}" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="{{ Config::get('stripe.apiPublicKey') }}"
data-email='{{ Auth::user()->email }}'
data-name="{{ Config::get('app.name') }}"
data-panel-label="{{ __d('users', 'Update Card Details') }}"
data-label="{{ __d('users', 'Update Card') }} ({{ $customer->default_source->last4 }})"
data-allow-remember-me=false
data-locale="auto">
</script>
</form>

Have this post to e page to save the changes.

In the post create an instance of the customer then update the source and save the changes.

//update card source
$customer = $this->getCustomer();
$customer->source = Input::get('stripeToken');
$customer->save();

This will update the card stored on Stripe, like with a subscription the card details won’t be on your server.

Fathom Analytics $10 discount on your first invoice using this link

David Carr - Laravel Developer

Hi, I’m David Carr

A Senior Developer at Vivedia
I love to use the TALL stack (Tailwind CSS, Alpine.js, Laravel, and Laravel Livewire)

I enjoy writing tutorials and working on Open Source packages.

I also write books. I'm writing a new book Laravel Testing Cookbook, This book focuses on testing coving both PestPHP and PHPUnit.

Sponsor me on GitHub

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Laravel Testing Cookbook

Help support the blog so that I can continue creating new content!

Fathom Analytics $10 discount on your first invoice using this link

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2006 - 2023 DC Blog. All code MIT license. All rights reserved.