#rajput.abd_22

1 messages · Page 1 of 1 (latest)

indigo prawnBOT
vital mauve
#

Hi! Let me help you with this.

#

Are you following any guide?

granite falcon
#

yup

vital mauve
#

As the error message suggests, it seems like your app is parsing the event payload.

#

You need to disable middleware that does that.

granite falcon
#

app.post('/webhook', express.raw({type: 'application/json'}), (request, response) => {
let event = request.body;
// Only verify the event if you have an endpoint secret defined.
// Otherwise use the basic event deserialized with JSON.parse
if (endpointSecret) {
// Get the signature sent by Stripe
const signature = request.headers['stripe-signature'];
try {
event = stripe.webhooks.constructEvent(
request.body,
signature,
endpointSecret
);
} catch (err) {
console.log(⚠️ Webhook signature verification failed., err.message);
return response.sendStatus(400);
}
}

// Handle the event
switch (event.type) {
  case 'payment_intent.succeeded':
    const paymentIntent = event.data.object;
    console.log(`PaymentIntent for ${paymentIntent.amount} was successful!`);
    // 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;
  default:
    // Unexpected event type
    console.log(`Unhandled event type ${event.type}.`);
}

// Return a 200 response to acknowledge receipt of the event
response.send();

});

i get this from the docs provided by stripe

#

i didn't change anything

vital mauve
#

What about the rest of the app?
Are you using any other middleware?

granite falcon
#

yes i used bodyparser and cors

vital mauve
#

"bodyparser" is the problem

#

You need to put your handler before it.

granite falcon
#

where i didn't get it actually

#

@vital mauve Are you there

vital mauve
#

Where are you using the body parser?

granite falcon
#

my whole application is using body-parser

#

can i share my dummy application code

#

@vital mauve are you there

vital mauve
#

Yes please

granite falcon
#

yes webhook is at the end of file @vital mauve

vital mauve
#

You need to put the webhook in the beginning, before app.use(bodyParser.json());

granite falcon
#

but this things make issue in my main project

vital mauve
#

Why?

#

What issues?

#

In any case, if you don't do this, the webhooks won't work.

granite falcon
#

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

#

this issue is coming

vital mauve
#

This is the same issue you shared initailly.

#

But we are talking about a different problem right now.

granite falcon
#

i changes code

vital mauve
#

Could you please share the new code?

granite falcon
#

okay

indigo prawnBOT
whole nacelle
#

Hey! Taking over for my colleague. Let me catch up.

granite falcon
#

okay Please

whole nacelle
#

Did you try to download that sample and simply run it without updating any thing ?

granite falcon
#

yupp this is the copy code

#

ctrl + c , then ctrl + v

#

@whole nacelle are you there

whole nacelle
#

Yes I'm here, please stop using mentions, we are monitoring all threads.

#

the code you've provided has changes.

granite falcon
#

thanks

#

for the help

whole nacelle
#

Between, You need to remove bodyParser.