#idhruv-expanding-charges

1 messages · Page 1 of 1 (latest)

acoustic chasm
#

Hi there

#

Yep you want to expand the PaymentIntent

#

Am I correct in understanding you are working backwards from a Subscription?

fossil nova
#

yes

#

but example shown makes use of charges by placing chargeId, so will the same trick work for paymentId

acoustic chasm
#

So then you would expand the latest_invoice.payment_intent

fossil nova
#

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

acoustic chasm
#

Okay let's back up

#

What exactly are you trying to do? Because you are right that the above won't work.

fossil nova
#

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

acoustic chasm
#

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']} );

fossil nova
#

ohhh

#

wait let me check n try the same

fossil nova
#

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

acoustic chasm
#

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?

fossil nova
#

yes

#

whereas there are already 2 payment methods attach to this user from before

#

let customer = await stripe.paymentMethods.list({ customer: stripeCustomerId, type: 'card' });

acoustic chasm
fossil nova
#

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' } ]

acoustic chasm
#

That allows you to attach the PaymentMethod to the Customer thereafter

fossil nova
#

okk

#

can i do it via frontend?

#

all this time i was only doing it on back

#

end

acoustic chasm
#

Yep you do that in the frontend here.

fossil nova
#

i will try just a moment

acoustic chasm
#

Yep give it a try

fossil nova
#

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

acoustic chasm
#

Yep that's correct

fossil nova
#

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?

acoustic chasm
#

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!

fossil nova
#

ohhk