#rstupek_api
1 messages ¡ Page 1 of 1 (latest)
đ 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.
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.
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
Awesome, let me know if you run in to anything implementing that
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
You just supply invoice
The Charge object does not have those properties. https://stripe.com/docs/api/charges/object
the example says stripe.charges.retrieve('ch_3Ln0H22eZvKYlo2C0tgkG5bn', {
expand: ['customer', 'invoice.subscription'],
});
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
ok so expand the payment intent settings on the charge
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.
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'],
});
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?
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
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
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?
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
I'm trying to process the refund though
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.
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
That's one way to do it yes
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
is there another simpler way?
if I need to specify an invoice be created on the session I can do that going forward
So you're not using Invoices? Or you are?
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?
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?
I wasn't since I wasn't aware I might need them
You don't need them. I was just asking because it would be easier for you to track the line items of a purchase if you just needed the Invoice. If you have some payments without an invoice, then you will need to make a series of API calls once you get refund.created
Refund --> Payment Intent --> List all Checkout Sessions by Payment Intent: https://docs.stripe.com/api/checkout/sessions/list#list_checkout_sessions-payment_intent
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
What do you mean? I linked the parameter for payment_intent
https://docs.stripe.com/api/checkout/sessions/list?lang=node
it says there are 2 parameters (payment_intnet and subscription) but the only parameter shown is a limit
do I pass {payment_intent:ID}?