#nikivi

1 messages · Page 1 of 1 (latest)

indigo smeltBOT
rapid crag
#

Hi 👋

What stripe objects are you working with and what webhook event are you listening to?

boreal fox
#

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

rapid crag
#

This is a lot of screenshots. I just need you to tell me what the object is. I think Checkout Session?

boreal fox
#

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

rapid crag
#

Okay, do you. have an example checkout session ID I can review?

rapid crag
#

Okay I see the metadata is associated

boreal fox
#

I have server running locally with my we hook

rapid crag
#

The screenshots are useless.

boreal fox
#

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?

#

reading this now but it's unclear where that's exposed

rapid crag
#

You keep talking about things that have nothing to do with metadata

#

I'm rather confused what you are trying to do

boreal fox
#

i basically need access to metadata in web hook

#

you say its passed

rapid crag
#

The Checkout Session object has metadata on it

#

When you receive the webhook event it will contain a property called object

boreal fox
#

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

rapid crag
boreal fox
#

i get request and response, i don't know where metadata is

rapid crag
#

Take a look at the code in the quickstart builder

#

it walks through getting the event object

boreal fox
#
    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

#

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

rapid crag
#

If you are using TypeScript you will need to cast the output to the correct Type

boreal fox
#
⚠️  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

rapid crag
#

Okay, then you need to look into troubleshooting your signature verification.

boreal fox
#

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?

rapid crag
#

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

boreal fox
#

stripe listen --forward-to localhost:4242/webhook

#

yes i have this running

rapid crag
#

Okay so the troubleshooting steps that make reference to a published webhook endpoint are not ones you need to focus on here

boreal fox
#

is there a different help url

#

for this case

#

because this is for published ones

#

if i get you right

rapid crag
#

You DO NOT want to attempt the verify them manually

boreal fox
#
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

rapid crag
#

The secret won't be in the dashboard because it's a local listener

boreal fox
rapid crag
#

You need to copy it from the terminal window

boreal fox
#

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

rapid crag
#

The code in the quickstart does not handle the checkout.session.completed event

#

You will need to write that yourself

boreal fox
#
      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

rapid crag
#

What do you see when you log the object for checkout.session.completed?

indigo smeltBOT
boreal fox
#

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

rapid crag
boreal fox
#
    // 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

boreal fox
#

async (request, response) => {

#

its ok to make it async?

#

i need it to do await fetch inside