28 Commits

Author SHA1 Message Date
c724bf1700 feat: conversion, per-link, churn and LTV metrics (G14, part 1)
GET /v1/analytics/metrics computes, from live sessions, payments,
subscriptions and catalog: checkout conversion, per-payment-link opened /
paid / conversion / revenue, repeat customers, average revenue per
customer, subscription churn, ARPU and an estimated lifetime value, with
exact bigint money. Checkout repositories gain listCreatedSince
(in-memory and Postgres). The dashboard Analytics page shows the new
cards and a payment-link table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 06:37:57 +03:00
1d92fa23f2 feat: branded hosted storefront per merchant (G12)
Merchants can publish a store (slug, title, tagline, https logo, accent
colour, search description, optional custom domain) through settings or
the dashboard. The checkout app serves it at /store/<slug> with SEO and
Open Graph metadata, listing active products (invoice products hidden)
that each open their payment link, and a middleware rewrites '/' on a
merchant's custom domain to its store when CHECKOUT_PRIMARY_HOSTS is set.
Slugs and domains are unique; public data at /v1/public/stores. Carts of
several products stay out of scope because hosted checkout fulfils one
product per session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 06:32:06 +03:00
132efd87b3 feat: cash-out hand-off to off-ramp partners (G11)
GET /v1/merchant/offramp builds sell links for Transak, MoonPay (signed
server-side with the secret key) and Ramp with the amount, network and
the merchant's own receiving wallet prefilled. SettleKit takes no
custody; partners appear only once the owner configures their keys
(TRANSAK_API_KEY, MOONPAY_PUBLISHABLE_KEY/MOONPAY_SECRET_KEY,
RAMP_HOST_API_KEY). The dashboard Balances page gets a Cash out action per
mainnet network.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 06:24:40 +03:00
6ba53b7a92 feat: refund to payer with prepared transfers verified onchain (G10)
Refunds no longer depend on a pasted hash alone. POST
/v1/merchant/payments/:id/refund/prepare creates a pending refund and
returns the exact transfer back to the buyer: ERC-20 transfer calldata,
token, chain id and an EIP-681 link on EVM networks, or a Solana Pay
transfer request with a unique reference. The destination is the wallet
that paid when known, else the merchant enters it (validated per chain).
POST /v1/merchant/refunds/:id/confirm verifies the signed transfer
onchain with the payment verifiers (destination, amount, time, Solana
reference, one refund per tx) and only then settles: access revoked,
payment refunded once fully refunded, refund.succeeded with source
wallet. Pending refunds can be canceled. Dashboard refund form gets a
'Send from my wallet' mode (browser wallet or mobile link, auto-verify).
apps/refund-protocol stays unwired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 06:21:27 +03:00
c14d0ab735 feat: team roles with invitations and enforced API key scopes (G9)
Security fix plus team access. Before this change any valid API key,
including access keys the delivery system hands to BUYERS, authenticated
as the merchant on the whole management API, and GET /v1/api-keys listed
every organization's keys. Now only platform keys (issued at sign-up or
via POST /v1/api-keys/platform, marked with the platform product id) can
call the API, and each request needs its resource scope
(<resource>:read|write, write implies read; platform:admin or * for
full access), answered with 403 and details.requiredScope otherwise.
Keys cannot mint broader keys, customer keys cannot carry management
scopes, key listing is tenant-scoped and keys can be revoked by id.

Dashboard sessions get team roles (owner, admin, developer, support,
viewer) mapped to scopes. /v1/team manages members and email
invitations (packages/invitations, token hash only, 7-day expiry);
/v1/auth/invitations/accept joins the org and creates the account. The
last owner is protected and only owners grant owner. Dashboard: Team
page, invite accept page, and an API keys page that creates restricted
keys and shows the secret once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 06:09:06 +03:00
40f90f1c5a feat: webhook event log with resend, test events, secret rotation and auto-disable (G8)
Every seller webhook delivery now keeps an attempt log (status code,
error, time, next retry) in the worker queue (Postgres) or in memory.
New routes: GET /v1/webhooks/deliveries(/:id), POST
/v1/webhooks/events/:id/resend, POST /v1/webhooks/endpoints/:id/test
(signed webhook.test event), rotate-secret with a 0-168h grace window
(both secrets sign as two v1 values, verified by @settlekit/webhooks, the
TS/Python/Go/Rust SDKs and the WooCommerce plugin), and disable/enable.
The worker retries on a 1m..6h exponential schedule instead of every tick,
signs with the live endpoint secret, skips disabled endpoints and
auto-disables one after 100 failed attempts in a row
(WEBHOOK_DISABLE_AFTER_FAILURES). Outbound requests get a 10s timeout.
The dashboard Webhooks page shows the event log with Resend and endpoint
actions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 05:34:39 +03:00
330d111510 feat: fiat pricing with live ECB rates locked per checkout (G7)
Prices can now be set in EUR, GBP and other ECB reference currencies
(displayCurrency + displayAmount, or currency on quick products). Each
checkout converts them to USDC at the live rate from a frankfurter
service (MIT, FX_RATES_URL), rounded half-up to the cent with exact
bigint math, and locks the quote on the session (fxQuote) until it
expires, so onchain verification expects exactly the quoted USDC. Promo,
tax, receipts and the hosted checkout lines use the locked rate; the
payment link page shows the fiat price and today's USDC amount. Missing
or implausible rates fail closed (503); fiat subscriptions and mixed
fiat currencies are refused. Dashboard product form gets a currency
picker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 05:13:37 +03:00
f1647a5a81 feat: embeddable checkout overlay (embed.js) with allow-listed success callback (G6, part 1)
apps/checkout/public/embed.js opens a payment link, checkout or invoice
from the same checkout origin in an overlay iframe on any site; links
marked data-settlekit-checkout bind automatically, SettleKit.open() is
available from code, and there is an open-in-new-tab fallback for
wallets that block iframes. The success page posts settlekit:success
only to a site the seller listed under Settings > Embedding
(org embedOrigins, validated https origins), and embed.js only accepts
messages from its checkout frame. Payment requests gain sendEmail and
successUrl so store plugins can redirect buyers and bring them back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 04:52:19 +03:00
a4d0f3f5cb feat: tax at checkout and tax-grade receipts (G4)
Sellers can turn on checkout tax in settings (label, own country and tax
ID, legal name, per-country rates, default rate, EU reverse charge).
Sessions add tax on top of the net price after any promo, so onchain
verification expects the tax-inclusive total. Buyers set billing country
and VAT ID via the API (billingCountry, vatId) or on the hosted checkout
until a payment is recorded; EU cross-border B2B with a VAT ID of the
right shape is zero-rated. Settled checkouts get a PDF receipt (pdfkit)
with the seller's tax ID, buyer country / VAT ID, tax rate and the
settlement transaction, linked from the success page, the receipt email
and the customer portal. packages/tax calculateTax is now used at
checkout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 04:30:53 +03:00
e0caf4bace feat: monthly platform fee statements with plan limits after grace (G1)
SettleKit's advertised per-payment fee was never collected because buyers
pay merchants' wallets directly. When PLATFORM_BILLING_ORG_ID is set, the
API now issues each merchant a monthly statement (confirmed payments x the
fee schedule) as an invoice from SettleKit's own org, paid through the
hosted checkout on the G2 payable-invoice path. Totals below the minimum
carry forward, test accounts are skipped, runs are idempotent and happen
automatically every six hours (or via POST /v1/billing/statements/run).
A statement unpaid past due + grace restricts new products to the free
plan limit from packages/pricing (402 with the pay link). Merchants see
accrued fees, statements and a Pay button on the Balances page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 03:50:08 +03:00
466c662ac3 feat: payable invoices and payment requests (G2)
Invoices can now be paid onchain. POST /v1/invoices/:id/send issues the
invoice, binds a public pay page (/i/<token> on the hosted checkout),
opens a checkout session for the invoice total on the merchant's
networks and emails the link. POST /v1/invoices/requests sends an
ad-hoc amount + memo to an email. The invoice turns paid only when a
confirmed onchain payment exists for one of its sessions (on read in the
API and in the new worker invoice-settle job) and emits invoice.paid.
Invoice and receipt PDFs render with pdfkit (MIT). Voiding cancels open
sessions. Dashboard gets a request-a-payment form, send buttons, pay
links and PDF downloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 03:35:06 +03:00
fd29a1de73 fix(dashboard): webhook endpoints register against the API and show their signing secret
The page posted to a route the API does not have and read fields it does not
return. It now creates /v1/webhooks/endpoints with the chosen events
(default: payment.confirmed, subscription.charged, subscription.canceled,
refund.succeeded) and reveals each endpoint's signing secret for verification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:35:22 +03:00
995083b651 feat(dashboard): onchain subscriptions page and refunds that send funds
- Subscriptions: every buyer subscription with plan, network and collection
  method, status, next charge, last charge (explorer link), dunning state and
  cancel at period end / now; active count, MRR and dunning totals. Falls back
  to the core list when onchain billing is off.
- Payment detail: Refund payment sends the funds on-chain through
  POST /v1/onchain-billing/refunds (operator wallet per network, Base escrow
  via the escrow) and shows the refund transaction link; when the operator is
  not configured for the network it offers "I refunded manually" to record
  the tx hash. Refund rows link to the explorer.
- Refunds ledger links each refund to its payment instead of creating
  unsent pending refunds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:35:22 +03:00
bcccfb0bf7 feat(discord): real paid-role delivery with Connect Discord at checkout
- checkout: buyers connect Discord (OAuth2 identify + guilds.join) in the
  delivery-fields step; the callback saves their user id on the session and
  joins them to the product's server. After payment the bot adds the role via
  PUT /guilds/{guild}/members/{user}/roles/{role}; the grant is recorded for
  access-sync revocation. Without DISCORD_BOT_TOKEN the buyer sees
  "pending setup" instead of a fake success.
- worker: discord-delivery-retry grants pending Discord entitlements once the
  bot is configured (backoff per entitlement); DISCORD_BOT_TOKEN is optional.
- api: a configured bot delivers roles even before GitHub is set up;
  checkout subscriptions pass the buyer's Discord / GitHub ids so subscription
  delivery reaches the right accounts.
- dashboard: product settings explain server / role ids and link the bot invite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:31:32 +03:00
7245d08879 feat(dashboard): guided onboarding, multi-chain payments, products with payment links, balances
- /onboarding: business name, accepted networks and receiving addresses
  (one EVM address for every EVM chain, Solana, HyperCore, Zcash t-address)
  validated per chain, first product, shareable link + embed button
- Payments list (network, asset, route, buyer, explorer link, filters) and
  detail with created/paid/verified/delivered timeline and refund recording
- Products create/edit with USD price, delivery type, per-network toggles,
  pause/re-open; customers with spend and access; live on-chain balances
- Settings: networks and addresses, webhooks, API keys; short sidebar

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 20:50:21 +03:00
874fa3a08a feat(apps): Phase 7 — escrow lifecycle, portal P2P send, checkout crosschain bridge
- dashboard: escrow detail lifecycle actions (assign/fund/submit/approve/refund) via server actions + api.escrow.* client methods.
- portal: P2P 'send USDC on Arc' page + nav (offline App Kit send, live swap documented); +@settlekit/app-kit dep.
- checkout: 'pay from another chain' crosschain bridge option (App Kit bridge, offline) next to wallet-pay.
- Built inline (subagent limit hit). Phase 7 complete. 1308 tests / 213 suites, typecheck + builds green.
2026-06-21 17:44:20 +03:00
b73437be14 feat(auth): active sessions — list + revoke (Phase 1.3)
- AuthService.listSessions (marks current) + revokeSessionById (account-scoped, not_found if not owned).
- store: listSessionsByAccount + deleteSessionById (InMemory + Pg).
- API: GET /v1/auth/sessions, DELETE /v1/auth/sessions/:id (bearer).
- dashboard: Security card — SessionList client + /api/sessions(+/[id]) routes (cookie->bearer, same-origin guard).
- Phase 1 complete. 1308 tests / 213 suites, typecheck + builds green.
2026-06-21 11:59:20 +03:00
9ed86fa715 feat(apps): roadmap batch — agent-console, creator-dashboard, marketplace, admin, dashboard
- agent-console: Agents (ERC-8004 identity/reputation) + Jobs (ERC-8183 lifecycle timeline) pages via Local ports; 'Agent economy' nav group.
- creator-dashboard: per-source detail + per-payout royalty-split breakdown pages (stable slug/settlementId routing).
- marketplace: listing/service detail page + tag/search filtering.
- admin: settlements console.
- dashboard: Profile card (EditProfile) wired to PATCH /v1/auth/account.
- 1308 tests / 213 suites, typecheck + all app builds green.
2026-06-21 02:04:43 +03:00
7f3f850104 feat(auth): wallet unlink + development roadmap (continuous loop)
- AuthService.unlinkWallet — clears the linked wallet, refusing to strand a
  wallet-only account (no password) from its only sign-in method.
- DELETE /v1/auth/wallet (bearer); dashboard Unlink button + /api/wallet/link DELETE.
- InMemoryAuthStore.saveAccount removes the stale wallet index on unlink (Pg: column→NULL).
- docs/DEVELOPMENT_ROADMAP.md: phased feature plan driving the continuous loop.
- 1308 tests / 213 suites, typecheck + builds green.
2026-06-21 01:51:48 +03:00
740ffe91aa feat(auth): web3 sign-in for portal + wallet-linking for existing accounts
- portal: 'Connect Wallet' SIWE sign-in on login/signup (customer accounts), lib/auth wallet helpers, viem dep. (checkout has no sign-in surface — skipped.)
- auth core: AuthService.linkWallet(sessionToken, {message, signature}) — verify session + SIWE sig + single-use nonce, attach wallet to the existing account, conflict if the wallet is already linked elsewhere. +2 tests (link, conflict).
- api: POST /v1/auth/wallet/link (bearer-authenticated).
- dashboard: 'Link wallet' button in Settings → /api/wallet/link route forwards the session cookie as bearer; Account.walletAddress surfaced.
- 1304 tests / 213 suites, typecheck + full build green.
2026-06-21 00:31:48 +03:00
9229638cea feat(auth): wire web3 wallet login end-to-end (API + dashboard + Pg store)
- apps/api: POST /v1/auth/wallet/nonce + /v1/auth/wallet/login (zod-validated, sets the signed sk_session cookie like password/magic-link).
- apps/dashboard: 'Connect Wallet' SIWE sign-in (plain viem + EIP-1193 personal_sign, no heavy deps) on login + signup; lib/auth wallet helpers.
- persistence: PgAuthStore.findAccountByWallet/saveWalletNonce/consumeWalletNonce (atomic single-use consume); accounts.wallet_address projection.
- database: auth_accounts.wallet_address column + auth_wallet_nonces table, migration 0006_auth_web3 + journal; re-export gt/lt operators.
- 1302 tests / 213 suites, typecheck + full build green.
2026-06-21 00:09:44 +03:00
3a52b61096 adas 2026-06-17 03:02:36 +03:00
a8d10c0916 asado 2026-06-17 02:31:22 +03:00
3853551433 asad 2026-06-17 02:09:36 +03:00
bd3c2a85e5 feat: full-product round 3 — commerce engines wired + worker comms
- apps/api: /v1/refunds, /v1/dunning, /v1/disputes, /v1/payouts routes + context
  services + mounts (refunds/dunning/disputes/payouts engines).
- apps/dashboard: refunds/dunning/disputes/payouts pages + nav + api client + types.
- apps/worker: 9 scheduled jobs incl. receipt, renewal-reminder, dunning, and
  access-granted email jobs via @settlekit/notifications (idempotent, injectable transport).

Full build 0 TS errors; dashboard typecheck clean; 591 tests pass.
2026-06-15 17:25:34 +03:00
5cb0f48db7 feat: full-product round 2 — auth end-to-end + commerce engines
- apps/api: public /v1/auth routes (register/login/magic-link/session/logout) via
  @settlekit/auth, AuthService in context, signed sk_session cookie; existing
  api-key guard untouched (14 api tests intact).
- apps/dashboard + apps/portal: real login/signup UIs (password + magic-link),
  httpOnly session cookie via route handlers, server session helpers, sign-out.
- packages: fleshed refunds, dunning (retry schedules), disputes (state machine),
  payouts (settlement + available-balance) into real engines with stores+services.

Verified: full build 0 TS errors; 591 tests pass; live auth flow
(register->login->session->magic-link->bad-login 401) confirmed end-to-end.
2026-06-15 17:06:29 +03:00
3220b85c57 feat: product expansion — marketing site, customer portal, coupons + invoices
- apps/web: public marketing site (Next.js) — hero/§34, what-you-can-sell grid,
  how-it-works, dev tools, marketplace teaser, /pricing (§32 tiers), /use-cases (§29).
- apps/portal: customer portal (Next.js, §31) — per-customer overview, purchases/
  receipts, license keys, api keys, github/discord access (+re-check), subscriptions,
  downloads; anchored on the universal entitlements layer.
- packages/coupons: real discount engine (percent/amount/free-trial, window, expiry,
  max + per-customer redemptions, min-subtotal, product scoping), bigint USDC math,
  CouponStore + service.
- packages/invoices: real invoicing (line items, discount, @settlekit/tax, statuses,
  HTML/text render), fixed float bug, InvoiceStore + service.
- apps/api: /v1/coupons + /v1/invoices routes wired into context + app.
- apps/dashboard: Coupons + Invoices pages + nav + client methods.

All package + backend builds 0 TS errors; web/portal/dashboard typecheck clean;
590 tests pass (two redesigned coupon/invoice tests updated to the new API).
2026-06-15 12:25:58 +03:00
598cd03f05 feat: implement all 8 SettleKit apps + fix x402 nonce round-trip
apps:
- api: Hono REST server, all §26 endpoints, 14 tests
- worker: delivery runner + payment-confirm + access-sync + renewal + webhook-retry jobs wired to real package clients
- dashboard: Next.js merchant dashboard, full §16/§27 sections + §28 product builder
- checkout: Next.js hosted USDC checkout with real delivery materialization
- marketplace: Next.js public marketplace + agent metadata.json route
- admin: Next.js risk/ops console wired to @settlekit/risk + database
- docs: Next.js docs site (9 static routes)
- examples: 5 runnable end-to-end examples

fix(x402): support pinned config.nonce so a stateless verifier can confirm
the challenge nonce round-trips (default stays random; package tests intact).

Full workspace: 590 tests passing (122 files), tsc green for all packages +
api/worker/examples, all 5 Next apps typecheck clean, docs next build green.
2026-06-15 10:49:14 +03:00