#Pavan-PaymentMethod
1 messages · Page 1 of 1 (latest)
No, that API only list the PaymentMethod attached
You might want to list PaymentIntent (https://stripe.com/docs/api/payment_intents/list) and grab the PaymentMethodId inside
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Couldn't find payment methodId in this. This is also a list how do we know which one to consider ?
yes it's a list of PaymentIntent objects. Inside each object, you should have the payment_method field which contains the Id
In the doc it is showing as "payment_method": null, and also which PaymentIntent to take from the list
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
{
"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
ah
yeah sorry
You would need to expand it. One moment
Here is the general doc about expanding response https://stripe.com/docs/api/expanding_objects
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
from your List PaymentIntent API, you would need something like --expand=payment_method
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
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
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
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
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
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
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 ?
I don't think there is a way in frontend to guarantee only one card existing. You would need to either
- Remove all payment methods before creating a setup intent
- 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