#idhruv-expanding-charges
1 messages · Page 1 of 1 (latest)
Hi there
Yep you want to expand the PaymentIntent
Am I correct in understanding you are working backwards from a Subscription?
yes
but example shown makes use of charges by placing chargeId, so will the same trick work for paymentId
So then you would expand the latest_invoice.payment_intent
stripe.charges.retrieve(invoice.id, { expand: ['customer', 'invoice.subscription'], });
this is clearly retrieving the charge, this syntax seems to be not matching with my requirement
because I don't want to retrieve any charges here with expanded customer and subscription sub-objects inside
Okay let's back up
What exactly are you trying to do? Because you are right that the above won't work.
invoice = await stripe.invoices.finalizeInvoice( subscription.latest_invoice );
as per this i should be getting paymentIntent object in return inside invoices
but i am getting only paymentIntent ID
https://discord.com/channels/841573134531821608/1017059192386883654 -> for your further reference
Okay so if you want that request to return the PaymentIntent object then you would do: invoice = await stripe.invoices.finalizeInvoice( subscription.latest_invoice, { expand: ['payment_intent']} );
You can see examples in our docs here: https://stripe.com/docs/expand
okay i was able to solve this. thanks, however, going down further as I proceed to add new card to existing cards in stripe it throws this payment method was previously used without being attached to a customer or was detached from a customer, and may not be used again here is the request id req_qOcULwBM0NDsKY
Okay so you are trying to attach the PaymentMethod that was collected via the initial payment for the Subscription to the Customer to be used for renewal payments in the future, correct?
yes
whereas there are already 2 payment methods attach to this user from before
let customer = await stripe.paymentMethods.list({ customer: stripeCustomerId, type: 'card' });
Gotcha. Okay in this case you want to set setup_future_usage when you confirm your PaymentIntent on your client: https://stripe.com/docs/js/payment_intents/confirm_card_payment#stripe_confirm_card_payment-data-setup_future_usage
to this i get
data: [ { id: 'pm_1LdWZVGdNldKu1zmr2C15dur', object: 'payment_method', billing_details: [Object], card: [Object], created: 1662112437, customer: 'cus_MLtD4v7ngE4tw6', livemode: false, metadata: {}, type: 'card' }, { id: 'pm_1LdTDaGdNldKu1zmcDpI2DK3', object: 'payment_method', billing_details: [Object], card: [Object], created: 1662099546, customer: 'cus_MLtD4v7ngE4tw6', livemode: false, metadata: {}, type: 'card' } ]
That allows you to attach the PaymentMethod to the Customer thereafter
Yep you do that in the frontend here.
i will try just a moment
Yep give it a try
i am adding `setup_future_usage: 'off_session'
and hoping that it will work for first charge when the customer is shown authentication screen for 3ds and also for subsequent charges which will be auto cut by stripe with customer not present when it happens
Yep that's correct
this worked
thanks a ton mate
so the charge next month as per the subscription schedule will also cut automatically? will it still ask for 3ds secure verification now?
You want to either set the customer's invoice_settings.default_payment_method or the Subscription's default_payment_method in order for the charge the next month to happen automatically.
Since the PaymentMethod is set up for off_session, we will apply for an exemption for 3DS. So likely 3DS will not be prompted, however it is always at the discretion of the issuer if they want to require it, so you should be ready to bring your customer back on-session if necessary.
I've got to step away but @solid garnet can help with any further questions!
ohhk