Repository navigation
feat(payments): Stripe webhook, ledger fulfillment and receipt email - #1792
Draft
ArendPeter wants to merge 2 commits into
Draft
ArendPeter wants to merge 2 commits into
ArendPeter wants to merge 2 commits into
Conversation
✅ Deploy Preview for bettervoting ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for bettervoting ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
ArendPeter
force-pushed
the
stripe-webhook
branch
from
November 15, 2026 20:17
7ba0cf1 to
794ec21
Compare
POST /API/StripeWebhook verifies the Stripe-Signature against the raw body (400 on a bad signature). checkout.session.completed and async_payment_succeeded re-fetch the session and, once paid, call fulfillTransaction: completeIfPending plus one purchase entitlement per line item, in one DB transaction. A redelivered event is a no-op. After commit, a newly completed transaction gets an itemized receipt email; a send failure is logged and the webhook still returns 200. expired marks the row expired (only while pending); async_payment_failed is logged. Implements #1587. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The checkout PR now defines PAYMENT_DISCLAIMER, so this branch no longer needs to add or move it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ArendPeter
force-pushed
the
stripe-webhook
branch
from
November 15, 2026 21:43
84a9ee8 to
9934f20
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human Summary
This adds webhooks so that the backend can respond to Stripe transactions and update the entitlements accordingly.
Summary
Stacked on #1790. Closes #1587.
POST /API/StripeWebhookis registered withexpress.rawbefore the app-wideexpress.json(), the same way as the SendGrid webhook, so theStripe-Signaturecan be checked against the raw body. A bad signature gets a 400.Notes:
quantity × unit_entitlement, using the per-unit values saved on the transaction at checkout (feat(payments): Checkout Session endpoint and shared product catalog #1790). A pricing change after checkout can't change what was bought.customer_details.email), not the account email. It's itemized from theline_itemssnapshot, with a total, a link to the election admin page and feat(payments): Checkout Session endpoint and shared product catalog #1790'sPAYMENT_DISCLAIMER. It's sent without the SendGrid unsubscribe group, since it's transactional.markExpirednow only changes apendingrow, so a lateexpiredevent can't undo a completed purchase. The spec didn't ask for this.expiredreturns 500, so Stripe retries it for about 3 days. That means someone paid and got nothing, so it may deserve an alert.STRIPE_WEBHOOK_SECRETis documented insample.env, with thestripe listencommand and its four events. The Provision Stripe webhook endpoint & retrieve signing secret #1588 wizard isn't on this branch, so the new events still need to be added there.updateElection(). The return page will finalize once the grant has landed.Test plan
stripeWebhook.test.ts(12 tests), with events signed byStripe.webhooks.generateTestHeaderString:completed+paidcompletes the row and inserts one entitlement per line item: 3 blocks → 300 voters, 1 block → 100 voters.async_payment_succeeded) inserts nothing more and sends one receipt.completed+unpaidgrants nothing, thenasync_payment_succeededgrants.expiredmarks the row expired. A lateexpiredleaves a completed row complete.paidcheck, or grantingunit_entitlementwithout multiplying by quantity, made a test fail.npm run build -wspasses.npm test -w @equal-vote/star-vote-backendpasses all 38 suites (317 tests).stripe listenwith the events insample.envand setSTRIPE_WEBHOOK_SECRET. Create a session through feat(payments): Checkout Session endpoint and shared product catalog #1790's endpoint and pay with a test card. ThetransactionsDBrow should becomecomplete, theentitlementsDBrows should appear, and a receipt should arrive. Runstripe trigger checkout.session.expiredto check the expiry path.🤖 Generated with Claude Code