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());
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.
However, you can change the default source by updating the Customer object and specifying the source as a value for default_source .
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”
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With