#rocket_error
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/1248066544437563444
📝 Have more to share? Add details, code, screenshots, videos, etc. below.
Hi there, what's the PaymentIntent ID?
pi_3POSohHvAVLYAKEc1UmwGdcc
so this issue arised today but it has worked fine for hundreds of payments before
so i'm unsure as to why
the customer said nothing strange occurred during the checkout process
here is the corresponding webhook event id as well if this helps
evt_1POSomHvAVLYAKEcck1qBpUt
https://dashboard.stripe.com/logs/req_DxaRDk4xdXumcp https://dashboard.stripe.com/logs/req_FaoKzoWxllF7ET so these are the requests that attempt the capture the payment_intent, and they are created from a server using your API key.
Have you checked these duplicate captures with your engineer ?
oh I am the engineer
the thing that's perplexing is that I only make a capture request once
is there a way I can share my endpoint code privately?
discord is a public channel. If you don't feel comfortable sharing your code here, you can reach out to support, and we'll continue helping you through emails https://support.stripe.com/contact/email
Find help and support for Stripe. Our support site provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
okay that's alright
i'll omit certain parts then
is the origin of the error from the webhook?
I see that for evt_1POSomHvAVLYAKEcck1qBpUt, there was a 500 error
so I'm wondering if it has to do with my updating of the customer?
I don't think hey they are related. evt_1POSomHvAVLYAKEcck1qBpUt wasn't sent successfully because your endpoint responded 500. Have you check your endpoint logs?
Hmm, you are right, I think they are connected.
Since your endpoint returned 500, stripe will automatically resend the webhook event, and trigger the capture call in the webhook handler.
so it seems like there was an issue parsing json?
i'm not sure what could cause that though
considering this issue didn't occur with previous transactions
Does your log tell you which line of the code that throws this error?
unfortunately it doesn't
but it does say JSON.parse
I have a line that says
const stripe = Stripe(process.env.STRIPE_SECRET_KEY);
const requestHeaders = new Headers(request.headers);
const signature = requestHeaders.get("stripe-signature");
if (!signature) {
return NextResponse.json({ error: "Unauthorized request." });
}
const signingSecret = process.env.STRIPE_SIGNING_SECRET;
const body = await request.text();
let event;
try {
if (!signature || !signingSecret) return;
event = stripe.webhooks.constructEvent(body, signature, signingSecret);
} catch (err) {
console.log(`❌ Error message: ${err.message}`);
return NextResponse.json({ err: err.message });
}
...
const items = JSON.parse(event.data.object.metadata.items); //Suspect line?
however, checking evt_1POSomHvAVLYAKEcck1qBpUt seems to be fine
the metadata is there
oh yeah if it helps, I pasted my code here https://codeshare.io/8Xq0oJ
Looks like it errs when parsing [{\"productId\":\"prod_OP1RocO0GBZk1J\",\"quantity\":1}] to json?
I tried recreating it and it seemed to work?
Why don't you just directly set the json data to the metadata, so that you don't need to convert from String to json?
could you elaborate
I don’t quite get it😓
oh is this when I create a checkout session?
are you saying I can set metadata of a checkout session to be a JSON object directly?
as opposed to stringifying
You can just set your metadata as
items:[{
productId: 'xyz',
quantity: 1
}]
In fact you can retrieve the same data from checkout session's line_items https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-line_items
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
is this available in the event?
line_items is not included in checkout session object by default, so you need to expand it https://docs.stripe.com/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.
on the webhook endpoint side, when it receives the event
does it have access to line items?
The event object doesn't include line_items, but you can retrieve the checkout session object again with line_items expanded.
ok so
the event object is a checkout session right
specfiically checkout.session.completed
and from here, I can get the id via event.data.object.id
using this, I can retrieve this by looking up the checkout session via id and expanding line items?
Yes you are right
instead of expanding, does await stripe.checkout.sessions.listLineItems suffice?
Sure that works as well
const checkoutSessionId = event.data.object.id;
const lineItems = await stripe.checkout.sessions.listLineItems(
checkoutSessionId,
{
limit: 100,
}
);
const items = lineItems.data;```
does that look correct?
Yes, looks good to me!
for (const item in items) {
...
}```
Inside this loop, i'd just call `item.price.product` to get the product id, and then `item.quantity` to get the quantity