Skip to content

fix(payments): verify Stripe webhook signatures#790

Open
EfeDurmaz16 wants to merge 2 commits into
codelitdev:mainfrom
EfeDurmaz16:efe/stripe-webhook-signature-verification
Open

fix(payments): verify Stripe webhook signatures#790
EfeDurmaz16 wants to merge 2 commits into
codelitdev:mainfrom
EfeDurmaz16:efe/stripe-webhook-signature-verification

Conversation

@EfeDurmaz16
Copy link
Copy Markdown

Summary

Partially addresses #535 by adding Stripe webhook signature verification for the payment webhook flow.

This PR:

  • keeps the raw request body in app/api/payment/webhook before JSON parsing
  • passes the raw body and stripe-signature header into the payment adapter
  • verifies Stripe webhook events with stripe.webhooks.constructEvent
  • requires and stores stripeWebhookSecret for Stripe payment settings
  • adds the Stripe webhook secret field to the admin payment settings UI
  • updates payment setup docs to tell admins to copy the Stripe webhook signing secret
  • adds focused tests for valid, missing, and tampered Stripe webhook signatures

Verification

  • pnpm install --frozen-lockfile
  • pnpm exec prettier --write apps/web/payments-new/payment.ts apps/web/payments-new/stripe-payment.ts apps/web/app/api/payment/webhook/route.ts apps/web/app/api/payment/__tests__/stripe-payment.test.ts packages/orm-models/src/models/site-info.ts apps/web/graphql/settings/logic.ts apps/web/graphql/settings/helpers.ts apps/web/components/admin/settings/index.tsx apps/web/ui-config/strings.ts apps/docs/src/pages/en/schools/set-up-payments.md apps/docs-new/content/docs/schools/set-up-payments.mdx
  • pnpm exec eslint apps/web/payments-new/payment.ts apps/web/payments-new/stripe-payment.ts apps/web/app/api/payment/webhook/route.ts apps/web/app/api/payment/__tests__/stripe-payment.test.ts apps/web/graphql/settings/logic.ts apps/web/graphql/settings/helpers.ts apps/web/components/admin/settings/index.tsx apps/web/ui-config/strings.ts packages/orm-models/src/models/site-info.ts --quiet
  • git diff --check
  • pre-commit hook: prettier --write packages apps docs *.md and eslint --quiet --cache --fix packages apps/docs apps/docs-new apps/web

I also smoke-tested Stripe's generateTestHeaderString + constructEvent flow against the installed stripe package.

Note: I did not implement Razorpay or Lemon Squeezy verification in this PR; this is intentionally limited to the Stripe path so the change remains reviewable.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 15, 2026

@EfeDurmaz16 is attempting to deploy a commit to the CourseLit Team on Vercel.

A member of the Team first needs to authorize it.

@EfeDurmaz16
Copy link
Copy Markdown
Author

Added a small follow-up for webhook failure semantics.

What changed:

  • Invalid Stripe webhook verification now returns 400 instead of a default 200 JSON response.
  • Missing payment method / membership paths now return explicit 404 responses instead of default 200 responses.
  • Fixed the new Stripe webhook unit test import so it resolves the concrete StripePayment class under Jest's current module mapper.

Verification:

  • pnpm test apps/web/app/api/payment/__tests__/stripe-payment.test.ts --runInBand -> 4 passed
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant