Skip to content

feat(ecommerce): add stripe and paypal online payments to the web shop - #1578

Merged
sung17 merged 2 commits into
mainfrom
feat/ecommerce-online-payments
Oct 28, 2026
Merged

sung17 merged 2 commits into
mainfrom
feat/ecommerce-online-payments

Conversation

@sung17

@sung17 sung17 commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

The web shop could only take cash on delivery. Stores can now take Stripe and PayPal payments. The money goes straight to each store's own account, and the customer pays on the provider's hosted page.

  • Connect in Settings → Integrations, after Make:
    • Stripe: a Stripe Connect (Standard) sign-in link, on the platform's or a reseller's own Connect app. The ca_… client id is set in Platform credentials → Stripe and is now required.
    • PayPal: a dialog for the store's own Client ID and Secret. Live keys are tried first, then sandbox. A webhook is created on the app.
  • Order first, pay after:
    • An online order is placed pending/unpaid with a 30-minute deadline (PAYMENT_EXPIRY_MINUTES). Nothing is announced (confirmation, push, events, checkout flow) until the money comes in.
    • A new expireUnpaidOrders schedule runs every minute. It cancels orders that stay unpaid, gives the stock and the discount code back, closes the provider page, and tells the customer why.
  • One settlement path: the return page, the webhook job (confirmOrderPayment) and the scan all go through syncAttempt.
    • Under the order lock, then the attempt lock, the provider is asked again; the webhook body is never trusted.
    • The amount is compared exactly, in the provider's minor units (no rounding; an amount that cannot be charged exactly is refused).
    • Money that does not match, or arrives for an order already cancelled or paid, is refunded. Money for a deleted order is only logged.
  • Refunds: cancelling a paid order refunds it, in two phases:
    • First every open page is closed.
    • Then each refund is made, with an idempotency key, and recorded outside the cancel transaction. A rolled-back cancel can never lose a refund.
  • White label:
    • The Connect redirect URI and the Connect webhook use the credential's origin: the reseller's own domain for their own app, the broker otherwise.
    • The PayPal webhook, shop links, return pages and getConnectLink use the workspace's domain (resolveWorkspaceAppUrl).
  • Orders UI: a Payment column and a payment badge on the orders list (paid / waiting until hh:mm / pay on delivery / not paid / refunded), plus the payment attempts on the order detail.
  • Public API:
    • New: paymentProviders.list, paymentProviders.getConnectLink, paymentProviders.disconnect, orders.getPaymentLink.
    • Orders now expose payments, paymentExpiresAt and paidAt.
    • CLI README updated.
  • Workspace purge: a purged workspace deauthorizes its Stripe account and deletes its PayPal webhook before the cascade. The worker passes the teardown into purgeDueScheduled.

Invariant 23 exemption

startStripeConnectAction and connectPaypalAction stay UI-only, for a workspace super admin. Connecting decides which account receives the store's money, which a workspace token must never do. Agents call paymentProviders.getConnectLink to get the page for the store owner, then check the result with paymentProviders.list.

Database

New migration 20261028134050_ecommerce_online_payments:

  • EcommercePaymentProvider and OrderPayment tables.
  • Order.paymentExpiresAt and Order.paidAt, with partial indexes.
  • paymentMethod gains stripe and paypal (ADD VALUE IF NOT EXISTS).

db:check-drift is clean.

New package

@chatbotx.io/payments holds the Stripe and PayPal gateways: Stripe through the official SDK, PayPal through REST over fetch. It has no zod and is Edge-safe for the builder graph.

Test plan

  • pnpm lint; check-types passes on all 64 packages
  • Tests:
    • payments: 54 passed
    • business: 8224 passed
    • worker: 4210 passed
    • builder: 9346 passed
    • database: 1790 passed
  • Stripe end to end in test mode: connect, pay, order marked paid with the exact amount
  • PayPal request bodies checked against PayPal's official OpenAPI specs (create order in USD/JPY/EUR, capture, refund, webhook create, webhook verify)
  • PayPal end to end in sandbox: not run yet, no sandbox keys available
  • Stripe refund on cancel and the 30-minute expiry in a live run

Known limits are in docs/ecommerce.md → Online payments:

  • A PayPal capture left PENDING keeps the order waiting.
  • A later Stripe refund.failed is not tracked.
  • Test-mode keys still take test money; this is only flagged in the UI.

🤖 Generated with Claude Code

Deathgiver and others added 2 commits October 28, 2026 20:54
- Stripe Connect (Standard accounts, OAuth) and PayPal (store's own REST app)
  connected under Settings → Integrations; money goes to each store's account
- hosted checkout, order created first and auto-cancelled after 30 minutes
  unpaid; cancelling a paid order refunds it
- settlement re-asks the provider under the order lock and compares the exact
  minor-unit amount; webhooks, return page and a per-minute sweep converge
- white label: Connect redirect URI and webhook on the credential's origin,
  PayPal webhook, shop links and return pages on the workspace's domain
- public API: payment-providers list/connect-link/disconnect and
  orders.getPaymentLink; payment status on the orders list and detail
- new @chatbotx.io/payments package, OrderPayment and
  EcommercePaymentProvider tables, confirmOrderPayment job and
  expireUnpaidOrders schedule

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…eardown

- the expiry cancel keeps an order whose page turns out paid as it is closed
  (LatePaymentArrivedError) instead of cancelling and refunding it
- the stale-attempt sweep postpones by touching updatedAt, so expiresAt stays
  the page's real end: no dead checkout link is offered again and the public
  API reports the right page end
- a purged workspace deauthorizes its Stripe account and deletes its PayPal
  webhook before the cascade
- the expiry cancel reason is translated in the builder
- paymentProviders.getConnectLink uses the workspace's own domain

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the feature New feature or request label Oct 28, 2026
@sung17
sung17 merged commit 392911b into main Oct 28, 2026
15 checks passed
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
…p (#1578)

* feat(ecommerce): add stripe and paypal online payments to the web shop

- Stripe Connect (Standard accounts, OAuth) and PayPal (store's own REST app)
  connected under Settings → Integrations; money goes to each store's account
- hosted checkout, order created first and auto-cancelled after 30 minutes
  unpaid; cancelling a paid order refunds it
- settlement re-asks the provider under the order lock and compares the exact
  minor-unit amount; webhooks, return page and a per-minute sweep converge
- white label: Connect redirect URI and webhook on the credential's origin,
  PayPal webhook, shop links and return pages on the workspace's domain
- public API: payment-providers list/connect-link/disconnect and
  orders.getPaymentLink; payment status on the orders list and detail
- new @chatbotx.io/payments package, OrderPayment and
  EcommercePaymentProvider tables, confirmOrderPayment job and
  expireUnpaidOrders schedule

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(ecommerce): keep payments made at the deadline and tidy payment teardown

- the expiry cancel keeps an order whose page turns out paid as it is closed
  (LatePaymentArrivedError) instead of cancelling and refunding it
- the stale-attempt sweep postpones by touching updatedAt, so expiresAt stays
  the page's real end: no dead checkout link is offered again and the public
  API reports the right page end
- a purged workspace deauthorizes its Stripe account and deletes its PayPal
  webhook before the cascade
- the expiry cancel reason is translated in the builder
- paymentProviders.getConnectLink uses the workspace's own domain

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Deathgiver <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[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