#nikivi
1 messages · Page 1 of 1 (latest)
Hello! Can you clarify - which event are you expecting?
this is my router currently
i create a checkout session here
on test account, i go through the payment with 424242
in local I run this
i expect the stripe to send events to my endpoint
but i get nothing
after completing this
Can you give me a checkout session ID I can look at?
When you ran the stripe listen command, did you make sure to run it before the payment was successful?
Possibly - are you sure you're logged into the same account in the CLI that's doing the payments?
there is only one account
so yes
just ran stripe login again
maybe localhost:8787/wiki-bought
should be full ip address
it doesn't like localhost
anything i can do to debug
never runs
let's pause for a second
just do stripe listen (don't include the forward-to)
and then try the payment again to see if you get the event
i do
stripe listen --forward-to http://127.0.0.1:8787/wiki-bought
going to try with this
ok that works
i do get this though
app.post("/wiki-bought", async (c: Context) => {
let event = c.req.body
const stripe = new Stripe(c.env.STRIPE_WIKI_SECRET_KEY!, {
apiVersion: "2022-11-15",
typescript: true,
})
const endpointSecret = c.env.STRIPE_WIKI_WEBHOOK_SECRET!
if (endpointSecret) {
// Get the signature sent by Stripe
const signature = c.req.header("stripe-signature")
try {
event = stripe.webhooks.constructEvent(c.body, signature, endpointSecret)
} catch (err) {
console.log(`⚠️ Webhook signature verification failed.`, err.message)
c.status(400)
return c.json({ err: "failed" })
}
}
// Handle the event
switch (event.type) {
case "checkout.session.completed":
const checkoutSessionCompleted = event.data.object
console.log(checkoutSessionCompleted)
break
default:
// Unexpected event type
console.log(`Unhandled event type ${event.type}.`)
}
return c.json({})
})
is my code
its not express
its using https://hono.dev
but that signature check should work
as thats unrelated to hono
i think
what could cause this
give me a few minutes to look
im running it in context of cloudflare workers
Still looking - sorry for the wait
yea ofc
Instead of constructEvent try using constructEventAsync
ok @digital zinc
that fixed that error
but now
app.post("/wiki-bought", async (c: Context) => {
let event = c.req.body
const stripe = new Stripe(c.env.STRIPE_WIKI_SECRET_KEY!, {
apiVersion: "2022-11-15",
typescript: true,
})
const endpointSecret = c.env.STRIPE_WIKI_WEBHOOK_SECRET!
if (endpointSecret) {
// Get the signature sent by Stripe
const signature = c.req.header("stripe-signature")
try {
event = stripe.webhooks.constructEventAsync(
c.body,
signature,
endpointSecret
)
} catch (err) {
console.log(`⚠️ Webhook signature verification failed.`, err.message)
c.status(400)
return c.json({ err: "failed" })
}
}
console.log(event, "event")
// Handle the event
switch (event.type) {
case "checkout.session.completed":
const checkoutSessionCompleted = event.data.object
console.log(checkoutSessionCompleted)
break
default:
// Unexpected event type
console.log(`Unhandled event type ${event.type}.`)
}
return c.json({})
})
on this code
it never reaches checkout.session.completed
i console logged event
these are logs i see
its taken from stripe example code
are logs in listen
Sorry I should've been more specific - constructEventAsync is an async function now, so you have to wait for it resolve before you get the event
event = await stripe.webhooks.constructEventAsync
yup
getting this
try {
event = await stripe.webhooks.constructEventAsync(
c.body,
i think its this c.body
Yeah, I don't know the specifics of how to do this with cloudflare workers, but agreed that c.body is likely the issue. You need to find out how to get the raw body (as a strong or buffer)
would array buffer work
I'm not sure - but you should just try it out and see
(I don't have a hono integration handy, so it'll be way faster for you to try this out on your end)
where is stripe.webhooks.constructEventAsync in stripe docs
can't find it
someone in hono discord asked
@digital zinc
I don't know where it is in the docs - I found it in by checking in the stripe-node library https://github.com/stripe/stripe-node
trying to debug now
if anyone knows a solution, would be lovely
but even the stream printed there should at least show some bytes, iirc
at least Node does, not sure if the CF runtime does too
perhaps this
Hello! I'm taking over and catching up...
thank you ❤️
Try passing it c.req.text().
Yep.
Sorry, I wasn't clear. c.req.text() returns a Promise that resolves with the text content of the body. You need to do something like const textBody = await c.req.text() and then pass in textBody.
so this
do you by chance know what those errors are about
signature!,
i can silence signature one like this i guess
but that would still be doing this
ok i get my events thank god
Those are type errors that are beyond the scope of what I can help with.
thank you kindly @thorn jolt
not sure if i should open new help thread
but basically
events don't get sent for me
this is for a different product
i wanted to move away from express
from it too
just completed this
this is running
but no events got sent to my endpoint
going to try with just stripe listen
as advice above
yea no events
dont get why
If you do just stripe listen does it work?
it does not
is it because i have to login individually
to each of those things
or something
i thought if stripe listen
because those checkouts
are on KusKus project
Oh, yeah, if it's happening on a different account then you need to use stripe login to log in to the different account.