#Mao
1 messages ยท Page 1 of 1 (latest)
Hi again!
Hi ! ๐
I did what you told me.
And I have an idea, I think my problem is due to my app.use(express.json()), which parses my data
Can you share your full code, and the exact error message you get?
My route :
app.route("/stripe/webhook")
.post(CommandeController.webhook, express.raw({ type: 'application/json' }));
And the code :
const stripe = new Stripe(process.env.STRIPE_PK_KEY, {
apiVersion: "2022-08-01"
});
const endpointSecret = "whsec_53a5c720f4f70edzhjzdhjzdhjdzhjzda33b53d0451f9172e4d925c9c42634fa8";
const sig = String(req.headers['stripe-signature']);
let event;
console.log("=====================================");
console.log(req);
console.log("=====================================");
console.log(sig);
try {
event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
And in req.body I have undefined
I recommend editing your message above to remove the whsec_xxx
Not sure what you mean by "not the real endpointSecret".
I voluntarily changed the endpointSecret for security so no problem
Got it!
And the console.log(req) and console.log(sig) is working in your code? only req.body is undefined?
console.log(sig) working, not problem.
console.log(req), too
Only the req.body
It's strange
Hi ๐ jumping in as my teammate needs to step away, can you share the contents of what you see when you log req? Maybe that'll give us some more insight into how that object is structured.
Sure, this is my req : https://pastebin.com/TsLYQW5e
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
If I add express.json() it works I have a req.body
But it modifies the JSON of the req.body sent by Stripe
Can you elaborate on how you're adding express.json(), I'm wondering if adding express.raw() in the same fashion would give you the raw body.
app.route("/")
.get(index);
// !OTHERS
app.route("/client/:clientId([0-9]+)")
.put(guardJwtFront, FrontClientController.update)
.delete(guardJwt, FrontClientController.destroy);
app.route("/stripe/webhook")
.post(CommandeController.webhook, express.raw({ type: 'application/json' }));
``` Express RAW
```js
app.route('/admin/*').all(express.json());
``` Express JSON
Oooooh that workings !!
Now I have that :
=====================================
. dev: <Buffer 7b 0a 20 20 22 69 64 22 3a 20 22 65 76 74 5f 31 4c 69 65 62 36 41 5a 78 64 63 55 7a 32 68 58 50 62 65 48 56 53 4e 6f 22 2c 0a 20 20 22 6f 62 6a 65 63 ... 2407 more bytes>
And the next :
Unhandled event type charge.succeeded
Thank's you very much !!
Wooh, glad to hear you were able to get that working!
Thank's !!! โค๏ธ
I have another question
In preproduction, should I be successful?
That looks like the screen that shows the delivery status of webhook events. I think that's indicating your endpoint returned an error rather than a 2XX status.
Yep :
Webhook Error: Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing
whyyyyyy ๐ข
That's usually caused by one of two reasons. Either the wrong webhook signing secret is being used, or you're not getting the raw contents of the request body.
But in local, that working, it's the same code for the raw request body
When you say local, were you using the Stripe CLI to forward the events to your endpoint?
Yep !
The Stripe CLI generates its own webhook signing secret, which is different from the ones that your Webhook Endpoints will use. Each Webhook Endpoint that you create will generate its own unique signing secret that must be used to validate its events.
If you go to this page in your dashboard, and then click on the endpoint that you're trying to use you'll see a reveal button that you can use to reveal the signing secret for that endpoint:
https://dashboard.stripe.com/test/webhooks
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
I will test in pre-production with the pre-production webhook key
It's working thank's !!!!
Thank's !