@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,29 @@
|
|
|
1
|
+
import type { PortalHandoff, PortalSessionInput } from "../contract";
|
|
2
|
+
import { type StripeCheckoutOptions } from "./checkout";
|
|
3
|
+
/**
|
|
4
|
+
* The Billing Portal: Stripe's own page for managing a subscription, and the whole of Pithy's plan-management
|
|
5
|
+
* surface **on this rail**.
|
|
6
|
+
*
|
|
7
|
+
* Two parameters go out — which customer, and where to send them afterwards — and that is deliberate. Everything
|
|
8
|
+
* a subscriber may do in the portal (cancel, switch plan, update a card, download invoices) is configured in
|
|
9
|
+
* Stripe's dashboard, per environment, by the adopter. A parameter here that decided any of it would be this
|
|
10
|
+
* capability computing proration and tax, which #79's locked decision 2 still says it never does. It also means
|
|
11
|
+
* store rules and dunning copy stay Stripe's to keep current rather than ours to age.
|
|
12
|
+
*
|
|
13
|
+
* **"The whole of it on this rail" is a narrower claim than it was.** The decision's other half was amended on
|
|
14
|
+
* 2026-08-28 and the kit may now invoke a plan change from the server, passing the provider's figures through
|
|
15
|
+
* unmodified — `{base}/subscription/preview|change|cancel|keep`, behind {@link SubscriptionRail}. Only Paddle
|
|
16
|
+
* implements it. The amendment permits the seam rather than requiring one per rail, so Stripe's answer to
|
|
17
|
+
* "change my plan" is still this page, and `providers.test.ts` holds that to what the providers actually
|
|
18
|
+
* declare rather than to this sentence.
|
|
19
|
+
*
|
|
20
|
+
* The customer is resolved from the provider-account map, never from a request. That map is written from
|
|
21
|
+
* `client_reference_id` when a checkout completes, so the caller can only ever reach their own billing.
|
|
22
|
+
*
|
|
23
|
+
* The failure every adopter meets once is a Billing Portal with no configuration: Stripe answers 400 until one is
|
|
24
|
+
* created in the dashboard. `api.ts` maps that to `payments/rail_not_configured`, which reads to a caller as "not
|
|
25
|
+
* available here" — true — and carries Stripe's own sentence in `detail` for whoever can fix it.
|
|
26
|
+
*/
|
|
27
|
+
/** Create a hosted Billing Portal session for one customer, and return where to send the browser. */
|
|
28
|
+
export declare function createStripePortalSession(input: PortalSessionInput, options: StripeCheckoutOptions): Promise<PortalHandoff>;
|
|
29
|
+
//# sourceMappingURL=portal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/portal.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,EAAiB,KAAK,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,qGAAqG;AACrG,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,kBAAkB,EACzB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,aAAa,CAAC,CAQxB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { stripeHttpFetch, stripeJson } from "./api.js";
|
|
2
|
+
import { hostedSession } from "./checkout.js";
|
|
3
|
+
//#region src/rails/stripe/portal.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Billing Portal: Stripe's own page for managing a subscription, and the whole of Pithy's plan-management
|
|
6
|
+
* surface **on this rail**.
|
|
7
|
+
*
|
|
8
|
+
* Two parameters go out — which customer, and where to send them afterwards — and that is deliberate. Everything
|
|
9
|
+
* a subscriber may do in the portal (cancel, switch plan, update a card, download invoices) is configured in
|
|
10
|
+
* Stripe's dashboard, per environment, by the adopter. A parameter here that decided any of it would be this
|
|
11
|
+
* capability computing proration and tax, which #79's locked decision 2 still says it never does. It also means
|
|
12
|
+
* store rules and dunning copy stay Stripe's to keep current rather than ours to age.
|
|
13
|
+
*
|
|
14
|
+
* **"The whole of it on this rail" is a narrower claim than it was.** The decision's other half was amended on
|
|
15
|
+
* 2026-08-28 and the kit may now invoke a plan change from the server, passing the provider's figures through
|
|
16
|
+
* unmodified — `{base}/subscription/preview|change|cancel|keep`, behind {@link SubscriptionRail}. Only Paddle
|
|
17
|
+
* implements it. The amendment permits the seam rather than requiring one per rail, so Stripe's answer to
|
|
18
|
+
* "change my plan" is still this page, and `providers.test.ts` holds that to what the providers actually
|
|
19
|
+
* declare rather than to this sentence.
|
|
20
|
+
*
|
|
21
|
+
* The customer is resolved from the provider-account map, never from a request. That map is written from
|
|
22
|
+
* `client_reference_id` when a checkout completes, so the caller can only ever reach their own billing.
|
|
23
|
+
*
|
|
24
|
+
* The failure every adopter meets once is a Billing Portal with no configuration: Stripe answers 400 until one is
|
|
25
|
+
* created in the dashboard. `api.ts` maps that to `payments/rail_not_configured`, which reads to a caller as "not
|
|
26
|
+
* available here" — true — and carries Stripe's own sentence in `detail` for whoever can fix it.
|
|
27
|
+
*/
|
|
28
|
+
/** Create a hosted Billing Portal session for one customer, and return where to send the browser. */
|
|
29
|
+
async function createStripePortalSession(input, options) {
|
|
30
|
+
const created = await stripeJson(options.transport ?? stripeHttpFetch, "/billing_portal/sessions", {
|
|
31
|
+
what: "a Billing Portal session",
|
|
32
|
+
secretKey: options.credentials.secretKey,
|
|
33
|
+
form: {
|
|
34
|
+
customer: input.providerAccountId,
|
|
35
|
+
return_url: input.returnUrl
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return hostedSession(created, "a Billing Portal session");
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { createStripePortalSession };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SubscriptionPricing } from "../../data/discount";
|
|
2
|
+
import type { PaymentsPurchase } from "../../data/purchase";
|
|
3
|
+
import type { PaymentsStripeCredentials } from "../../secret/registry";
|
|
4
|
+
import { type StripeHttpFetch } from "./api";
|
|
5
|
+
/**
|
|
6
|
+
* What a Stripe subscription pays now, what it becomes, and when.
|
|
7
|
+
*
|
|
8
|
+
* Read from the store rather than computed. Stripe carries the discount on the subscription and the
|
|
9
|
+
* arithmetic on an upcoming invoice, so both are asked for and neither is derived: Pithy never multiplies a
|
|
10
|
+
* price by a percentage, here or anywhere.
|
|
11
|
+
*
|
|
12
|
+
* **`discountEndsAt` is the field this exists for.** Stripe reports a repeating discount's `end` on the
|
|
13
|
+
* subscription's discount object, and that date is what a customer must be told — a rate that lapses with
|
|
14
|
+
* nothing having said so is, from their seat, a billing error.
|
|
15
|
+
*/
|
|
16
|
+
/** What reading pricing needs. */
|
|
17
|
+
export interface StripePricingOptions {
|
|
18
|
+
/** Stripe's credential block. Only `secretKey` is used here. */
|
|
19
|
+
credentials: PaymentsStripeCredentials;
|
|
20
|
+
/** The HTTP seam. Defaults to the runtime's `fetch`. */
|
|
21
|
+
transport?: StripeHttpFetch;
|
|
22
|
+
}
|
|
23
|
+
/** Read what this subscription pays, or `undefined` when Stripe has nothing to say. */
|
|
24
|
+
export declare function readStripePricing(purchase: PaymentsPurchase, options: StripePricingOptions): Promise<SubscriptionPricing | undefined>;
|
|
25
|
+
//# sourceMappingURL=pricing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/pricing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,KAAK,eAAe,EAA+B,MAAM,OAAO,CAAC;AAE1E;;;;;;;;;;GAUG;AAEH,kCAAkC;AAClC,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,WAAW,EAAE,yBAAyB,CAAC;IACvC,wDAAwD;IACxD,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AA0BD,uFAAuF;AACvF,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAiD1C"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { stripeHttpFetch, stripeJson } from "./api.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/rails/stripe/pricing.ts
|
|
4
|
+
/** A subscription, narrowed to the discount in force. */
|
|
5
|
+
const DiscountedSubscription = z.object({
|
|
6
|
+
currency: z.string().nullish(),
|
|
7
|
+
discount: z.object({
|
|
8
|
+
end: z.number().nullish(),
|
|
9
|
+
promotion_code: z.unknown().nullish(),
|
|
10
|
+
coupon: z.object({ name: z.string().nullish() }).loose().nullish()
|
|
11
|
+
}).loose().nullish(),
|
|
12
|
+
items: z.object({ data: z.array(z.object({ price: z.object({ unit_amount: z.number().nullish() }).loose() }).loose()) }).loose().nullish()
|
|
13
|
+
}).loose();
|
|
14
|
+
/** The upcoming invoice, which is Stripe's own answer to "what comes off and what is left". */
|
|
15
|
+
const UpcomingInvoice = z.object({
|
|
16
|
+
currency: z.string().nullish(),
|
|
17
|
+
total: z.number().nullish(),
|
|
18
|
+
subtotal: z.number().nullish()
|
|
19
|
+
}).loose();
|
|
20
|
+
/** Read what this subscription pays, or `undefined` when Stripe has nothing to say. */
|
|
21
|
+
async function readStripePricing(purchase, options) {
|
|
22
|
+
const subscriptionId = purchase.originalTransactionId;
|
|
23
|
+
if (subscriptionId === null || !subscriptionId.startsWith("sub_")) return void 0;
|
|
24
|
+
const transport = options.transport ?? stripeHttpFetch;
|
|
25
|
+
const found = await stripeJson(transport, `/subscriptions/${encodeURIComponent(subscriptionId)}`, {
|
|
26
|
+
what: `subscription ${subscriptionId} pricing`,
|
|
27
|
+
secretKey: options.credentials.secretKey,
|
|
28
|
+
absentOn404: true
|
|
29
|
+
});
|
|
30
|
+
if (found === void 0) return void 0;
|
|
31
|
+
const parsed = DiscountedSubscription.safeParse(found);
|
|
32
|
+
if (!parsed.success) return void 0;
|
|
33
|
+
const subscription = parsed.data;
|
|
34
|
+
const upcoming = await stripeJson(transport, "/invoices/create_preview", {
|
|
35
|
+
what: `subscription ${subscriptionId} next invoice`,
|
|
36
|
+
secretKey: options.credentials.secretKey,
|
|
37
|
+
form: { subscription: subscriptionId },
|
|
38
|
+
absentOn404: true
|
|
39
|
+
});
|
|
40
|
+
const invoice = upcoming === void 0 ? void 0 : UpcomingInvoice.safeParse(upcoming);
|
|
41
|
+
const amounts = invoice?.success === true ? invoice.data : void 0;
|
|
42
|
+
const listed = subscription.items?.data[0]?.price.unit_amount ?? null;
|
|
43
|
+
const end = subscription.discount?.end;
|
|
44
|
+
return {
|
|
45
|
+
currency: amounts?.currency ?? subscription.currency ?? null,
|
|
46
|
+
currentAmountMinor: amounts?.total ?? null,
|
|
47
|
+
listAmountMinor: amounts?.subtotal ?? listed,
|
|
48
|
+
discountCode: promotionCode(subscription.discount?.promotion_code),
|
|
49
|
+
discountEndsAt: typeof end === "number" ? /* @__PURE__ */ new Date(end * 1e3) : null
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The customer-facing code off Stripe's `promotion_code` field, or null.
|
|
54
|
+
*
|
|
55
|
+
* Stripe returns either the id (`promo_…`) or, when expanded, the object carrying `code`. Only the second
|
|
56
|
+
* is a code a customer would recognize; a bare id is reported as null, because "no code shown" is honest
|
|
57
|
+
* and "PROMO_1QxYz" on a billing screen is not.
|
|
58
|
+
*/
|
|
59
|
+
function promotionCode(value) {
|
|
60
|
+
if (typeof value === "string") return value.startsWith("promo_") ? null : value;
|
|
61
|
+
if (typeof value === "object" && value !== null) {
|
|
62
|
+
const code = value.code;
|
|
63
|
+
return typeof code === "string" && code !== "" ? code : null;
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { readStripePricing };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PaymentsStripeCredentials } from "../../secret/registry";
|
|
2
|
+
import type { CheckoutRail, DiscountRail, PaymentsRailProvider, PricingRail } from "../contract";
|
|
3
|
+
import type { StripeHttpFetch } from "./api";
|
|
4
|
+
/**
|
|
5
|
+
* The Stripe rail as one provider object — and the only rail that implements both halves of the contract.
|
|
6
|
+
*
|
|
7
|
+
* Apple and Google purchases have already happened inside a store SDK by the time the server hears of them. A
|
|
8
|
+
* Stripe purchase is one Pithy initiates: `/checkout` creates a hosted session and sends the browser to it. That
|
|
9
|
+
* asymmetry is why {@link CheckoutRail} is a separate interface rather than two methods Apple would have to stub,
|
|
10
|
+
* and this is the object that satisfies both.
|
|
11
|
+
*
|
|
12
|
+
* Built per request from credentials the caller resolved through the secrets store, rather than reading them
|
|
13
|
+
* itself. That keeps the rail a pure function of its inputs and keeps the secret read at the point of need.
|
|
14
|
+
*
|
|
15
|
+
* **Hosted only, and that is a decision rather than a stage.** No Payment Element, no card fields, no proration
|
|
16
|
+
* or plan-change logic — Stripe owns the payment page, SCA, tax, and every rule that changes underneath them.
|
|
17
|
+
* Nothing in this module would be a small edit away from owning any of that, which is the point.
|
|
18
|
+
*/
|
|
19
|
+
/** How the Stripe rail's transport and replay window may be varied. Both exist for the tests. */
|
|
20
|
+
export interface StripeRailOptions {
|
|
21
|
+
/** The HTTP seam Stripe's API is reached through. Defaults to the runtime's `fetch`. */
|
|
22
|
+
transport?: StripeHttpFetch;
|
|
23
|
+
/** The signature freshness window, in seconds. Defaults to Stripe's own five minutes. */
|
|
24
|
+
toleranceSeconds?: number;
|
|
25
|
+
}
|
|
26
|
+
/** The Stripe rail. Verifies a returning Checkout Session, verifies webhooks, and creates hosted sessions. */
|
|
27
|
+
export declare function stripeRail(credentials: PaymentsStripeCredentials, options?: StripeRailOptions): PaymentsRailProvider & CheckoutRail & DiscountRail & PricingRail;
|
|
28
|
+
//# sourceMappingURL=rail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/rail.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAMZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAU7C;;;;;;;;;;;;;;GAcG;AAEH,iGAAiG;AACjG,MAAM,WAAW,iBAAiB;IAChC,wFAAwF;IACxF,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,yFAAyF;IACzF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,8GAA8G;AAC9G,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,GAAE,iBAAsB,GAC9B,oBAAoB,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CA8ElE"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { StripeEvent, mapStripeEvent } from "./objects.js";
|
|
2
|
+
import { createStripeCheckoutSession } from "./checkout.js";
|
|
3
|
+
import { createStripeDiscount, listStripeDiscounts } from "./discounts.js";
|
|
4
|
+
import { createStripePortalSession } from "./portal.js";
|
|
5
|
+
import { readStripePricing } from "./pricing.js";
|
|
6
|
+
import { refreshStripeSubscription } from "./refresh.js";
|
|
7
|
+
import { verifyStripeSession } from "./verify.js";
|
|
8
|
+
import { parseStripeNotification } from "./webhook.js";
|
|
9
|
+
//#region src/rails/stripe/rail.ts
|
|
10
|
+
/** The Stripe rail. Verifies a returning Checkout Session, verifies webhooks, and creates hosted sessions. */
|
|
11
|
+
function stripeRail(credentials, options = {}) {
|
|
12
|
+
return {
|
|
13
|
+
rail: "stripe",
|
|
14
|
+
async verify(receipt, context) {
|
|
15
|
+
return await verifyStripeSession(receipt, {
|
|
16
|
+
credentials,
|
|
17
|
+
now: context.now,
|
|
18
|
+
transport: options.transport
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
async parseNotification(delivery, context) {
|
|
22
|
+
return await parseStripeNotification(delivery, {
|
|
23
|
+
credentials,
|
|
24
|
+
now: context.now,
|
|
25
|
+
toleranceSeconds: options.toleranceSeconds
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
async replay(payload, _context) {
|
|
29
|
+
const parsed = StripeEvent.safeParse(payload);
|
|
30
|
+
if (!parsed.success) return void 0;
|
|
31
|
+
const mapped = mapStripeEvent(parsed.data);
|
|
32
|
+
return {
|
|
33
|
+
providerEventId: parsed.data.id,
|
|
34
|
+
payload: parsed.data,
|
|
35
|
+
event: mapped.event,
|
|
36
|
+
providerAccountId: mapped.providerAccountId,
|
|
37
|
+
accountReference: mapped.accountReference,
|
|
38
|
+
note: mapped.note
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
async refresh(purchase, context) {
|
|
42
|
+
return await refreshStripeSubscription(purchase, {
|
|
43
|
+
credentials,
|
|
44
|
+
now: context.now,
|
|
45
|
+
transport: options.transport
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
async createCheckoutSession(input) {
|
|
49
|
+
return await createStripeCheckoutSession(input, {
|
|
50
|
+
credentials,
|
|
51
|
+
transport: options.transport
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
async createPortalSession(input) {
|
|
55
|
+
return await createStripePortalSession(input, {
|
|
56
|
+
credentials,
|
|
57
|
+
transport: options.transport
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
async readPricing(purchase, _context) {
|
|
61
|
+
return await readStripePricing(purchase, {
|
|
62
|
+
credentials,
|
|
63
|
+
transport: options.transport
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
async listDiscounts() {
|
|
67
|
+
return await listStripeDiscounts({
|
|
68
|
+
credentials,
|
|
69
|
+
transport: options.transport
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
async createDiscount(terms) {
|
|
73
|
+
return await createStripeDiscount(terms, {
|
|
74
|
+
credentials,
|
|
75
|
+
transport: options.transport
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
export { stripeRail };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PaymentsPurchase } from "../../data/purchase";
|
|
2
|
+
import type { PaymentsStripeCredentials } from "../../secret/registry";
|
|
3
|
+
import type { UnboundProviderEvent } from "../contract";
|
|
4
|
+
import { type StripeHttpFetch } from "./api";
|
|
5
|
+
/**
|
|
6
|
+
* Re-read one stored subscription at Stripe, normalized — the reconciliation path for this rail.
|
|
7
|
+
*
|
|
8
|
+
* **A subscription retrieve, not an invoice one, and that is the whole design.** A row is keyed on the invoice
|
|
9
|
+
* because each billing period is its own purchase; the *subscription* is what has a current state, and it is
|
|
10
|
+
* what `originalTransactionId` holds. So the retrieve is by `sub_…` and the mapping is the identical one the
|
|
11
|
+
* webhook path uses — `mapStripeSubscription`, not a second reading of Stripe's vocabulary that could drift
|
|
12
|
+
* from it. The invoice the answer names becomes the row's key, which means a period this deployment never
|
|
13
|
+
* heard a webhook for projects as its own new row rather than overwriting the last one it did hear about.
|
|
14
|
+
*
|
|
15
|
+
* **Subscriptions only.** A one-time Stripe purchase is a payment intent, and a payment intent does not change
|
|
16
|
+
* after it succeeds — the one thing that changes it is a refund, which arrives as `charge.refunded`. There is
|
|
17
|
+
* nothing for a periodic re-read to discover, so there is no call here to make.
|
|
18
|
+
*
|
|
19
|
+
* **Unlike Google there is nothing to batch.** Stripe authenticates every request with the secret key
|
|
20
|
+
* directly, so a hundred refreshes are a hundred round-trips and no token minting at all.
|
|
21
|
+
*/
|
|
22
|
+
/** What a Stripe refresh needs: the API key, the clock, and the transport. */
|
|
23
|
+
export interface StripeRefreshOptions {
|
|
24
|
+
/** Stripe's credential block. Only `secretKey` is used here. */
|
|
25
|
+
credentials: PaymentsStripeCredentials;
|
|
26
|
+
/** The clock. A retrieve is a read of the state now, so this is the honest provider event time. */
|
|
27
|
+
now: Date;
|
|
28
|
+
/** The HTTP seam. Defaults to the runtime's `fetch`. */
|
|
29
|
+
transport?: StripeHttpFetch;
|
|
30
|
+
}
|
|
31
|
+
/** Re-read a stored Stripe subscription, or `undefined` when there is nothing addressable to read. */
|
|
32
|
+
export declare function refreshStripeSubscription(purchase: PaymentsPurchase, options: StripeRefreshOptions): Promise<UnboundProviderEvent | undefined>;
|
|
33
|
+
//# sourceMappingURL=refresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/refresh.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,KAAK,eAAe,EAA+B,MAAM,OAAO,CAAC;AAG1E;;;;;;;;;;;;;;;;GAgBG;AAEH,8EAA8E;AAC9E,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,WAAW,EAAE,yBAAyB,CAAC;IACvC,mGAAmG;IACnG,GAAG,EAAE,IAAI,CAAC;IACV,wDAAwD;IACxD,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,sGAAsG;AACtG,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAoC3C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
2
|
+
import { stripeHttpFetch, stripeJson } from "./api.js";
|
|
3
|
+
import { StripeSubscription, mapStripeSubscription } from "./objects.js";
|
|
4
|
+
//#region src/rails/stripe/refresh.ts
|
|
5
|
+
/** Re-read a stored Stripe subscription, or `undefined` when there is nothing addressable to read. */
|
|
6
|
+
async function refreshStripeSubscription(purchase, options) {
|
|
7
|
+
if (purchase.type !== "subscription") return void 0;
|
|
8
|
+
const subscriptionId = purchase.originalTransactionId;
|
|
9
|
+
if (subscriptionId === null) return void 0;
|
|
10
|
+
const retrieved = await stripeJson(options.transport ?? stripeHttpFetch, `/subscriptions/${encodeURIComponent(subscriptionId)}`, {
|
|
11
|
+
what: "the subscription",
|
|
12
|
+
secretKey: options.credentials.secretKey,
|
|
13
|
+
absentOn404: true
|
|
14
|
+
});
|
|
15
|
+
if (retrieved === void 0) return void 0;
|
|
16
|
+
const parsed = StripeSubscription.safeParse(retrieved);
|
|
17
|
+
if (!parsed.success) throw new PaymentsVerificationFailedError({ detail: `Stripe: the answer is not a Subscription — ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "<root>"}:${issue.code}`).join(", ")}.` });
|
|
18
|
+
return mapStripeSubscription(parsed.data, options.now).event ?? void 0;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { refreshStripeSubscription };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type SignedWebhookHeader } from "@pithy-sh/core/src/http/signedWebhook";
|
|
2
|
+
/**
|
|
3
|
+
* Stripe's authenticity proof: an HMAC over the exact received bytes, dated, in one header.
|
|
4
|
+
*
|
|
5
|
+
* `Stripe-Signature: t=1768435200,v1=5257a8…` — the timestamp the delivery claims, then one hex HMAC-SHA256 per
|
|
6
|
+
* active signing secret, each computed over `<timestamp>.<body>` and keyed with the endpoint's `whsec_…`.
|
|
7
|
+
*
|
|
8
|
+
* ## Why the scheme itself is not here
|
|
9
|
+
*
|
|
10
|
+
* It is `@pithy-sh/core`'s `signed-webhook` primitive, and this module is one of its callers. Stripe's format is
|
|
11
|
+
* the one every other sender copied, so the kit implements it once — the freshness window in both directions, the
|
|
12
|
+
* timestamp inside the signed payload, `crypto.subtle.verify` instead of a hand-written compare, every listed
|
|
13
|
+
* signature tried, and a cap on how many. Each of those is a security property with a reason written down beside
|
|
14
|
+
* it, and a second copy here would be a second set of reasons to keep in step: a parser fix landing in one and
|
|
15
|
+
* not the other, with money on the side that missed it.
|
|
16
|
+
*
|
|
17
|
+
* What stays is what is Stripe's: the header name, the accepted scheme key, the tolerance, and the wording of a
|
|
18
|
+
* refusal.
|
|
19
|
+
*
|
|
20
|
+
* ## Why the window matters to this rail in particular
|
|
21
|
+
*
|
|
22
|
+
* A captured `customer.subscription.updated` replayed months later is a state claim about a subscription that has
|
|
23
|
+
* since lapsed. The projection's monotonic rule would correctly ignore it *only because* the stored event time is
|
|
24
|
+
* newer — and relying on that would make the window a happy accident of another rule. Five minutes is Stripe's own
|
|
25
|
+
* default and is generous against delivery latency and clock skew.
|
|
26
|
+
*
|
|
27
|
+
* Freshness is not uniqueness. Inside the window a captured delivery replays as often as it is sent, which is what
|
|
28
|
+
* the guard's `UNIQUE (rail, providerEventId)` insert is for.
|
|
29
|
+
*
|
|
30
|
+
* ## What a refusal says
|
|
31
|
+
*
|
|
32
|
+
* `payments/verification_failed`, with the reason in `detail` and nothing else. Never the secret, never the body,
|
|
33
|
+
* never the signature: `detail` reaches an operator's log, and the webhook guard maps this to
|
|
34
|
+
* `payments/webhook_unverified` (401) before anything reaches the sender — a forger learns only that it failed.
|
|
35
|
+
* That code is this rail's contract with its guard, which is why verification goes through the primitive's
|
|
36
|
+
* reporting seam rather than its throwing one.
|
|
37
|
+
*/
|
|
38
|
+
/** The header Stripe puts its proof in. Lower case, because that is how Hono presents a header name. */
|
|
39
|
+
export declare const STRIPE_SIGNATURE_HEADER = "stripe-signature";
|
|
40
|
+
/** How far a delivery's own timestamp may be from now. Stripe's default, and generous against clock skew. */
|
|
41
|
+
export declare const STRIPE_SIGNATURE_TOLERANCE_SECONDS = 300;
|
|
42
|
+
/**
|
|
43
|
+
* A parsed `Stripe-Signature` header: when the delivery says it was signed, and with what. The primitive's
|
|
44
|
+
* shape under this rail's name — the format is Stripe's, the parser is the kit's.
|
|
45
|
+
*/
|
|
46
|
+
export type StripeSignatureHeader = SignedWebhookHeader;
|
|
47
|
+
/** What verification needs beyond the bytes: the clock, and how wide the freshness window is. */
|
|
48
|
+
export interface VerifyStripeSignatureOptions {
|
|
49
|
+
/** The clock. Injected so the replay window is deterministic in tests rather than wall-clock dependent. */
|
|
50
|
+
now: Date;
|
|
51
|
+
/** The freshness window, in seconds. Defaults to {@link STRIPE_SIGNATURE_TOLERANCE_SECONDS}. */
|
|
52
|
+
toleranceSeconds?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Read a `Stripe-Signature` header, or `undefined` when it is not one.
|
|
56
|
+
*
|
|
57
|
+
* Undefined rather than a throw for every unreadable shape, because the caller turns them all into one refusal:
|
|
58
|
+
* distinguishing "no `t`" from "no `v1`" would describe our parser to a sender, and neither is actionable by
|
|
59
|
+
* anyone but an operator reading the endpoint's configuration.
|
|
60
|
+
*
|
|
61
|
+
* Unknown schemes are dropped rather than refused. Stripe already sends `v0` alongside `v1` for thin Connect
|
|
62
|
+
* events and may add another after this package shipped, and a delivery whose `v1` is good is authentic whatever
|
|
63
|
+
* else it carries. A header carrying *only* unknown schemes has proved nothing, so it yields undefined.
|
|
64
|
+
*/
|
|
65
|
+
export declare function parseStripeSignatureHeader(header: string): StripeSignatureHeader | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Verify one delivery's `Stripe-Signature`. Resolves when Stripe signed these exact bytes inside the window, and
|
|
68
|
+
* throws `payments/verification_failed` otherwise.
|
|
69
|
+
*/
|
|
70
|
+
export declare function verifyStripeSignature(body: string, header: string | null, secret: string, options: VerifyStripeSignatureOptions): Promise<void>;
|
|
71
|
+
//# sourceMappingURL=signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/signature.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,mBAAmB,EAEzB,MAAM,uCAAuC,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,wGAAwG;AACxG,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAE1D,6GAA6G;AAC7G,eAAO,MAAM,kCAAkC,MAAM,CAAC;AAQtD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAExD,iGAAiG;AACjG,MAAM,WAAW,4BAA4B;IAC3C,2GAA2G;IAC3G,GAAG,EAAE,IAAI,CAAC;IACV,gGAAgG;IAChG,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAE5F;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,IAAI,CAAC,CAWf"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
2
|
+
import { checkSignedWebhook, parseSignedWebhookHeader } from "@pithy-sh/core/src/http/signedWebhook";
|
|
3
|
+
//#region src/rails/stripe/signature.ts
|
|
4
|
+
/**
|
|
5
|
+
* Stripe's authenticity proof: an HMAC over the exact received bytes, dated, in one header.
|
|
6
|
+
*
|
|
7
|
+
* `Stripe-Signature: t=1768435200,v1=5257a8…` — the timestamp the delivery claims, then one hex HMAC-SHA256 per
|
|
8
|
+
* active signing secret, each computed over `<timestamp>.<body>` and keyed with the endpoint's `whsec_…`.
|
|
9
|
+
*
|
|
10
|
+
* ## Why the scheme itself is not here
|
|
11
|
+
*
|
|
12
|
+
* It is `@pithy-sh/core`'s `signed-webhook` primitive, and this module is one of its callers. Stripe's format is
|
|
13
|
+
* the one every other sender copied, so the kit implements it once — the freshness window in both directions, the
|
|
14
|
+
* timestamp inside the signed payload, `crypto.subtle.verify` instead of a hand-written compare, every listed
|
|
15
|
+
* signature tried, and a cap on how many. Each of those is a security property with a reason written down beside
|
|
16
|
+
* it, and a second copy here would be a second set of reasons to keep in step: a parser fix landing in one and
|
|
17
|
+
* not the other, with money on the side that missed it.
|
|
18
|
+
*
|
|
19
|
+
* What stays is what is Stripe's: the header name, the accepted scheme key, the tolerance, and the wording of a
|
|
20
|
+
* refusal.
|
|
21
|
+
*
|
|
22
|
+
* ## Why the window matters to this rail in particular
|
|
23
|
+
*
|
|
24
|
+
* A captured `customer.subscription.updated` replayed months later is a state claim about a subscription that has
|
|
25
|
+
* since lapsed. The projection's monotonic rule would correctly ignore it *only because* the stored event time is
|
|
26
|
+
* newer — and relying on that would make the window a happy accident of another rule. Five minutes is Stripe's own
|
|
27
|
+
* default and is generous against delivery latency and clock skew.
|
|
28
|
+
*
|
|
29
|
+
* Freshness is not uniqueness. Inside the window a captured delivery replays as often as it is sent, which is what
|
|
30
|
+
* the guard's `UNIQUE (rail, providerEventId)` insert is for.
|
|
31
|
+
*
|
|
32
|
+
* ## What a refusal says
|
|
33
|
+
*
|
|
34
|
+
* `payments/verification_failed`, with the reason in `detail` and nothing else. Never the secret, never the body,
|
|
35
|
+
* never the signature: `detail` reaches an operator's log, and the webhook guard maps this to
|
|
36
|
+
* `payments/webhook_unverified` (401) before anything reaches the sender — a forger learns only that it failed.
|
|
37
|
+
* That code is this rail's contract with its guard, which is why verification goes through the primitive's
|
|
38
|
+
* reporting seam rather than its throwing one.
|
|
39
|
+
*/
|
|
40
|
+
/** The header Stripe puts its proof in. Lower case, because that is how Hono presents a header name. */
|
|
41
|
+
const STRIPE_SIGNATURE_HEADER = "stripe-signature";
|
|
42
|
+
/** How far a delivery's own timestamp may be from now. Stripe's default, and generous against clock skew. */
|
|
43
|
+
const STRIPE_SIGNATURE_TOLERANCE_SECONDS = 300;
|
|
44
|
+
/** The one signature scheme this build accepts. `v0` is Stripe's thin-event variant and proves nothing here. */
|
|
45
|
+
const ACCEPTED_SCHEME = "v1";
|
|
46
|
+
/** The timestamp key Stripe writes. The primitive's default, named here so this file states its own format. */
|
|
47
|
+
const TIMESTAMP_KEY = "t";
|
|
48
|
+
/**
|
|
49
|
+
* Read a `Stripe-Signature` header, or `undefined` when it is not one.
|
|
50
|
+
*
|
|
51
|
+
* Undefined rather than a throw for every unreadable shape, because the caller turns them all into one refusal:
|
|
52
|
+
* distinguishing "no `t`" from "no `v1`" would describe our parser to a sender, and neither is actionable by
|
|
53
|
+
* anyone but an operator reading the endpoint's configuration.
|
|
54
|
+
*
|
|
55
|
+
* Unknown schemes are dropped rather than refused. Stripe already sends `v0` alongside `v1` for thin Connect
|
|
56
|
+
* events and may add another after this package shipped, and a delivery whose `v1` is good is authentic whatever
|
|
57
|
+
* else it carries. A header carrying *only* unknown schemes has proved nothing, so it yields undefined.
|
|
58
|
+
*/
|
|
59
|
+
function parseStripeSignatureHeader(header) {
|
|
60
|
+
return parseSignedWebhookHeader(header, TIMESTAMP_KEY, ACCEPTED_SCHEME);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Verify one delivery's `Stripe-Signature`. Resolves when Stripe signed these exact bytes inside the window, and
|
|
64
|
+
* throws `payments/verification_failed` otherwise.
|
|
65
|
+
*/
|
|
66
|
+
async function verifyStripeSignature(body, header, secret, options) {
|
|
67
|
+
const refusal = await checkSignedWebhook(body, header, {
|
|
68
|
+
header: STRIPE_SIGNATURE_HEADER,
|
|
69
|
+
timestampKey: TIMESTAMP_KEY,
|
|
70
|
+
signatureKey: ACCEPTED_SCHEME,
|
|
71
|
+
secret,
|
|
72
|
+
toleranceSeconds: options.toleranceSeconds ?? 300,
|
|
73
|
+
now: options.now
|
|
74
|
+
});
|
|
75
|
+
if (refusal === void 0) return;
|
|
76
|
+
throw new PaymentsVerificationFailedError({ detail: stripeRefusal(refusal) });
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* This rail's wording for the primitive's three refusals.
|
|
80
|
+
*
|
|
81
|
+
* Prefixed `Stripe:` because a payments Worker composes several rails and `detail` is what an operator reads to
|
|
82
|
+
* find out which one refused. The strings say what failed and what to check, and nothing the delivery carried.
|
|
83
|
+
*/
|
|
84
|
+
function stripeRefusal(refusal) {
|
|
85
|
+
switch (refusal.reason) {
|
|
86
|
+
case "unreadable": return "Stripe: the delivery carries no readable Stripe-Signature header with a t= timestamp and a v1= HMAC.";
|
|
87
|
+
case "stale": return `Stripe: the delivery is dated ${refusal.skew}s from now, outside the ${refusal.tolerance}s tolerance. Check this Worker's clock, or a replayed delivery.`;
|
|
88
|
+
case "unmatched": return "Stripe: no signature in the Stripe-Signature header matches these bytes under the configured signing secret. Check that the secret belongs to this endpoint and this environment.";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { STRIPE_SIGNATURE_HEADER, STRIPE_SIGNATURE_TOLERANCE_SECONDS, parseStripeSignatureHeader, verifyStripeSignature };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PaymentsStripeCredentials } from "../../secret/registry";
|
|
2
|
+
import { type VerifiedPurchase } from "../contract";
|
|
3
|
+
import { type StripeHttpFetch } from "./api";
|
|
4
|
+
/** What verifying a submitted session needs: the API key, a clock, and the transport. */
|
|
5
|
+
export interface StripeVerifyOptions {
|
|
6
|
+
/** Stripe's credential block. Only `secretKey` is used here. */
|
|
7
|
+
credentials: PaymentsStripeCredentials;
|
|
8
|
+
/** The clock. A retrieve is a read of the state now, so this is the honest provider event time. */
|
|
9
|
+
now: Date;
|
|
10
|
+
/** The HTTP seam. Defaults to the runtime's `fetch`. */
|
|
11
|
+
transport?: StripeHttpFetch;
|
|
12
|
+
}
|
|
13
|
+
/** Verify a client-submitted Checkout Session and normalize it. The caller binds the authenticated purchaser. */
|
|
14
|
+
export declare function verifyStripeSession(receipt: string, options: StripeVerifyOptions): Promise<VerifiedPurchase>;
|
|
15
|
+
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/verify.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAY,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,KAAK,eAAe,EAA+B,MAAM,OAAO,CAAC;AAkC1E,yFAAyF;AACzF,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,WAAW,EAAE,yBAAyB,CAAC;IACvC,mGAAmG;IACnG,GAAG,EAAE,IAAI,CAAC;IACV,wDAAwD;IACxD,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,iHAAiH;AACjH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqDlH"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { PaymentsInvalidReceiptError, PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
2
|
+
import { noteText } from "../contract.js";
|
|
3
|
+
import { stripeHttpFetch, stripeJson } from "./api.js";
|
|
4
|
+
import { StripeCheckoutSession, mapStripeSession } from "./objects.js";
|
|
5
|
+
//#region src/rails/stripe/verify.ts
|
|
6
|
+
/**
|
|
7
|
+
* The client-submission path for Stripe: the Checkout Session id a returning browser carries.
|
|
8
|
+
*
|
|
9
|
+
* Hosted Checkout sends the buyer back to `success_url`, and Stripe substitutes the session id into it wherever
|
|
10
|
+
* the adopter put `{CHECKOUT_SESSION_ID}`. Posting that id to `/payments/purchases` is the Stripe equivalent of
|
|
11
|
+
* submitting a StoreKit transaction: **nothing about correctness rests on it**, because the webhook produces the
|
|
12
|
+
* identical row through the same idempotent writer. What it buys is immediacy — the buyer sees their entitlement
|
|
13
|
+
* when they land on the thank-you page rather than when Stripe gets round to delivering.
|
|
14
|
+
*
|
|
15
|
+
* ## Why a session id is safe to accept, and where it stops
|
|
16
|
+
*
|
|
17
|
+
* A session id is not a bearer artifact the way a receipt is: it is not a secret, and it is not proof of anything
|
|
18
|
+
* on its own. What makes this path safe is that the session **names its own purchaser**. Pithy set
|
|
19
|
+
* `client_reference_id` from the authenticated caller when it created the session, and that value comes back on
|
|
20
|
+
* the retrieve — so a caller submitting somebody else's session id is refused by the route, before the projection
|
|
21
|
+
* writer's owner check ever has to catch it. The shape is checked here first, so an Apple receipt posted to the
|
|
22
|
+
* Stripe rail costs no round-trip.
|
|
23
|
+
*
|
|
24
|
+
* ## Why all three expansions
|
|
25
|
+
*
|
|
26
|
+
* `line_items` because a session's price is otherwise unknowable, and Stripe's own answer is better than the copy
|
|
27
|
+
* this deployment stamped into metadata. `subscription` because a subscription-mode session carries only an id,
|
|
28
|
+
* and expanding it turns one retrieve into the whole state — the same row the subscription's own webhook will
|
|
29
|
+
* later produce. And **`payment_intent.latest_charge` because a completed session is refund-blind**: its
|
|
30
|
+
* `payment_status` reads `paid` for ever, so without the charge this path would answer `active` on a purchase
|
|
31
|
+
* Stripe has already given back. The charge is the only object here that knows what became of the money.
|
|
32
|
+
*/
|
|
33
|
+
/** A Checkout Session id. Stripe's are `cs_` plus base62; the bound is generous and the shape is exact. */
|
|
34
|
+
const SESSION_ID = /^cs_[A-Za-z0-9_]{1,255}$/;
|
|
35
|
+
/** Verify a client-submitted Checkout Session and normalize it. The caller binds the authenticated purchaser. */
|
|
36
|
+
async function verifyStripeSession(receipt, options) {
|
|
37
|
+
if (!SESSION_ID.test(receipt)) throw new PaymentsInvalidReceiptError({ detail: "Stripe: the submitted value is not a Checkout Session id. Submit the `cs_…` id from your success URL." });
|
|
38
|
+
const retrieved = await stripeJson(options.transport ?? stripeHttpFetch, `/checkout/sessions/${encodeURIComponent(receipt)}`, {
|
|
39
|
+
what: "the Checkout Session",
|
|
40
|
+
secretKey: options.credentials.secretKey,
|
|
41
|
+
query: { expand: [
|
|
42
|
+
"subscription",
|
|
43
|
+
"line_items",
|
|
44
|
+
"payment_intent.latest_charge"
|
|
45
|
+
] },
|
|
46
|
+
absentOn404: true
|
|
47
|
+
});
|
|
48
|
+
if (retrieved === void 0) throw new PaymentsVerificationFailedError({ detail: "Stripe: no Checkout Session exists under the submitted id in this environment." });
|
|
49
|
+
const parsed = StripeCheckoutSession.safeParse(retrieved);
|
|
50
|
+
if (!parsed.success) throw new PaymentsVerificationFailedError({ detail: `Stripe: the answer is not a Checkout Session — ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "<root>"}:${issue.code}`).join(", ")}.` });
|
|
51
|
+
const mapped = mapStripeSession(parsed.data, {
|
|
52
|
+
eventAt: null,
|
|
53
|
+
now: options.now
|
|
54
|
+
});
|
|
55
|
+
if (mapped.event === null) throw new PaymentsVerificationFailedError({ detail: noteText(mapped.note) ?? "Stripe: that checkout has not completed into a purchase yet. It will project from the webhook when it does." });
|
|
56
|
+
return {
|
|
57
|
+
event: mapped.event,
|
|
58
|
+
providerAccountId: mapped.providerAccountId,
|
|
59
|
+
accountReference: mapped.accountReference
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { verifyStripeSession };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PaymentsStripeCredentials } from "../../secret/registry";
|
|
2
|
+
import type { VerifiedNotification, WebhookDelivery } from "../contract";
|
|
3
|
+
/**
|
|
4
|
+
* One Stripe webhook delivery: verified, read, and normalized.
|
|
5
|
+
*
|
|
6
|
+
* Three steps, in this order, and the order is the point. **Authenticity first** — the HMAC covers the exact
|
|
7
|
+
* received bytes, so nothing about the body is trustworthy until it passes, and a forgery is refused before a
|
|
8
|
+
* single field is read. Then the **envelope**, because an event's `type` is what says which object it carries.
|
|
9
|
+
* Then the **mapping**, which is `objects.ts`'s job and the only part that knows what Stripe's vocabulary means.
|
|
10
|
+
*
|
|
11
|
+
* The stored payload is the whole event, not the object inside it. The webhook row is the replay source, and
|
|
12
|
+
* the envelope carries the event id, the type, and Stripe's own timestamp — which is what makes "why didn't this
|
|
13
|
+
* renew" answerable from the table without going back to Stripe.
|
|
14
|
+
*/
|
|
15
|
+
/** What verifying one Stripe delivery needs: the endpoint's secret, and a clock for the replay window. */
|
|
16
|
+
export interface StripeWebhookOptions {
|
|
17
|
+
/** Stripe's credential block. Only `webhookSecret` is used here; the API key belongs to the other paths. */
|
|
18
|
+
credentials: PaymentsStripeCredentials;
|
|
19
|
+
/** The clock, for the signature's freshness window. Injected so tests are deterministic. */
|
|
20
|
+
now: Date;
|
|
21
|
+
/** The freshness window, in seconds. Defaults to Stripe's own five minutes. */
|
|
22
|
+
toleranceSeconds?: number;
|
|
23
|
+
}
|
|
24
|
+
/** Verify and normalize one Stripe webhook delivery. Throws when authenticity cannot be established. */
|
|
25
|
+
export declare function parseStripeNotification(delivery: WebhookDelivery, options: StripeWebhookOptions): Promise<VerifiedNotification>;
|
|
26
|
+
//# sourceMappingURL=webhook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/webhook.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAIzE;;;;;;;;;;;GAWG;AAEH,0GAA0G;AAC1G,MAAM,WAAW,oBAAoB;IACnC,4GAA4G;IAC5G,WAAW,EAAE,yBAAyB,CAAC;IACvC,4FAA4F;IAC5F,GAAG,EAAE,IAAI,CAAC;IACV,+EAA+E;IAC/E,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,wGAAwG;AACxG,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,oBAAoB,CAAC,CA0C/B"}
|