#rocket_error

1 messages · Page 1 of 1 (latest)

swift gladeBOT
#

👋 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.

zenith sluice
#

Hi there, what's the PaymentIntent ID?

quasi meteor
#

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

zenith sluice
#

Have you checked these duplicate captures with your engineer ?

quasi meteor
#

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?

zenith sluice
#

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

quasi meteor
#

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?

zenith sluice
#

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?

quasi meteor
#

yes, unfortunately i haven't been able to figure out what it is from the logs

zenith sluice
#

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.

quasi meteor
#

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

zenith sluice
#

Does your log tell you which line of the code that throws this error?

quasi meteor
#

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

zenith sluice
#

Looks like it errs when parsing [{\"productId\":\"prod_OP1RocO0GBZk1J\",\"quantity\":1}] to json?

quasi meteor
#

I tried recreating it and it seemed to work?

zenith sluice
#

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?

quasi meteor
#

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

zenith sluice
#

You can just set your metadata as

items:[{
  productId: 'xyz',
  quantity: 1
}]
quasi meteor
zenith sluice
quasi meteor
#

on the webhook endpoint side, when it receives the event

#

does it have access to line items?

zenith sluice
#

The event object doesn't include line_items, but you can retrieve the checkout session object again with line_items expanded.

quasi meteor
#

ok so

#

the event object is a checkout session right

#

specfiically checkout.session.completed

#

using this, I can retrieve this by looking up the checkout session via id and expanding line items?

zenith sluice
#

Yes you are right

quasi meteor
#

instead of expanding, does await stripe.checkout.sessions.listLineItems suffice?

zenith sluice
#

Sure that works as well

quasi meteor
#
const checkoutSessionId = event.data.object.id;
const lineItems = await stripe.checkout.sessions.listLineItems(
  checkoutSessionId,
  {
    limit: 100,
  }
);
const items = lineItems.data;```
#

does that look correct?

zenith sluice
#

Yes, looks good to me!

quasi meteor
#

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