@pithy-sh/payments 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/coverage.d.ts +35 -0
- package/dist/admin/coverage.d.ts.map +1 -0
- package/dist/admin/coverage.js +56 -0
- package/dist/admin/read.d.ts +222 -0
- package/dist/admin/read.d.ts.map +1 -0
- package/dist/admin/read.js +159 -0
- package/dist/audit/actions.d.ts +211 -0
- package/dist/audit/actions.d.ts.map +1 -0
- package/dist/audit/actions.js +211 -0
- package/dist/capability.d.ts +72 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +228 -0
- package/dist/client/api.d.ts +435 -0
- package/dist/client/api.d.ts.map +1 -0
- package/dist/client/api.js +415 -0
- package/dist/client/checkout.d.ts +144 -0
- package/dist/client/checkout.d.ts.map +1 -0
- package/dist/client/checkout.js +173 -0
- package/dist/client/fixtures/price-preview-de.js +89 -0
- package/dist/client/fixtures/price-preview-gb.js +89 -0
- package/dist/client/fixtures/price-preview-jp-yen.js +89 -0
- package/dist/client/fixtures/price-preview-us-country-only.js +89 -0
- package/dist/client/fixtures/price-preview-us-new-york.js +89 -0
- package/dist/client/fixtures/pricePreview.d.ts +54 -0
- package/dist/client/fixtures/pricePreview.d.ts.map +1 -0
- package/dist/client/fixtures/pricePreview.js +61 -0
- package/dist/client/hooks.d.ts +235 -0
- package/dist/client/hooks.d.ts.map +1 -0
- package/dist/client/hooks.js +428 -0
- package/dist/client/paddle.d.ts +433 -0
- package/dist/client/paddle.d.ts.map +1 -0
- package/dist/client/paddle.js +391 -0
- package/dist/client/paddleCache.d.ts +123 -0
- package/dist/client/paddleCache.d.ts.map +1 -0
- package/dist/client/paddleCache.js +159 -0
- package/dist/client/paddlePrices.d.ts +94 -0
- package/dist/client/paddlePrices.d.ts.map +1 -0
- package/dist/client/paddlePrices.js +55 -0
- package/dist/client/paddlePricesTag.d.ts +127 -0
- package/dist/client/paddlePricesTag.d.ts.map +1 -0
- package/dist/client/paddlePricesTag.js +207 -0
- package/dist/client/projection.d.ts +128 -0
- package/dist/client/projection.d.ts.map +1 -0
- package/dist/client/projection.js +0 -0
- package/dist/client/test-utils/cacheStore.d.ts +18 -0
- package/dist/client/test-utils/cacheStore.d.ts.map +1 -0
- package/dist/client/test-utils/cacheStore.js +42 -0
- package/dist/client/wholeUnits.d.ts +18 -0
- package/dist/client/wholeUnits.d.ts.map +1 -0
- package/dist/client/wholeUnits.js +120 -0
- package/dist/config/config.d.ts +238 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +249 -0
- package/dist/data/discount.d.ts +127 -0
- package/dist/data/discount.d.ts.map +1 -0
- package/dist/data/discount.js +91 -0
- package/dist/data/entitlement.d.ts +43 -0
- package/dist/data/entitlement.d.ts.map +1 -0
- package/dist/data/entitlement.js +43 -0
- package/dist/data/money.d.ts +15 -0
- package/dist/data/money.d.ts.map +1 -0
- package/dist/data/money.js +76 -0
- package/dist/data/pause.d.ts +133 -0
- package/dist/data/pause.d.ts.map +1 -0
- package/dist/data/pause.js +63 -0
- package/dist/data/providerAccount.d.ts +40 -0
- package/dist/data/providerAccount.d.ts.map +1 -0
- package/dist/data/providerAccount.js +34 -0
- package/dist/data/purchase.d.ts +107 -0
- package/dist/data/purchase.d.ts.map +1 -0
- package/dist/data/purchase.js +77 -0
- package/dist/data/rail.d.ts +74 -0
- package/dist/data/rail.d.ts.map +1 -0
- package/dist/data/rail.js +74 -0
- package/dist/data/reconcileRun.d.ts +120 -0
- package/dist/data/reconcileRun.d.ts.map +1 -0
- package/dist/data/reconcileRun.js +120 -0
- package/dist/data/renderMoney.d.ts +85 -0
- package/dist/data/renderMoney.d.ts.map +1 -0
- package/dist/data/renderMoney.js +146 -0
- package/dist/data/status.d.ts +58 -0
- package/dist/data/status.d.ts.map +1 -0
- package/dist/data/status.js +68 -0
- package/dist/data/subject.d.ts +111 -0
- package/dist/data/subject.d.ts.map +1 -0
- package/dist/data/subject.js +125 -0
- package/dist/data/subscription.d.ts +624 -0
- package/dist/data/subscription.d.ts.map +1 -0
- package/dist/data/subscription.js +497 -0
- package/dist/data/syncCursor.d.ts +33 -0
- package/dist/data/syncCursor.d.ts.map +1 -0
- package/dist/data/syncCursor.js +29 -0
- package/dist/data/tables.d.ts +37 -0
- package/dist/data/tables.d.ts.map +1 -0
- package/dist/data/tables.js +44 -0
- package/dist/data/webhookEvent.d.ts +134 -0
- package/dist/data/webhookEvent.d.ts.map +1 -0
- package/dist/data/webhookEvent.js +128 -0
- package/dist/entitlement/manual.d.ts +101 -0
- package/dist/entitlement/manual.d.ts.map +1 -0
- package/dist/entitlement/manual.js +84 -0
- package/dist/entitlement/resolver.d.ts +60 -0
- package/dist/entitlement/resolver.d.ts.map +1 -0
- package/dist/entitlement/resolver.js +101 -0
- package/dist/entitlement/subjectSeam.d.ts +102 -0
- package/dist/entitlement/subjectSeam.d.ts.map +1 -0
- package/dist/entitlement/subjectSeam.js +85 -0
- package/dist/error/errors.d.ts +247 -0
- package/dist/error/errors.d.ts.map +1 -0
- package/dist/error/errors.js +326 -0
- package/dist/grants/apply.d.ts +74 -0
- package/dist/grants/apply.d.ts.map +1 -0
- package/dist/grants/apply.js +148 -0
- package/dist/grants/clawback.d.ts +43 -0
- package/dist/grants/clawback.d.ts.map +1 -0
- package/dist/grants/clawback.js +71 -0
- package/dist/grants/ledgerSeam.d.ts +89 -0
- package/dist/grants/ledgerSeam.d.ts.map +1 -0
- package/dist/grants/ledgerSeam.js +66 -0
- package/dist/http/dispatch.d.ts +35 -0
- package/dist/http/dispatch.d.ts.map +1 -0
- package/dist/http/dispatch.js +40 -0
- package/dist/http/guards.d.ts +43 -0
- package/dist/http/guards.d.ts.map +1 -0
- package/dist/http/guards.js +52 -0
- package/dist/http/manifestConfig.d.ts +38 -0
- package/dist/http/manifestConfig.d.ts.map +1 -0
- package/dist/http/manifestConfig.js +49 -0
- package/dist/http/responses.d.ts +1455 -0
- package/dist/http/responses.d.ts.map +1 -0
- package/dist/http/responses.js +728 -0
- package/dist/http/routes.d.ts +315 -0
- package/dist/http/routes.d.ts.map +1 -0
- package/dist/http/routes.js +1966 -0
- package/dist/http/schemas.d.ts +404 -0
- package/dist/http/schemas.d.ts.map +1 -0
- package/dist/http/schemas.js +359 -0
- package/dist/http/scopes.d.ts +160 -0
- package/dist/http/scopes.d.ts.map +1 -0
- package/dist/http/scopes.js +240 -0
- package/dist/http/view.d.ts +96 -0
- package/dist/http/view.d.ts.map +1 -0
- package/dist/http/view.js +170 -0
- package/dist/http/webhookGuard.d.ts +109 -0
- package/dist/http/webhookGuard.d.ts.map +1 -0
- package/dist/http/webhookGuard.js +206 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/migrations/0001_purchases.d.ts +35 -0
- package/dist/migrations/0001_purchases.d.ts.map +1 -0
- package/dist/migrations/0001_purchases.js +80 -0
- package/dist/pricing/location.d.ts +138 -0
- package/dist/pricing/location.d.ts.map +1 -0
- package/dist/pricing/location.js +81 -0
- package/dist/pricing/visitor.d.ts +56 -0
- package/dist/pricing/visitor.d.ts.map +1 -0
- package/dist/pricing/visitor.js +35 -0
- package/dist/projection/event.d.ts +66 -0
- package/dist/projection/event.d.ts.map +1 -0
- package/dist/projection/event.js +45 -0
- package/dist/projection/orphans.d.ts +114 -0
- package/dist/projection/orphans.d.ts.map +1 -0
- package/dist/projection/orphans.js +162 -0
- package/dist/projection/owner.d.ts +121 -0
- package/dist/projection/owner.d.ts.map +1 -0
- package/dist/projection/owner.js +114 -0
- package/dist/projection/resolve.d.ts +30 -0
- package/dist/projection/resolve.d.ts.map +1 -0
- package/dist/projection/resolve.js +42 -0
- package/dist/projection/writer.d.ts +103 -0
- package/dist/projection/writer.d.ts.map +1 -0
- package/dist/projection/writer.js +280 -0
- package/dist/provision/resolvePaymentsConfig.d.ts +48 -0
- package/dist/provision/resolvePaymentsConfig.d.ts.map +1 -0
- package/dist/provision/resolvePaymentsConfig.js +41 -0
- package/dist/rails/apple/certs.d.ts +7 -0
- package/dist/rails/apple/certs.d.ts.map +1 -0
- package/dist/rails/apple/certs.js +8 -0
- package/dist/rails/apple/der.d.ts +107 -0
- package/dist/rails/apple/der.d.ts.map +1 -0
- package/dist/rails/apple/der.js +217 -0
- package/dist/rails/apple/fixtures/chain.d.ts +117 -0
- package/dist/rails/apple/fixtures/chain.d.ts.map +1 -0
- package/dist/rails/apple/fixtures/chain.js +289 -0
- package/dist/rails/apple/http.d.ts +74 -0
- package/dist/rails/apple/http.d.ts.map +1 -0
- package/dist/rails/apple/http.js +32 -0
- package/dist/rails/apple/jws.d.ts +17 -0
- package/dist/rails/apple/jws.d.ts.map +1 -0
- package/dist/rails/apple/jws.js +75 -0
- package/dist/rails/apple/notification.d.ts +116 -0
- package/dist/rails/apple/notification.d.ts.map +1 -0
- package/dist/rails/apple/notification.js +199 -0
- package/dist/rails/apple/rail.d.ts +25 -0
- package/dist/rails/apple/rail.d.ts.map +1 -0
- package/dist/rails/apple/rail.js +68 -0
- package/dist/rails/apple/serverApi.d.ts +120 -0
- package/dist/rails/apple/serverApi.d.ts.map +1 -0
- package/dist/rails/apple/serverApi.js +244 -0
- package/dist/rails/apple/verify.d.ts +36 -0
- package/dist/rails/apple/verify.d.ts.map +1 -0
- package/dist/rails/apple/verify.js +46 -0
- package/dist/rails/apple/x509.d.ts +85 -0
- package/dist/rails/apple/x509.d.ts.map +1 -0
- package/dist/rails/apple/x509.js +273 -0
- package/dist/rails/contract.d.ts +871 -0
- package/dist/rails/contract.d.ts.map +1 -0
- package/dist/rails/contract.js +60 -0
- package/dist/rails/google/fixtures/push.d.ts +71 -0
- package/dist/rails/google/fixtures/push.d.ts.map +1 -0
- package/dist/rails/google/fixtures/push.js +107 -0
- package/dist/rails/google/http.d.ts +77 -0
- package/dist/rails/google/http.d.ts.map +1 -0
- package/dist/rails/google/http.js +39 -0
- package/dist/rails/google/jwt.d.ts +53 -0
- package/dist/rails/google/jwt.d.ts.map +1 -0
- package/dist/rails/google/jwt.js +94 -0
- package/dist/rails/google/oidc.d.ts +112 -0
- package/dist/rails/google/oidc.d.ts.map +1 -0
- package/dist/rails/google/oidc.js +179 -0
- package/dist/rails/google/playApi.d.ts +188 -0
- package/dist/rails/google/playApi.d.ts.map +1 -0
- package/dist/rails/google/playApi.js +350 -0
- package/dist/rails/google/rail.d.ts +57 -0
- package/dist/rails/google/rail.d.ts.map +1 -0
- package/dist/rails/google/rail.js +70 -0
- package/dist/rails/google/rtdn.d.ts +105 -0
- package/dist/rails/google/rtdn.d.ts.map +1 -0
- package/dist/rails/google/rtdn.js +179 -0
- package/dist/rails/google/verify.d.ts +20 -0
- package/dist/rails/google/verify.d.ts.map +1 -0
- package/dist/rails/google/verify.js +76 -0
- package/dist/rails/lemonSqueezy/api.d.ts +92 -0
- package/dist/rails/lemonSqueezy/api.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/api.js +121 -0
- package/dist/rails/lemonSqueezy/checkout.d.ts +52 -0
- package/dist/rails/lemonSqueezy/checkout.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/checkout.js +84 -0
- package/dist/rails/lemonSqueezy/discounts.d.ts +50 -0
- package/dist/rails/lemonSqueezy/discounts.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/discounts.js +75 -0
- package/dist/rails/lemonSqueezy/fixtures/events.d.ts +56 -0
- package/dist/rails/lemonSqueezy/fixtures/events.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/fixtures/events.js +144 -0
- package/dist/rails/lemonSqueezy/objects.d.ts +229 -0
- package/dist/rails/lemonSqueezy/objects.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/objects.js +379 -0
- package/dist/rails/lemonSqueezy/portal.d.ts +35 -0
- package/dist/rails/lemonSqueezy/portal.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/portal.js +18 -0
- package/dist/rails/lemonSqueezy/pricing.d.ts +25 -0
- package/dist/rails/lemonSqueezy/pricing.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/pricing.js +54 -0
- package/dist/rails/lemonSqueezy/rail.d.ts +41 -0
- package/dist/rails/lemonSqueezy/rail.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/rail.js +67 -0
- package/dist/rails/lemonSqueezy/read.d.ts +28 -0
- package/dist/rails/lemonSqueezy/read.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/read.js +37 -0
- package/dist/rails/lemonSqueezy/refresh.d.ts +42 -0
- package/dist/rails/lemonSqueezy/refresh.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/refresh.js +40 -0
- package/dist/rails/lemonSqueezy/signature.d.ts +56 -0
- package/dist/rails/lemonSqueezy/signature.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/signature.js +92 -0
- package/dist/rails/lemonSqueezy/verify.d.ts +33 -0
- package/dist/rails/lemonSqueezy/verify.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/verify.js +41 -0
- package/dist/rails/lemonSqueezy/webhook.d.ts +53 -0
- package/dist/rails/lemonSqueezy/webhook.d.ts.map +1 -0
- package/dist/rails/lemonSqueezy/webhook.js +179 -0
- package/dist/rails/paddle/adjustments.d.ts +60 -0
- package/dist/rails/paddle/adjustments.d.ts.map +1 -0
- package/dist/rails/paddle/adjustments.js +66 -0
- package/dist/rails/paddle/api.d.ts +138 -0
- package/dist/rails/paddle/api.d.ts.map +1 -0
- package/dist/rails/paddle/api.js +152 -0
- package/dist/rails/paddle/checkout.d.ts +69 -0
- package/dist/rails/paddle/checkout.d.ts.map +1 -0
- package/dist/rails/paddle/checkout.js +100 -0
- package/dist/rails/paddle/discounts.d.ts +67 -0
- package/dist/rails/paddle/discounts.d.ts.map +1 -0
- package/dist/rails/paddle/discounts.js +73 -0
- package/dist/rails/paddle/events.d.ts +140 -0
- package/dist/rails/paddle/events.d.ts.map +1 -0
- package/dist/rails/paddle/events.js +183 -0
- package/dist/rails/paddle/fixtures/browserForged.d.ts +42 -0
- package/dist/rails/paddle/fixtures/browserForged.d.ts.map +1 -0
- package/dist/rails/paddle/fixtures/browserForged.js +52 -0
- package/dist/rails/paddle/fixtures/pausedSubscription.d.ts +78 -0
- package/dist/rails/paddle/fixtures/pausedSubscription.d.ts.map +1 -0
- package/dist/rails/paddle/fixtures/pausedSubscription.js +76 -0
- package/dist/rails/paddle/objects.d.ts +519 -0
- package/dist/rails/paddle/objects.d.ts.map +1 -0
- package/dist/rails/paddle/objects.js +588 -0
- package/dist/rails/paddle/portal.d.ts +45 -0
- package/dist/rails/paddle/portal.d.ts.map +1 -0
- package/dist/rails/paddle/portal.js +42 -0
- package/dist/rails/paddle/rail.d.ts +55 -0
- package/dist/rails/paddle/rail.d.ts.map +1 -0
- package/dist/rails/paddle/rail.js +117 -0
- package/dist/rails/paddle/read.d.ts +53 -0
- package/dist/rails/paddle/read.d.ts.map +1 -0
- package/dist/rails/paddle/read.js +66 -0
- package/dist/rails/paddle/recorded.d.ts +49 -0
- package/dist/rails/paddle/recorded.d.ts.map +1 -0
- package/dist/rails/paddle/recorded.js +79 -0
- package/dist/rails/paddle/refresh.d.ts +54 -0
- package/dist/rails/paddle/refresh.d.ts.map +1 -0
- package/dist/rails/paddle/refresh.js +94 -0
- package/dist/rails/paddle/refund.d.ts +82 -0
- package/dist/rails/paddle/refund.d.ts.map +1 -0
- package/dist/rails/paddle/refund.js +175 -0
- package/dist/rails/paddle/signature.d.ts +83 -0
- package/dist/rails/paddle/signature.d.ts.map +1 -0
- package/dist/rails/paddle/signature.js +163 -0
- package/dist/rails/paddle/subscription.d.ts +137 -0
- package/dist/rails/paddle/subscription.d.ts.map +1 -0
- package/dist/rails/paddle/subscription.js +538 -0
- package/dist/rails/paddle/verify.d.ts +46 -0
- package/dist/rails/paddle/verify.d.ts.map +1 -0
- package/dist/rails/paddle/verify.js +43 -0
- package/dist/rails/paddle/webhook.d.ts +98 -0
- package/dist/rails/paddle/webhook.d.ts.map +1 -0
- package/dist/rails/paddle/webhook.js +181 -0
- package/dist/rails/providers.d.ts +73 -0
- package/dist/rails/providers.d.ts.map +1 -0
- package/dist/rails/providers.js +62 -0
- package/dist/rails/stripe/api.d.ts +118 -0
- package/dist/rails/stripe/api.d.ts.map +1 -0
- package/dist/rails/stripe/api.js +153 -0
- package/dist/rails/stripe/checkout.d.ts +60 -0
- package/dist/rails/stripe/checkout.d.ts.map +1 -0
- package/dist/rails/stripe/checkout.js +86 -0
- package/dist/rails/stripe/discounts.d.ts +50 -0
- package/dist/rails/stripe/discounts.d.ts.map +1 -0
- package/dist/rails/stripe/discounts.js +87 -0
- package/dist/rails/stripe/fixtures/events.d.ts +64 -0
- package/dist/rails/stripe/fixtures/events.d.ts.map +1 -0
- package/dist/rails/stripe/fixtures/events.js +67 -0
- package/dist/rails/stripe/objects.d.ts +237 -0
- package/dist/rails/stripe/objects.d.ts.map +1 -0
- package/dist/rails/stripe/objects.js +389 -0
- package/dist/rails/stripe/portal.d.ts +29 -0
- package/dist/rails/stripe/portal.d.ts.map +1 -0
- package/dist/rails/stripe/portal.js +41 -0
- package/dist/rails/stripe/pricing.d.ts +25 -0
- package/dist/rails/stripe/pricing.d.ts.map +1 -0
- package/dist/rails/stripe/pricing.js +68 -0
- package/dist/rails/stripe/rail.d.ts +28 -0
- package/dist/rails/stripe/rail.d.ts.map +1 -0
- package/dist/rails/stripe/rail.js +81 -0
- package/dist/rails/stripe/refresh.d.ts +33 -0
- package/dist/rails/stripe/refresh.d.ts.map +1 -0
- package/dist/rails/stripe/refresh.js +21 -0
- package/dist/rails/stripe/signature.d.ts +71 -0
- package/dist/rails/stripe/signature.d.ts.map +1 -0
- package/dist/rails/stripe/signature.js +92 -0
- package/dist/rails/stripe/verify.d.ts +15 -0
- package/dist/rails/stripe/verify.d.ts.map +1 -0
- package/dist/rails/stripe/verify.js +63 -0
- package/dist/rails/stripe/webhook.d.ts +26 -0
- package/dist/rails/stripe/webhook.d.ts.map +1 -0
- package/dist/rails/stripe/webhook.js +31 -0
- package/dist/secret/registry.d.ts +192 -0
- package/dist/secret/registry.d.ts.map +1 -0
- package/dist/secret/registry.js +154 -0
- package/dist/seeds/example.d.ts +3 -0
- package/dist/seeds/example.d.ts.map +1 -0
- package/dist/seeds/example.js +171 -0
- package/dist/version.generated.d.ts +5 -0
- package/dist/version.generated.d.ts.map +1 -0
- package/dist/version.generated.js +7 -0
- package/dist/workflows/paddleSweep.d.ts +175 -0
- package/dist/workflows/paddleSweep.d.ts.map +1 -0
- package/dist/workflows/paddleSweep.js +433 -0
- package/dist/workflows/railAccess.d.ts +48 -0
- package/dist/workflows/railAccess.d.ts.map +1 -0
- package/dist/workflows/railAccess.js +36 -0
- package/dist/workflows/reconcile.d.ts +161 -0
- package/dist/workflows/reconcile.d.ts.map +1 -0
- package/dist/workflows/reconcile.js +352 -0
- package/dist/workflows/report.d.ts +28 -0
- package/dist/workflows/report.d.ts.map +1 -0
- package/dist/workflows/report.js +54 -0
- package/dist/workflows/retryPolicy.d.ts +29 -0
- package/dist/workflows/retryPolicy.d.ts.map +1 -0
- package/dist/workflows/retryPolicy.js +37 -0
- package/dist/workflows/specs.d.ts +102 -0
- package/dist/workflows/specs.d.ts.map +1 -0
- package/dist/workflows/specs.js +84 -0
- package/dist/workflows/worker.d.ts +62 -0
- package/dist/workflows/worker.d.ts.map +1 -0
- package/dist/workflows/worker.js +92 -0
- package/dist/workflows/workerConfig.d.ts +46 -0
- package/dist/workflows/workerConfig.d.ts.map +1 -0
- package/dist/workflows/workerConfig.js +38 -0
- package/package.json +22 -13
- package/pithy.manifest.json +19 -13
- package/src/version.generated.ts +1 -1
- package/src/client/paddlePrices.iife.ts +0 -43
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { PithyError } from "@pithy-sh/core/src/error/pithyError";
|
|
2
|
+
//#region src/error/errors.ts
|
|
3
|
+
/** The receipt could not be read at all. Nothing was asked of the provider. */
|
|
4
|
+
var PaymentsInvalidReceiptError = class extends PithyError {
|
|
5
|
+
constructor(args = {}, options) {
|
|
6
|
+
super({
|
|
7
|
+
code: "payments/invalid_receipt",
|
|
8
|
+
status: 400,
|
|
9
|
+
message: args.message ?? "That receipt could not be read.",
|
|
10
|
+
action: args.action ?? "Submit the transaction exactly as the store SDK returned it.",
|
|
11
|
+
detail: args.detail,
|
|
12
|
+
params: args.params
|
|
13
|
+
}, options);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/** The rail was asked and said no. Distinct from the rail failing to answer at all. */
|
|
17
|
+
var PaymentsVerificationFailedError = class extends PithyError {
|
|
18
|
+
constructor(args = {}, options) {
|
|
19
|
+
super({
|
|
20
|
+
code: "payments/verification_failed",
|
|
21
|
+
status: 400,
|
|
22
|
+
message: args.message ?? "The store did not recognize that purchase.",
|
|
23
|
+
action: args.action ?? "Restore purchases and retry. If it persists, contact support.",
|
|
24
|
+
detail: args.detail,
|
|
25
|
+
params: args.params
|
|
26
|
+
}, options);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* An inbound notification failed its authenticity check. 401, not 403: a failed signature means the caller
|
|
31
|
+
* did not prove who it is, which is a different statement from a known caller being refused.
|
|
32
|
+
*/
|
|
33
|
+
var PaymentsWebhookUnverifiedError = class extends PithyError {
|
|
34
|
+
constructor(args = {}, options) {
|
|
35
|
+
super({
|
|
36
|
+
code: "payments/webhook_unverified",
|
|
37
|
+
status: 401,
|
|
38
|
+
message: args.message ?? "That notification could not be verified.",
|
|
39
|
+
action: args.action ?? "Check the webhook signing secret registered for this environment.",
|
|
40
|
+
detail: args.detail,
|
|
41
|
+
params: args.params
|
|
42
|
+
}, options);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/** The request names a rail this project has not enabled. Rails are config, so a missing one is a 404. */
|
|
46
|
+
var PaymentsRailNotConfiguredError = class extends PithyError {
|
|
47
|
+
constructor(args = {}, options) {
|
|
48
|
+
super({
|
|
49
|
+
code: "payments/rail_not_configured",
|
|
50
|
+
status: 404,
|
|
51
|
+
message: args.message ?? "That payment method is not available.",
|
|
52
|
+
action: args.action ?? "Enable the rail in the `rails` block of pithy.config.ts and redeploy.",
|
|
53
|
+
detail: args.detail,
|
|
54
|
+
params: args.params
|
|
55
|
+
}, options);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Reconciliation cannot be started here: the pass's Workflow host is not deployed or not bound.
|
|
60
|
+
*
|
|
61
|
+
* **501 rather than 404 or 500.** The route exists and the caller's scope was right, so 404 would send them
|
|
62
|
+
* looking for a typo; nothing failed, so 500 would send them looking at logs. What is true is that this
|
|
63
|
+
* deployment does not implement the operation yet, and the fix is a deploy the adopter performs. `action` says
|
|
64
|
+
* which one.
|
|
65
|
+
*
|
|
66
|
+
* The read is unaffected and stays useful: a project with no Workflow host has an empty run log, which is the
|
|
67
|
+
* loudest thing that read says.
|
|
68
|
+
*/
|
|
69
|
+
var PaymentsReconcileNotProvisionedError = class extends PithyError {
|
|
70
|
+
constructor(args = {}, options) {
|
|
71
|
+
super({
|
|
72
|
+
code: "payments/reconcile_not_provisioned",
|
|
73
|
+
status: 501,
|
|
74
|
+
message: args.message ?? "Reconciliation is not set up for this deployment.",
|
|
75
|
+
action: args.action ?? "Deploy the payments workflow host, then bind PAYMENTS_RECONCILE in wrangler.jsonc.",
|
|
76
|
+
detail: args.detail,
|
|
77
|
+
params: args.params
|
|
78
|
+
}, options);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
/** No catalog product maps the rail's SKU. The catalog is config, so a new SKU needs a deploy. */
|
|
82
|
+
var PaymentsProductNotFoundError = class extends PithyError {
|
|
83
|
+
constructor(args = {}, options) {
|
|
84
|
+
super({
|
|
85
|
+
code: "payments/product_not_found",
|
|
86
|
+
status: 404,
|
|
87
|
+
message: args.message ?? "That product is not for sale here.",
|
|
88
|
+
action: args.action ?? "Add the SKU to the `products` catalog in pithy.config.ts and redeploy.",
|
|
89
|
+
detail: args.detail,
|
|
90
|
+
params: args.params
|
|
91
|
+
}, options);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* A sandbox purchase reached a production deployment, or the reverse. Rejected outright — granting a real
|
|
96
|
+
* entitlement from a sandbox transaction is the most common in-app-purchase security defect there is.
|
|
97
|
+
*/
|
|
98
|
+
var PaymentsEnvironmentMismatchError = class extends PithyError {
|
|
99
|
+
constructor(args = {}, options) {
|
|
100
|
+
super({
|
|
101
|
+
code: "payments/environment_mismatch",
|
|
102
|
+
status: 400,
|
|
103
|
+
message: args.message ?? "That purchase belongs to a different store environment.",
|
|
104
|
+
action: args.action ?? "Use a production purchase against production, and a sandbox one against sandbox.",
|
|
105
|
+
detail: args.detail,
|
|
106
|
+
params: args.params
|
|
107
|
+
}, options);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* The transaction is already projected against a different user. A replay by its own owner is a 200 — the
|
|
112
|
+
* write path is idempotent — but a receipt lifted from another account is refused rather than silently
|
|
113
|
+
* rebound, which is what makes a stolen receipt worthless.
|
|
114
|
+
*/
|
|
115
|
+
var PaymentsReceiptAlreadyOwnedError = class extends PithyError {
|
|
116
|
+
constructor(args = {}, options) {
|
|
117
|
+
super({
|
|
118
|
+
code: "payments/receipt_already_owned",
|
|
119
|
+
status: 409,
|
|
120
|
+
message: args.message ?? "That purchase belongs to another account.",
|
|
121
|
+
action: args.action ?? "Sign in as the account that made the purchase, then restore it.",
|
|
122
|
+
detail: args.detail,
|
|
123
|
+
params: args.params
|
|
124
|
+
}, options);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* The rail could not be reached, or answered with a server error. The purchase is neither granted nor
|
|
129
|
+
* refused: the reconciliation Workflow repairs it, so the caller may retry.
|
|
130
|
+
*/
|
|
131
|
+
var PaymentsProviderUnavailableError = class extends PithyError {
|
|
132
|
+
constructor(args = {}, options) {
|
|
133
|
+
super({
|
|
134
|
+
code: "payments/provider_unavailable",
|
|
135
|
+
status: 503,
|
|
136
|
+
message: args.message ?? "The store did not answer.",
|
|
137
|
+
action: args.action ?? "Retry shortly. Your purchase is safe and will be reconciled either way.",
|
|
138
|
+
detail: args.detail,
|
|
139
|
+
params: args.params
|
|
140
|
+
}, options);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* A refund's clawback debit was refused by the ledger, because the balance no longer covers it.
|
|
145
|
+
*
|
|
146
|
+
* Constructed far more often than it is thrown. A clawback runs after the refund is already recorded, so
|
|
147
|
+
* raising this at the caller would undo nothing and would turn a store's own webhook into a 5xx it retries
|
|
148
|
+
* forever. Instead the payload is *recorded* — the audit trail carries the code, the amount, and the account —
|
|
149
|
+
* which is what makes a failed clawback queryable and alertable rather than a line in a log. The class exists
|
|
150
|
+
* so that record is the same shape as every other failure in the system, and so an adopter's own tooling can
|
|
151
|
+
* raise the code when it has a caller to answer.
|
|
152
|
+
*/
|
|
153
|
+
var PaymentsClawbackFailedError = class extends PithyError {
|
|
154
|
+
constructor(args = {}, options) {
|
|
155
|
+
super({
|
|
156
|
+
code: "payments/clawback_failed",
|
|
157
|
+
status: 409,
|
|
158
|
+
message: args.message ?? "That refund could not be reversed against the balance.",
|
|
159
|
+
action: args.action ?? "Review the account's ledger. The balance was spent before the refund arrived.",
|
|
160
|
+
detail: args.detail,
|
|
161
|
+
params: args.params
|
|
162
|
+
}, options);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* A manual grant named an entitlement key this project does not define.
|
|
167
|
+
*
|
|
168
|
+
* 400 rather than the 404 the catalog's other refusals use, and the difference is what the caller named. A
|
|
169
|
+
* SKU or a product id names a *resource* the catalog either holds or does not, so a miss is Not Found. An
|
|
170
|
+
* entitlement key names the *vocabulary* gating code is written in, and a key outside it is a malformed
|
|
171
|
+
* request — `pr` for `pro`, `pro ` with a trailing space, a key renamed a release ago. Unchecked, each of
|
|
172
|
+
* those was a 200, a row, and a customer who stays locked out with nothing anywhere to read.
|
|
173
|
+
*
|
|
174
|
+
* **The `message` echoes the key and never the set.** A caller learns which key it got wrong, because it
|
|
175
|
+
* sent it. What this project defines is a separate disclosure behind `payments:catalog:read`, and a refusal
|
|
176
|
+
* that listed it would be that read, ungated.
|
|
177
|
+
*/
|
|
178
|
+
var PaymentsEntitlementNotInCatalogError = class extends PithyError {
|
|
179
|
+
constructor(args = {}, options) {
|
|
180
|
+
super({
|
|
181
|
+
code: "payments/entitlement_not_in_catalog",
|
|
182
|
+
status: 400,
|
|
183
|
+
message: args.message ?? "That entitlement is not one this project defines.",
|
|
184
|
+
action: args.action ?? "Grant a key one of the catalog's products lists, or declare it in `manualEntitlements` in pithy.config.ts.",
|
|
185
|
+
detail: args.detail,
|
|
186
|
+
params: args.params
|
|
187
|
+
}, options);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
/** The caller does not hold an entitlement the route requires. Core's gate is what normally raises it. */
|
|
191
|
+
var PaymentsEntitlementRequiredError = class extends PithyError {
|
|
192
|
+
constructor(args = {}, options) {
|
|
193
|
+
super({
|
|
194
|
+
code: "payments/entitlement_required",
|
|
195
|
+
status: 403,
|
|
196
|
+
message: args.message ?? "This feature requires an active subscription or purchase.",
|
|
197
|
+
action: args.action ?? "Purchase or restore the product that grants access, then retry.",
|
|
198
|
+
detail: args.detail,
|
|
199
|
+
params: args.params
|
|
200
|
+
}, options);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* A discount code the store would not accept — unknown, expired, exhausted, or not valid for what is being
|
|
205
|
+
* bought.
|
|
206
|
+
*
|
|
207
|
+
* **400 and its own code, never a generic checkout failure.** A customer told "something went wrong" at
|
|
208
|
+
* checkout concludes their card was declined and stops trying; one told their code was not accepted removes
|
|
209
|
+
* the code and buys. The two are a different sentence on the screen and a different outcome for the sale.
|
|
210
|
+
*
|
|
211
|
+
* The code is echoed in `message` because the caller sent it and it is what they need to correct. The
|
|
212
|
+
* store's own reason rides in `detail`, which the HTTP codec strips.
|
|
213
|
+
*/
|
|
214
|
+
var PaymentsDiscountInvalidError = class extends PithyError {
|
|
215
|
+
constructor(args = {}, options) {
|
|
216
|
+
super({
|
|
217
|
+
code: "payments/discount_invalid",
|
|
218
|
+
status: 400,
|
|
219
|
+
message: args.message ?? "That discount code was not accepted.",
|
|
220
|
+
action: args.action ?? "Check the code, or continue without one.",
|
|
221
|
+
detail: args.detail,
|
|
222
|
+
params: args.params
|
|
223
|
+
}, options);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* A write path could not learn which subject the caller is acting for.
|
|
228
|
+
*
|
|
229
|
+
* Under organization billing the capability asks the adopter *who is this caller acting for* and the
|
|
230
|
+
* adopter answers from its own session — it has the memberships, and this package never learns what an
|
|
231
|
+
* organization is. An unanswered seam on a **read** needs no code at all: the query holds nothing, the
|
|
232
|
+
* gate denies, and unentitled is the direction every gate in the kit already fails. A **write** has
|
|
233
|
+
* nowhere to fail to. Submitting a purchase, restoring, opening checkout, opening the billing portal —
|
|
234
|
+
* each of them has a row or a session to create and no holder to create it against. Writing nothing and
|
|
235
|
+
* answering 200 is the worse outcome by a distance: the customer is charged by the store, the webhook
|
|
236
|
+
* arrives for a subject nobody stamped, and the money is real while the entitlement is not.
|
|
237
|
+
*
|
|
238
|
+
* **403, not 400 and not 500.** The caller is authenticated and the request is well-formed, so it is not
|
|
239
|
+
* a bad request. And an operator reading *our* logs finds nothing to fix, because what is missing is the
|
|
240
|
+
* adopter's resolver returning a value — so it is not a fault of ours either.
|
|
241
|
+
*
|
|
242
|
+
* The three fields split hard here. `message` tells a caller to pick an account, which is the one thing
|
|
243
|
+
* they can do about it. `action` names `billingSubject` and the resolver, which are an operator's words
|
|
244
|
+
* and a small map of the deployment a stranger has no need of. `detail` carries what the resolver was
|
|
245
|
+
* asked and what it gave back. The codec strips the last two.
|
|
246
|
+
*/
|
|
247
|
+
var PaymentsSubjectUnresolvedError = class extends PithyError {
|
|
248
|
+
constructor(args = {}, options) {
|
|
249
|
+
super({
|
|
250
|
+
code: "payments/subject_unresolved",
|
|
251
|
+
status: 403,
|
|
252
|
+
message: args.message ?? "No billing account is selected. Choose one, then retry.",
|
|
253
|
+
action: args.action ?? "This project sets `billingSubject: \"organization\"`. Have the subject resolver in pithy.config.ts return the organization the caller is acting for.",
|
|
254
|
+
detail: args.detail,
|
|
255
|
+
params: args.params
|
|
256
|
+
}, options);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* A subscription cannot be changed, or refunded, the way it was asked. The item shape is one this rail
|
|
261
|
+
* will not reproduce, the subscription is already canceled, there is no payment on it to refund, or the
|
|
262
|
+
* outcome asked for contradicts the state it is in — a plan move on a subscription whose cancellation is
|
|
263
|
+
* already scheduled, where honoring one instruction means discarding the other (#465).
|
|
264
|
+
*
|
|
265
|
+
* **A no-op is not a contradiction, and must not throw.** A change to the plan already held, and a cancel
|
|
266
|
+
* when that cancellation is already scheduled, name a state the subscription is already in. Both return
|
|
267
|
+
* success without calling the provider. That is the idempotency answer for a retried write: a client that
|
|
268
|
+
* loses a response and sends the same instruction again is not in conflict with anything, and answering 409
|
|
269
|
+
* would turn every duplicate submission into an incident. Only a request that cannot be reconciled with the
|
|
270
|
+
* present state reaches this code.
|
|
271
|
+
*
|
|
272
|
+
* **One code for all of it, and that is the argument, not an economy.** The obvious alternative was four:
|
|
273
|
+
* `subscription_multi_item`, `subscription_quantity_ambiguous`, `subscription_already_canceled`,
|
|
274
|
+
* `subscription_state_conflict`. Every one of them is the same 409, hands a caller the same sentence, and
|
|
275
|
+
* asks them to do the same thing — re-read the subscription and ask for something its present state
|
|
276
|
+
* allows. A code exists so a client can *branch*, and four codes nothing branches on is four members of
|
|
277
|
+
* core's closed union, four translation catalog keys, and a `switch` whose arms all render one string.
|
|
278
|
+
* What actually differs between the four is a fact about somebody's billing — how many items, which
|
|
279
|
+
* price, what quantity, what date — and that is throw-site context, which is what `detail` is and which
|
|
280
|
+
* the codec strips. So the distinction is kept where it is useful and off the wire where it is a leak.
|
|
281
|
+
*
|
|
282
|
+
* **The refund verb refuses through this code too, and the name is the only reason that needs saying.**
|
|
283
|
+
* `subscription_change_refused` reads as being about a plan move, so a reader looking for the code a
|
|
284
|
+
* refund refusal carries would conclude there is none. There is: a set with no payment in it, a payment
|
|
285
|
+
* the store will not refund because it is not completed, a transaction the store does not know, and a set
|
|
286
|
+
* too large to issue inside one request are all 409s, all tell the caller the same thing — re-read the
|
|
287
|
+
* subscription and its payments, then ask for something the present state allows — and nothing branches on
|
|
288
|
+
* telling them apart. Which of the four it was is a fact about somebody's billing, which is `detail`.
|
|
289
|
+
* **A refund that is already standing is not here at all**: it is a per-payment `already_requested`
|
|
290
|
+
* outcome and a 200, because it is the state the caller asked for. See `data/subscription.ts`.
|
|
291
|
+
*
|
|
292
|
+
* The one case that could earn its own code is "already canceled", because a screen genuinely wants to
|
|
293
|
+
* say *ends on the 15th* rather than *cannot be changed*. It does not earn it here: the screen learns
|
|
294
|
+
* that from the subscription it just read, which carries `scheduled_change.effective_at`. An error code
|
|
295
|
+
* is for a caller holding nothing else, and this caller is holding the subscription.
|
|
296
|
+
*
|
|
297
|
+
* **409, and neither 400 nor 500.** The request is well-formed and names a price this project sells, so
|
|
298
|
+
* it is not a bad request. Nothing is broken and there is nothing in a log for an operator to fix, so it
|
|
299
|
+
* is not ours. It is a conflict with the current state of the resource, which is the one thing 409 says,
|
|
300
|
+
* and it is what tells a client to refetch rather than to re-word.
|
|
301
|
+
*
|
|
302
|
+
* **Why refusing beats guessing**, since the refusal is the expensive-looking choice. A plan change
|
|
303
|
+
* replaces the whole items array: sending one item to a two-item subscription silently deletes the other,
|
|
304
|
+
* and inventing a quantity over- or under-charges a real card. Both failures are writes to somebody's
|
|
305
|
+
* billing that no read afterwards can distinguish from an intended change. A 409 is recoverable by a
|
|
306
|
+
* human in a minute; a dropped add-on is discovered on an invoice.
|
|
307
|
+
*
|
|
308
|
+
* `message` is safe to hand a stranger and names nothing about the subscription. `action` is the
|
|
309
|
+
* operator's half. `detail` carries the subscription id, the item shape, the status, the dates — none of
|
|
310
|
+
* which cross the boundary. `params` is the exception, and deliberately: it is client-facing, so a date a
|
|
311
|
+
* screen means to render in the reader's own language goes there and nowhere else.
|
|
312
|
+
*/
|
|
313
|
+
var PaymentsSubscriptionChangeRefusedError = class extends PithyError {
|
|
314
|
+
constructor(args = {}, options) {
|
|
315
|
+
super({
|
|
316
|
+
code: "payments/subscription_change_refused",
|
|
317
|
+
status: 409,
|
|
318
|
+
message: args.message ?? "That subscription cannot be changed that way.",
|
|
319
|
+
action: args.action ?? "Re-read the subscription's current state — its status, what it holds, and any scheduled change — then ask for a move that state allows.",
|
|
320
|
+
detail: args.detail,
|
|
321
|
+
params: args.params
|
|
322
|
+
}, options);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
//#endregion
|
|
326
|
+
export { PaymentsClawbackFailedError, PaymentsDiscountInvalidError, PaymentsEntitlementNotInCatalogError, PaymentsEntitlementRequiredError, PaymentsEnvironmentMismatchError, PaymentsInvalidReceiptError, PaymentsProductNotFoundError, PaymentsProviderUnavailableError, PaymentsRailNotConfiguredError, PaymentsReceiptAlreadyOwnedError, PaymentsReconcileNotProvisionedError, PaymentsSubjectUnresolvedError, PaymentsSubscriptionChangeRefusedError, PaymentsVerificationFailedError, PaymentsWebhookUnverifiedError };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
2
|
+
import { type AuditEmit } from "@pithy-sh/core/src/audit/recorder";
|
|
3
|
+
import type { PaymentsConfig, PaymentsLedgerGrant } from "../config/config";
|
|
4
|
+
import type { PaymentsPurchase } from "../data/purchase";
|
|
5
|
+
import type { PurchaseProjection } from "../projection/writer";
|
|
6
|
+
import { type ClawbackOutcome } from "./clawback";
|
|
7
|
+
import { type PaymentsLedger } from "./ledgerSeam";
|
|
8
|
+
/** One balance credit a purchase produced, with the ref that makes it happen exactly once. */
|
|
9
|
+
export interface AppliedGrant {
|
|
10
|
+
/** The ledger currency credited. */
|
|
11
|
+
currency: string;
|
|
12
|
+
/** How much, as an integer in the currency's minor unit. */
|
|
13
|
+
amount: number;
|
|
14
|
+
/** The idempotency key the ledger recorded it under. */
|
|
15
|
+
ref: string;
|
|
16
|
+
}
|
|
17
|
+
/** What one fulfillment did in both directions. Empty on both sides for a catalog with no `grants` clause. */
|
|
18
|
+
export interface FulfillmentReport {
|
|
19
|
+
/** The credits applied, in catalog order. */
|
|
20
|
+
granted: readonly AppliedGrant[];
|
|
21
|
+
/** The refund reversals attempted, whether or not the balance covered them. */
|
|
22
|
+
clawedBack: readonly ClawbackOutcome[];
|
|
23
|
+
}
|
|
24
|
+
/** What the grant modules need beyond the projection: the catalog the `grants` clause lives in. */
|
|
25
|
+
export interface GrantOptions {
|
|
26
|
+
/** The resolved catalog. */
|
|
27
|
+
config: PaymentsConfig;
|
|
28
|
+
}
|
|
29
|
+
/** What {@link fulfillPurchase} needs: the catalog, the audit seam, and optionally a ledger to use. */
|
|
30
|
+
export interface FulfillPurchaseOptions extends GrantOptions {
|
|
31
|
+
/** The audit seam. Defaults to core's no-op, so a caller with no recorder composed needs no branch. */
|
|
32
|
+
emit?: AuditEmit;
|
|
33
|
+
/** An already-open ledger. Absent in production — the guarded import supplies one only when it is needed. */
|
|
34
|
+
ledger?: PaymentsLedger;
|
|
35
|
+
/** The clock the ledger stamps its rows with. Injected so a fulfillment is deterministic under test. */
|
|
36
|
+
now?: () => number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The idempotency key for one credit. A pure function of two durable identifiers, and the only place the
|
|
40
|
+
* shape is written — a caller reconciling a ledger row back to a purchase derives it the same way.
|
|
41
|
+
*/
|
|
42
|
+
export declare function grantRef(purchaseId: string, currency: string): string;
|
|
43
|
+
/** The ledger grant this purchase's catalog product declares, or undefined for the products that declare none. */
|
|
44
|
+
export declare function ledgerGrantFor(config: PaymentsConfig, productId: string): PaymentsLedgerGrant | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Whether this purchase's charge stands, and so whether what it bought should be credited.
|
|
47
|
+
*
|
|
48
|
+
* **A `state` row is never paid, whatever its status says**, and the check is on `role` before it is on
|
|
49
|
+
* `status` because the two answer different questions. `status` asks what became of a charge; a
|
|
50
|
+
* subscription's standing is not a charge, so the question does not apply to it and an honest `active`
|
|
51
|
+
* would otherwise read as money that arrived. Lemon Squeezy is the only rail that writes such a row —
|
|
52
|
+
* its subscription webhooks carry no charge at all — and without this line every LS subscriber would be
|
|
53
|
+
* credited once for the subscription on top of once per invoice. See {@link PurchaseRole}.
|
|
54
|
+
*/
|
|
55
|
+
export declare function purchaseIsPaid(purchase: Pick<PaymentsPurchase, "status" | "role">): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Credit what a fulfilled purchase's `grants` clause promised. Returns what was asked of the ledger, which is
|
|
58
|
+
* not the same as what changed: a replay asks for the identical credit and the ledger no-ops it.
|
|
59
|
+
*/
|
|
60
|
+
export declare function applyGrants(ledger: PaymentsLedger, projection: PurchaseProjection, options: GrantOptions): Promise<AppliedGrant[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Fulfill one projected purchase in both directions: credit what it bought, and reverse what a refund took
|
|
63
|
+
* back where the catalog asks for it.
|
|
64
|
+
*
|
|
65
|
+
* The ledger is opened **lazily, and only when the catalog names a currency**. That laziness is the whole
|
|
66
|
+
* reason the optional peer stays optional: a project selling nothing but features never resolves the import,
|
|
67
|
+
* so it neither installs `@pithy-sh/ledger` nor carries it in a Worker bundle.
|
|
68
|
+
*
|
|
69
|
+
* A refused clawback is recorded here rather than thrown. It is the one fulfillment fact no other table
|
|
70
|
+
* holds — a successful credit or debit is already a ledger row, keyed by a ref that names the purchase — so
|
|
71
|
+
* the audit trail is where a shortfall becomes queryable and alertable.
|
|
72
|
+
*/
|
|
73
|
+
export declare function fulfillPurchase(d1: D1Database, projection: PurchaseProjection, options: FulfillPurchaseOptions): Promise<FulfillmentReport>;
|
|
74
|
+
//# sourceMappingURL=apply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/grants/apply.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,mCAAmC,CAAC;AAE7E,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,YAAY,CAAC;AAClE,OAAO,EAAuC,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAwDxF,8FAA8F;AAC9F,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,GAAG,EAAE,MAAM,CAAC;CACb;AAED,8GAA8G;AAC9G,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;IACjC,+EAA+E;IAC/E,UAAU,EAAE,SAAS,eAAe,EAAE,CAAC;CACxC;AAED,mGAAmG;AACnG,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,uGAAuG;AACvG,MAAM,WAAW,sBAAuB,SAAQ,YAAY;IAC1D,uGAAuG;IACvG,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,6GAA6G;IAC7G,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,wGAAwG;IACxG,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,kHAAkH;AAClH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAEzG;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,MAAM,CAAC,GAAG,OAAO,CAG3F;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,kBAAkB,EAC9B,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,EAAE,CAAC,CAezB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,UAAU,EACd,UAAU,EAAE,kBAAkB,EAC9B,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,iBAAiB,CAAC,CAoC5B"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { PaymentsAuditActions } from "../audit/actions.js";
|
|
2
|
+
import { ledgerAccountId, openPaymentsLedger } from "./ledgerSeam.js";
|
|
3
|
+
import { clawbackGrants } from "./clawback.js";
|
|
4
|
+
import { noopEmit } from "@pithy-sh/core/src/audit/recorder";
|
|
5
|
+
//#region src/grants/apply.ts
|
|
6
|
+
/**
|
|
7
|
+
* Fulfillment: turning a projected purchase into the balance a `grants` clause promised.
|
|
8
|
+
*
|
|
9
|
+
* This is deliberately **not** in the projection writer. The writer stays pure D1 so its tests resolve no
|
|
10
|
+
* optional package, and the credit is a separate step its caller runs on what it returned — a route, or any
|
|
11
|
+
* other caller holding a projection. Nothing is lost by the separation, because the credit's idempotency has
|
|
12
|
+
* never rested on call ordering: it rests on the ledger's `UNIQUE (ref)`.
|
|
13
|
+
*
|
|
14
|
+
* ## The ref, which is the whole design
|
|
15
|
+
*
|
|
16
|
+
* `payments:grant:<purchaseId>:<currency>`. Three properties, each load-bearing:
|
|
17
|
+
*
|
|
18
|
+
* - **Per credit, never per purchase.** A duplicate `ref` aborts the ledger's batch, and the ledger reports
|
|
19
|
+
* that abort as *success* with the current balance — a replay must be a no-op, so it cannot distinguish
|
|
20
|
+
* itself from one. So a purchase crediting two currencies under one ref would credit the first and silently
|
|
21
|
+
* drop the second, with nothing anywhere to read. The currency is in the ref for that reason alone.
|
|
22
|
+
* - **A pure function of durable identifiers.** Never `crypto.randomUUID()`, never `Date.now()`. `purchaseId`
|
|
23
|
+
* is minted once, at first projection, and every later write keeps it — so a retry three days later derives
|
|
24
|
+
* the identical ref and the ledger recognizes the replay. A ref that varied would double-credit.
|
|
25
|
+
* - **Per billing period on a subscription, for free.** Each renewal is a distinct provider transaction on all
|
|
26
|
+
* three rails, so it is a distinct purchase row with a distinct id, so it is a distinct ref. The same guard
|
|
27
|
+
* that makes a redelivery a no-op lets next month's renewal through, with no period arithmetic anywhere.
|
|
28
|
+
*
|
|
29
|
+
* ## When a credit fires
|
|
30
|
+
*
|
|
31
|
+
* Whenever the charge stands — regardless of the projection's `outcome`. Applying a grant for an `ignored`
|
|
32
|
+
* replay is not waste, it is the repair: if a previous delivery projected the purchase and then failed before
|
|
33
|
+
* the ledger write, the redelivery is the only thing that will ever fix it, and the stable ref makes trying
|
|
34
|
+
* free. The one thing checked is whether the money is actually with us; see {@link UNPAID_STATUSES}.
|
|
35
|
+
*
|
|
36
|
+
* A failure that is not the ledger's own refusal propagates. `openLedger` classifies aborts by regexing the
|
|
37
|
+
* error message, so a transient D1 fault arrives unwrapped and un-typed — treating it as "credited nothing"
|
|
38
|
+
* would drop a purchase's currency permanently, where letting it raise leaves the retry to settle it.
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* The statuses in which this charge's money is not with us: a payment still outstanding, one that never
|
|
42
|
+
* arrived at all, or one that was taken back. Everything else — `active`, `canceled`, `expired`, `paused` —
|
|
43
|
+
* describes a period that was paid for, whatever has since become of the subscription.
|
|
44
|
+
*
|
|
45
|
+
* `expired` is the member most easily got wrong in the other direction. It says a period ended, not that its
|
|
46
|
+
* invoice failed; refusing to credit on it would lose a coin pack whose only delivery arrived late. Which is
|
|
47
|
+
* precisely why a termination that took no money needs its own status: **`never_paid`** is here, and reading
|
|
48
|
+
* a never-paid ending as `expired` credited a 100-coin pack for a bank debit that bounced — with no clawback
|
|
49
|
+
* ever to follow it, because nothing was ever charged to reverse. See `data/status.ts`.
|
|
50
|
+
*/
|
|
51
|
+
const UNPAID_STATUSES = /* @__PURE__ */ new Set([
|
|
52
|
+
"in_grace",
|
|
53
|
+
"on_hold",
|
|
54
|
+
"never_paid",
|
|
55
|
+
"refunded",
|
|
56
|
+
"revoked"
|
|
57
|
+
]);
|
|
58
|
+
/**
|
|
59
|
+
* The idempotency key for one credit. A pure function of two durable identifiers, and the only place the
|
|
60
|
+
* shape is written — a caller reconciling a ledger row back to a purchase derives it the same way.
|
|
61
|
+
*/
|
|
62
|
+
function grantRef(purchaseId, currency) {
|
|
63
|
+
return `payments:grant:${purchaseId}:${currency}`;
|
|
64
|
+
}
|
|
65
|
+
/** The ledger grant this purchase's catalog product declares, or undefined for the products that declare none. */
|
|
66
|
+
function ledgerGrantFor(config, productId) {
|
|
67
|
+
return config.products[productId]?.grants?.ledger;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Whether this purchase's charge stands, and so whether what it bought should be credited.
|
|
71
|
+
*
|
|
72
|
+
* **A `state` row is never paid, whatever its status says**, and the check is on `role` before it is on
|
|
73
|
+
* `status` because the two answer different questions. `status` asks what became of a charge; a
|
|
74
|
+
* subscription's standing is not a charge, so the question does not apply to it and an honest `active`
|
|
75
|
+
* would otherwise read as money that arrived. Lemon Squeezy is the only rail that writes such a row —
|
|
76
|
+
* its subscription webhooks carry no charge at all — and without this line every LS subscriber would be
|
|
77
|
+
* credited once for the subscription on top of once per invoice. See {@link PurchaseRole}.
|
|
78
|
+
*/
|
|
79
|
+
function purchaseIsPaid(purchase) {
|
|
80
|
+
if (purchase.role === "state") return false;
|
|
81
|
+
return !UNPAID_STATUSES.has(purchase.status);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Credit what a fulfilled purchase's `grants` clause promised. Returns what was asked of the ledger, which is
|
|
85
|
+
* not the same as what changed: a replay asks for the identical credit and the ledger no-ops it.
|
|
86
|
+
*/
|
|
87
|
+
async function applyGrants(ledger, projection, options) {
|
|
88
|
+
const { purchase } = projection;
|
|
89
|
+
const grant = ledgerGrantFor(options.config, purchase.productId);
|
|
90
|
+
if (grant === void 0 || !purchaseIsPaid(purchase)) return [];
|
|
91
|
+
const ref = grantRef(purchase.id, grant.currency);
|
|
92
|
+
await ledger.credit(ledgerAccountId(purchase), grant.currency, grant.amount, ref, { memo: `payments ${purchase.rail} ${purchase.productId}` });
|
|
93
|
+
return [{
|
|
94
|
+
currency: grant.currency,
|
|
95
|
+
amount: grant.amount,
|
|
96
|
+
ref
|
|
97
|
+
}];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Fulfill one projected purchase in both directions: credit what it bought, and reverse what a refund took
|
|
101
|
+
* back where the catalog asks for it.
|
|
102
|
+
*
|
|
103
|
+
* The ledger is opened **lazily, and only when the catalog names a currency**. That laziness is the whole
|
|
104
|
+
* reason the optional peer stays optional: a project selling nothing but features never resolves the import,
|
|
105
|
+
* so it neither installs `@pithy-sh/ledger` nor carries it in a Worker bundle.
|
|
106
|
+
*
|
|
107
|
+
* A refused clawback is recorded here rather than thrown. It is the one fulfillment fact no other table
|
|
108
|
+
* holds — a successful credit or debit is already a ledger row, keyed by a ref that names the purchase — so
|
|
109
|
+
* the audit trail is where a shortfall becomes queryable and alertable.
|
|
110
|
+
*/
|
|
111
|
+
async function fulfillPurchase(d1, projection, options) {
|
|
112
|
+
const { purchase } = projection;
|
|
113
|
+
if (ledgerGrantFor(options.config, purchase.productId) === void 0) return {
|
|
114
|
+
granted: [],
|
|
115
|
+
clawedBack: []
|
|
116
|
+
};
|
|
117
|
+
const ledger = options.ledger ?? await openPaymentsLedger(d1, { now: options.now });
|
|
118
|
+
const granted = await applyGrants(ledger, projection, options);
|
|
119
|
+
const clawedBack = await clawbackGrants(ledger, projection, options);
|
|
120
|
+
const emit = options.emit ?? noopEmit;
|
|
121
|
+
for (const attempt of clawedBack) {
|
|
122
|
+
if (attempt.outcome !== "refused") continue;
|
|
123
|
+
await emit({
|
|
124
|
+
action: PaymentsAuditActions.clawbackFailed,
|
|
125
|
+
outcome: "failure",
|
|
126
|
+
severity: "critical",
|
|
127
|
+
actorType: "system",
|
|
128
|
+
resourceType: "purchase",
|
|
129
|
+
resourceId: purchase.id,
|
|
130
|
+
metadata: {
|
|
131
|
+
rail: purchase.rail,
|
|
132
|
+
productId: purchase.productId,
|
|
133
|
+
subjectType: purchase.subjectType,
|
|
134
|
+
subjectId: purchase.subjectId,
|
|
135
|
+
currency: attempt.currency,
|
|
136
|
+
amount: attempt.amount,
|
|
137
|
+
ref: attempt.ref,
|
|
138
|
+
reason: attempt.error.payload.code
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
granted,
|
|
144
|
+
clawedBack
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
export { applyGrants, fulfillPurchase, grantRef, ledgerGrantFor, purchaseIsPaid };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PaymentsClawbackFailedError } from "../error/errors";
|
|
2
|
+
import type { PurchaseProjection } from "../projection/writer";
|
|
3
|
+
import type { GrantOptions } from "./apply";
|
|
4
|
+
import { type PaymentsLedger } from "./ledgerSeam";
|
|
5
|
+
/**
|
|
6
|
+
* One attempted reversal. `refused` carries its payload rather than a boolean, because the shortfall has to
|
|
7
|
+
* survive as far as the audit trail with its code and its context intact.
|
|
8
|
+
*/
|
|
9
|
+
export type ClawbackOutcome = {
|
|
10
|
+
/** The debit applied, or was recognized as one already applied. */
|
|
11
|
+
outcome: "reversed";
|
|
12
|
+
/** The ledger currency debited. */
|
|
13
|
+
currency: string;
|
|
14
|
+
/** How much, as an integer in the currency's minor unit. */
|
|
15
|
+
amount: number;
|
|
16
|
+
/** The idempotency key the ledger recorded it under. */
|
|
17
|
+
ref: string;
|
|
18
|
+
} | {
|
|
19
|
+
/** The balance could not cover it. The refund stands; the difference is a fact for a human. */
|
|
20
|
+
outcome: "refused";
|
|
21
|
+
/** The ledger currency the debit was attempted in. */
|
|
22
|
+
currency: string;
|
|
23
|
+
/** How much the reversal would have taken. */
|
|
24
|
+
amount: number;
|
|
25
|
+
/** The idempotency key the debit was attempted under. */
|
|
26
|
+
ref: string;
|
|
27
|
+
/** The refusal, as the payload the audit trail records. */
|
|
28
|
+
error: PaymentsClawbackFailedError;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The idempotency key for one reversal. Distinct from the grant's by its verb: sharing the grant's ref would
|
|
32
|
+
* make the debit look like a replayed credit, which the ledger swallows as success — so the reversal would
|
|
33
|
+
* report success and move nothing.
|
|
34
|
+
*/
|
|
35
|
+
export declare function clawbackRef(purchaseId: string, currency: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Reverse what a refunded purchase credited, if the catalog opted in.
|
|
38
|
+
*
|
|
39
|
+
* Runs on every delivery of the refund, not only the first: the debit is idempotent on its ref, so a
|
|
40
|
+
* redelivery is a no-op and a delivery that arrived after an earlier attempt failed is the repair.
|
|
41
|
+
*/
|
|
42
|
+
export declare function clawbackGrants(ledger: PaymentsLedger, projection: PurchaseProjection, options: GrantOptions): Promise<ClawbackOutcome[]>;
|
|
43
|
+
//# sourceMappingURL=clawback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clawback.d.ts","sourceRoot":"","sources":["../../src/grants/clawback.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AA4BpE;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB;IACE,mEAAmE;IACnE,OAAO,EAAE,UAAU,CAAC;IACpB,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,GAAG,EAAE,MAAM,CAAC;CACb,GACD;IACE,+FAA+F;IAC/F,OAAO,EAAE,SAAS,CAAC;IACnB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAC;IACZ,2DAA2D;IAC3D,KAAK,EAAE,2BAA2B,CAAC;CACpC,CAAC;AAEN;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,kBAAkB,EAC9B,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,eAAe,EAAE,CAAC,CA2C5B"}
|