feat(payments): add client-facing invoice payments via Stripe#23
Open
feat(payments): add client-facing invoice payments via Stripe#23
Conversation
Dual-mode Stripe integration for invoice payments: - Direct keys mode (self-hosted): agency pastes Stripe secret key, app encrypts it and auto-registers webhook - Connect OAuth mode (hosted): activated via STRIPE_CONNECT_CLIENT_ID env var, agencies click "Connect with Stripe" Core features: - Pay Now button on portal invoices (sent/overdue) redirects to Stripe Checkout - Webhook auto-marks invoices as paid with idempotent processing - Email + in-app + push notifications on payment received - Dashboard shows "Paid via Stripe" vs "Marked as paid" distinction - Stripe-paid invoices are protected from deletion - Account deauthorization webhook auto-disables payments Security: - HMAC-signed OAuth state with timing-safe comparison - Org-scoped webhook URLs prevent cross-org event injection - URL origin validation prevents open redirects - Encrypted key storage (AES-256-GCM) - Sensitive fields masked in API responses Schema changes: - SystemSettings: stripeSecretKey, stripeWebhookSecret, stripeConnectAccountId, stripeConnectEnabled, stripeConnectLivemode - Invoice: stripeCheckoutSessionId, stripePaymentIntentId, paidAt, paidAmount
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.
Summary
How it works
STRIPE_CONNECT_CLIENT_IDBoth modes use the same checkout flow, webhook handling, and portal UI. Mode is auto-detected based on whether
STRIPE_CONNECT_CLIENT_IDis set.New files
apps/api/src/payments/— NestJS module (service, controller, webhook controller, DTOs)apps/web/.../payments-section.tsx— Settings UI for both modespackages/email/src/templates/invoice-paid.tsx— Payment received email templatee2e/tests/invoice-payments.e2e.ts— 13 e2e testsdocs/testing-stripe-connect.md— Manual testing guideSchema changes
SystemSettings:stripeSecretKey,stripeWebhookSecret,stripeConnectAccountId,stripeConnectEnabled,stripeConnectLivemodeInvoice:stripeCheckoutSessionId,stripePaymentIntentId,paidAt,paidAmountSecurity
/webhook/:orgId) prevent cross-org injectionTest plan
STRIPE_CONNECT_CLIENT_ID)