@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,350 @@
|
|
|
1
|
+
import { PaymentsProviderUnavailableError, PaymentsRailNotConfiguredError, PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
2
|
+
import { googleHttpFetch, googleJson } from "./http.js";
|
|
3
|
+
import { base64UrlEncode, pemPrivateKey } from "./jwt.js";
|
|
4
|
+
import { pauseResumesAt } from "../../data/pause.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
//#region src/rails/google/playApi.ts
|
|
7
|
+
/**
|
|
8
|
+
* The Play Developer API — the call that turns a purchase token into a state, and the mapping of Play's
|
|
9
|
+
* vocabulary into the normalized status set.
|
|
10
|
+
*
|
|
11
|
+
* This is the half of Google's rail that has no Apple equivalent. A StoreKit transaction *is* the state, signed;
|
|
12
|
+
* a Play purchase token is a pointer, so every Google projection costs a network round-trip. Two, in fact — the
|
|
13
|
+
* API is OAuth-protected, so a service-account assertion buys an access token first.
|
|
14
|
+
*
|
|
15
|
+
* ## Two statuses Play has and the other rails do not
|
|
16
|
+
*
|
|
17
|
+
* `on_hold` and `paused` are Play's own. **On hold** is a subscription whose billing retry window has run out:
|
|
18
|
+
* Google keeps trying for up to 30 days and access is withdrawn throughout, which is why `on_hold` never
|
|
19
|
+
* grants. **Paused** is a subscription the *user* suspended, usually with an `autoResumeTime` set; they will
|
|
20
|
+
* come back, and until they do they are not entitled — so that date lands on the row as `resumesAt`, and its
|
|
21
|
+
* absence is Play reporting an indefinite pause rather than this rail declining to look (`data/pause.ts`).
|
|
22
|
+
* Neither state has an Apple analog, and both would be lost by a status set built from Apple's
|
|
23
|
+
* notifications alone.
|
|
24
|
+
*
|
|
25
|
+
* ## What Play does not report, and what follows
|
|
26
|
+
*
|
|
27
|
+
* **No price.** Neither `purchases.subscriptionsv2.get` nor `purchases.products.get` returns an amount or a
|
|
28
|
+
* currency, so `amountMinor` and `currency` are null on every Google purchase. That is what those columns are
|
|
29
|
+
* nullable for. Revenue figures for the Play rail come from Google's own reporting, not from here.
|
|
30
|
+
*
|
|
31
|
+
* **No last-modified time.** So the caller supplies the event time: the notification's `eventTimeMillis` on the
|
|
32
|
+
* webhook path, and the clock on a client submission. Both are honest — a submission is a read of the current
|
|
33
|
+
* state, so treating it as the freshest fact is right — and both feed the monotonic write rule, which is why
|
|
34
|
+
* neither may be invented here.
|
|
35
|
+
*
|
|
36
|
+
* ## The environment check
|
|
37
|
+
*
|
|
38
|
+
* A test purchase is a real Play purchase made by a license-tested account, and it must never grant a
|
|
39
|
+
* production entitlement. Play marks one differently in each shape: `testPurchase` is present on a
|
|
40
|
+
* subscription, `purchaseType: 0` on a one-time product. Both are read, and anything unmarked is production —
|
|
41
|
+
* which is safe because Play only ever omits the marker on a real purchase.
|
|
42
|
+
*/
|
|
43
|
+
/** Google's OAuth token endpoint. The audience of the service-account assertion as well as its destination. */
|
|
44
|
+
const GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
45
|
+
/** The Play Developer API's base. Public, so it is pinned here rather than configured. */
|
|
46
|
+
const PLAY_API_BASE = "https://androidpublisher.googleapis.com/androidpublisher/v3";
|
|
47
|
+
/** The one OAuth scope payments asks for. Read-and-acknowledge on purchases, nothing else in the console. */
|
|
48
|
+
const PLAY_SCOPE = "https://www.googleapis.com/auth/androidpublisher";
|
|
49
|
+
/** RSASSA-PKCS1-v1_5 with SHA-256 — `RS256`, the algorithm a Google service-account assertion is signed with. */
|
|
50
|
+
const RS256 = {
|
|
51
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
52
|
+
hash: "SHA-256"
|
|
53
|
+
};
|
|
54
|
+
/** How long an assertion claims to be good for. Google's ceiling is an hour and there is no reason to ask less. */
|
|
55
|
+
const ASSERTION_LIFETIME_SECONDS = 3600;
|
|
56
|
+
/** Play's `purchaseType` for a license-test purchase. The one-time equivalent of `testPurchase`. */
|
|
57
|
+
const PLAY_PURCHASE_TYPE_TEST = 0;
|
|
58
|
+
/**
|
|
59
|
+
* Play's subscription states, mapped.
|
|
60
|
+
*
|
|
61
|
+
* Two are worth reading twice. **`CANCELED` still grants**: the user turned auto-renew off and keeps the period
|
|
62
|
+
* they paid for, which `expiresAt` ends — mapping it to anything non-granting would strip access from somebody
|
|
63
|
+
* who is still paid up. And **`PENDING` does not**: a deferred-payment purchase (cash, direct debit) has not
|
|
64
|
+
* been paid yet, so it is treated as `on_hold` — not `expired`, because it may still become active.
|
|
65
|
+
*
|
|
66
|
+
* `PENDING_PURCHASE_CANCELED` is `never_paid`: the deferred payment never arrived and never will. Deliberately
|
|
67
|
+
* not `canceled`, which grants; not `refunded`, because no money moved; and **not `expired`**, because an
|
|
68
|
+
* expired period is one we were paid for and a `grants` clause credits on it.
|
|
69
|
+
*/
|
|
70
|
+
const SUBSCRIPTION_STATES = {
|
|
71
|
+
SUBSCRIPTION_STATE_ACTIVE: "active",
|
|
72
|
+
SUBSCRIPTION_STATE_IN_GRACE_PERIOD: "in_grace",
|
|
73
|
+
SUBSCRIPTION_STATE_ON_HOLD: "on_hold",
|
|
74
|
+
SUBSCRIPTION_STATE_PAUSED: "paused",
|
|
75
|
+
SUBSCRIPTION_STATE_CANCELED: "canceled",
|
|
76
|
+
SUBSCRIPTION_STATE_EXPIRED: "expired",
|
|
77
|
+
SUBSCRIPTION_STATE_PENDING: "on_hold",
|
|
78
|
+
SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED: "never_paid"
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Play's one-time purchase states, mapped.
|
|
82
|
+
*
|
|
83
|
+
* `1` is Play's `Canceled`, and it is the trap in this table. It must **not** become the normalized `canceled`,
|
|
84
|
+
* which means "auto-renew off, still granting" — Play means the order was taken back. It is mapped to
|
|
85
|
+
* `refunded`, which is the normalized member for "taken back", does not grant, and is the state an opt-in
|
|
86
|
+
* clawback acts on. Play cannot distinguish a refunded order from a deferred purchase that was canceled before
|
|
87
|
+
* payment, so a clawback on the latter finds nothing to debit and is refused into a recorded state — which is
|
|
88
|
+
* the designed behavior for a failed clawback rather than a defect.
|
|
89
|
+
*
|
|
90
|
+
* `2` is `Pending`: awaiting a deferred payment, so it does not grant, and `on_hold` is the member that says so
|
|
91
|
+
* without claiming the purchase is over.
|
|
92
|
+
*/
|
|
93
|
+
const PRODUCT_STATES = {
|
|
94
|
+
0: "active",
|
|
95
|
+
1: "refunded",
|
|
96
|
+
2: "on_hold"
|
|
97
|
+
};
|
|
98
|
+
/** Google's OAuth token response, narrowed to the one field that matters. */
|
|
99
|
+
const GoogleAccessToken = z.object({
|
|
100
|
+
access_token: z.string().min(1).describe("The bearer token the Play Developer API is called with."),
|
|
101
|
+
expires_in: z.number().int().optional().describe("How long it lasts, in seconds. Informational here."),
|
|
102
|
+
token_type: z.string().min(1).optional().describe("Always `Bearer` in practice.")
|
|
103
|
+
}).loose().describe("Google's OAuth 2.0 token response to a service-account assertion.");
|
|
104
|
+
/** One line item on a subscription — the product, and when its paid period ends. */
|
|
105
|
+
const PlaySubscriptionLineItem = z.object({
|
|
106
|
+
productId: z.string().min(1).describe("The subscription product id as listed in the Play Console — the SKU the catalog maps."),
|
|
107
|
+
expiryTime: z.string().min(1).optional().describe("When the paid period ends, RFC 3339. Absent on a paused or never-paid subscription."),
|
|
108
|
+
autoRenewingPlan: z.object({ autoRenewEnabled: z.boolean().optional().describe("Whether the plan will renew. Reported, never mapped.") }).loose().optional().describe("The auto-renewing plan's own state, when the line item is one.")
|
|
109
|
+
}).loose().describe("One line item of a Play subscription purchase.");
|
|
110
|
+
/**
|
|
111
|
+
* `purchases.subscriptionsv2.get`, as much of it as the projection reads. `.loose()` keeps the rest: Play adds
|
|
112
|
+
* fields, the whole response is stored for reconciliation, and a strict object would refuse a real purchase for
|
|
113
|
+
* carrying something new.
|
|
114
|
+
*/
|
|
115
|
+
const PlaySubscriptionPurchase = z.object({
|
|
116
|
+
subscriptionState: z.string().min(1).describe("Play's own state for the subscription. Mapped to a normalized status; an unknown one is refused."),
|
|
117
|
+
latestOrderId: z.string().min(1).optional().describe("The most recent order. This is the transaction identity — it changes every renewal, which is what makes each period its own purchase row."),
|
|
118
|
+
startTime: z.string().min(1).optional().describe("When the subscription began, RFC 3339."),
|
|
119
|
+
linkedPurchaseToken: z.string().min(1).optional().describe("The token this purchase replaced, on an upgrade or a resubscribe."),
|
|
120
|
+
acknowledgementState: z.string().min(1).optional().describe("Whether the app has acknowledged the purchase. Recorded, never mapped: an unacknowledged purchase is still paid, and acknowledging is the app's job through Play Billing."),
|
|
121
|
+
testPurchase: z.object({}).loose().optional().describe("Present only for a license-test purchase. Its presence is the whole environment decision for a subscription."),
|
|
122
|
+
pausedStateContext: z.object({ autoResumeTime: z.string().min(1).optional().describe("When a paused subscription resumes, RFC 3339.") }).loose().optional().describe("Present while the subscription is paused."),
|
|
123
|
+
externalAccountIdentifiers: z.object({
|
|
124
|
+
obfuscatedExternalAccountId: z.string().min(1).optional().describe("The identifier the app set at purchase time — the only hook back to the subject that bought."),
|
|
125
|
+
obfuscatedExternalProfileId: z.string().min(1).optional().describe("The profile identifier, if the app set one.")
|
|
126
|
+
}).loose().optional().describe("The identifiers the app attached to the purchase."),
|
|
127
|
+
lineItems: z.array(PlaySubscriptionLineItem).min(1).describe("What the subscription includes. The first line item is the product this purchase is projected as.")
|
|
128
|
+
}).loose().describe("Play's SubscriptionPurchaseV2, as much of it as the projection reads.");
|
|
129
|
+
/** `purchases.products.get`, as much of it as the projection reads. `.loose()` for the same reason. */
|
|
130
|
+
const PlayProductPurchase = z.object({
|
|
131
|
+
purchaseState: z.number().int().describe("0 purchased, 1 canceled, 2 pending. Mapped to a normalized status; an unknown one is refused."),
|
|
132
|
+
purchaseTimeMillis: z.string().regex(/^\d+$/).optional().describe("When the purchase was made, as a decimal string of milliseconds since the epoch."),
|
|
133
|
+
orderId: z.string().min(1).optional().describe("The order. This is the transaction identity for a one-time purchase. Absent until it is paid."),
|
|
134
|
+
purchaseType: z.number().int().optional().describe("0 test, 1 promo, 2 rewarded — and absent for an ordinary paid purchase. Only 0 makes it a sandbox purchase."),
|
|
135
|
+
acknowledgementState: z.number().int().optional().describe("0 unacknowledged, 1 acknowledged. Recorded, never mapped — the app owns acknowledging."),
|
|
136
|
+
consumptionState: z.number().int().optional().describe("0 yet to be consumed, 1 consumed. Recorded only."),
|
|
137
|
+
quantity: z.number().int().optional().describe("How many were bought. One unless the product allows more."),
|
|
138
|
+
obfuscatedExternalAccountId: z.string().min(1).optional().describe("The identifier the app set at purchase time — the only hook back to the subject that bought."),
|
|
139
|
+
regionCode: z.string().min(1).optional().describe("Where the purchase was made. Recorded only.")
|
|
140
|
+
}).loose().describe("Play's ProductPurchase, as much of it as the projection reads.");
|
|
141
|
+
/**
|
|
142
|
+
* Mint an access token for the Play Developer API from the service-account key.
|
|
143
|
+
*
|
|
144
|
+
* The JWT-bearer grant: we sign an assertion saying who we are and what we want, Google hands back a token. No
|
|
145
|
+
* refresh token, no user consent, nothing stored — which is why the credential bundle holds a private key
|
|
146
|
+
* rather than an OAuth client.
|
|
147
|
+
*/
|
|
148
|
+
async function mintPlayAccessToken(credentials, options) {
|
|
149
|
+
let key;
|
|
150
|
+
try {
|
|
151
|
+
key = await crypto.subtle.importKey("pkcs8", pemPrivateKey(credentials.privateKey), RS256, false, ["sign"]);
|
|
152
|
+
} catch (cause) {
|
|
153
|
+
if (cause instanceof PaymentsRailNotConfiguredError) throw cause;
|
|
154
|
+
throw new PaymentsRailNotConfiguredError({ detail: "Google: the service-account private key could not be imported as a PKCS#8 RSA key." }, { cause });
|
|
155
|
+
}
|
|
156
|
+
const issuedAt = Math.floor(options.now.getTime() / 1e3);
|
|
157
|
+
const encoder = new TextEncoder();
|
|
158
|
+
const head = base64UrlEncode(encoder.encode(JSON.stringify({
|
|
159
|
+
alg: "RS256",
|
|
160
|
+
typ: "JWT"
|
|
161
|
+
})));
|
|
162
|
+
const body = base64UrlEncode(encoder.encode(JSON.stringify({
|
|
163
|
+
iss: credentials.serviceAccountEmail,
|
|
164
|
+
scope: PLAY_SCOPE,
|
|
165
|
+
aud: GOOGLE_TOKEN_URL,
|
|
166
|
+
iat: issuedAt,
|
|
167
|
+
exp: issuedAt + ASSERTION_LIFETIME_SECONDS
|
|
168
|
+
})));
|
|
169
|
+
const signature = new Uint8Array(await crypto.subtle.sign(RS256.name, key, encoder.encode(`${head}.${body}`)));
|
|
170
|
+
const assertion = `${head}.${body}.${base64UrlEncode(signature)}`;
|
|
171
|
+
const answered = await googleJson(options.transport ?? googleHttpFetch, GOOGLE_TOKEN_URL, {
|
|
172
|
+
what: "an access token for the Play Developer API",
|
|
173
|
+
method: "POST",
|
|
174
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
175
|
+
body: new URLSearchParams({
|
|
176
|
+
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
177
|
+
assertion
|
|
178
|
+
}).toString()
|
|
179
|
+
});
|
|
180
|
+
const parsed = GoogleAccessToken.safeParse(answered);
|
|
181
|
+
if (!parsed.success) throw new PaymentsProviderUnavailableError({ detail: "Google: the token endpoint answered without an access token." });
|
|
182
|
+
return parsed.data.access_token;
|
|
183
|
+
}
|
|
184
|
+
/** The access token for one lookup: the caller's, or a freshly minted one. */
|
|
185
|
+
async function bearer(options) {
|
|
186
|
+
return options.accessToken ?? await mintPlayAccessToken(options.credentials, options);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The current state of a subscription purchase token, or `undefined` when Play has no subscription under it.
|
|
190
|
+
*
|
|
191
|
+
* `undefined` is how a one-time purchase identifies itself: Play has no "what kind of purchase is this" call, so
|
|
192
|
+
* the subscription endpoint's 404 is the answer. That is why this is the probe and the product lookup is the
|
|
193
|
+
* fallback — the subscription call takes a token alone, while the product call needs a product id we would
|
|
194
|
+
* otherwise have to take on a client's word.
|
|
195
|
+
*/
|
|
196
|
+
async function fetchPlaySubscription(purchaseToken, options) {
|
|
197
|
+
const url = `${PLAY_API_BASE}/applications/${encodeURIComponent(options.credentials.packageName)}/purchases/subscriptionsv2/tokens/${encodeURIComponent(purchaseToken)}`;
|
|
198
|
+
const answered = await googleJson(options.transport ?? googleHttpFetch, url, {
|
|
199
|
+
what: "the subscription purchase",
|
|
200
|
+
headers: { authorization: `Bearer ${await bearer(options)}` },
|
|
201
|
+
absentOn404: true
|
|
202
|
+
});
|
|
203
|
+
if (answered === void 0) return void 0;
|
|
204
|
+
return parseOrRefuse(PlaySubscriptionPurchase, answered, "SubscriptionPurchaseV2");
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* The current state of a one-time purchase token under one product id, or `undefined` when Play has none.
|
|
208
|
+
*
|
|
209
|
+
* The product id is part of the URL, which is what makes a client-declared one safe to use: Play answers 404
|
|
210
|
+
* when the token does not belong to that product, so presenting a cheap token under an expensive SKU fails at
|
|
211
|
+
* Google rather than being believed here.
|
|
212
|
+
*/
|
|
213
|
+
async function fetchPlayProduct(productId, purchaseToken, options) {
|
|
214
|
+
const url = `${PLAY_API_BASE}/applications/${encodeURIComponent(options.credentials.packageName)}/purchases/products/${encodeURIComponent(productId)}/tokens/${encodeURIComponent(purchaseToken)}`;
|
|
215
|
+
const answered = await googleJson(options.transport ?? googleHttpFetch, url, {
|
|
216
|
+
what: "the one-time purchase",
|
|
217
|
+
headers: { authorization: `Bearer ${await bearer(options)}` },
|
|
218
|
+
absentOn404: true
|
|
219
|
+
});
|
|
220
|
+
if (answered === void 0) return void 0;
|
|
221
|
+
return parseOrRefuse(PlayProductPurchase, answered, "ProductPurchase");
|
|
222
|
+
}
|
|
223
|
+
/** The normalized status for a Play subscription state. An unmapped state is refused, never granted. */
|
|
224
|
+
function playSubscriptionStatus(state) {
|
|
225
|
+
const status = SUBSCRIPTION_STATES[state];
|
|
226
|
+
if (status === void 0) throw new PaymentsVerificationFailedError({ detail: `Google: subscription state "${state}" is not one this build maps. The purchase was left as it stood.` });
|
|
227
|
+
return status;
|
|
228
|
+
}
|
|
229
|
+
/** The normalized status for a Play one-time purchase state. An unmapped state is refused, never granted. */
|
|
230
|
+
function playProductStatus(purchaseState) {
|
|
231
|
+
const status = PRODUCT_STATES[purchaseState];
|
|
232
|
+
if (status === void 0) throw new PaymentsVerificationFailedError({ detail: `Google: purchase state ${purchaseState} is not one this build maps. The purchase was left as it stood.` });
|
|
233
|
+
return status;
|
|
234
|
+
}
|
|
235
|
+
/** One Play subscription purchase, normalized. */
|
|
236
|
+
function playSubscriptionEvent(purchase, context) {
|
|
237
|
+
const item = purchase.lineItems[0];
|
|
238
|
+
const status = context.statusOverride ?? playSubscriptionStatus(purchase.subscriptionState);
|
|
239
|
+
const expiresAt = item.expiryTime === void 0 ? null : timestamp(item.expiryTime, "the expiry time");
|
|
240
|
+
return {
|
|
241
|
+
event: {
|
|
242
|
+
rail: "google",
|
|
243
|
+
providerTransactionId: purchase.latestOrderId ?? context.purchaseToken,
|
|
244
|
+
providerProductId: item.productId,
|
|
245
|
+
status,
|
|
246
|
+
environment: subscriptionEnvironment(purchase),
|
|
247
|
+
purchasedAt: purchase.startTime === void 0 ? context.eventAt : timestamp(purchase.startTime, "the start time"),
|
|
248
|
+
expiresAt,
|
|
249
|
+
revokedAt: status === "revoked" || status === "refunded" ? context.eventAt : null,
|
|
250
|
+
resumesAt: pauseResumesAt({
|
|
251
|
+
rail: "google",
|
|
252
|
+
status,
|
|
253
|
+
reported: purchase.pausedStateContext?.autoResumeTime
|
|
254
|
+
}),
|
|
255
|
+
originalTransactionId: context.purchaseToken,
|
|
256
|
+
amountMinor: null,
|
|
257
|
+
currency: null,
|
|
258
|
+
providerEventAt: context.eventAt,
|
|
259
|
+
payload: purchase
|
|
260
|
+
},
|
|
261
|
+
providerAccountId: purchase.externalAccountIdentifiers?.obfuscatedExternalAccountId ?? null
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/** One Play one-time purchase, normalized. */
|
|
265
|
+
function playProductEvent(purchase, context) {
|
|
266
|
+
const status = context.statusOverride ?? playProductStatus(purchase.purchaseState);
|
|
267
|
+
return {
|
|
268
|
+
event: {
|
|
269
|
+
rail: "google",
|
|
270
|
+
providerTransactionId: purchase.orderId ?? context.purchaseToken,
|
|
271
|
+
providerProductId: context.productId,
|
|
272
|
+
status,
|
|
273
|
+
environment: purchase.purchaseType === PLAY_PURCHASE_TYPE_TEST ? "sandbox" : "production",
|
|
274
|
+
purchasedAt: purchase.purchaseTimeMillis === void 0 ? context.eventAt : new Date(Number(purchase.purchaseTimeMillis)),
|
|
275
|
+
expiresAt: null,
|
|
276
|
+
revokedAt: status === "revoked" || status === "refunded" ? context.eventAt : null,
|
|
277
|
+
originalTransactionId: null,
|
|
278
|
+
amountMinor: null,
|
|
279
|
+
currency: null,
|
|
280
|
+
providerEventAt: context.eventAt,
|
|
281
|
+
payload: purchase
|
|
282
|
+
},
|
|
283
|
+
providerAccountId: purchase.obfuscatedExternalAccountId ?? null
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Resolve one notification pointer to a state, or `undefined` when Play has no purchase under that token.
|
|
288
|
+
*
|
|
289
|
+
* The pointer says which lookup to make, so there is no probing on this path — the notification already told us
|
|
290
|
+
* whether it concerns a subscription or a one-time product.
|
|
291
|
+
*/
|
|
292
|
+
async function resolvePlayPointer(pointer, options) {
|
|
293
|
+
const context = {
|
|
294
|
+
purchaseToken: pointer.purchaseToken,
|
|
295
|
+
eventAt: pointer.eventAt,
|
|
296
|
+
statusOverride: pointer.statusOverride
|
|
297
|
+
};
|
|
298
|
+
if (pointer.kind === "subscription") {
|
|
299
|
+
const purchase = await fetchPlaySubscription(pointer.purchaseToken, options);
|
|
300
|
+
return purchase === void 0 ? void 0 : playSubscriptionEvent(purchase, context);
|
|
301
|
+
}
|
|
302
|
+
if (pointer.productId === null) return void 0;
|
|
303
|
+
const purchase = await fetchPlayProduct(pointer.productId, pointer.purchaseToken, options);
|
|
304
|
+
return purchase === void 0 ? void 0 : playProductEvent(purchase, {
|
|
305
|
+
...context,
|
|
306
|
+
productId: pointer.productId
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Re-read one stored purchase at Play, normalized — the reconciliation path for this rail.
|
|
311
|
+
*
|
|
312
|
+
* **Subscriptions only, and the reason is what the row keeps.** A Play purchase is addressed by its *purchase
|
|
313
|
+
* token*, and only a subscription row stores one: `originalTransactionId` is the token, because the token is
|
|
314
|
+
* the family key every renewal shares. A one-time row is keyed on Play's order id and stores no token at all,
|
|
315
|
+
* and `purchases.products.get` takes a token — so there is no call this function could make for one. That is a
|
|
316
|
+
* real gap rather than a shortcut: a refunded one-time Play purchase reaches this deployment as a
|
|
317
|
+
* voided-purchase notification, which is recorded with its order id and its reason, and repairing it needs the
|
|
318
|
+
* token recovered from somewhere the row does not have it.
|
|
319
|
+
*
|
|
320
|
+
* A subscription that has never been paid has no order id yet and is keyed on its own token, so
|
|
321
|
+
* `originalTransactionId` is null and `providerTransactionId` is the token. Both spellings resolve.
|
|
322
|
+
*/
|
|
323
|
+
async function refreshPlayPurchase(purchase, options) {
|
|
324
|
+
if (purchase.type !== "subscription") return void 0;
|
|
325
|
+
const purchaseToken = purchase.originalTransactionId ?? purchase.providerTransactionId;
|
|
326
|
+
const found = await fetchPlaySubscription(purchaseToken, options);
|
|
327
|
+
if (found === void 0) return void 0;
|
|
328
|
+
return playSubscriptionEvent(found, {
|
|
329
|
+
purchaseToken,
|
|
330
|
+
eventAt: options.now
|
|
331
|
+
}).event;
|
|
332
|
+
}
|
|
333
|
+
/** A subscription's environment. `testPurchase` present is the whole decision; absent means a real purchase. */
|
|
334
|
+
function subscriptionEnvironment(purchase) {
|
|
335
|
+
return purchase.testPurchase === void 0 ? "production" : "sandbox";
|
|
336
|
+
}
|
|
337
|
+
/** One RFC 3339 timestamp from Play. An unreadable one is refused rather than becoming an Invalid Date. */
|
|
338
|
+
function timestamp(value, what) {
|
|
339
|
+
const parsed = new Date(value);
|
|
340
|
+
if (Number.isNaN(parsed.getTime())) throw new PaymentsVerificationFailedError({ detail: `Google: ${what} "${value}" is not a timestamp.` });
|
|
341
|
+
return parsed;
|
|
342
|
+
}
|
|
343
|
+
/** Parse a Play response, or refuse it. Never echoes the body: the response quotes the purchase token. */
|
|
344
|
+
function parseOrRefuse(schema, value, what) {
|
|
345
|
+
const parsed = schema.safeParse(value);
|
|
346
|
+
if (!parsed.success) throw new PaymentsVerificationFailedError({ detail: `Google: the answer is not a ${what} — ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "<root>"}:${issue.code}`).join(", ")}.` });
|
|
347
|
+
return parsed.data;
|
|
348
|
+
}
|
|
349
|
+
//#endregion
|
|
350
|
+
export { GOOGLE_TOKEN_URL, PLAY_API_BASE, PLAY_SCOPE, PlayProductPurchase, PlaySubscriptionPurchase, fetchPlayProduct, fetchPlaySubscription, mintPlayAccessToken, playProductEvent, playProductStatus, playSubscriptionEvent, playSubscriptionStatus, refreshPlayPurchase, resolvePlayPointer };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { PaymentsGoogleCredentials } from "../../secret/registry";
|
|
2
|
+
import type { PaymentsRailProvider } from "../contract";
|
|
3
|
+
import type { GoogleHttpFetch } from "./http";
|
|
4
|
+
import { type GoogleJwk } from "./oidc";
|
|
5
|
+
/**
|
|
6
|
+
* The Google Play rail as one provider object — the two halves of the contract, closed over the app's identity.
|
|
7
|
+
*
|
|
8
|
+
* Built per request from credentials the caller resolved through the secrets store, rather than reading them
|
|
9
|
+
* itself. That keeps the rail a pure function of its inputs, and it keeps the secret read at the point of need.
|
|
10
|
+
*
|
|
11
|
+
* ## Three checks, in this order, and each covers what the one before it cannot
|
|
12
|
+
*
|
|
13
|
+
* 1. **The OIDC token proves Google sent the delivery.** It arrives in the `Authorization` header rather than in
|
|
14
|
+
* the body, because a Pub/Sub push is not signed — the token is the whole proof.
|
|
15
|
+
* 2. **The audience claim proves it was minted for *this* endpoint.** Google signs these tokens for every push
|
|
16
|
+
* subscription in the world with the same keys, so the signature alone is worth nothing. See `oidc.ts`.
|
|
17
|
+
* 3. **The package name proves it concerns *this app*.** A token says who delivered it and nothing about what it
|
|
18
|
+
* is about, so without this any Play developer who can reach the endpoint could name a SKU in our catalog.
|
|
19
|
+
*
|
|
20
|
+
* ## And then a fourth call, which is Google's own doing
|
|
21
|
+
*
|
|
22
|
+
* A Real-time Developer Notification is a pointer: a purchase token and a notification type, with no state. So
|
|
23
|
+
* every projectable notification costs a Play Developer API lookup. That is the shape of Play's API rather than
|
|
24
|
+
* a choice here, and it is why an unreachable Play API is `payments/provider_unavailable` (503) — the route
|
|
25
|
+
* rethrows that so Pub/Sub redelivers, because the alternative is projecting a guess.
|
|
26
|
+
*
|
|
27
|
+
* ## One gap, recorded rather than papered over
|
|
28
|
+
*
|
|
29
|
+
* A **voided one-time purchase** cannot be resolved on this path. Play's voided-purchase notification names an
|
|
30
|
+
* order id and no product, and Play's one-time lookup takes the product id as a path segment — so there is no
|
|
31
|
+
* call this module can make that turns that token into a state. The delivery is recorded with a note carrying
|
|
32
|
+
* the order id, which is the key the purchase row is already stored under, and the reconciliation Workflow
|
|
33
|
+
* resolves it with one query. Subscription refunds have no such gap: they arrive as `SUBSCRIPTION_REVOKED` and
|
|
34
|
+
* project immediately.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* How the Google rail's trust and transport may be widened, and the only callers with a reason to.
|
|
38
|
+
*
|
|
39
|
+
* `trustedKeys` is additive, so nothing can narrow production's trust: a token whose `kid` these do not cover is
|
|
40
|
+
* still resolved against Google's published set. It exists for the tests, which mint their own key so the
|
|
41
|
+
* signature check is exercised for real, and for a local **Pub/Sub emulator**, whose tokens are signed by a key
|
|
42
|
+
* Google never saw.
|
|
43
|
+
*/
|
|
44
|
+
export interface GoogleRailOptions {
|
|
45
|
+
/** Verification keys accepted in addition to Google's published set, matched by `kid`. */
|
|
46
|
+
trustedKeys?: readonly GoogleJwk[];
|
|
47
|
+
/** The HTTP seam Google's two endpoints are reached through. Defaults to the runtime's `fetch`. */
|
|
48
|
+
transport?: GoogleHttpFetch;
|
|
49
|
+
/**
|
|
50
|
+
* A Play access token already minted, so a batch of refreshes pays for one round-trip instead of one each.
|
|
51
|
+
* Passed down by the reconciliation Workflow; absent everywhere else, where one call mints its own.
|
|
52
|
+
*/
|
|
53
|
+
accessToken?: string;
|
|
54
|
+
}
|
|
55
|
+
/** The Google Play rail. Verifies client submissions at Play, and Pub/Sub pushes on the webhook. */
|
|
56
|
+
export declare function googleRail(credentials: PaymentsGoogleCredentials, options?: GoogleRailOptions): PaymentsRailProvider;
|
|
57
|
+
//# sourceMappingURL=rail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/google/rail.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EACV,oBAAoB,EAMrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,QAAQ,CAAC;AAK/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,0FAA0F;IAC1F,WAAW,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IACnC,mGAAmG;IACnG,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAKD,oGAAoG;AACpG,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,GAAE,iBAAsB,GAC9B,oBAAoB,CA8FtB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
2
|
+
import { verifyGoogleOidcToken } from "./oidc.js";
|
|
3
|
+
import { refreshPlayPurchase, resolvePlayPointer } from "./playApi.js";
|
|
4
|
+
import { parseGoogleNotification } from "./rtdn.js";
|
|
5
|
+
import { verifyGooglePurchase } from "./verify.js";
|
|
6
|
+
//#region src/rails/google/rail.ts
|
|
7
|
+
/** The `Authorization` scheme a Pub/Sub push uses for its OIDC token. */
|
|
8
|
+
const BEARER = "bearer ";
|
|
9
|
+
/** The Google Play rail. Verifies client submissions at Play, and Pub/Sub pushes on the webhook. */
|
|
10
|
+
function googleRail(credentials, options = {}) {
|
|
11
|
+
return {
|
|
12
|
+
rail: "google",
|
|
13
|
+
async verify(receipt, context) {
|
|
14
|
+
return await verifyGooglePurchase(receipt, {
|
|
15
|
+
credentials,
|
|
16
|
+
now: context.now,
|
|
17
|
+
transport: options.transport
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
async parseNotification(delivery, context) {
|
|
21
|
+
const authorization = delivery.headers.get("authorization") ?? "";
|
|
22
|
+
if (!authorization.toLowerCase().startsWith(BEARER)) throw new PaymentsVerificationFailedError({ detail: "Google: the push carries no Authorization bearer token. Configure the Pub/Sub push subscription to authenticate with a service account." });
|
|
23
|
+
await verifyGoogleOidcToken(authorization.slice(7).trim(), {
|
|
24
|
+
audience: credentials.pubsubAudience,
|
|
25
|
+
serviceAccountEmail: credentials.serviceAccountEmail,
|
|
26
|
+
now: context.now,
|
|
27
|
+
transport: options.transport,
|
|
28
|
+
trustedKeys: options.trustedKeys
|
|
29
|
+
});
|
|
30
|
+
const parsed = parseGoogleNotification(delivery.body, { packageName: credentials.packageName });
|
|
31
|
+
if (parsed.pointer === null) return {
|
|
32
|
+
providerEventId: parsed.providerEventId,
|
|
33
|
+
payload: parsed.payload,
|
|
34
|
+
event: null,
|
|
35
|
+
providerAccountId: null,
|
|
36
|
+
voidedOrderId: parsed.voidedOrderId,
|
|
37
|
+
note: parsed.note === null ? null : { stated: parsed.note }
|
|
38
|
+
};
|
|
39
|
+
const state = await resolvePlayPointer(parsed.pointer, {
|
|
40
|
+
credentials,
|
|
41
|
+
now: context.now,
|
|
42
|
+
transport: options.transport
|
|
43
|
+
});
|
|
44
|
+
if (state === void 0) return {
|
|
45
|
+
providerEventId: parsed.providerEventId,
|
|
46
|
+
payload: parsed.payload,
|
|
47
|
+
event: null,
|
|
48
|
+
providerAccountId: null,
|
|
49
|
+
note: { read: `google: Play has no ${parsed.pointer.kind === "subscription" ? "subscription" : "one-time purchase"} under the token this notification points at.` }
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
providerEventId: parsed.providerEventId,
|
|
53
|
+
payload: parsed.payload,
|
|
54
|
+
event: state.event,
|
|
55
|
+
providerAccountId: state.providerAccountId,
|
|
56
|
+
note: null
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
async refresh(purchase, context) {
|
|
60
|
+
return await refreshPlayPurchase(purchase, {
|
|
61
|
+
credentials,
|
|
62
|
+
now: context.now,
|
|
63
|
+
transport: options.transport,
|
|
64
|
+
accessToken: options.accessToken
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { googleRail };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { PurchaseStatus } from "../../data/status";
|
|
3
|
+
/** The Pub/Sub push envelope. `.loose()` so a new envelope field never refuses a real notification. */
|
|
4
|
+
export declare const GooglePubSubPush: z.ZodObject<{
|
|
5
|
+
message: z.ZodObject<{
|
|
6
|
+
data: z.ZodString;
|
|
7
|
+
messageId: z.ZodString;
|
|
8
|
+
publishTime: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$loose>;
|
|
10
|
+
subscription: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, z.core.$loose>;
|
|
12
|
+
export type GooglePubSubPush = z.infer<typeof GooglePubSubPush>;
|
|
13
|
+
/** One Play Developer Notification. Exactly one of the four notification blocks is present. */
|
|
14
|
+
export declare const GoogleDeveloperNotification: z.ZodObject<{
|
|
15
|
+
version: z.ZodString;
|
|
16
|
+
packageName: z.ZodString;
|
|
17
|
+
eventTimeMillis: z.ZodString;
|
|
18
|
+
subscriptionNotification: z.ZodOptional<z.ZodObject<{
|
|
19
|
+
version: z.ZodString;
|
|
20
|
+
notificationType: z.ZodNumber;
|
|
21
|
+
purchaseToken: z.ZodString;
|
|
22
|
+
subscriptionId: z.ZodString;
|
|
23
|
+
}, z.core.$loose>>;
|
|
24
|
+
oneTimeProductNotification: z.ZodOptional<z.ZodObject<{
|
|
25
|
+
version: z.ZodString;
|
|
26
|
+
notificationType: z.ZodNumber;
|
|
27
|
+
purchaseToken: z.ZodString;
|
|
28
|
+
sku: z.ZodString;
|
|
29
|
+
}, z.core.$loose>>;
|
|
30
|
+
voidedPurchaseNotification: z.ZodOptional<z.ZodObject<{
|
|
31
|
+
purchaseToken: z.ZodString;
|
|
32
|
+
orderId: z.ZodString;
|
|
33
|
+
productType: z.ZodNumber;
|
|
34
|
+
refundType: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
}, z.core.$loose>>;
|
|
36
|
+
testNotification: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
version: z.ZodString;
|
|
38
|
+
}, z.core.$loose>>;
|
|
39
|
+
}, z.core.$loose>;
|
|
40
|
+
export type GoogleDeveloperNotification = z.infer<typeof GoogleDeveloperNotification>;
|
|
41
|
+
/** Which Play lookup resolves a pointer. The two take different endpoints and different path parameters. */
|
|
42
|
+
export type GoogleNotificationKind = "subscription" | "one_time";
|
|
43
|
+
/**
|
|
44
|
+
* Which purchase a notification is about. Deliberately carries no state — see the module doc.
|
|
45
|
+
*/
|
|
46
|
+
export interface GoogleNotificationPointer {
|
|
47
|
+
/** Which Play lookup resolves it. */
|
|
48
|
+
kind: GoogleNotificationKind;
|
|
49
|
+
/** The purchase token the lookup is keyed by. */
|
|
50
|
+
purchaseToken: string;
|
|
51
|
+
/** The product id, when the notification names one. Required for a one-time lookup, informational otherwise. */
|
|
52
|
+
productId: string | null;
|
|
53
|
+
/** Play's own notification type. Reported and audited; never mapped to a status. */
|
|
54
|
+
notificationType: number;
|
|
55
|
+
/**
|
|
56
|
+
* The one status the Play API cannot report and the notification can. `revoked` for a revoked subscription,
|
|
57
|
+
* which the API reports as merely expired, and null for everything else.
|
|
58
|
+
*/
|
|
59
|
+
statusOverride: PurchaseStatus | null;
|
|
60
|
+
/** Google's own event time. What the monotonic write rule compares against. */
|
|
61
|
+
eventAt: Date;
|
|
62
|
+
}
|
|
63
|
+
/** A verified, decoded notification: what to record, and what to resolve. */
|
|
64
|
+
export interface ParsedGoogleNotification {
|
|
65
|
+
/** Pub/Sub's message id — the dedupe key. */
|
|
66
|
+
providerEventId: string;
|
|
67
|
+
/** What to store on the webhook row: the decoded notification plus the envelope's own metadata. */
|
|
68
|
+
payload: Record<string, unknown>;
|
|
69
|
+
/** The app the notification concerns, already checked against ours. */
|
|
70
|
+
packageName: string;
|
|
71
|
+
/** Google's own event time. */
|
|
72
|
+
eventAt: Date;
|
|
73
|
+
/** Which purchase changed, or null when the notification concerns none. */
|
|
74
|
+
pointer: GoogleNotificationPointer | null;
|
|
75
|
+
/**
|
|
76
|
+
* Why a notification with no pointer had none, when that is worth recording. Null when there is nothing to
|
|
77
|
+
* say — a test notification needs no explanation.
|
|
78
|
+
*/
|
|
79
|
+
note: string | null;
|
|
80
|
+
/**
|
|
81
|
+
* The order a voided-purchase notification refunded, or null. Reported rather than only described, because
|
|
82
|
+
* an order id is exactly what a Google purchase's `providerTransactionId` is — so the route can find the
|
|
83
|
+
* row this refund is about even though Play offers no lookup that would.
|
|
84
|
+
*/
|
|
85
|
+
voidedOrderId: string | null;
|
|
86
|
+
}
|
|
87
|
+
/** What parsing needs: our own application id, and nothing else. */
|
|
88
|
+
export interface ParseGoogleNotificationOptions {
|
|
89
|
+
/** Our Android application id. A notification for any other app is refused. */
|
|
90
|
+
packageName: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Decode one Pub/Sub push into a pointer.
|
|
94
|
+
*
|
|
95
|
+
* Authenticity is not established here — that is `verifyGoogleOidcToken`, and it runs first. What this adds is
|
|
96
|
+
* the check a token cannot make: Google signs a push token for every Pub/Sub subscription there is, so a valid
|
|
97
|
+
* token says nothing about which app a notification concerns. Without the package check, any Play developer who
|
|
98
|
+
* can reach our endpoint can send us a SKU that happens to match our catalog.
|
|
99
|
+
*
|
|
100
|
+
* @throws {@link PaymentsInvalidReceiptError} when the body cannot be read as a Pub/Sub push carrying a
|
|
101
|
+
* Developer Notification.
|
|
102
|
+
* @throws {@link PaymentsVerificationFailedError} when it is readable and concerns another app.
|
|
103
|
+
*/
|
|
104
|
+
export declare function parseGoogleNotification(body: string, options: ParseGoogleNotificationOptions): ParsedGoogleNotification;
|
|
105
|
+
//# sourceMappingURL=rtdn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rtdn.d.ts","sourceRoot":"","sources":["../../../src/rails/google/rtdn.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AA0CxD,uGAAuG;AACvG,eAAO,MAAM,gBAAgB;;;;;;;iBAyB4B,CAAC;AAC1D,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,+FAA+F;AAC/F,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;iBAiEsD,CAAC;AAC/F,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEtF,4GAA4G;AAC5G,MAAM,MAAM,sBAAsB,GAAG,cAAc,GAAG,UAAU,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,qCAAqC;IACrC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,iDAAiD;IACjD,aAAa,EAAE,MAAM,CAAC;IACtB,gHAAgH;IAChH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,oFAAoF;IACpF,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,+EAA+E;IAC/E,OAAO,EAAE,IAAI,CAAC;CACf;AAED,6EAA6E;AAC7E,MAAM,WAAW,wBAAwB;IACvC,6CAA6C;IAC7C,eAAe,EAAE,MAAM,CAAC;IACxB,mGAAmG;IACnG,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,OAAO,EAAE,IAAI,CAAC;IACd,2EAA2E;IAC3E,OAAO,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAC1C;;;OAGG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB;;;;OAIG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,oEAAoE;AACpE,MAAM,WAAW,8BAA8B;IAC7C,+EAA+E;IAC/E,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,8BAA8B,GACtC,wBAAwB,CA0G1B"}
|