#cookernetes
1 messages ยท Page 1 of 1 (latest)
Where exactly is that crash happening?
In an express route, following this guide: https://stripe.com/docs/payments/checkout/fulfill-orders?locale=en-GB
It's trying to read properties of undefined so something isn't working like you expect
app.post("/downProduct", bodyParser.raw({ type: "application/json" }), async (req, res) => {
const dataPayload = req.body;
const sig = req.headers["stripe-signature"];
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(dataPayload, sig, endpointSecret);
} catch (err) {
return res.status(400).send(`Webhook Error: ${err.message}`);
}
if (event.type === "checkout.session.completed") {
// Retrieve session
const sessionWithLineItems = await stripe.checkout.sessions.retrieve(dataPayload.data.object.id, {
expand: ["line_items"],
});
const lineItems = sessionWithLineItems.line_items;
// Order Fulfillment
console.log(lineItems);
}
res.status(200).end();
});
That's the full code
Oh right, it might have something to do with dataPayload being:
<Buffer 7b 0a 20 20 22 69 64 22 3a 20 22 65 76 74 5f 31 4d 57 52 5a 47 45 4a 79 49 32 71 46 5a 65 68 6f 49 6e 78 51 6e 65 41 22 2c 0a 20 20 22 6f 62 6a 65 63 ... 3553 more bytes>
lol
How can I do this?
(@sturdy narwhal)
(sorry for the ping, this is something that needs to go into prod very soon)
As a fallback, signature verification is optional. You could use parseEvent in the interim while you sort out signature verification
Assuming you pass the raw body and the correct endpointSecret that's expected to work
So I can do the rest
I would expect that payload/body to be a string at that point, i think.
Nah it's parsing in a buffer
It's getting raw... which is a buffer amiright?
Yeah
"Returns middleware that parses all bodies as a Buffer and only looks at requests where the Content-Type header matches the type option."
Hi there ๐ taking over, as my colleague needs to step away
Wasn't this working earlier when we chatted?
It was working in the IDE, didn't run it ๐คฃ
Lmao
I just want to follow this guide in my code
Can you post the URL that leads to this guide?
Then lang is set to node on the site
But it's so weird as session is not defined anywhere in that code....
Yeah, I think that's a placeholder that's intended to be changed
oh hang on just a sec before i go, if that's crashing in your retrieve() call (not constructEvent) then you need to replace dataPayload there with event
Yes and this is the issue I had and spoke to @opal crater about earlier
However, surely from the data I am getting back, it would be event.data.object.id... right? Well it doesn't let me.
event.data.object.id should be the session id
This is what error I get
And I have defined event as Stripe.Event; like this:
let event: Stripe.Event;
Is that the wrong typedef for event?
Because the constructEvent returns it...
Is there a way to fix this? (I basically want to get the id from the object in data in event, but TS doesn't like that)
@opal crater
Can you try ignoring typescript for that line and running the code to see if it works?
Yeah, that just sounds like it's not configured to know that the object will be a Stripe Event when the code receives a request. I'm not sure of a bette workaround beyond simply telling TS to ignore that line