#Scheggia-webhook-signature

1 messages · Page 1 of 1 (latest)

velvet echo
#

Hello!

pearl locust
#

Hi

velvet echo
#

What's the issue exactly

pearl locust
#

in my code:

#
const endpointSecret = "copied from website";
app.post('/stripe/webhook', express.raw({type: 'application/json'}), (request, response) => {
    const sig = request.headers['stripe-signature'];
  
    let event;
  
    try {
      event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret);
    } catch (err) {
      response.status(400).send(`Webhook Error: ${err.message}`);
      return;
    }
  
    // Handle the event

#

I need to send event id?

velvet echo
#

Nope, one sec.

pearl locust
#

okay thanks

#

Error is 400 ERR

velvet echo
#

What does your Express initialization look like?

#

Are you using app.use(express.json())?

pearl locust
#
var express = require('express');
var session = require('express-session');
var bodyParser = require('body-parser');
var path = require('path');
var app = express();
app.use(session({secret: 'secret',resave: true,saveUninitialized: true}));
app.use(bodyParser.urlencoded({extended : true}));
app.use(bodyParser.json());
pearl locust
velvet echo
#

Okay try changing that to app.use((req, res, next) => { if (req.originalUrl === '/stripe/webhook') { next(); // Do nothing with the body because I need it in a raw state. } else { app.use(session({secret: 'secret',resave: true,saveUninitialized: true})); app.use(bodyParser.urlencoded({extended : true})); app.use(bodyParser.json()); } });

pearl locust
#

okay

pearl locust
#

now i try

#

nice, thank you!

#

Working

velvet echo
#

🎉

pearl locust
#

Nice day!

velvet echo
#

You too!

pearl locust
#

sorry

#

another problem @velvet echo

velvet echo
#

Sure

pearl locust
#

please check this

#

From webhook i get disabled reason, ok but i don't see the details_submitted


      "requirements": {
        "alternatives": [
        ],
        "current_deadline": null,
        "currently_due": [
        ],
        "disabled_reason": null,
        "errors": [
        ],
        "eventually_due": [
        ],
        "past_due": [
        ],
        "pending_verification": [
        ]
      },
#

My code is
if (account.requirements.disabled_reason === null && account.requirements.details_submitted === true) {

velvet echo
#

details submitted is not a property of the requirements object

#

It is at the account object level

#

So it should be account.detailed_submitted === true

pearl locust
#

There is nowhere in the request

#

oh sorry

#

i saw

#

fixed!

#

thanks for support

#

and nice day again!