#bilalahmer

1 messages · Page 1 of 1 (latest)

hearty harborBOT
midnight knot
#

Stripe::PaymentMethod.retrieve works to retrieve both PaymentMethods and legacy Cards card_xxx and Sources src_xxx, it takes any of the IDs

#

you should really store the customer's "default card ID" as something in your own database instead

cursive cradle
#

Okay, So it is okay to use Stripe::PaymentMethod.retrieve with setupIntent ?

midnight knot
#

not sure what you mean by that

#

Stripe::PaymentMethod.retrieve can retrieve a PaymentMethod or Card or Source, like I said. You would not pass it a SetupIntent ID, that wouldn't make sense

cursive cradle
#

Yes I got that, But I was confirming that we can also get card payment method details through this setupIntent code Stripe::SetupIntent.retrieve({expand: ['payment_method'], id: id }.
Which one is the best way to do it ? or both are okay ?
Stripe::PaymentMethod.retrieve(@customer.default_source)

midnight knot
#

theyre both okay

cursive cradle
#

Stripe::PaymentMethod.retrieve(@customer.default_source) this one is using default_source and my customer object have null default_source.
`{
"id": "cus_O7dnlqIeBihizi",
"object": "customer",
"address": null,
"balance": 0,
"created": 1687344246,
"currency": null,
"default_currency": null,
"default_source": null,
"delinquent": false,
"description": "aasdasdsadsa",
"discount": null,
"email": "abcd@gmail.com",
"invoice_prefix": "20387AB4",
"invoice_settings": {"custom_fields":null,"default_payment_method":null,"footer":null,"rendering_options":null},
"livemode": false,
"metadata": {},
"name": null,
"next_invoice_sequence": 1,
"phone": null,
"preferred_locales": [

],
"shipping": null,
"tax_exempt": "none",
"test_clock": null
}`
.

midnight knot
#

yep, that just means your customer doensn't have one

#

default_source is a legacy field, it only exists when you're using legacy integrations like Card/Source, there's no such thing when using PaymentMethods

#

so as I mentioned earlier:
you should really store the customer's "default card ID" as something in your own database instead
i.e. if you want a concept of "this is the card I charge by default for this customer", you need to store and manage that yourself and stop assuming the presence of default_source

cursive cradle
#

By "default card ID" you mean something like that "id": "card_1NLOl4Kv7Wi3E5ylMuIVbIbv" ?

midnight knot
#

or id:'pm_xxxx"

cursive cradle
#

Getting confused , I have users who already saved through legacy integrations and now I'm moving to setupIntent and I need to get their paymentMethod details .I found after discussion with you we can use Stripe::PaymentMethod.retrieve(@customer.default_source)
Which will work for old users not for the new setupIntent users.
So i need a way or method which I can use for both users ?

midnight knot
#

the best way is probably to store all this in your own database instead

cursive cradle
#

Your suggestion is to store PaymentMethod ID of all users(old & new ) ?
And use that for getting payment method details ?

midnight knot
#

so for old customers, update your database record for your user/customer and store the current value of their default_source into a column on it

#

and add code so that you are storing an ID for that same column for new customers, based on whatever logic you'd like to have there

cursive cradle
#

But the new customer's don't have default_source ?

#

Using default_source doesn't mean we are still using legacy API ?

midnight knot
#

for new customers, if you want to have a concept of "this is the card I charge by default for this customer", you need to store and manage that yourself , for example you can say that the first PaymentMethod accepted with the SetupIntent is their default, and you write the ID of that PaymentMethod into your database.

For existing customers, you do a script to update your database to save their current value of default_source to the same field.

later when you want details of the customer's default card, you call Stripe::PaymentMethod.retrieve(value_from_my_database_customer_default_card_id) and it all just works, and you have no code that is using default_source in the Stripe API any more.