Skip to content

feat(ecommerce): connect stripe with the store's own secret key - #1592

Merged
sung17 merged 1 commit into
mainfrom
feat/stripe-secret-key-connect
Oct 30, 2026
Merged

sung17 merged 1 commit into
mainfrom
feat/stripe-secret-key-connect

Conversation

@sung17

@sung17 sung17 commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Stores can connect Stripe in two ways: Stripe Connect (OAuth), which already existed, or their own secret key (sk_…, or a restricted key rk_…). The key option works on platforms without Stripe Connect set up.
  • For a key connection, the key is checked with Stripe and a webhook is created on the store's own account. The key and the webhook secret are stored encrypted. Payments use the store's key and send no Stripe-Account header.
  • Agent-first: the new public procedure paymentProviders.connectStripeKey (POST /v1/payment-providers/stripe/api-key) makes this available in the CLI and MCP.

Changes

  • packages/payments:
    • createStripeGateway accepts { secretKey } for a key connection.
    • New helpers: readStripeKeyAccount, createStripeAccountWebhook, deleteStripeAccountWebhook, parseStripeAccountWebhook.
  • packages/business — paymentProviderService:
    • New connectStripeKey.
    • loadGateway, disconnect and teardownForPurge handle key connections.
    • toView returns connectionType (oauth | apiKey).
    • Key rows: secret is not null and platformCredentialId is null. No migration.
  • New per-workspace webhook route api/payments/stripe/workspace/[workspaceId]/webhook → receiveStripeAccountWebhook. It only queues events whose metadata names that workspace.
  • Fixes found in review:
    • The open-orders guard treats the same account in the other mode (test/live) as a different account.
    • When a key is replaced, the old webhook is removed with the new key, falling back to the old key.
    • Only one Stripe connect (key or OAuth) runs at a time per workspace, using a Redis lock.
  • UI: the Stripe row offers "Connect with Stripe" and "Use secret key". The badge shows the connection type. The "cannot take payments yet" warning now appears only for live connections.
  • i18n in all 21 locales. Updated docs/ecommerce.md, apps/cli/README.md, the public-spec snapshot and the parity manifest.

Open question ⚠️

paymentProviders.connectStripeKey lets any workspace token with the ecommerce scope change which Stripe account receives the store's money. The UI requires a workspace super admin, but tokens record no creator, so the API cannot apply the same check. Options under consideration:

  • accept only test keys through the API, leaving live keys to the UI;
  • drop the public procedure and keep connecting UI-only, as for PayPal;
  • keep it as is. Every connect is audited.

Decision pending before merge.

Test plan

  • pnpm lint
  • pnpm --filter builder check-types, @chatbotx.io/business, @chatbotx.io/payments
  • Unit tests in payments and business (payment-provider, order-payment), plus the builder suite (public spec, parity)
  • Manual: connected an sk_test_ key locally. The connection row was saved and the webhook created on Stripe.
  • Manual: place a web shop order, pay with 4242 4242 4242 4242, check the order becomes paid, then refund it
  • Manual: disconnect, then check the webhook was deleted in the Stripe Dashboard

Stores can now connect Stripe either through Stripe Connect (OAuth) or by
pasting their own secret / restricted key. The key is verified, a webhook is
created on the store's account and both are stored encrypted. Payments with
a key connection use the store's key without Stripe-Account.

- Same account in the other mode (test/live) counts as a different account
  for the open-orders guard
- The replaced key's webhook is removed with the new key when possible
- One Stripe connect at a time per workspace (redis lock)
- The "cannot take payments yet" warning only shows for live connections
@github-actions github-actions Bot added the feature New feature or request label Oct 30, 2026
@sung17
sung17 merged commit 0561ad3 into main Oct 30, 2026
15 checks passed
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
Stores can now connect Stripe either through Stripe Connect (OAuth) or by
pasting their own secret / restricted key. The key is verified, a webhook is
created on the store's account and both are stored encrypted. Payments with
a key connection use the store's key without Stripe-Account.

- Same account in the other mode (test/live) counts as a different account
  for the open-orders guard
- The replaced key's webhook is removed with the new key when possible
- One Stripe connect at a time per workspace (redis lock)
- The "cannot take payments yet" warning only shows for live connections

Co-authored-by: Deathgiver <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant