#cnguyen-customer-default-pm
1 messages · Page 1 of 1 (latest)
Hey! You'll want the invoice_settings.default_payment_method field: https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
ok I need to expand the customer retrieve so
For the full Payment Method object, yes. Unless you just need the ID pm_xxx
I just need the pm_XXXX to create a subcription
Then you can retrieve the customer record, and just pull the payment method ID from the invoice_settings.default_payment_method field (assuming that the default payment method has been previously set).
https://stripe.com/docs/api/customers/retrieve
I try to expand
but it's because I not set the default I suppose
but in the payment method on stripe, I have the default tag on my payment method
Could you check if the default_source field, on the customer object, has the information that you're expecting?
I speak about the default here
What is the response that you get when you retrieve that customer?
{
"id": "cus_KdtKmyWjioXrVG",
"object": "customer",
"address": {
"city": "",
"country": "",
"line1": "",
"line2": null,
"postal_code": "24242",
"state": null
},
"balance": 0,
"created": 1637583748,
"currency": null,
"default_source": "card_1JybfoED5xkfDv2cVdPAfJbp",
"delinquent": false,
"description": null,
"discount": null,
"email": "010rfkf8r@test.com",
"invoice_prefix": "1A50B3F5",
"invoice_settings": {
"custom_fields": null,
"default_payment_method": null,
"footer": null
},
"livemode": false,
"metadata": {
},
"name": "John Doe",
"phone": "01212121212",
"preferred_locales": [
],
"shipping": null,
"tax_exempt": "none"
}
I have to expand the default_source ?
So you're not going to find a pm_xxx ID for that card, because it was created as a source rather than a payment method.
That card_1Jy... value is the ID for it.
What is the best practice ? To set up the default payment method and the default source ? On pi successfull event ?
Is it possible to have a pm in the default_source ? WHy I have a card_XXX ?
Because you seem to have created a source object rather than a payment method object. We recommend using payment methods:
https://stripe.com/docs/payments/payment-methods/transitioning
mmm I checked but I miss something I think
I create a PI stripe.paymentIntents.create
The PI is confirmed in front by the customer
So normally, the customer has the default source to the create PM no ?
I set the PI with something like :
{
...
payment_method_types: ['card'],
amount: price, // in cents
currency: currency,
customer: user.stripeId,
on_behalf_of: stripeMerchantId,
setup_future_usage: 'off_session'
payment_method: stripePaymentMethod
};
So I don't see why it's a card_XXX and why the customer don't have the default pm or default source with pm ?
Or maybe, when it's like that, the customer info is not updated with this information (pm) ?
Bear with me, there are a couple things to break down here.
In this line, what is contained in the stripePaymentMethod variable?
payment_method: stripePaymentMethod
pm_XXXX
that is the pm generated by Stripe Element
To give you my flow :
I create the customer first (cus_XXX).
Then I create the PM with Stripe Element
Then I create the PI with the stripe customer id and the PM
Gotcha, so that flow shouldn't have resulted in a card_xxx object like we saw above. Also we don't set defaults for a customer, we leave that up to you.
And for now, I update the invoice default pm on 'payment_intent.succeeded'.
But I would like to attach the default pm before the payment_intent.succeeded , if it's possible
OK. So the best way is to make the :
await stripe.customers.update(
stripeCustomerId,
{ invoice_settings: { default_payment_method: eventObject.payment_method } }
);
When I create the PI for the customer for example ?
Or when the confirmCardPayment is done ?
That is the way to set the value, but when you do is up to you and depends on how you want your flow to be structured. If you set it before the card's confirmed to be valid, then you may need to reset it if the customer provides a different payment method.
yes that's why I do it on the webhook "payment successful"
Seems like a good place to do that.