#rstupek_api

1 messages ¡ Page 1 of 1 (latest)

daring dustBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1251188719365656648

📝 Have more to share? Add details, code, screenshots, videos, etc. below.

gentle walrusBOT
ornate atlas
#

Hello, the products for that transaction are assosciated with the Invoice object. The PaymentIntent related to that charge has an invoice field so if you expand the invoice field while retrieving the intent you will get the full object back https://docs.stripe.com/api/expanding_objects

#

Basically, Charge objects refer to a specfic attempt to pay and PaymentIntents are a state machine that track a customer's potentially many attempts to pay for a thing, but neither of them have a concept of products. Invoices are kind of a wrapper around PaymentIntents that do have a concept of products, so that is where to look.

fleet ingot
#

so retrieve the paymentintent, expanding the invoice field on the payment intent. how is the expansion done using the nodejs sdk?

#

I think I see how

ornate atlas
#

Awesome, let me know if you run in to anything implementing that

fleet ingot
#

appreciate the help

#

if the refund is not for a subscription, how do you expand the invoice? using 'invoice' isn't returning anything. the example shows to use invoice.subscription

ornate atlas
#

You just supply invoice

fleet ingot
#

let ch=await stripe.charges.retrieve(data.id, {
expand: ['customer', 'invoice'],
});

ornate atlas
fleet ingot
#

the example says stripe.charges.retrieve('ch_3Ln0H22eZvKYlo2C0tgkG5bn', {
expand: ['customer', 'invoice.subscription'],
});

ornate atlas
#

If you are looking at the charge object you will want to expand payment_intent.invoice and payment_intent.customer

#

So the way that expansion works is that you need to list a field that is directly on the object that you are retrieving

fleet ingot
#

ok so expand the payment intent settings on the charge

ornate atlas
#

Right, you can expand the payment intent and then you can add a . and the name of a field on the payment intent to expand that

#

Though again, the field has to be directly on the payment intent.

fleet ingot
#

sorry still not understanding... I had it expand the payment intent invoice and it is still null
let ch=await stripe.charges.retrieve(data.id, {
expand: ['customer', 'payment_intent.invoice'],
});

ornate atlas
#

I would point to the API reference again. If you look it over, those fields are the only things that you can expand on the charge itself The Charge object does not have those properties. https://stripe.com/docs/api/charges/object

#

Oh both of those are on the charge. Can you send me the ID of the payment intent on that charge? If invoice is null, then it sounds like that intent was not created from a subscription or invoice. Do you know how this PI was created?

fleet ingot
#

pi_2PQenxPXI34JMUGQ1sS2fXk7

#

It was done through a session created on a website which took them to stripe's site to pay (checkout)?

#

these would be test transactions

#

trying to figure out the items that were purchased so I can remove them from our db

ornate atlas
#

Ah gotcha, so Checkout Sessions are another wrapper around the PaymentIntent. For that intent you will have to list your Checkout Sessions and filter by the payment intent's ID: https://docs.stripe.com/api/checkout/sessions/list#list_checkout_sessions-payment_intent
You can turn on a setting when creating your Checkout Sessions so that the session will create an invoice, but otherwise by default the Checkout Session will not create an Invoice (though in subscription mode, the subscription will create an invoice so the intent will still have one attached)
https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-invoice_creation

fleet ingot
#

so I need to find the session they used to find the item they purchased or alternatively have the session create an invoice which will be on the charge? or paymentintent on the charge?

ornate atlas
#

Correct. Only the Invoices and Checkout Sessions have a concept of line items and products and such. So when you get the Charge/PaymentIntent you need to find the Invoice or Checkout Session associated with them

#

Because you are listening to webhook events, it may be easier to listen to invoice.paid and checkout.session.succeeded as those will have the line item info within them

daring dustBOT
fleet ingot
#

I'm trying to process the refund though

zenith olive
#

You need a Payment Intent or Charge object to process a refund right? So once you have one of those objects, you're good to go.

fleet ingot
#

so without setting the invoice setting on the initial session, the mechanism for determining the items on the refund is to list all sessions, find the session with the payment intent id from the refund, get the items on the session

zenith olive
#

That's one way to do it yes

fleet ingot
#

by "process the refund" I'm referring to receiving the webhook charge.refunded, locating what items are being refunded without having previously set the invoice field on the session

fleet ingot
#

if I need to specify an invoice be created on the session I can do that going forward

zenith olive
#

So you're not using Invoices? Or you are?

fleet ingot
#

I wasn't using invoices but we do have subscriptions as well as non-subscriptions so my understanding is a subscription automatically creates invoices where single products do not (unless the session was told to create them)

#

if I set that to enabled do I need to not set that when a subscriptions is being ordered?

zenith olive
#

Correct, if you're creating a Subscription, then you're creating Invoices automatically.

#

So are you creating Invoices for your one-off payments too? Or not?

fleet ingot
#

I wasn't since I wasn't aware I might need them

zenith olive
fleet ingot
#

so get the sessions for the payment intent on the refund which will know what the products were... let me give that a shot

#

the documentation you reference lists 2 parameters but I don't see how to pass the payment intent id

zenith olive
#

What do you mean? I linked the parameter for payment_intent

fleet ingot