#daniell_webhooks

1 messages · Page 1 of 1 (latest)

elder ermineBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1308784893471227976

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

cinder patrol
#

👋 happy to help

#

would you mind sharing your account ID?

brisk glade
#

where can i find it?

elder ermineBOT
quaint hedge
#

it's ok, we don't need it. Let's step back a bit, what do you mean by 'not triggered'? What do you see in the output of stripe listen, what do you expect to see?

brisk glade
#

on my local machine it works as expected. the problem is, when i run it on my server, the webhook failes to call this endpoint

quaint hedge
#

if you check the logs you can see that we do send it, but you're returning an error about the signature verification.

brisk glade
#

here is a view of my webhook implementation:

export const action: ActionFunction = async ({
request,
}: ActionFunctionArgs) => {
if (request.method.toUpperCase() !== "POST") {
return json({ message: "Method not allowed" }, 405);
}
let stripeEvent: Stripe.Event;

try {
const SIG_HEADER = request.headers.get("stripe-signature");
if (!SIG_HEADER) {
throw new Error("Missing Stripe signature");
}
const BODY = await request.text();
if (WEBHOOK_ENDPOINT_SECRET_FOR_TESTING === undefined) {
throw new Error("Missing Stripe Key");
}
stripeEvent = stripe.webhooks.constructEvent(
BODY,
SIG_HEADER,
WEBHOOK_ENDPOINT_SECRET_FOR_TESTING
);
} catch (err) {
if (err instanceof stripe.errors.StripeSignatureVerificationError) {
// Ungültige Signatur
return json({ error: err.message }, 400);
} else if (err instanceof SyntaxError) {
// Ungültiges Payload
return json({ error: err.message }, 400);
}
// Andere Fehler
return json({ error: err }, 400);
}

switch (stripeEvent.type) {
case "checkout.session.completed":
await processPaidStripeEvent(stripeEvent);
break;

case "checkout.session.async_payment_succeeded":
  await processPaidStripeEvent(stripeEvent);
  break;

case "checkout.session.async_payment_failed":
  await emailCustomerAboutFailedPayment(stripeEvent.data.object);
  break;

default:
  console.log(`Unhandled event type ${stripeEvent.type}`);

}

return new Response(null, { status: 200 });
};

quaint hedge
#

did you change the WEBHOOK_ENDPOINT_SECRET_FOR_TESTING to be the correct secret?

#

when you move to production, you need to use the secret from the endpoint you created on the Dashboard.

#

it's not the same one that is printed when running stripe listen.

brisk glade
#

no, i did not

#

i am going to change it now and test it

quaint hedge
#

great!

brisk glade
#

give me a moment

#

I change it and it I got a 200 back. Does it mean, that is working?

quaint hedge
#

I would say yes

brisk glade
#

in this webhook, i am sending a confirmation mail. i do not get anything in testmode on my server.

#

i am using this libraries "@stripe/react-stripe-js": "^3.0.0",
"@stripe/stripe-js": "^5.2.0", and the api version is "2024-09-30.acacia" selected.

import Stripe from "stripe";

let stripe: Stripe;

if (!process.env.STRIPE_SECRET_KEY) {
throw new Error("Missing STRIPE_SECRET_KEY");
}

if (process.env.NODE_ENV === "production") {
stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
typescript: true,
apiVersion: "2024-09-30.acacia",
});
} else {
const globalWithStripe = global as typeof globalThis & {
stripe: Stripe;
};

if (!globalWithStripe.stripe) {
globalWithStripe.stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
typescript: true,
apiVersion: "2024-09-30.acacia",
});
}
stripe = globalWithStripe.stripe;
}

export { stripe };

But on my dashboard stand this look at screenshot please.

quaint hedge
#

I don't understand the question/problem

brisk glade
#

in my code the apiVersion is "2024-09-30.acacia" select. On my stripe dashboard is the version "2024-10-28.acacia" selected. When I change the apiversion in my code i got an error.

#

The apiversion in my code and dashboard is not the same. is this a problem?

#

now, i can see also this api version on my code. how can i set the apiversion on my dashboard to the apiversion in my code?

#

i am currently in test-mode

quaint hedge
#

When I change the apiversion in my code i got an error.
what error did you get?

brisk glade
#

TS2322: Type '"2024-10-28.acacia"' is not assignable to type '"2024-09-30.acacia"'.

quaint hedge
#

yes, because you can not change the API version the library uses

#

you can only update the version of the library. If you want the library to use 2024-10-28.acacia so it matches your webhook, you need to update your dependency on stripe-node to a later version

brisk glade
#

i do not have ´stripe-node´ in my dependency

#

"dependencies": {
"@getbrevo/brevo": "^2.2.0",
"@headlessui/react": "2.2.0",
"@notionhq/client": "^2.2.15",
"@prisma/client": "^5.20.0",
"@react-email/render": "^1.0.2",
"@remix-run/express": "^2.12.1",
"@remix-run/node": "^2.12.1",
"@remix-run/react": "^2.12.1",
"@stripe/react-stripe-js": "^3.0.0",
"@stripe/stripe-js": "^5.2.0",
"@vimeo/player": "^2.24.0",
"clsx": "^2.1.1",
"compression": "^1.7.4",
"cross-env": "^7.0.3",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"isbot": "^4.1.0",
"morgan": "^1.10.0",
"nanoid": "^5.0.7",
"pdfkit": "^0.15.0",
"puppeteer-core": "^23.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-turnstile": "^1.1.4",
"remix-auth-totp": "^3.4.2",
"resend": "^4.0.0",
"stripe": "^17.1.0",
"uuid": "^9.0.1",
"validator": "^13.12.0"
},
"devDependencies": {
"@react-email/components": "^0.0.25",
"@remix-run/dev": "^2.12.1",
"@types/compression": "^1.7.5",
"@types/express": "^4.17.20",
"@types/morgan": "^1.9.9",
"@types/pdfkit": "^0.13.5",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@types/uuid": "^9.0.8",
"@types/validator": "^13.12.2",
"@types/vimeo__player": "^2.18.3",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"autoprefixer": "^10.4.19",
"date-fns": "^4.1.0",
"eslint": "^8.38.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"postcss": "^8.4.38",
"prisma": "^5.20.0",
"react-email": "^3.0.1",
"tailwindcss": "^3.4.4",
"typescript": "^5.1.6",
"vite": "^5.1.0",
"vite-tsconfig-paths": "^4.2.1"
},
"engines": {
"node": ">=20.0.0"
}

#

i have onle "@stripe/react-stripe-js": "^3.0.0",
"@stripe/stripe-js": "^5.2.0",

#

to impelment stripe checkout, i used your code examples

quaint hedge
#

stripe": "^17.1.0" is stripe-node

brisk glade
#

I have overlooked it. now, i am going to update it

#

and test it, if i get a confirmation mail from my webhook

#

is there any other api secrets to change besides WEBHOOK_ENDPOINT_SECRET_FOR_TESTING when going to production?

quaint hedge
#

you'd want to use live mode keys pk_live_xxx and sk_live_xxx

brisk glade
#

ok thank you. i am going to search why confirmation mail is not sent from my webhook implementation.

#

when are your opening hours?

quaint hedge