#Abhi ->

1 messages · Page 1 of 1 (latest)

pliant lionBOT
stiff remnant
#

Can you share your code please

low scaffold
#

const sig = req.headers['stripe-signature'];

let event;

console.log(req.body,sig,stripeWebhookSecret);
try {
event = stripe.webhooks.constructEvent(req.body, sig, stripeWebhookSecret);
} catch (err) {
console.log( ^}^l STRIPE KYC Error message: ${err.message});
return res.status(400).send(Webhook Error: ${err.message});
}
console.log('STRIPE EVENT>>',event.type);

#

you need req body

stiff remnant
#

The full webhook route/handler please

low scaffold
stiff remnant
#

What framework is this?

low scaffold
#

express js

#

that file function handles that webhook endpoint that is connected to stripe acc

#

i got the err in this section
const sig = req.headers['stripe-signature'];

    let event;
console.log(req.body,sig,stripeWebhookSecret);
    try {
      event = stripe.webhooks.constructEvent(req.body, sig, stripeWebhookSecret);
    } catch (err) {
        // On error, log and return the error message
        console.log(`❌ STRIPE KYC Error message: ${err.message}`);
        return res.status(400).send(`Webhook Error: ${err.message}`);
    }
    console.log('STRIPE EVENT>>',event.type);
#

you need any req body or header data?

stiff remnant
#

Express.js is likely parsing the Request object so its not the raw object as the constructEvents expects:

app.post('/webhook', express.raw({type: 'application/json'}), (req, res) => 
low scaffold
#

so which row object constructEvents expects

#

is req.body.data.object

stiff remnant
#

Did you look at the example I just shared?

low scaffold
#

yes applied and get same as previous
Updated:
router.post('/identityWebhook',express.raw({type: 'application/json'}),ctrl.identityWebhook)

#

sorry to create a problem for u but can you help me to solve this.

stiff remnant
#

You haven't shared your full code with me in its current state

low scaffold
stiff remnant
#

And what's the exact error?

low scaffold
#

raw body
{
id: 'evt_1NYPHbGYQpSlp3uiTYqciO1p',
object: 'event',
api_version: '2019-09-09',
created: 1690445451,
data: {
object: {
id: 'vs_1NYPHbGYQpSlp3uiMU4bwcal',
object: 'identity.verification_session',
client_secret: 'xxx',
created: 1690445451,
last_error: null,
last_verification_report: null,
livemode: true,
metadata: [Object],
options: [Object],
redaction: null,
status: 'requires_input',
type: 'document',
url: 'https://verify.stripe.com/start/live_YWNjdF8xRkoxZ2hHWVFwU2xwM3VpLF9PTDVTS3VaM3ZpeHc0YmhYeUF5elJUazVVOEk2elZJ01007iaQnYJs'
}
},
livemode: true,
pending_webhooks: 1,
request: {
id: 'req_07CtPeNOwmUmk7',
idempotency_key: '5ac161cb-ac2b-47a1-b7be-2f2480b168fc'
},
type: 'identity.verification_session.created'
}

stiff remnant
#

Where did you log that in your code? That's not the raw body

low scaffold
#

so which raw body expects can u help me in that

stiff remnant
#

req.body. If you're doing console.log(req.body) somewhere then that'll parse it and it'll no longer be 'raw'

low scaffold
#

still getting err

stiff remnant
#

Are you doing a console.log(req.body)?

low scaffold
#

not at all now

#

async (req, res, next) => {
const sig = req.headers['stripe-signature'];

let event;

try {
event = stripe.webhooks.constructEvent(req.body, sig, stripeWebhookSecret);
} catch (err) {

#

now direct call constructEvents

stiff remnant
#

Where's the express.raw() middleware gone?

low scaffold
#

budy after that raw this will be called

#

router.post('/identityWebhook',express.raw({type: 'application/json'}),async (req, res, next) => {
const sig = req.headers['stripe-signature'];

    let event;
    try {
      event = stripe.webhooks.constructEvent(req.body, sig, stripeWebhookSecret);
    } catch (err) {
stiff remnant
#

I'm confused, why do you have 2 different async functions that call constructEvent?

low scaffold
#

why you think both are diff upper one is a part of second one

stiff remnant
#

I've asked you to share your full code, yet you keep sharing smaller parts of it which is seemingly different every time

low scaffold
stiff remnant
#

Ok, now what is the error message?

#

Where is stripeWebhookSecret defined?

low scaffold
#

yes

stiff remnant
#

I don't see it in your code

low scaffold
#

let stripeKey =
process.env.STRIPE_SANDBOX === 'true'
? process.env.STRIPE_SANDBOX_SK
: process.env.STRIPE_PRODUCTION_SK;

const stripe = require('stripe')(stripeKey);
const stripeWebhookSecret = process.env.STRIPE_SANDBOX === 'true'
? process.env.STRIPE_SANDBOX_WEBHOOK_SEC
: process.env.STRIPE_PRODUCTION_WEBHOOK_SEC;

#

buddy i have more wbhook rather then stripe so that's why i can not give you full file,

stiff remnant
#

This is why I asked to see the full code

#

How am I meant to help you without the full context of your code?

#

Is this running locally, or hosted?

low scaffold
#

problem was occurs in hosted

stiff remnant
#

Ok, hosted where?

low scaffold
#

sorry but for now i'm checking in local

#

hello can we just finish this here

#

thanks for try to help me

stiff remnant
#

What was the issue?

low scaffold
#

still not found buddy but i'll try

stiff remnant
#

Does it work locally?

low scaffold
#

i tried in test mode

#

not in live mode

#

that's all is now in local and try to test in live mode

stiff remnant
#

Yes, but can you run the code locally on your machine? You can use the CLI to trigger an event

stiff remnant
low scaffold
#

not like that we have staging env so i can test in that and set the webhook in stripe

sinful dune
#

Hi! I'm taking over this thread.

low scaffold
#

hello soma

sinful dune
#

Can you console.log the stripeWebhookSecret, and check that it matches the one you see in your Stripe dashboard? It should start with whsec_.

low scaffold
#

yes i check previously, above i loged those details

sinful dune
#

Can you tripe check just to make sure? This is a very common mistake.

#

Also can you share your webhook endpoint ID (we_xxx)?

low scaffold
#

ok

low scaffold
#

below works for me,
req.rawBody = req.body.toString();

#

thanks to you and your college for help me, u both r good.