#Pavan-PaymentMethod

1 messages · Page 1 of 1 (latest)

bronze dust
#

No, that API only list the PaymentMethod attached

jagged star
#

Couldn't find payment methodId in this. This is also a list how do we know which one to consider ?

bronze dust
#

yes it's a list of PaymentIntent objects. Inside each object, you should have the payment_method field which contains the Id

jagged star
#

In the doc it is showing as "payment_method": null, and also which PaymentIntent to take from the list

bronze dust
#

Which doc are you refer to?

#

And it's correct to be a list (since your customer could have paid multiple times). You would need to loop through the list, and take the PaymentMethod inside each object

jagged star
#

{
"object": "list",
"url": "/v1/payment_intents",
"has_more": false,
"data": [
{
"id": "pi_1HoxGXCuLjRTHyU3Z7jitoow",
"object": "payment_intent",
"amount": 1000,
"amount_capturable": 0,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"url": "/v1/charges?payment_intent=pi_1HoxGXCuLjRTHyU3Z7jitoow"
},
"client_secret": "pi_1HoxGXCuLjRTHyU3Z7jitoow_secret_Su4MtXUiwTptlM92u1CEYqW6C",
"confirmation_method": "automatic",
"created": 1605731313,
"currency": "usd",
"customer": null,
"description": "Created by stripe.com/docs demo",
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_options": {
"card": {
"installments": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
},
{...},
{...}
]
}

#

This is the response from list of paymentIntents

#

and payment_method is shown as null

bronze dust
#

ah

#

yeah sorry

#

You would need to expand it. One moment

#

from your List PaymentIntent API, you would need something like --expand=payment_method

jagged star
#

PaymentIntent is generated whenever there is an invoice and amount is due. Suppose last month money deducted from one card. Now customer wants to update a new card. Does paymentIntent will be generated since customer updates payment Method ?

#

I don't understand which paymentIntent to consider from the list

#

to get the latest card

bronze dust
#

Not until you charge your customer, like they actually paid

#

for the latest card you would want to sort by timestamp

#

I believe that's the created parameter

jagged star
#

Suppose there is one payment method which is a card. In the middle of monthly subscription i want to update card, even though deduction happens in the next billing cycle. Then how can we get latest card, since paymentIntent might not be generated for new card, since no money deducted from it

bronze dust
#

Okie so that will go back to the original method, because no PaymentIntent happen yet. You would want to List Payment Methods attached to a customer, and sorted by its created parameter

jagged star
#

Ok one final question, my requirement is not to maintain multiple cards always replace existing card with new one. It's possible to do it from frontend right as part of custom flow ? In that case there will be always only one payment method and we can retrieve and show it right ?

#

@bronze dust

bronze dust
#

Hi, sorry I am in multiple other workstream

#

Hmm

#

you would need to control over the cards registered and make sure you only registered one, so I think you will need to be in server side any way

jagged star
#

For card update backend will generate a setupIntent, frontend will update card details right. Can't we make sure only card present all the time ?

bronze dust
#

I don't think there is a way in frontend to guarantee only one card existing. You would need to either

  1. Remove all payment methods before creating a setup intent
  2. After confirm the setup intent, go back to server you would need to list all payment methods including the new one, and remove all older payment methods
jagged star
#

ok

#

got it

#

Thanks for answering patiently. Much appreciated !!