#nikivi
1 messages · Page 1 of 1 (latest)
Hi 👋
What stripe objects are you working with and what webhook event are you listening to?
so the metadata
100 is just mock
but will be actual user id
then on web hook side
im reading docs now and I am not sure how to read the userId
also I am not sure if my event validation is right
basically when user succesfully pays here, this web hook should be hit with the userId
after running stripe trigger, checkout.session.completed is one that looked like what I need
not sure though
This is a lot of screenshots. I just need you to tell me what the object is. I think Checkout Session?
yes
const data = await stripe.checkout.sessions.create
try {
const data = await stripe.checkout.sessions.create({
success_url: process.env.STRIPE_SUCCESS_URL!,
mode: "subscription",
metadata: {
userId: 100,
},
line_items: [
{
quantity: 1,
price: process.env.STRIPE_PRICE_ID!,
},
],
})
full call
Okay, do you. have an example checkout session ID I can review?
Okay I see the metadata is associated
I have server running locally with my we hook
The screenshots are useless.
apologise
app.post(
"/webhook",
express.raw({ type: "application/json" }),
async (request: any, response: any) => {
i don't have types on req and resp
and not sure where can i read the metadata
is it possible to type the req/respo in node.js?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
reading this now but it's unclear where that's exposed
You keep talking about things that have nothing to do with metadata
I'm rather confused what you are trying to do
The Checkout Session object has metadata on it
When you receive the webhook event it will contain a property called object
so thats request. something?
or response.
app.post(
"/webhook",
express.raw({ type: "application/json" }),
async (request: any, response: any) => {
const sig = request.headers["stripe-signature"]
is my web hook, code from stripe docs
You can review how that works here: https://stripe.com/docs/webhooks/quickstart?lang=node
i get request and response, i don't know where metadata is
Take a look at the code in the quickstart builder
it walks through getting the event object
let event = request.body
console.log(event.data.object.metadata.userId)
ok perfect
trying this
ok thats not it, reading it again
for some reason I thought object included .metadata
https://stripe.com/docs/webhooks/quickstart?lang=node this link you sent has no mention of metadata
will try log object i guess
this makes no sense
i don't know how to not describe it with screenshots, sorry
just confused
im doing essentially same thing
ok i removed ts and doing it as they do in docs exactly
If you are using TypeScript you will need to cast the output to the correct Type
⚠️ Webhook signature verification failed. No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
getting this
Okay, then you need to look into troubleshooting your signature verification.
A colleague of mine wrote a great guide for this here: https://support.stripe.com/questions/troubleshooting-webhook-delivery-issues
I can't do step 3 of it
Switch to the Failed tab
there is no failed tab for me
I see this
and I thought this was for when you want to do production
my node http server is not yet deployed
its on localhost now
so don't really know how to get to the failed tab
or i should create it for localhost
ok I need to deploy it
to debug?
You need to slow down, not share screenshots, and think this through
Are you using the stripe CLI to forward webhook events to your local development server
Okay so the troubleshooting steps that make reference to a published webhook endpoint are not ones you need to focus on here
is there a different help url
for this case
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
because this is for published ones
if i get you right
You can review how to check signatures in this doc here: https://stripe.com/docs/webhooks/signatures
You DO NOT want to attempt the verify them manually
2023-05-12 19:10:14 --> checkout.session.completed [evt_1N6zTuKmRnbuc3WvDVNgIlYP]
2023-05-12 19:10:14 <-- [400] POST http://localhost:4242/webhook [evt_1N6zTuKmRnbuc3WvDVNgIlYP]
2023-05-12 19:10:14 --> charge.succeeded [evt_3N6zTsKmRnbuc3Wv14n2gyIq]
2023-05-12 19:10:14 <-- [400] POST http://localhost:4242/webhook [evt_3N6zTsKmRnbuc3Wv14n2gyIq]
2023-05-12 19:10:14 --> payment_method.attached [evt_1N6zTuKmRnbuc3WvfpUB7Tyx]
2023-05-12 19:10:14 <-- [400] POST http://localhost:4242/webhook [evt_1N6zTuKmRnbuc3WvfpUB7Tyx]
2023-05-12 19:10:14 --> customer.created [evt_1N6zTuKmRnbuc3WvOixdzRjM]
2023-05-12 19:10:14 <-- [400] POST http://localhost:4242/webhook [evt_1N6zTuKmRnbuc3WvOixdzRjM]
2023-05-12 19:10:14 --> customer.updated [evt_1N6zTuKmRnbuc3Wv9MRkm6o6]
i get this showing when I do payment
it repeats even more but can't share due to length
const endpointSecret = "whsec_..."
have a feeling its failing due to this
trying to find secret in dashboard now
The secret won't be in the dashboard because it's a local listener
You need to copy it from the terminal window
its code 1 to 1 copied to my editor
oh ok will copy now
Running on port 4242
Unhandled event type checkout.session.completed.
Unhandled event type charge.succeeded.
Unhandled event type customer.created.
Unhandled event type customer.updated.
Unhandled event type invoice.created.
Unhandled event type invoice.finalized.
Unhandled event type customer.subscription.created.
Unhandled event type invoice.updated.
Unhandled event type customer.subscription.updated.
Unhandled event type invoice.paid.
Unhandled event type invoice.payment_succeeded.
PaymentIntent for 1000 was successful!
Unhandled event type payment_intent.created.
beauty, ok that was my issue
the thing not clear still is how to get access to metadata
its in event. somewhere
console.log(`PaymentIntent for ${paymentIntent.amount} was successful!`)
console.log(event.data.object)
ok i did this
ok its not anywhere there
no userId passed
The code in the quickstart does not handle the checkout.session.completed event
You will need to write that yourself
case "payment_intent.succeeded":
const paymentIntent = event.data.object
console.log(`PaymentIntent for ${paymentIntent.amount} was successful!`)
console.log(event.data.object)
// Then define and call a method to handle the successful payment intent.
// handlePaymentIntentSucceeded(paymentIntent);
break
case "payment_method.attached":
const paymentMethod = event.data.object
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handlePaymentMethodAttached(paymentMethod);
break
can i remove these
case "checkout.session.completed":
const paymentMethod = event.data.object
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handlePaymentMethodAttached(paymentMethod);
break
and just have this?
or i need all?
case "checkout.session.completed":
console.log(event.data.object)
ok trying this
not really sure how to proceed, is there a doc on how to do checkout.session.completed properly?
with metadata processing
What do you see when you log the object for checkout.session.completed?
metadata: { userId: '100' },
ok that worked
its there
just one question then
for my use case of just wanting to validate that checkout.session.completed
its enough to have one event?
im reading the object
event.data.object
and trying to find if there is .success: true/false somewhere there
or i should instead create an event for that
checkout.session.failed perhaps
status: 'complete',
ok there is this
not sure how to test failure case
We have separate events for that. You can review them here: https://stripe.com/docs/api/events/types
// Handle the event
switch (event.type) {
case "checkout.session.completed":
if (event.data.object.status === "complete") {
// call my db, update User model
return
}
break
default:
// Unexpected event type
console.log(`Unhandled event type ${event.type}.`)
}
basically i have this now
great thank you
async (request, response) => {
its ok to make it async?
i need it to do await fetch inside