#Ajith Selvakumar-webhook-metadata

1 messages · Page 1 of 1 (latest)

ember lodge
#

Hey, what parameter did you pass to set the metadata?

#

What events are you subscribed to?

green heron
#

Subscribed to all invoice events

ember lodge
#

Yes, so that metadata parameter will on be set on the Checkout Session object, not the underlying subscription object

green heron
#

is this correct? And i need the meta data on all the invoice events

#

Will this work for that use case?

ember lodge
green heron
#

What do you mean by expand?

#

How can i do that

ember lodge
#

You'll need to make an API call to retrieve the Invoice object, passing the expand: ['subscription'] parameter

green heron
#

Okay do you have any code examples for this

#

I am not a great developer just 1 year of experience, i am finding it too difficult

ember lodge
#

With stripe-node?

const invoice = await stripe.invoices.retrieve(
  'in_xxx', {
    expand: ['subscription']
  }
);
green heron
#

Okay in order to get metadata, i need to retrieve the session. Won't i get them in the response body of the webhook where we can get the event.

ember lodge
#

No, as explained the subscription field on the Invoice object is just the sub_xxx ID. If you need the metadata field from the Subscription object you'll need to expand (using that API call ☝️ ) and it'll be in the response

green heron
#

is this fine?

ember lodge
#

Why are you retrieving the Checkout Session?

#

You should retrieve the Invoice in your webhook that is receiving the invoice.* events

#

There won't be any Checkout Session context in those event payloads

green heron
#

Okay

#

Is this fine?

#

This is the webhook code

ember lodge
#

event.type isn't the parameter you need to pass there. It'll be event.data.object.id

green heron
ember lodge
#

.id

green heron
#

Oops

ember lodge
#

Are you testing this webhook code locally via the Stripe CLI?

green heron
#

Yes i am trying to do so, but it says "No signatures found matching the expected signature for payload"

ember lodge
#

You need to use the webhook secret whsec_xxx that the CLI prints out

#

Not the one from the Dashboard

green heron
#

Yes I gave the secret key from the cli only, still it says that error

ember lodge
#

My guess is whatever framework/library you're using is manipulating _req.body

#

The constructEvent function expects the raw request object

green heron
#

Ohh okay

ember lodge
green heron
#

Can you assist on checking this webhook with a trigger to setup subscription?

ember lodge
#

I'm not sure what you mean

green heron
#

I have the webhook running locally and it will be called while any trigger.

#

I need to set a trigger to test it. So that i can confirm that we are getting the metadata in the webhook

ember lodge
#

stripe trigger invoice.paid

green heron
#

I think first we need to give metadata in some format right?

ember lodge
#

If you have a pre-existing subscription with the metadata, you can just re-send a related event to the webhook