#Nadiya-default-payment-method
1 messages · Page 1 of 1 (latest)
Hi there! Are you using Stripe Billing? Can you tell me a little bit more about your use-case?
no
i would like to save card when we register a customer
while making the first purchase , would like to save that card as default payment method
because, while making a subscription payment off session, i'm getting this error
"This customer has no attached payment source or default payment method."
i'm confused about these 3 params on customer object
default_source, invoice_settings.default_payment_method, source
Thanks for clarifying!
If you are using the PaymentMethods API (which you should be!), then you want to set the invoice_settings.default_payment_method
The other params on the customer object are for our older legacy APIs.
No, for one time payments you always have to pass the paymentmethod ID that you want to charge.
is it possbile to get the default_payment_method through customer api and charge it?
Sorry! Missed you response. Yes you can list a customer's paymentmethods: https://stripe.com/docs/api/payment_methods/customer_list
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
if there are multiple cards attached to this customer, and one of them is set as default, is it possible to identify which one is default from the list of available payment methods?
i'm sorry for the continuous question, currently, we're doing like this to get the payment method
$paymentMethods = $stripe->paymentMethods->all(['customer' => $customer_id, 'type' => 'card']); if (sizeof($paymentMethods->data) > 0) { $paymentMethod = $paymentMethods->data[0]; }
This one always get the first payment method, regardless of their default payment method
Gotcha, so when you retrieve the paymentmethods for a customer, you can expand the customer object and see which one is set as the default.
You are only seeing the first paymentmethod there because you are pulling from data[0] which is the first index, right?
yes right. Is there any params which can represent the default one?
invoice_settings.default_payment_method this one again?
It all depends on how you are setting the default, but yes the invoice_settings.default_payment_method is the recommended one to use!
ok, understood. Thank you so much!
sorry, am i following correct step?
- expanding customer in paymentDetail object
$paymentIntentDetail = $stripe->paymentIntents->retrieve( $request->stripe_payment_id, ['expand' => ['invoice.subscription', 'customer']] );
- if there is a customer object, then update the customer's default payment method
if ($paymentIntentDetail->customer) { $stripe->customers->update( $paymentIntentDetail->customer->id, ['invoice_settings' => ['default_payment_method' => $paymentIntentDetail->payment_method]] ); }
Hey there, just stepping in for @crimson birch who needs to step away
In your example 1/ that looks to be retrieving an existing payment intent, while what was discussed was looking at existing payment methods and expanding the customer to inspect the invoice_settings.default_payment_method . Can you explain what you're trying to do here with the invoice/subscription expansion?
2/ Yes that would be how you'd set the customer invoice settings default payment method to a given payment method ID. Are you having some trouble with this?
oh sorry, that was related to other code (which is not related to what we discussed here) for subscription.
this api call can be called while submitting one time / subscription payment
Actually, i was adding this bit of code between 1 and 2
$subscriptionDetail = $paymentIntentDetail->invoice->subscription ?? null; if ($subscriptionDetail) { $stripe->subscriptions->update( $subscriptionDetail->id, ['default_payment_method' => $paymentIntentDetail->payment_method], ); }
Sure, that would let you set an a default payment method for that subscription
If you have that default set on the subscription, it will be used first, then we'd check for a customer default PM in the invoice settings
ok, understood