Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update customer default paymentMethod in Stripe?

Let's assume that we have created a payment method - pm_xxx. When we create a customer we can attache this method as the default payment method to the customer via java code:

CustomerCreateParams.Builder customerCreateParamsBuilder = CustomerCreateParams.builder()
                    .setEmail(email)
                    .setPaymentMethod('pm_xxx');       
Customer.create(customerCreateParamsBuilder.build());

Unfortunately corresponding api for update customer is not available. So the question is what is preferred way to update customer default payment method in Stripe?

EDIT: Based on @karllekko answer, because My use case is recurring payments so I combine 2 actions: attach customer to payment method:

paymentMethod.attach(PaymentMethodAttachParams.builder().setCustomer(customer.getId()).build());            

and make payment method default for customer invoice:

customer.update(CustomerUpdateParams.builder().setInvoiceSettings(CustomerUpdateParams.InvoiceSettings.builder().setDefaultPaymentMethod(token).build()).build());
like image 990
snieguu Avatar asked Jul 01 '19 07:07

snieguu


People also ask

How do I set default payment method to customer in Stripe?

To use this PaymentMethod as the default for invoice or subscription payments, set invoice_settings. default_payment_method , on the Customer to the PaymentMethod's ID.

How do I change my default source in Stripe?

However, you can change the default source by updating the Customer object and specifying the source as a value for default_source .

How do I update my Stripe customer card?

You can locate an existing customer by searching by email address or customer ID on your Stripe Dashboard. To add a new card, navigate to the Customer screen for the customer on your Stripe Dashboard: Under “Cards” click “Add Card” Enter the credit card information and click “Add Card”

Does Stripe automatically update card?

Automatic card updatesStripe works with card networks and automatically attempts to update saved card details whenever a customer receives a new card (for example, replacing an expired card or one that was reported lost or stolen).


1 Answers

The PaymentMethod.attach doc page (1) says this:

To use this PaymentMethod as the default for invoice or subscription payments, set invoice_settings.default_payment_method, on the Customer to the PaymentMethod’s ID.

So you can use the Customer.update API route (2) and fill the invoice_settings attribute.

(1) - https://stripe.com/docs/api/payment_methods/attach

(2) - https://stripe.com/docs/api/customers/update#update_customer-invoice_settings

like image 200
Pierre-Yves O. Avatar answered Nov 15 '22 16:11

Pierre-Yves O.