4.1 KiB
4.1 KiB
Tasks: enterprise-payment-providers
Change ID: enterprise-payment-providers
Package: @suaveplan/payment-providers
Target path: universal/commerce/payment-providers
Prerequisite packages on Verdaccio: @suaveplan/error, @suaveplan/types, @suaveplan/payment, @suaveplan/retry, @suaveplan/crypto
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Scaffold
- Create
universal/commerce/payment-providers/withsrc/,tests/,src/__benchmarks__/and all feature subdirectories per the layout inproposal.md. - Write
package.jsonat version0.1.0with"type": "module","sideEffects": false, correctexportsmap,dependencies, anddevDependencies. - Write
tsconfig.jsonextending@suaveplan/typescript-config/library.json. - Write
vitest.config.tsusingcreateTestConfig()from@suaveplan/testing/config. - Add
lint,typecheck,test,test:coverage,build,docs:checkscripts.
2. Types + errors
src/types/common.ts—BaseAdapterOptions,StripeAdapterOptions,PayPalAdapterOptions,SquareAdapterOptions,MollieAdapterOptions,AdyenAdapterOptions,PaymentProviderErrorDetail.src/types/common.md(≥200 words, both examples, API reference).src/error-codes.ts— no new error codes beyond@suaveplan/payment; re-exportPaymentErrorand addPaymentProviderErrorDetailcontext injection helpers. Register docs call.src/types/schemas.ts+schemas.md— Zod schemas for all option types and raw response shapes.
3. Provider adapters (one sub-task per provider)
For each of stripe, paypal, square, mollie, adyen:
- Implement
create{Provider}Adapter(options: {Provider}AdapterOptions): PaymentAdapter.create: POST to provider create endpoint; include caller idempotency key as provider-specific header.authorise: POST to provider confirm/capture endpoint.capture: POST to provider capture endpoint.refund: POST to provider refund endpoint.cancel: POST to provider cancel/void endpoint.verifyWebhook: provider-specific HMAC or RSA verification via@suaveplan/crypto.normalizeWebhook(body): parse provider events toPaymentWebhookEvent[].- Wrap all API calls with
@suaveplan/retry(3 retries, exponential backoff); circuit breaker opens after 5 failures. - Environment switching: sandbox URLs when
options.environment === 'sandbox'.
- Export
normalize{Provider}{Entity}mapper functions (e.g.normalizeStripePaymentIntent). - Write unit tests per provider:
createsuccess,create4xx maps toPAYMENT_PROVIDER_ERROR,verifyWebhookvalid/invalid,normalizeWebhooksample payload.
4. OTel instrumentation
- Span
payment_provider.api_callwith attributespayment_provider.name,payment_provider.method; counterpayment_provider.api_total; histogrampayment_provider.api_duration_ms.
5. Benchmarks (src/__benchmarks__/payment-providers.bench.ts)
normalizeStripePaymentIntent100 000 times.
6. Docs + verify
- One
.mdper implementation file (≥200 words, both examples, API reference). RootREADME.md. bunx turbo lint typecheck test --filter=@suaveplan/payment-providers— green.bunx turbo test:coverage --filter=@suaveplan/payment-providers— 100%.bun scripts/publish.ts --package @suaveplan/payment-providers.- Archive:
openspec/archive/2026-04-24-enterprise-payment-providers/.