@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,42 @@
|
|
|
1
|
+
import { PaymentsProviderUnavailableError } from "../../error/errors.js";
|
|
2
|
+
import { paddleHttpFetch, paddleJson } from "./api.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/rails/paddle/portal.ts
|
|
5
|
+
/**
|
|
6
|
+
* Paddle asks for at most 25 subscription ids. More than that is not a shape this rail produces — one
|
|
7
|
+
* caller with 26 live subscriptions is not a case worth failing a portal open over — so the list is
|
|
8
|
+
* truncated with the newest kept rather than the request being refused.
|
|
9
|
+
*/
|
|
10
|
+
const MAX_PORTAL_SUBSCRIPTIONS = 25;
|
|
11
|
+
/** A created portal session, narrowed to the URLs it carries. */
|
|
12
|
+
const PaddlePortalSession = z.object({ urls: z.object({
|
|
13
|
+
general: z.object({ overview: z.string().min(1).describe("The portal's overview page for this customer.") }).loose().describe("The account-wide links."),
|
|
14
|
+
subscriptions: z.array(z.object({
|
|
15
|
+
id: z.string().min(1).describe("The subscription these links act on."),
|
|
16
|
+
cancel_subscription: z.string().min(1).describe("Where this subscription is canceled."),
|
|
17
|
+
update_subscription_payment_method: z.string().min(1).describe("Where this subscription's payment method is changed.")
|
|
18
|
+
}).loose()).optional().describe("Per-subscription deep links, one entry per id asked for.")
|
|
19
|
+
}).loose() }).loose().describe("A Paddle customer portal session — an overview page, and the deep links asked for.");
|
|
20
|
+
/** Create a portal session for one customer, and return where they manage their billing. */
|
|
21
|
+
async function createPaddlePortalSession(input, options) {
|
|
22
|
+
const ids = (input.subscriptionIds ?? []).slice(0, MAX_PORTAL_SUBSCRIPTIONS);
|
|
23
|
+
const answer = await paddleJson(options.transport ?? paddleHttpFetch, `/customers/${encodeURIComponent(input.providerAccountId)}/portal-sessions`, {
|
|
24
|
+
what: "a customer portal session",
|
|
25
|
+
apiKey: options.credentials.apiKey,
|
|
26
|
+
environment: options.environment,
|
|
27
|
+
body: ids.length === 0 ? {} : { subscription_ids: ids }
|
|
28
|
+
});
|
|
29
|
+
const parsed = PaddlePortalSession.safeParse(answer?.data);
|
|
30
|
+
if (!parsed.success) throw new PaymentsProviderUnavailableError({ detail: `Paddle returned a portal session for customer ${input.providerAccountId} with no authenticated URLs. Check that the API key carries \`customer_portal_session.write\`.` });
|
|
31
|
+
const subscriptions = (parsed.data.urls.subscriptions ?? []).map((entry) => ({
|
|
32
|
+
subscriptionId: entry.id,
|
|
33
|
+
cancel: entry.cancel_subscription,
|
|
34
|
+
updatePaymentMethod: entry.update_subscription_payment_method
|
|
35
|
+
}));
|
|
36
|
+
return {
|
|
37
|
+
url: parsed.data.urls.general.overview,
|
|
38
|
+
...ids.length === 0 ? {} : { subscriptions }
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { createPaddlePortalSession };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { PaymentsPaddleCredentials } from "../../secret/registry";
|
|
2
|
+
import type { CheckoutRail, DiscountRail, PaymentsRailProvider, PricingRail, RefundRail, SubscriptionRail } from "../contract";
|
|
3
|
+
import { type PaddleEnvironment, type PaddleHttpFetch } from "./api";
|
|
4
|
+
/**
|
|
5
|
+
* The Paddle rail as one provider object — the fifth, and the second merchant of record.
|
|
6
|
+
*
|
|
7
|
+
* Like Stripe and Lemon Squeezy this rail *initiates* purchases, so it implements {@link CheckoutRail}.
|
|
8
|
+
* Unlike Lemon Squeezy it also implements `verify`, and that is not a nicety: `dev` is not publicly
|
|
9
|
+
* routable, so a dev checkout's webhooks land at `staging`, and a submitted `txn_…` checked against a
|
|
10
|
+
* proven ownership stamp is what makes local development work at all. See `verify.ts`.
|
|
11
|
+
*
|
|
12
|
+
* It is also the first rail to implement {@link SubscriptionRail} — read a subscription's standing, quote a
|
|
13
|
+
* plan change, make one, cancel, and withdraw a cancellation. That is a third interface rather than three
|
|
14
|
+
* more methods on the shared contract for {@link CheckoutRail}'s reason: an Apple or Google subscription is
|
|
15
|
+
* changed inside the store's own UI, on the device, and a rail forced to declare `changePlan` would declare a
|
|
16
|
+
* method that cannot be written. `subscription.ts` holds the five, and every rule they enforce came out of
|
|
17
|
+
* sandbox recordings rather than the documentation (#465).
|
|
18
|
+
*
|
|
19
|
+
* It implements {@link RefundRail} too, and that is a *sixth* interface rather than a sixth subscription verb.
|
|
20
|
+
* The two abilities are independent in both directions — Play refunds from the server and changes no plan from
|
|
21
|
+
* it, Apple's only refund endpoint is a lookup — and `isSubscriptionRail` ANDs its methods, so widening it
|
|
22
|
+
* would have de-narrowed every rail already shipping the five. `refund.ts` holds it.
|
|
23
|
+
*
|
|
24
|
+
* Built per request from credentials the caller resolved through the secrets store, rather than reading
|
|
25
|
+
* them itself. That keeps the rail a pure function of its inputs and keeps the secret read at the point of
|
|
26
|
+
* need.
|
|
27
|
+
*
|
|
28
|
+
* **Merchant of record.** Paddle is the seller on the customer's statement. It calculates and remits sales
|
|
29
|
+
* tax and VAT worldwide, issues the invoices, runs dunning, and absorbs the chargebacks. The one place
|
|
30
|
+
* that shows in this package is that a refund can arrive with no local write preceding it — Paddle issues
|
|
31
|
+
* them on its own account.
|
|
32
|
+
*/
|
|
33
|
+
/** How the Paddle rail is varied. */
|
|
34
|
+
export interface PaddleRailOptions {
|
|
35
|
+
/** Which Paddle account this deployment sells through — sandbox or production. */
|
|
36
|
+
environment: PaddleEnvironment;
|
|
37
|
+
/** The publishable client token a browser initializes Paddle.js with. */
|
|
38
|
+
clientToken: string;
|
|
39
|
+
/** Whether checkout opens as an overlay, inline, or on Paddle's own hosted page. */
|
|
40
|
+
checkout: "overlay" | "inline" | "hosted";
|
|
41
|
+
/** How many seconds either side of now a delivery may be dated. Undefined uses the rail's 300. */
|
|
42
|
+
freshnessSeconds?: number;
|
|
43
|
+
/**
|
|
44
|
+
* The currency this project's Paddle catalog prices in, when the project declared one.
|
|
45
|
+
*
|
|
46
|
+
* Only used to refuse a fixed discount in another currency before it reaches Paddle — see
|
|
47
|
+
* `discounts.ts` for why that refusal has to happen at creation rather than at redemption.
|
|
48
|
+
*/
|
|
49
|
+
storeCurrency?: string;
|
|
50
|
+
/** The HTTP seam Paddle's API is reached through. Defaults to the runtime's `fetch`. */
|
|
51
|
+
transport?: PaddleHttpFetch;
|
|
52
|
+
}
|
|
53
|
+
/** The Paddle rail. */
|
|
54
|
+
export declare function paddleRail(credentials: PaymentsPaddleCredentials, options: PaddleRailOptions): PaymentsRailProvider & CheckoutRail & DiscountRail & PricingRail & SubscriptionRail & RefundRail;
|
|
55
|
+
//# sourceMappingURL=rail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/rail.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAEX,UAAU,EAIV,gBAAgB,EAKjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAmB,MAAM,OAAO,CAAC;AAkBtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,WAAW,EAAE,iBAAiB,CAAC;IAC/B,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,oFAAoF;IACpF,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C,kGAAkG;IAClG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wFAAwF;IACxF,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,uBAAuB;AACvB,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,EAAE,iBAAiB,GACzB,oBAAoB,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,GAAG,gBAAgB,GAAG,UAAU,CAqHlG"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { paddleHttpFetch } from "./api.js";
|
|
2
|
+
import { PaddleEvent } from "./objects.js";
|
|
3
|
+
import { createPaddleCheckoutSession } from "./checkout.js";
|
|
4
|
+
import { createPaddleDiscount, listPaddleDiscounts } from "./discounts.js";
|
|
5
|
+
import { createPaddlePortalSession } from "./portal.js";
|
|
6
|
+
import { PADDLE_ADJUSTMENTS_INCLUDE, readTransaction } from "./read.js";
|
|
7
|
+
import { readPaddlePricing, refreshPaddlePurchase } from "./refresh.js";
|
|
8
|
+
import { requestPaddleRefunds } from "./refund.js";
|
|
9
|
+
import { cancelPaddleSubscription, changePaddlePlan, keepPaddleSubscription, previewPaddleChange, readPaddleStanding } from "./subscription.js";
|
|
10
|
+
import { verifyPaddleTransaction } from "./verify.js";
|
|
11
|
+
import { parsePaddleNotification, readPaddleEvent } from "./webhook.js";
|
|
12
|
+
//#region src/rails/paddle/rail.ts
|
|
13
|
+
/** The Paddle rail. */
|
|
14
|
+
function paddleRail(credentials, options) {
|
|
15
|
+
const transport = options.transport ?? paddleHttpFetch;
|
|
16
|
+
const base = {
|
|
17
|
+
credentials,
|
|
18
|
+
environment: options.environment,
|
|
19
|
+
transport
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
rail: "paddle",
|
|
23
|
+
async verify(receipt, context) {
|
|
24
|
+
return await verifyPaddleTransaction(receipt, {
|
|
25
|
+
...base,
|
|
26
|
+
deployment: context.deployment,
|
|
27
|
+
now: context.now
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
async parseNotification(delivery, context) {
|
|
31
|
+
return await parsePaddleNotification(delivery, {
|
|
32
|
+
credentials,
|
|
33
|
+
environment: options.environment,
|
|
34
|
+
now: context.now,
|
|
35
|
+
deployment: context.deployment,
|
|
36
|
+
freshnessSeconds: options.freshnessSeconds,
|
|
37
|
+
readTransaction: (id) => readTransaction(id, base, PADDLE_ADJUSTMENTS_INCLUDE)
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
async replay(payload, context) {
|
|
41
|
+
const parsed = PaddleEvent.safeParse(payload);
|
|
42
|
+
if (!parsed.success) return void 0;
|
|
43
|
+
return await readPaddleEvent(parsed.data, {
|
|
44
|
+
credentials,
|
|
45
|
+
environment: options.environment,
|
|
46
|
+
now: context.now,
|
|
47
|
+
deployment: context.deployment,
|
|
48
|
+
readTransaction: (id) => readTransaction(id, base, PADDLE_ADJUSTMENTS_INCLUDE)
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
async refresh(purchase, context) {
|
|
52
|
+
return await refreshPaddlePurchase(purchase, {
|
|
53
|
+
...base,
|
|
54
|
+
now: context.now
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
async createCheckoutSession(input, context) {
|
|
58
|
+
return await createPaddleCheckoutSession(input, {
|
|
59
|
+
credentials,
|
|
60
|
+
environment: options.environment,
|
|
61
|
+
clientToken: options.clientToken,
|
|
62
|
+
checkout: options.checkout,
|
|
63
|
+
deployment: context.deployment,
|
|
64
|
+
transport
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
async createPortalSession(input) {
|
|
68
|
+
return await createPaddlePortalSession(input, {
|
|
69
|
+
credentials,
|
|
70
|
+
environment: options.environment,
|
|
71
|
+
transport
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
async readPricing(purchase, context) {
|
|
75
|
+
return await readPaddlePricing(purchase, {
|
|
76
|
+
...base,
|
|
77
|
+
now: context.now
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
async listDiscounts() {
|
|
81
|
+
return await listPaddleDiscounts({
|
|
82
|
+
credentials,
|
|
83
|
+
environment: options.environment,
|
|
84
|
+
storeCurrency: options.storeCurrency,
|
|
85
|
+
transport
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
async createDiscount(terms) {
|
|
89
|
+
return await createPaddleDiscount(terms, {
|
|
90
|
+
credentials,
|
|
91
|
+
environment: options.environment,
|
|
92
|
+
storeCurrency: options.storeCurrency,
|
|
93
|
+
transport
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
async readStanding(purchase) {
|
|
97
|
+
return await readPaddleStanding(purchase, base);
|
|
98
|
+
},
|
|
99
|
+
async previewChange(input, context) {
|
|
100
|
+
return await previewPaddleChange(input, base, context.locale);
|
|
101
|
+
},
|
|
102
|
+
async changePlan(input) {
|
|
103
|
+
return await changePaddlePlan(input, base);
|
|
104
|
+
},
|
|
105
|
+
async cancelSubscription(input) {
|
|
106
|
+
return await cancelPaddleSubscription(input, base);
|
|
107
|
+
},
|
|
108
|
+
async keepSubscription(purchase) {
|
|
109
|
+
return await keepPaddleSubscription(purchase, base);
|
|
110
|
+
},
|
|
111
|
+
async requestRefunds(input) {
|
|
112
|
+
return await requestPaddleRefunds(input, base);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { paddleRail };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PaymentsPaddleCredentials } from "../../secret/registry";
|
|
2
|
+
import { type PaddleEnvironment, type PaddleHttpFetch } from "./api";
|
|
3
|
+
import { PaddleSubscription, PaddleTransaction } from "./objects";
|
|
4
|
+
/**
|
|
5
|
+
* The reads this rail makes of Paddle: a transaction, and a subscription.
|
|
6
|
+
*
|
|
7
|
+
* Both return `undefined` rather than throwing on an absent object, because two callers with different
|
|
8
|
+
* needs share them. The webhook parser reads a transaction to learn whether a refund covers its whole
|
|
9
|
+
* total; the reconciliation pass reads one to find out what a purchase looks like now. For the first, an
|
|
10
|
+
* absent transaction is a delivery this deployment cannot project; for the second it is the contract's
|
|
11
|
+
* documented "the store no longer knows this purchase". Neither is a failure of the rail.
|
|
12
|
+
*
|
|
13
|
+
* A store that cannot be *reached* throws `payments/provider_unavailable`, which is what tells the
|
|
14
|
+
* reconciliation Workflow to fail the step and retry, and what makes the webhook guard answer non-2xx so
|
|
15
|
+
* Paddle redelivers.
|
|
16
|
+
*/
|
|
17
|
+
/** What a read needs: the credentials, which account, and the transport. */
|
|
18
|
+
export interface PaddleReadOptions {
|
|
19
|
+
/** The rail's credentials. The API key is read at the point of need and never cached. */
|
|
20
|
+
credentials: PaymentsPaddleCredentials;
|
|
21
|
+
/** Which Paddle account to reach. */
|
|
22
|
+
environment: PaddleEnvironment;
|
|
23
|
+
/** The HTTP seam. */
|
|
24
|
+
transport: PaddleHttpFetch;
|
|
25
|
+
}
|
|
26
|
+
/** The include the adjustment map needs, named once so a call site cannot spell it differently. */
|
|
27
|
+
export declare const PADDLE_ADJUSTMENTS_INCLUDE: readonly string[];
|
|
28
|
+
/**
|
|
29
|
+
* The transaction with this id, or `undefined` when Paddle has none.
|
|
30
|
+
*
|
|
31
|
+
* **An `include` is a permission demand, so it is asked for only by the caller that needs it.** Three of
|
|
32
|
+
* this rail's four transaction reads — receipt verification, reconciliation, and the sweep's own
|
|
33
|
+
* projection — want a status, a total and a `custom_data` stamp, all of which are on the transaction
|
|
34
|
+
* itself. Only the adjustment map needs the array, because an adjustment says how much came off and never
|
|
35
|
+
* what the original was: Paddle raises one adjustment per refund, so a transaction refunded in two goes
|
|
36
|
+
* carries two, and only their sum tells a full refund from a partial one.
|
|
37
|
+
*
|
|
38
|
+
* An earlier build sent `include=adjustments` on every read and its docstring claimed *"a key without
|
|
39
|
+
* adjustment-read permission simply gets no array back rather than a refusal"*. Paddle's own reference
|
|
40
|
+
* says the opposite — see {@link INCLUDE_PERMISSIONS} — so that build made `adjustment.read` a
|
|
41
|
+
* requirement of checking out, on a rail whose documentation tells adopters to scope keys narrowly. The
|
|
42
|
+
* adopter documentation now states the requirement where it is real, and the refusal names it.
|
|
43
|
+
*/
|
|
44
|
+
export declare function readTransaction(id: string, options: PaddleReadOptions, include?: readonly string[]): Promise<PaddleTransaction | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* The subscription with this id, or `undefined` when Paddle has none.
|
|
47
|
+
*
|
|
48
|
+
* `include=next_transaction,recurring_transaction_details` is asked for by the pricing read, which needs
|
|
49
|
+
* what the next invoice comes to and what it becomes once a discount lapses. It costs nothing on the
|
|
50
|
+
* paths that ignore it, and asking twice would be two round trips for one question.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readSubscription(id: string, options: PaddleReadOptions, include?: readonly string[]): Promise<PaddleSubscription | undefined>;
|
|
53
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/read.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAc,MAAM,OAAO,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAElE;;;;;;;;;;;;GAYG;AAEH,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IAChC,yFAAyF;IACzF,WAAW,EAAE,yBAAyB,CAAC;IACvC,qCAAqC;IACrC,WAAW,EAAE,iBAAiB,CAAC;IAC/B,qBAAqB;IACrB,SAAS,EAAE,eAAe,CAAC;CAC5B;AAED,mGAAmG;AACnG,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAAoB,CAAC;AAa7E;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAC1B,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAkBxC;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAC1B,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAWzC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { paddleJson } from "./api.js";
|
|
2
|
+
import { PaddleSubscription, PaddleTransaction } from "./objects.js";
|
|
3
|
+
//#region src/rails/paddle/read.ts
|
|
4
|
+
/** The include the adjustment map needs, named once so a call site cannot spell it differently. */
|
|
5
|
+
const PADDLE_ADJUSTMENTS_INCLUDE = ["adjustments"];
|
|
6
|
+
/**
|
|
7
|
+
* The permission each include this rail asks for demands of the key, so a refusal names what to grant.
|
|
8
|
+
*
|
|
9
|
+
* Paddle's permissions reference: *"Your key needs read permission for any entity added via the `include`
|
|
10
|
+
* parameter"*, and a key without it gets `forbidden` (403). The OpenAPI spec says the same thing in
|
|
11
|
+
* machine-readable form — `x-enum-permissions: {adjustments: ['adjustment.read']}` on this very query
|
|
12
|
+
* parameter. A 403 whose message says only "Paddle refused" sends an operator to check the key itself,
|
|
13
|
+
* which is the one thing that is not wrong.
|
|
14
|
+
*/
|
|
15
|
+
const INCLUDE_PERMISSIONS = { adjustments: "adjustment.read" };
|
|
16
|
+
/**
|
|
17
|
+
* The transaction with this id, or `undefined` when Paddle has none.
|
|
18
|
+
*
|
|
19
|
+
* **An `include` is a permission demand, so it is asked for only by the caller that needs it.** Three of
|
|
20
|
+
* this rail's four transaction reads — receipt verification, reconciliation, and the sweep's own
|
|
21
|
+
* projection — want a status, a total and a `custom_data` stamp, all of which are on the transaction
|
|
22
|
+
* itself. Only the adjustment map needs the array, because an adjustment says how much came off and never
|
|
23
|
+
* what the original was: Paddle raises one adjustment per refund, so a transaction refunded in two goes
|
|
24
|
+
* carries two, and only their sum tells a full refund from a partial one.
|
|
25
|
+
*
|
|
26
|
+
* An earlier build sent `include=adjustments` on every read and its docstring claimed *"a key without
|
|
27
|
+
* adjustment-read permission simply gets no array back rather than a refusal"*. Paddle's own reference
|
|
28
|
+
* says the opposite — see {@link INCLUDE_PERMISSIONS} — so that build made `adjustment.read` a
|
|
29
|
+
* requirement of checking out, on a rail whose documentation tells adopters to scope keys narrowly. The
|
|
30
|
+
* adopter documentation now states the requirement where it is real, and the refusal names it.
|
|
31
|
+
*/
|
|
32
|
+
async function readTransaction(id, options, include) {
|
|
33
|
+
const asked = include === void 0 || include.length === 0 ? void 0 : include.join(",");
|
|
34
|
+
const needs = (include ?? []).map((entity) => INCLUDE_PERMISSIONS[entity]).filter((permission) => permission !== void 0);
|
|
35
|
+
const answer = await paddleJson(options.transport, `/transactions/${encodeURIComponent(id)}`, {
|
|
36
|
+
what: asked === void 0 ? `transaction ${id}` : `transaction ${id} with include=${asked}${needs.length === 0 ? "" : ` (this key needs the ${needs.join(" and ")} permission)`}`,
|
|
37
|
+
apiKey: options.credentials.apiKey,
|
|
38
|
+
environment: options.environment,
|
|
39
|
+
query: asked === void 0 ? void 0 : [["include", asked]],
|
|
40
|
+
absentOn404: true
|
|
41
|
+
});
|
|
42
|
+
if (answer === void 0) return void 0;
|
|
43
|
+
const parsed = PaddleTransaction.safeParse(answer.data);
|
|
44
|
+
return parsed.success ? parsed.data : void 0;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The subscription with this id, or `undefined` when Paddle has none.
|
|
48
|
+
*
|
|
49
|
+
* `include=next_transaction,recurring_transaction_details` is asked for by the pricing read, which needs
|
|
50
|
+
* what the next invoice comes to and what it becomes once a discount lapses. It costs nothing on the
|
|
51
|
+
* paths that ignore it, and asking twice would be two round trips for one question.
|
|
52
|
+
*/
|
|
53
|
+
async function readSubscription(id, options, include) {
|
|
54
|
+
const answer = await paddleJson(options.transport, `/subscriptions/${encodeURIComponent(id)}`, {
|
|
55
|
+
what: `subscription ${id}`,
|
|
56
|
+
apiKey: options.credentials.apiKey,
|
|
57
|
+
environment: options.environment,
|
|
58
|
+
query: include === void 0 || include.length === 0 ? void 0 : [["include", include.join(",")]],
|
|
59
|
+
absentOn404: true
|
|
60
|
+
});
|
|
61
|
+
if (answer === void 0) return void 0;
|
|
62
|
+
const parsed = PaddleSubscription.safeParse(answer.data);
|
|
63
|
+
return parsed.success ? parsed.data : void 0;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { PADDLE_ADJUSTMENTS_INCLUDE, readSubscription, readTransaction };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { PaddleEvent } from "./objects";
|
|
2
|
+
/**
|
|
3
|
+
* What of a Paddle event this build writes down — the control that keeps a live client token out of D1.
|
|
4
|
+
*
|
|
5
|
+
* ## The hazard
|
|
6
|
+
*
|
|
7
|
+
* Paddle's notification destinations and its `/events` stream are **account-wide**. A destination
|
|
8
|
+
* subscribed to `*`, or a sweep whose query filter is not honored, carries `api_key.*`,
|
|
9
|
+
* `client_token.*`, `product.*`, `price.*` and `discount.*` alongside the events this package acts on.
|
|
10
|
+
* Verified against the assigned sandbox's own stream: it carries `api_key.created` and
|
|
11
|
+
* `client_token.created`, and while Paddle redacts the api key's `key`, **it does not redact the client
|
|
12
|
+
* token's `token`.**
|
|
13
|
+
*
|
|
14
|
+
* `PaddleEvent` is `.loose()` and its `data` is `z.record(z.string(), z.unknown())`, so nothing in the
|
|
15
|
+
* schema narrows an unknown event's body. Storing the delivery whole therefore persists a live credential
|
|
16
|
+
* into `pithy_payments_webhook_events` — a table an operator greps, an export copies, and a backup keeps.
|
|
17
|
+
*
|
|
18
|
+
* ## Why the control is here rather than in the query
|
|
19
|
+
*
|
|
20
|
+
* The sweep does ask Paddle for only the types below, and that filter is worth having. But a query
|
|
21
|
+
* parameter is a *request*: it is honored by someone else's service, on someone else's release cadence,
|
|
22
|
+
* and it does not exist at all on the webhook path, where the subscribed-event list is set in Paddle's
|
|
23
|
+
* dashboard by a human. An allowlist on what is **recorded** is a control this package owns and can prove.
|
|
24
|
+
*
|
|
25
|
+
* So: a type on this list is recorded whole, because its body is a transaction, a subscription or an
|
|
26
|
+
* adjustment and that body is the replay source. A type not on this list is recorded as its **envelope
|
|
27
|
+
* only** — id, type, and when — which keeps the row that makes the event id idempotent and drops the body
|
|
28
|
+
* this build was never going to read.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Every event type recorded in full. Exactly the types the event map in `webhook.ts` acts on.
|
|
32
|
+
*
|
|
33
|
+
* Written out rather than derived from that module's sets on purpose: a list computed from the thing it is
|
|
34
|
+
* meant to constrain cannot constrain it. `recorded.test.ts` cross-checks the two declarations against
|
|
35
|
+
* each other in both directions, so adding a case to the map without adding its type here fails, and so
|
|
36
|
+
* does the reverse.
|
|
37
|
+
*/
|
|
38
|
+
export declare const PADDLE_RECORDED_EVENT_TYPES: ReadonlySet<string>;
|
|
39
|
+
/**
|
|
40
|
+
* What to store for this event: the whole delivery, or the envelope alone.
|
|
41
|
+
*
|
|
42
|
+
* The envelope keeps `event_id` — which is the whole point of the row, since `UNIQUE (rail,
|
|
43
|
+
* providerEventId)` is what makes a redelivery recognized rather than reprocessed — plus the type and the
|
|
44
|
+
* time, so an operator can still see that an event arrived and what it was. Everything else is dropped,
|
|
45
|
+
* including any top-level key `.loose()` let through, because a key this build cannot name is a key it
|
|
46
|
+
* cannot vouch for.
|
|
47
|
+
*/
|
|
48
|
+
export declare function recordedPayload(event: PaddleEvent): Record<string, unknown>;
|
|
49
|
+
//# sourceMappingURL=recorded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recorded.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/recorded.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,EAAE,WAAW,CAAC,MAAM,CAsB1D,CAAC;AAEH;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAO3E"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/rails/paddle/recorded.ts
|
|
2
|
+
/**
|
|
3
|
+
* What of a Paddle event this build writes down — the control that keeps a live client token out of D1.
|
|
4
|
+
*
|
|
5
|
+
* ## The hazard
|
|
6
|
+
*
|
|
7
|
+
* Paddle's notification destinations and its `/events` stream are **account-wide**. A destination
|
|
8
|
+
* subscribed to `*`, or a sweep whose query filter is not honored, carries `api_key.*`,
|
|
9
|
+
* `client_token.*`, `product.*`, `price.*` and `discount.*` alongside the events this package acts on.
|
|
10
|
+
* Verified against the assigned sandbox's own stream: it carries `api_key.created` and
|
|
11
|
+
* `client_token.created`, and while Paddle redacts the api key's `key`, **it does not redact the client
|
|
12
|
+
* token's `token`.**
|
|
13
|
+
*
|
|
14
|
+
* `PaddleEvent` is `.loose()` and its `data` is `z.record(z.string(), z.unknown())`, so nothing in the
|
|
15
|
+
* schema narrows an unknown event's body. Storing the delivery whole therefore persists a live credential
|
|
16
|
+
* into `pithy_payments_webhook_events` — a table an operator greps, an export copies, and a backup keeps.
|
|
17
|
+
*
|
|
18
|
+
* ## Why the control is here rather than in the query
|
|
19
|
+
*
|
|
20
|
+
* The sweep does ask Paddle for only the types below, and that filter is worth having. But a query
|
|
21
|
+
* parameter is a *request*: it is honored by someone else's service, on someone else's release cadence,
|
|
22
|
+
* and it does not exist at all on the webhook path, where the subscribed-event list is set in Paddle's
|
|
23
|
+
* dashboard by a human. An allowlist on what is **recorded** is a control this package owns and can prove.
|
|
24
|
+
*
|
|
25
|
+
* So: a type on this list is recorded whole, because its body is a transaction, a subscription or an
|
|
26
|
+
* adjustment and that body is the replay source. A type not on this list is recorded as its **envelope
|
|
27
|
+
* only** — id, type, and when — which keeps the row that makes the event id idempotent and drops the body
|
|
28
|
+
* this build was never going to read.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Every event type recorded in full. Exactly the types the event map in `webhook.ts` acts on.
|
|
32
|
+
*
|
|
33
|
+
* Written out rather than derived from that module's sets on purpose: a list computed from the thing it is
|
|
34
|
+
* meant to constrain cannot constrain it. `recorded.test.ts` cross-checks the two declarations against
|
|
35
|
+
* each other in both directions, so adding a case to the map without adding its type here fails, and so
|
|
36
|
+
* does the reverse.
|
|
37
|
+
*/
|
|
38
|
+
const PADDLE_RECORDED_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
39
|
+
"transaction.created",
|
|
40
|
+
"transaction.ready",
|
|
41
|
+
"transaction.paid",
|
|
42
|
+
"transaction.completed",
|
|
43
|
+
"transaction.payment_failed",
|
|
44
|
+
"transaction.past_due",
|
|
45
|
+
"transaction.canceled",
|
|
46
|
+
"transaction.updated",
|
|
47
|
+
"transaction.revised",
|
|
48
|
+
"transaction.billed",
|
|
49
|
+
"subscription.created",
|
|
50
|
+
"subscription.activated",
|
|
51
|
+
"subscription.resumed",
|
|
52
|
+
"subscription.trialing",
|
|
53
|
+
"subscription.past_due",
|
|
54
|
+
"subscription.paused",
|
|
55
|
+
"subscription.canceled",
|
|
56
|
+
"subscription.updated",
|
|
57
|
+
"subscription.imported",
|
|
58
|
+
"adjustment.created",
|
|
59
|
+
"adjustment.updated"
|
|
60
|
+
]);
|
|
61
|
+
/**
|
|
62
|
+
* What to store for this event: the whole delivery, or the envelope alone.
|
|
63
|
+
*
|
|
64
|
+
* The envelope keeps `event_id` — which is the whole point of the row, since `UNIQUE (rail,
|
|
65
|
+
* providerEventId)` is what makes a redelivery recognized rather than reprocessed — plus the type and the
|
|
66
|
+
* time, so an operator can still see that an event arrived and what it was. Everything else is dropped,
|
|
67
|
+
* including any top-level key `.loose()` let through, because a key this build cannot name is a key it
|
|
68
|
+
* cannot vouch for.
|
|
69
|
+
*/
|
|
70
|
+
function recordedPayload(event) {
|
|
71
|
+
if (PADDLE_RECORDED_EVENT_TYPES.has(event.event_type)) return { ...event };
|
|
72
|
+
return {
|
|
73
|
+
event_id: event.event_id,
|
|
74
|
+
event_type: event.event_type,
|
|
75
|
+
occurred_at: event.occurred_at
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { PADDLE_RECORDED_EVENT_TYPES, recordedPayload };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { SubscriptionPricing } from "../../data/discount";
|
|
2
|
+
import type { PaymentsPurchase } from "../../data/purchase";
|
|
3
|
+
import type { PaymentsPaddleCredentials } from "../../secret/registry";
|
|
4
|
+
import type { UnboundProviderEvent } from "../contract";
|
|
5
|
+
import { type PaddleEnvironment, type PaddleHttpFetch } from "./api";
|
|
6
|
+
/**
|
|
7
|
+
* Re-read a Paddle purchase — the reconciliation path — and read what it pays.
|
|
8
|
+
*
|
|
9
|
+
* Webhooks are dropped, destinations are misconfigured, and a subscription can lapse with no notification
|
|
10
|
+
* arriving at all. This is the question the reconciliation Workflow exists to ask, and this rail answers
|
|
11
|
+
* it for real.
|
|
12
|
+
*
|
|
13
|
+
* ## Which rows it can answer for
|
|
14
|
+
*
|
|
15
|
+
* Paddle's ids are globally prefixed, so the row's own key says what to ask: `sub_…` is a subscription,
|
|
16
|
+
* `txn_…` is a transaction. Both are addressable, so both are re-read — unlike Lemon Squeezy, where a
|
|
17
|
+
* money row records a closed period and has nothing to re-read.
|
|
18
|
+
*
|
|
19
|
+
* A **subscription** transaction's money row is born `expired`, which is in the Workflow's terminal set,
|
|
20
|
+
* so the pass never selects one. Should one reach here it is answered honestly rather than skipped: a
|
|
21
|
+
* refunded transaction is exactly the thing worth re-reading.
|
|
22
|
+
*
|
|
23
|
+
* ## The clock is ours
|
|
24
|
+
*
|
|
25
|
+
* `providerEventAt` is `context.now`, not the object's `updated_at`, as the contract requires. A refresh
|
|
26
|
+
* is a read of the state *now*, so it is the freshest fact there is — dating it earlier would let the
|
|
27
|
+
* monotonic write rule discard the very repair this pass exists to make.
|
|
28
|
+
*/
|
|
29
|
+
/** What a refresh needs: the credentials, the account, the clock, and the transport. */
|
|
30
|
+
export interface RefreshPaddleOptions {
|
|
31
|
+
/** The rail's credentials. */
|
|
32
|
+
credentials: PaymentsPaddleCredentials;
|
|
33
|
+
/** Which Paddle account to read from. */
|
|
34
|
+
environment: PaddleEnvironment;
|
|
35
|
+
/** The clock. Stamped onto the returned event, per the contract. */
|
|
36
|
+
now: Date;
|
|
37
|
+
/** The HTTP seam. Defaults to the runtime's `fetch`. */
|
|
38
|
+
transport?: PaddleHttpFetch;
|
|
39
|
+
}
|
|
40
|
+
/** Re-read one purchase, or `undefined` when Paddle has nothing to say about it. */
|
|
41
|
+
export declare function refreshPaddlePurchase(purchase: PaymentsPurchase, options: RefreshPaddleOptions): Promise<UnboundProviderEvent | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* What a Paddle subscription pays now, what it becomes, and when.
|
|
44
|
+
*
|
|
45
|
+
* Read from Paddle rather than computed. `include=next_transaction` carries what the next invoice comes
|
|
46
|
+
* to under any discount in force; `include=recurring_transaction_details` carries what it comes to at
|
|
47
|
+
* list price. Nothing here multiplies a price by a percentage — a second calculation would be a second
|
|
48
|
+
* answer to the one question a customer checks against their statement.
|
|
49
|
+
*
|
|
50
|
+
* Only a `sub_…` row can be asked. A transaction records one closed period and has no "next", so it
|
|
51
|
+
* answers `undefined` — the same "nothing to say about this purchase" the refresh path uses.
|
|
52
|
+
*/
|
|
53
|
+
export declare function readPaddlePricing(purchase: PaymentsPurchase, options: RefreshPaddleOptions): Promise<SubscriptionPricing | undefined>;
|
|
54
|
+
//# sourceMappingURL=refresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/refresh.ts"],"names":[],"mappings":"AAGA,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,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAA+B,MAAM,OAAO,CAAC;AAIlG;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,wFAAwF;AACxF,MAAM,WAAW,oBAAoB;IACnC,8BAA8B;IAC9B,WAAW,EAAE,yBAAyB,CAAC;IACvC,yCAAyC;IACzC,WAAW,EAAE,iBAAiB,CAAC;IAC/B,oEAAoE;IACpE,GAAG,EAAE,IAAI,CAAC;IACV,wDAAwD;IACxD,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,oFAAoF;AACpF,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CA2B3C;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAoC1C"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { paddleHttpFetch, paddleJson } from "./api.js";
|
|
2
|
+
import { currencyOf, minorAmount, subscriptionEvent, transactionEvent } from "./objects.js";
|
|
3
|
+
import { readSubscription, readTransaction } from "./read.js";
|
|
4
|
+
//#region src/rails/paddle/refresh.ts
|
|
5
|
+
/** Re-read one purchase, or `undefined` when Paddle has nothing to say about it. */
|
|
6
|
+
async function refreshPaddlePurchase(purchase, options) {
|
|
7
|
+
const read = {
|
|
8
|
+
credentials: options.credentials,
|
|
9
|
+
environment: options.environment,
|
|
10
|
+
transport: options.transport ?? paddleHttpFetch
|
|
11
|
+
};
|
|
12
|
+
const id = purchase.providerTransactionId;
|
|
13
|
+
const environment = options.environment === "production" ? "production" : "sandbox";
|
|
14
|
+
if (id.startsWith("sub_")) {
|
|
15
|
+
const subscription = await readSubscription(id, read);
|
|
16
|
+
if (subscription === void 0) return void 0;
|
|
17
|
+
return {
|
|
18
|
+
...subscriptionEvent(subscription, options.now, environment),
|
|
19
|
+
providerEventAt: options.now
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (id.startsWith("txn_")) {
|
|
23
|
+
const transaction = await readTransaction(id, read);
|
|
24
|
+
if (transaction === void 0) return void 0;
|
|
25
|
+
return {
|
|
26
|
+
...transactionEvent(transaction, options.now, environment),
|
|
27
|
+
providerEventAt: options.now
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What a Paddle subscription pays now, what it becomes, and when.
|
|
33
|
+
*
|
|
34
|
+
* Read from Paddle rather than computed. `include=next_transaction` carries what the next invoice comes
|
|
35
|
+
* to under any discount in force; `include=recurring_transaction_details` carries what it comes to at
|
|
36
|
+
* list price. Nothing here multiplies a price by a percentage — a second calculation would be a second
|
|
37
|
+
* answer to the one question a customer checks against their statement.
|
|
38
|
+
*
|
|
39
|
+
* Only a `sub_…` row can be asked. A transaction records one closed period and has no "next", so it
|
|
40
|
+
* answers `undefined` — the same "nothing to say about this purchase" the refresh path uses.
|
|
41
|
+
*/
|
|
42
|
+
async function readPaddlePricing(purchase, options) {
|
|
43
|
+
const id = purchase.providerTransactionId;
|
|
44
|
+
if (!id.startsWith("sub_")) return void 0;
|
|
45
|
+
const answer = await paddleJson(options.transport ?? paddleHttpFetch, `/subscriptions/${encodeURIComponent(id)}`, {
|
|
46
|
+
what: `subscription ${id}'s pricing`,
|
|
47
|
+
apiKey: options.credentials.apiKey,
|
|
48
|
+
environment: options.environment,
|
|
49
|
+
query: [["include", "next_transaction,recurring_transaction_details"]],
|
|
50
|
+
absentOn404: true
|
|
51
|
+
});
|
|
52
|
+
if (answer === void 0) return void 0;
|
|
53
|
+
const data = answer.data;
|
|
54
|
+
if (data === null || typeof data !== "object") return void 0;
|
|
55
|
+
const next = totalsOf(data.next_transaction);
|
|
56
|
+
const recurring = totalsOf(data.recurring_transaction_details);
|
|
57
|
+
const discount = data.discount;
|
|
58
|
+
const endsAt = typeof discount?.ends_at === "string" ? new Date(discount.ends_at) : null;
|
|
59
|
+
return {
|
|
60
|
+
currency: next.currency ?? recurring.currency,
|
|
61
|
+
currentAmountMinor: next.total ?? recurring.total,
|
|
62
|
+
listAmountMinor: recurring.total ?? next.total,
|
|
63
|
+
discountCode: null,
|
|
64
|
+
discountEndsAt: endsAt !== null && !Number.isNaN(endsAt.getTime()) ? endsAt : null
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Pull the total and its currency out of whichever include shape carried it.
|
|
69
|
+
*
|
|
70
|
+
* **The two includes are not the same shape**, and a reader that knew only one would silently answer null
|
|
71
|
+
* for the other — leaving a screen reporting no list price and a customer told nothing about the date
|
|
72
|
+
* their rate changes. `next_transaction` nests its figures under `details.totals`; `recurring_transaction
|
|
73
|
+
* _details` carries `totals` at the top. Both are checked, in that order.
|
|
74
|
+
*/
|
|
75
|
+
function totalsOf(value) {
|
|
76
|
+
if (value === null || typeof value !== "object") return {
|
|
77
|
+
total: null,
|
|
78
|
+
currency: null
|
|
79
|
+
};
|
|
80
|
+
const bagged = value;
|
|
81
|
+
const details = bagged.details;
|
|
82
|
+
const totals = (details !== null && typeof details === "object" ? details.totals : null) ?? bagged.totals ?? null;
|
|
83
|
+
if (totals === null || typeof totals !== "object") return {
|
|
84
|
+
total: null,
|
|
85
|
+
currency: null
|
|
86
|
+
};
|
|
87
|
+
const bag = totals;
|
|
88
|
+
return {
|
|
89
|
+
total: minorAmount(typeof bag.total === "string" ? bag.total : bag.grand_total),
|
|
90
|
+
currency: currencyOf(typeof bag.currency_code === "string" ? bag.currency_code : null)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { readPaddlePricing, refreshPaddlePurchase };
|