#strmzi

1 messages ยท Page 1 of 1 (latest)

jade tideBOT
limpid burrow
#

Actually I just saw there is information about the user on the event, but since i'm still developing and not in production, how do I send web hooks to my endpoint when i'm going through the checkout process in test mode?

serene flower
#

Do you have an endpoint available on the public internet?

#

YOu can set up test mode webhook endpoints for development

#

If your endpoint isn't online/publi yet, you can use the CLI to forward events to a local endpoint:

jade tideBOT
limpid burrow
#

I am using the CLI to do so, but the consumer data is empty since it's not actually a customer, so how can I fake that so I can do some backend work?

obtuse lion
#

Is this event created by the CLI or are you actually making these payments and forwarding the events?

limpid burrow
#

no i'm using stripe trigger payment.intent

#

i'm trying to figure out how I can forward real test events

obtuse lion
#

Gotcha, you can do this either way. When triggering you can override the customer so that it does use a customer ID or you can just use stripe listen and do test payments to trigger the events

#

The CLI command would be stripe trigger payment_intent.succeeded --override payment_intent:customer=cus_12345 but with an actual customer ID at the end

limpid burrow
#

Where do I find more information about the customer Id and how I can set it?
And also do you mean writing this in the CLI: stripe listen --forward-to localhost:8000/stripe-webhook? I've got that running but i'm pretty sure that isn't actually connected to the checkout since I didn't specify it was on port 8000 anywhere (couldn't get the web hooks set up with nextjs so it's separate)

obtuse lion
#

The API reference is a good place to start. It talks about customers on payment intents https://stripe.com/docs/api/payment_intents/object#payment_intent_object-customer
And on customer objects in general https://stripe.com/docs/api/customers

#

That stripe listen command would work for any events on your account. If you complete a Checkout Session after running that command, the event should show up in the terminal

#

localhost:8000 is just where the stripe CLI forwards events to

limpid burrow
#

Got the customer part working, thanks ๐Ÿ‘๐Ÿผ

limpid burrow
#

Oh and since i'm already here, can I ask about setting up the webhook endpoint with next js? I'm on an express server right now since I couldn't figure out how to get the raw body with next and couldn't find anything online about it

obtuse lion
#

Yeah sure happy to help though we aren't as familiar with next. To take a quick step back: have you double checked that your webhook secret is being passed in to the function that constructs the webhook event? It is surprisingly common for the variable that is supposed to have it to be empty or be set to the secret for a different endpoint

limpid burrow
#

Yeah:

event = stripe.webhooks.constructEvent(
          request.body,
          signature,
          endpointSecret // whsec_....
        );
limpid burrow
#
export const config = {
  api: {
    bodyParser: false,
  },
};

export async function POST(request:any) {
console.log("event received");
  try {
    const rawBody = await buffer(request); // Invalid body
  } catch (err) {
    console.log(err);
  }
  return NextResponse.json({ status: 200 });
}
#

Also if I just log the body like so:

console.log(request.body)

I get the attached response, is it supposed to look like that?

obtuse lion
limpid burrow
#

that's what it looks like right after I run "stripe trigger payment_intent.succeeded"

obtuse lion
limpid burrow
#

Not entirely sure what you mean why pause in the debugger, but if I log the entire request and look through it, there is nothing that resembles the event object

#

I can send you the request in chunks (max length), if you'd like to see the request i'm getting

obtuse lion
#

Ah it looks like ReadableStream is a Next.js object

#

So your output is json of the ReadableStream object rather than the string contained by the stream

jade tideBOT
limpid burrow
#

I see, so i've just go to find a way to get the string inside the stream?

surreal burrow
#

Hi ๐Ÿ‘‹

I"m stepping in as @obtuse lion needs to go soon. The issue of getting raw bodies has come up specifically for Next.js and Stripe here: https://github.com/vercel/next.js/discussions/13405. You may find some of the work arounds developers suggested to be useful

limpid burrow
#

@obtuse lion thanks for the help ๐Ÿ‘๐Ÿผ

limpid burrow