#strmzi
1 messages ยท Page 1 of 1 (latest)
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?
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:
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?
Is this event created by the CLI or are you actually making these payments and forwarding the events?
no i'm using stripe trigger payment.intent
i'm trying to figure out how I can forward real test events
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
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)
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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
Got the customer part working, thanks ๐๐ผ
It did, thanks for the help
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
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
Though for express specifically there are a couple known workarounds for getting the raw body:
https://github.com/stripe/stripe-node/issues/341
https://github.com/stripe/stripe-node/issues/356
Yeah:
event = stripe.webhooks.constructEvent(
request.body,
signature,
endpointSecret // whsec_....
);
With express I got it working pretty quickly but with next js, which is what i'm using to build my app, I couldn't figure it out... I'll get my code 1 moment
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?
That isn't what it is expected to look like. The body should look similat to our example event on this page https://site-admin.stripe.com/docs/api/events/object
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
that's what it looks like right after I run "stripe trigger payment_intent.succeeded"
Can you pause in your debugger and see if anything looks like that event? It sounds like request.body might be something very different. If you have the ID of the event you can see what Stripe sent you by looking at https://dashboard.stripe.com/test/events/evt_1234
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
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
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
I see, so i've just go to find a way to get the string inside the stream?
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
@obtuse lion thanks for the help ๐๐ผ
I actually just solved it :) thanks though ๐๐ผ