#raulru

1 messages ยท Page 1 of 1 (latest)

uncut fogBOT
kindred ingot
#

Hello

#

How are you testing here? Are you forwarding from the CLI or you receiving on an HTTPS endpoint?

high sun
#

i tried both, i get the same result with cli and ngrok https

kindred ingot
#

Are you using our Node SDK here?

#

And did you double check that you are using the correct webhook signing secret?

high sun
#

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

kindred ingot
#

Hvae you logged out the body that you are passing to constructEvent?

high sun
#

`// 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"));`

kindred ingot
#

Log out req.body in the line before event = stripe.webhooks.constructEvent(req.body, sig, webhookSecret); and let me know what you see

kindred ingot
#

Okay that looks good

#

Are you currently testing with the CLI or directly to your HTTPS endpoint?

high sun
#

Currently with HTTPS

kindred ingot
#

Okay can you go in your Dashboard and double check that you have the correct Webhook secret in your code

high sun
#

Yup, its the same code, i just tried using the cli again and i have the same result

kindred ingot
#

Can you provide me one of those Event IDs?

high sun
#

Sure evt_3O05UhDaFxfZlKZw3ZLK3STG

#

At the webhooks dashboard it gives me a success status but what bothers me are those signature errors

kindred ingot
#

Yeah some are failing and some are succeeding which is very strange...

high sun
#

yeah, and its just one trigger

kindred ingot
#

Can you try not using the CLI to trigger events here

#

Just create a PaymentIntent yourself

high sun
#

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();

}
);`

kindred ingot
#

Make sure you redact your secret

#

Since this is a public server

high sun
#

Opps

kindred ingot
#

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.

high sun
#

Yup, it seems like that was the issue, thank you!!!!!!

#

Everything is working fine now!

kindred ingot
#

๐ŸŽ‰