#raulru
1 messages ยท Page 1 of 1 (latest)
Hello
How are you testing here? Are you forwarding from the CLI or you receiving on an HTTPS endpoint?
i tried both, i get the same result with cli and ngrok https
Are you using our Node SDK here?
And did you double check that you are using the correct webhook signing secret?
Yup, im using it, as you can see it gives me 2 success logs but a ton of errors, so i dont know if thats normal
Hvae you logged out the body that you are passing to constructEvent?
`// This is your test secret API key.
const stripe = require("stripe")(
"sk_test_51Nzj90DaFxfZlKZXXXXXXXXXlnkA1NO4iF8PiJ4kvrXXXXXXXVa009IHU726h"
);
const express = require("express");
const app = express();
app.use(express.static("public"));
app.use(express.urlencoded({ extended: true }));
const YOUR_DOMAIN = "http://localhost:4242";
app.use((req, res, next) => {
if (req.originalUrl === "/webhook") {
next();
} else {
express.json()(req, res, next);
}
});
app.post("/webhook", express.raw({ type: "application/json" }), (req, res) => {
const sig = req.headers["stripe-signature"];
let event;
const webhookSecret = "whsec_3XXXXXXXXXdnTHWGB1Rxe";
try {
event = stripe.webhooks.constructEvent(req.body, sig, webhookSecret);
} catch (err) {
// On error, log and return the error message
console.log(โ Error message: ${err.message});
return res.status(400).send(Webhook Error: ${err.message});
}
// Successfully constructed event
console.log("โ
Success:", event.id);
// Return a response to acknowledge receipt of the event
res.json({ received: true });
});
app.use(express.json());
app.listen(4242, () => console.log("Running on port 4242"));`
Log out req.body in the line before event = stripe.webhooks.constructEvent(req.body, sig, webhookSecret); and let me know what you see
Okay that looks good
Are you currently testing with the CLI or directly to your HTTPS endpoint?
Currently with HTTPS
Okay can you go in your Dashboard and double check that you have the correct Webhook secret in your code
Yup, its the same code, i just tried using the cli again and i have the same result
Can you provide me one of those Event IDs?
Sure evt_3O05UhDaFxfZlKZw3ZLK3STG
At the webhooks dashboard it gives me a success status but what bothers me are those signature errors
Yeah some are failing and some are succeeding which is very strange...
yeah, and its just one trigger
Can you try not using the CLI to trigger events here
Just create a PaymentIntent yourself
It looks like it works at the end but still a lot of errors
app.post( "/webhook", express.raw({ type: "application/json" }), (request, response) => { let event = request.body; const endpointSecret = "whsec_3rt8XXXXXXqlrdnTHWGB1Rxe"; if (endpointSecret) { // Get the signature sent by Stripe const signature = request.headers["stripe-signature"]; try { event = stripe.webhooks.constructEvent( request.body, signature, endpointSecret ); console.log("Webhook Event Type:", event.type); } catch (err) { console.log(โ ๏ธ Webhook signature verification failed., err.message); return response.sendStatus(400); } } let subscription; let status; switch (event.type) { case "customer.subscription.trial_will_end": subscription = event.data.object; console.log(subscription); status = subscription.status; console.log(Subscription status is ${status}.); break; case "customer.subscription.deleted": subscription = event.data.object; status = subscription.status; console.log(Subscription status is ${status}.`);
break;
case "customer.subscription.created":
subscription = event.data.object;
status = subscription.status;
const subscription_id = subscription.id;
console.log("Subscription ID:", subscription_id);
console.log(`Subscription status is ${status}.`);
break;
case "customer.subscription.updated":
subscription = event.data.object;
status = subscription.status;
console.log(`Subscription status is ${status}.`);
break;
default:
console.log(`Unhandled event type ${event.type}.`);
}
// Return a 200 response to acknowledge receipt of the event
response.send();
}
);`
Opps
Can you check if you are still forwarding via a CLI terminal right now?
The ones that are failing are generated via the CLI
The CLI provides you its own Webhook secret
Different from the one in the Dashboard
So I assume that is what is going on here.
๐