@owlmeans/server-payment 0.1.18-rc.8 → 0.1.18
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/README.md +157 -26
- package/agent-meta/manifest.json +30 -4
- package/agent-meta/skills/server-payment/SKILL.md +613 -54
- package/agent-meta/skills/server-payment/parts/reference.md +174 -0
- package/build/access/types.d.ts +46 -0
- package/build/access/types.d.ts.map +1 -0
- package/build/access/types.js +2 -0
- package/build/access/types.js.map +1 -0
- package/build/access.d.ts +6 -0
- package/build/access.d.ts.map +1 -0
- package/build/access.js +45 -0
- package/build/access.js.map +1 -0
- package/build/actions/index.d.ts +1 -0
- package/build/actions/index.d.ts.map +1 -1
- package/build/actions/index.js +1 -0
- package/build/actions/index.js.map +1 -1
- package/build/actions/resync-subscriptions.d.ts +3 -0
- package/build/actions/resync-subscriptions.d.ts.map +1 -0
- package/build/actions/resync-subscriptions.js +7 -0
- package/build/actions/resync-subscriptions.js.map +1 -0
- package/build/actions/resync.d.ts +6 -1
- package/build/actions/resync.d.ts.map +1 -1
- package/build/actions/resync.js +15 -5
- package/build/actions/resync.js.map +1 -1
- package/build/actions/webhook.d.ts +2 -1
- package/build/actions/webhook.d.ts.map +1 -1
- package/build/actions/webhook.js +10 -4
- package/build/actions/webhook.js.map +1 -1
- package/build/bootstrap/types.d.ts +16 -0
- package/build/bootstrap/types.d.ts.map +1 -0
- package/build/bootstrap/types.js +2 -0
- package/build/bootstrap/types.js.map +1 -0
- package/build/bootstrap.d.ts +6 -0
- package/build/bootstrap.d.ts.map +1 -0
- package/build/bootstrap.js +26 -0
- package/build/bootstrap.js.map +1 -0
- package/build/catalogue/types.d.ts +38 -0
- package/build/catalogue/types.d.ts.map +1 -0
- package/build/catalogue/types.js +2 -0
- package/build/catalogue/types.js.map +1 -0
- package/build/catalogue.d.ts +6 -0
- package/build/catalogue.d.ts.map +1 -0
- package/build/catalogue.js +110 -0
- package/build/catalogue.js.map +1 -0
- package/build/commit/types.d.ts +22 -0
- package/build/commit/types.d.ts.map +1 -0
- package/build/commit/types.js +2 -0
- package/build/commit/types.js.map +1 -0
- package/build/commit.d.ts +6 -0
- package/build/commit.d.ts.map +1 -0
- package/build/commit.js +125 -0
- package/build/commit.js.map +1 -0
- package/build/config.d.ts +44 -5
- package/build/config.d.ts.map +1 -1
- package/build/config.js +216 -10
- package/build/config.js.map +1 -1
- package/build/consts.d.ts +74 -16
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +86 -23
- package/build/consts.js.map +1 -1
- package/build/consts.local.d.ts +94 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +44 -0
- package/build/consts.local.js.map +1 -0
- package/build/consumer/cancellation/types.d.ts +11 -0
- package/build/consumer/cancellation/types.d.ts.map +1 -0
- package/build/consumer/cancellation/types.js +2 -0
- package/build/consumer/cancellation/types.js.map +1 -0
- package/build/consumer/cancellation.d.ts +6 -0
- package/build/consumer/cancellation.d.ts.map +1 -0
- package/build/consumer/cancellation.js +33 -0
- package/build/consumer/cancellation.js.map +1 -0
- package/build/consumer/capture/types.d.ts +50 -0
- package/build/consumer/capture/types.d.ts.map +1 -0
- package/build/consumer/capture/types.js +2 -0
- package/build/consumer/capture/types.js.map +1 -0
- package/build/consumer/capture.d.ts +6 -0
- package/build/consumer/capture.d.ts.map +1 -0
- package/build/consumer/capture.js +284 -0
- package/build/consumer/capture.js.map +1 -0
- package/build/consumer/consts.local.d.ts +10 -0
- package/build/consumer/consts.local.d.ts.map +1 -0
- package/build/consumer/consts.local.js +11 -0
- package/build/consumer/consts.local.js.map +1 -0
- package/build/consumer/format/types.d.ts +30 -0
- package/build/consumer/format/types.d.ts.map +1 -0
- package/build/consumer/format/types.js +2 -0
- package/build/consumer/format/types.js.map +1 -0
- package/build/consumer/format.d.ts +4 -0
- package/build/consumer/format.d.ts.map +1 -0
- package/build/consumer/format.js +73 -0
- package/build/consumer/format.js.map +1 -0
- package/build/consumer/handlers.d.ts +21 -0
- package/build/consumer/handlers.d.ts.map +1 -0
- package/build/consumer/handlers.js +174 -0
- package/build/consumer/handlers.js.map +1 -0
- package/build/consumer/index.d.ts +10 -0
- package/build/consumer/index.d.ts.map +1 -0
- package/build/consumer/index.js +6 -0
- package/build/consumer/index.js.map +1 -0
- package/build/consumer/mail/types.d.ts +29 -0
- package/build/consumer/mail/types.d.ts.map +1 -0
- package/build/consumer/mail/types.js +2 -0
- package/build/consumer/mail/types.js.map +1 -0
- package/build/consumer/mail.d.ts +6 -0
- package/build/consumer/mail.d.ts.map +1 -0
- package/build/consumer/mail.js +313 -0
- package/build/consumer/mail.js.map +1 -0
- package/build/consumer/observers/types.d.ts +15 -0
- package/build/consumer/observers/types.d.ts.map +1 -0
- package/build/consumer/observers/types.js +2 -0
- package/build/consumer/observers/types.js.map +1 -0
- package/build/consumer/observers.d.ts +6 -0
- package/build/consumer/observers.d.ts.map +1 -0
- package/build/consumer/observers.js +74 -0
- package/build/consumer/observers.js.map +1 -0
- package/build/consumer/origin/types.d.ts +17 -0
- package/build/consumer/origin/types.d.ts.map +1 -0
- package/build/consumer/origin/types.js +2 -0
- package/build/consumer/origin/types.js.map +1 -0
- package/build/consumer/origin.d.ts +8 -0
- package/build/consumer/origin.d.ts.map +1 -0
- package/build/consumer/origin.js +43 -0
- package/build/consumer/origin.js.map +1 -0
- package/build/consumer/reconcile/types.d.ts +13 -0
- package/build/consumer/reconcile/types.d.ts.map +1 -0
- package/build/consumer/reconcile/types.js +2 -0
- package/build/consumer/reconcile/types.js.map +1 -0
- package/build/consumer/reconcile.d.ts +5 -0
- package/build/consumer/reconcile.d.ts.map +1 -0
- package/build/consumer/reconcile.js +320 -0
- package/build/consumer/reconcile.js.map +1 -0
- package/build/consumer/records/types.d.ts +66 -0
- package/build/consumer/records/types.d.ts.map +1 -0
- package/build/consumer/records/types.js +2 -0
- package/build/consumer/records/types.js.map +1 -0
- package/build/consumer/records.d.ts +6 -0
- package/build/consumer/records.d.ts.map +1 -0
- package/build/consumer/records.js +243 -0
- package/build/consumer/records.js.map +1 -0
- package/build/consumer/service.d.ts +28 -0
- package/build/consumer/service.d.ts.map +1 -0
- package/build/consumer/service.js +706 -0
- package/build/consumer/service.js.map +1 -0
- package/build/consumer/types.d.ts +84 -0
- package/build/consumer/types.d.ts.map +1 -0
- package/build/consumer/types.js +2 -0
- package/build/consumer/types.js.map +1 -0
- package/build/consumer/types.local.d.ts +26 -0
- package/build/consumer/types.local.d.ts.map +1 -0
- package/build/consumer/types.local.js +2 -0
- package/build/consumer/types.local.js.map +1 -0
- package/build/consumer/withdrawal/types.d.ts +36 -0
- package/build/consumer/withdrawal/types.d.ts.map +1 -0
- package/build/consumer/withdrawal/types.js +2 -0
- package/build/consumer/withdrawal/types.js.map +1 -0
- package/build/consumer/withdrawal.d.ts +6 -0
- package/build/consumer/withdrawal.d.ts.map +1 -0
- package/build/consumer/withdrawal.js +237 -0
- package/build/consumer/withdrawal.js.map +1 -0
- package/build/entitlement.d.ts +4 -0
- package/build/entitlement.d.ts.map +1 -0
- package/build/entitlement.js +72 -0
- package/build/entitlement.js.map +1 -0
- package/build/entrypoints.d.ts +19 -2
- package/build/entrypoints.d.ts.map +1 -1
- package/build/entrypoints.js +16 -4
- package/build/entrypoints.js.map +1 -1
- package/build/gate/request.d.ts +4 -0
- package/build/gate/request.d.ts.map +1 -0
- package/build/gate/request.js +17 -0
- package/build/gate/request.js.map +1 -0
- package/build/gate/types.d.ts +15 -0
- package/build/gate/types.d.ts.map +1 -0
- package/build/gate/types.js +2 -0
- package/build/gate/types.js.map +1 -0
- package/build/gate.d.ts +13 -9
- package/build/gate.d.ts.map +1 -1
- package/build/gate.js +36 -21
- package/build/gate.js.map +1 -1
- package/build/index.d.ts +50 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +29 -3
- package/build/index.js.map +1 -1
- package/build/limit.d.ts +11 -0
- package/build/limit.d.ts.map +1 -0
- package/build/limit.js +48 -0
- package/build/limit.js.map +1 -0
- package/build/log.d.ts +3 -0
- package/build/log.d.ts.map +1 -0
- package/build/log.js +4 -0
- package/build/log.js.map +1 -0
- package/build/models/declarations/types.d.ts +22 -0
- package/build/models/declarations/types.d.ts.map +1 -0
- package/build/models/declarations/types.js +2 -0
- package/build/models/declarations/types.js.map +1 -0
- package/build/models/declarations.d.ts +4 -0
- package/build/models/declarations.d.ts.map +1 -0
- package/build/models/declarations.js +26 -0
- package/build/models/declarations.js.map +1 -0
- package/build/models/purchase/types.d.ts +13 -0
- package/build/models/purchase/types.d.ts.map +1 -0
- package/build/models/purchase/types.js +2 -0
- package/build/models/purchase/types.js.map +1 -0
- package/build/models/purchase.d.ts +4 -0
- package/build/models/purchase.d.ts.map +1 -0
- package/build/models/purchase.js +37 -0
- package/build/models/purchase.js.map +1 -0
- package/build/observer.d.ts +9 -0
- package/build/observer.d.ts.map +1 -1
- package/build/observer.js +38 -12
- package/build/observer.js.map +1 -1
- package/build/plan/types.d.ts +21 -0
- package/build/plan/types.d.ts.map +1 -0
- package/build/plan/types.js +2 -0
- package/build/plan/types.js.map +1 -0
- package/build/plan.d.ts +7 -0
- package/build/plan.d.ts.map +1 -0
- package/build/plan.js +29 -0
- package/build/plan.js.map +1 -0
- package/build/plugins/checkout-plugins/types.d.ts +25 -0
- package/build/plugins/checkout-plugins/types.d.ts.map +1 -0
- package/build/plugins/checkout-plugins/types.js +2 -0
- package/build/plugins/checkout-plugins/types.js.map +1 -0
- package/build/plugins/checkout-plugins.d.ts +12 -0
- package/build/plugins/checkout-plugins.d.ts.map +1 -0
- package/build/plugins/checkout-plugins.js +72 -0
- package/build/plugins/checkout-plugins.js.map +1 -0
- package/build/plugins/checkout-policy/types.d.ts +18 -0
- package/build/plugins/checkout-policy/types.d.ts.map +1 -0
- package/build/plugins/checkout-policy/types.js +2 -0
- package/build/plugins/checkout-policy/types.js.map +1 -0
- package/build/plugins/checkout-policy.d.ts +4 -0
- package/build/plugins/checkout-policy.d.ts.map +1 -0
- package/build/plugins/checkout-policy.js +26 -0
- package/build/plugins/checkout-policy.js.map +1 -0
- package/build/plugins/checkout-registry/types.d.ts +7 -0
- package/build/plugins/checkout-registry/types.d.ts.map +1 -0
- package/build/plugins/checkout-registry/types.js +2 -0
- package/build/plugins/checkout-registry/types.js.map +1 -0
- package/build/plugins/checkout-registry.d.ts +8 -0
- package/build/plugins/checkout-registry.d.ts.map +1 -0
- package/build/plugins/checkout-registry.js +21 -0
- package/build/plugins/checkout-registry.js.map +1 -0
- package/build/plugins/consts.local.d.ts +13 -0
- package/build/plugins/consts.local.d.ts.map +1 -0
- package/build/plugins/consts.local.js +22 -0
- package/build/plugins/consts.local.js.map +1 -0
- package/build/plugins/customer-lock/types.d.ts +6 -0
- package/build/plugins/customer-lock/types.d.ts.map +1 -0
- package/build/plugins/customer-lock/types.js +2 -0
- package/build/plugins/customer-lock/types.js.map +1 -0
- package/build/plugins/customer-lock.d.ts +5 -0
- package/build/plugins/customer-lock.d.ts.map +1 -0
- package/build/plugins/customer-lock.js +22 -0
- package/build/plugins/customer-lock.js.map +1 -0
- package/build/plugins/estimate/cache.d.ts +4 -0
- package/build/plugins/estimate/cache.d.ts.map +1 -0
- package/build/plugins/estimate/cache.js +7 -0
- package/build/plugins/estimate/cache.js.map +1 -0
- package/build/plugins/estimate/types.d.ts +27 -0
- package/build/plugins/estimate/types.d.ts.map +1 -0
- package/build/plugins/estimate/types.js +2 -0
- package/build/plugins/estimate/types.js.map +1 -0
- package/build/plugins/estimate.d.ts +6 -0
- package/build/plugins/estimate.d.ts.map +1 -0
- package/build/plugins/estimate.js +271 -0
- package/build/plugins/estimate.js.map +1 -0
- package/build/plugins/events/types.d.ts +12 -0
- package/build/plugins/events/types.d.ts.map +1 -0
- package/build/plugins/events/types.js +2 -0
- package/build/plugins/events/types.js.map +1 -0
- package/build/plugins/events.d.ts +6 -13
- package/build/plugins/events.d.ts.map +1 -1
- package/build/plugins/events.js +441 -144
- package/build/plugins/events.js.map +1 -1
- package/build/plugins/fx/types.d.ts +33 -0
- package/build/plugins/fx/types.d.ts.map +1 -0
- package/build/plugins/fx/types.js +2 -0
- package/build/plugins/fx/types.js.map +1 -0
- package/build/plugins/fx.d.ts +6 -0
- package/build/plugins/fx.d.ts.map +1 -0
- package/build/plugins/fx.js +83 -0
- package/build/plugins/fx.js.map +1 -0
- package/build/plugins/portal/types.d.ts +44 -0
- package/build/plugins/portal/types.d.ts.map +1 -0
- package/build/plugins/portal/types.js +2 -0
- package/build/plugins/portal/types.js.map +1 -0
- package/build/plugins/portal.d.ts +6 -0
- package/build/plugins/portal.d.ts.map +1 -0
- package/build/plugins/portal.js +255 -0
- package/build/plugins/portal.js.map +1 -0
- package/build/plugins/refunds/types.d.ts +35 -0
- package/build/plugins/refunds/types.d.ts.map +1 -0
- package/build/plugins/refunds/types.js +2 -0
- package/build/plugins/refunds/types.js.map +1 -0
- package/build/plugins/refunds.d.ts +6 -0
- package/build/plugins/refunds.d.ts.map +1 -0
- package/build/plugins/refunds.js +81 -0
- package/build/plugins/refunds.js.map +1 -0
- package/build/plugins/session/types.d.ts +32 -0
- package/build/plugins/session/types.d.ts.map +1 -0
- package/build/plugins/session/types.js +2 -0
- package/build/plugins/session/types.js.map +1 -0
- package/build/plugins/session.d.ts +4 -0
- package/build/plugins/session.d.ts.map +1 -0
- package/build/plugins/session.js +58 -0
- package/build/plugins/session.js.map +1 -0
- package/build/plugins/status.d.ts +8 -0
- package/build/plugins/status.d.ts.map +1 -0
- package/build/plugins/status.js +21 -0
- package/build/plugins/status.js.map +1 -0
- package/build/plugins/stripe/types.d.ts +20 -0
- package/build/plugins/stripe/types.d.ts.map +1 -0
- package/build/plugins/stripe/types.js +2 -0
- package/build/plugins/stripe/types.js.map +1 -0
- package/build/plugins/stripe.d.ts +5 -13
- package/build/plugins/stripe.d.ts.map +1 -1
- package/build/plugins/stripe.js +481 -129
- package/build/plugins/stripe.js.map +1 -1
- package/build/plugins/subscriptions/types.d.ts +41 -0
- package/build/plugins/subscriptions/types.d.ts.map +1 -0
- package/build/plugins/subscriptions/types.js +2 -0
- package/build/plugins/subscriptions/types.js.map +1 -0
- package/build/plugins/subscriptions.d.ts +6 -0
- package/build/plugins/subscriptions.d.ts.map +1 -0
- package/build/plugins/subscriptions.js +169 -0
- package/build/plugins/subscriptions.js.map +1 -0
- package/build/plugins/types.d.ts +7 -0
- package/build/plugins/types.d.ts.map +1 -0
- package/build/plugins/types.js +2 -0
- package/build/plugins/types.js.map +1 -0
- package/build/plugins/types.local.d.ts +75 -0
- package/build/plugins/types.local.d.ts.map +1 -0
- package/build/plugins/types.local.js +2 -0
- package/build/plugins/types.local.js.map +1 -0
- package/build/plugins/webhook-manager/types.d.ts +62 -0
- package/build/plugins/webhook-manager/types.d.ts.map +1 -0
- package/build/plugins/webhook-manager/types.js +2 -0
- package/build/plugins/webhook-manager/types.js.map +1 -0
- package/build/plugins/webhook-manager.d.ts +8 -0
- package/build/plugins/webhook-manager.d.ts.map +1 -0
- package/build/plugins/webhook-manager.js +245 -0
- package/build/plugins/webhook-manager.js.map +1 -0
- package/build/protocol.d.ts +13 -0
- package/build/protocol.d.ts.map +1 -0
- package/build/protocol.js +17 -0
- package/build/protocol.js.map +1 -0
- package/build/reconcile/types.d.ts +17 -0
- package/build/reconcile/types.d.ts.map +1 -0
- package/build/reconcile/types.js +2 -0
- package/build/reconcile/types.js.map +1 -0
- package/build/reconcile.d.ts +12 -0
- package/build/reconcile.d.ts.map +1 -0
- package/build/reconcile.js +91 -0
- package/build/reconcile.js.map +1 -0
- package/build/resource.d.ts +12 -1
- package/build/resource.d.ts.map +1 -1
- package/build/resource.js +97 -6
- package/build/resource.js.map +1 -1
- package/build/schemas.d.ts +19 -0
- package/build/schemas.d.ts.map +1 -0
- package/build/schemas.js +244 -0
- package/build/schemas.js.map +1 -0
- package/build/service.d.ts +28 -3
- package/build/service.d.ts.map +1 -1
- package/build/service.js +140 -19
- package/build/service.js.map +1 -1
- package/build/subscription/types.d.ts +21 -0
- package/build/subscription/types.d.ts.map +1 -0
- package/build/subscription/types.js +2 -0
- package/build/subscription/types.js.map +1 -0
- package/build/subscription.d.ts +4 -0
- package/build/subscription.d.ts.map +1 -0
- package/build/subscription.js +84 -0
- package/build/subscription.js.map +1 -0
- package/build/sync/types.d.ts +25 -0
- package/build/sync/types.d.ts.map +1 -0
- package/build/sync/types.js +2 -0
- package/build/sync/types.js.map +1 -0
- package/build/sync.d.ts +4 -3
- package/build/sync.d.ts.map +1 -1
- package/build/sync.js +231 -79
- package/build/sync.js.map +1 -1
- package/build/types.d.ts +1258 -36
- package/build/types.d.ts.map +1 -1
- package/build/types.local.d.ts +22 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/build/usage/types.d.ts +56 -0
- package/build/usage/types.d.ts.map +1 -0
- package/build/usage/types.js +2 -0
- package/build/usage/types.js.map +1 -0
- package/build/usage.d.ts +6 -0
- package/build/usage.d.ts.map +1 -0
- package/build/usage.js +365 -0
- package/build/usage.js.map +1 -0
- package/build/utils/types.d.ts +31 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/utils/types.js +2 -0
- package/build/utils/types.js.map +1 -0
- package/build/utils.d.ts +21 -7
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +56 -17
- package/build/utils.js.map +1 -1
- package/package.json +22 -17
- package/src/access/types.ts +52 -0
- package/src/access.ts +86 -0
- package/src/actions/index.ts +1 -0
- package/src/actions/resync-subscriptions.ts +10 -0
- package/src/actions/resync.ts +14 -5
- package/src/actions/webhook.ts +9 -4
- package/src/bootstrap/types.ts +16 -0
- package/src/bootstrap.ts +31 -0
- package/src/catalogue/types.ts +32 -0
- package/src/catalogue.ts +135 -0
- package/src/commit/types.ts +27 -0
- package/src/commit.ts +152 -0
- package/src/config.ts +234 -14
- package/src/consts.local.ts +62 -0
- package/src/consts.ts +100 -36
- package/src/consumer/cancellation/types.ts +13 -0
- package/src/consumer/cancellation.ts +43 -0
- package/src/consumer/capture/types.ts +53 -0
- package/src/consumer/capture.ts +321 -0
- package/src/consumer/consts.local.ts +18 -0
- package/src/consumer/format/types.ts +29 -0
- package/src/consumer/format.ts +85 -0
- package/src/consumer/handlers.ts +204 -0
- package/src/consumer/index.ts +9 -0
- package/src/consumer/mail/types.ts +31 -0
- package/src/consumer/mail.ts +353 -0
- package/src/consumer/observers/types.ts +22 -0
- package/src/consumer/observers.ts +97 -0
- package/src/consumer/origin/types.ts +17 -0
- package/src/consumer/origin.ts +61 -0
- package/src/consumer/reconcile/types.ts +13 -0
- package/src/consumer/reconcile.ts +330 -0
- package/src/consumer/records/types.ts +64 -0
- package/src/consumer/records.ts +288 -0
- package/src/consumer/service.ts +768 -0
- package/src/consumer/types.local.ts +22 -0
- package/src/consumer/types.ts +96 -0
- package/src/consumer/withdrawal/types.ts +37 -0
- package/src/consumer/withdrawal.ts +268 -0
- package/src/entitlement.ts +85 -0
- package/src/entrypoints.ts +17 -4
- package/src/gate/request.ts +24 -0
- package/src/gate/types.ts +13 -0
- package/src/gate.ts +47 -30
- package/src/index.ts +55 -3
- package/src/limit.ts +54 -0
- package/src/log.ts +4 -0
- package/src/models/declarations/types.ts +22 -0
- package/src/models/declarations.ts +30 -0
- package/src/models/purchase/types.ts +13 -0
- package/src/models/purchase.ts +43 -0
- package/src/observer.ts +44 -11
- package/src/plan/types.ts +21 -0
- package/src/plan.ts +46 -0
- package/src/plugins/checkout-plugins/types.ts +25 -0
- package/src/plugins/checkout-plugins.ts +90 -0
- package/src/plugins/checkout-policy/types.ts +18 -0
- package/src/plugins/checkout-policy.ts +34 -0
- package/src/plugins/checkout-registry/types.ts +7 -0
- package/src/plugins/checkout-registry.ts +23 -0
- package/src/plugins/consts.local.ts +30 -0
- package/src/plugins/customer-lock/types.ts +5 -0
- package/src/plugins/customer-lock.ts +25 -0
- package/src/plugins/estimate/cache.ts +12 -0
- package/src/plugins/estimate/types.ts +28 -0
- package/src/plugins/estimate.ts +305 -0
- package/src/plugins/events/types.ts +11 -0
- package/src/plugins/events.ts +466 -132
- package/src/plugins/fx/types.ts +40 -0
- package/src/plugins/fx.ts +101 -0
- package/src/plugins/portal/types.ts +45 -0
- package/src/plugins/portal.ts +284 -0
- package/src/plugins/refunds/types.ts +31 -0
- package/src/plugins/refunds.ts +95 -0
- package/src/plugins/session/types.ts +28 -0
- package/src/plugins/session.ts +73 -0
- package/src/plugins/status.ts +22 -0
- package/src/plugins/stripe/types.ts +20 -0
- package/src/plugins/stripe.ts +523 -135
- package/src/plugins/subscriptions/types.ts +39 -0
- package/src/plugins/subscriptions.ts +195 -0
- package/src/plugins/types.local.ts +61 -0
- package/src/plugins/types.ts +7 -0
- package/src/plugins/webhook-manager/types.ts +63 -0
- package/src/plugins/webhook-manager.ts +288 -0
- package/src/protocol.ts +29 -0
- package/src/reconcile/types.ts +17 -0
- package/src/reconcile.ts +110 -0
- package/src/resource.ts +158 -11
- package/src/schemas.ts +271 -0
- package/src/service.ts +161 -19
- package/src/subscription/types.ts +23 -0
- package/src/subscription.ts +104 -0
- package/src/sync/types.ts +25 -0
- package/src/sync.ts +255 -72
- package/src/types.local.ts +18 -0
- package/src/types.ts +1365 -32
- package/src/usage/types.ts +51 -0
- package/src/usage.ts +432 -0
- package/src/utils/types.ts +30 -0
- package/src/utils.ts +94 -29
- package/tests/checkout-consumer.spec.ts +366 -0
- package/tests/checkout-locks.spec.ts +161 -0
- package/tests/checkout-plugins.spec.ts +164 -0
- package/tests/checkout.spec.ts +209 -93
- package/tests/consumer-events.spec.ts +215 -0
- package/tests/consumer-fixtures.ts +134 -0
- package/tests/consumer-ops.spec.ts +350 -0
- package/tests/consumer-rights.integration.spec.ts +147 -0
- package/tests/consumer-rights.spec.ts +572 -0
- package/tests/context.ts +110 -0
- package/tests/entitlement.spec.ts +139 -0
- package/tests/estimate.spec.ts +350 -0
- package/tests/events.spec.ts +357 -0
- package/tests/fake-stripe.ts +981 -0
- package/tests/gate-handlers.spec.ts +120 -0
- package/tests/gate.spec.ts +63 -72
- package/tests/gateway-options.spec.ts +180 -0
- package/tests/limit-gate.spec.ts +66 -0
- package/tests/portal.spec.ts +202 -0
- package/tests/protocol.spec.ts +17 -3
- package/tests/sync.spec.ts +114 -0
- package/tests/usage.integration.spec.ts +133 -0
- package/tests/usage.spec.ts +169 -0
- package/tests/webhook-manager.spec.ts +149 -0
- package/build/model.d.ts +0 -6
- package/build/model.d.ts.map +0 -1
- package/build/model.js +0 -33
- package/build/model.js.map +0 -1
- package/src/model.ts +0 -37
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CheckoutPlugin } from '../types.js'
|
|
2
|
+
import type { CheckoutPluginRegistry } from './checkout-registry/types.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The gateway's checkout plugins, the way `ExecutionService.use` seats its own: a plugin with an
|
|
6
|
+
* alias already registered replaces it in place (a layer wired twice must not answer twice), one
|
|
7
|
+
* without an alias is appended.
|
|
8
|
+
*/
|
|
9
|
+
export const makeCheckoutPluginRegistry = (): CheckoutPluginRegistry => {
|
|
10
|
+
const plugins: CheckoutPlugin[] = []
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
use: plugin => {
|
|
14
|
+
const at = plugin.alias != null ? plugins.findIndex(entry => entry.alias === plugin.alias) : -1
|
|
15
|
+
if (at < 0) {
|
|
16
|
+
plugins.push(plugin)
|
|
17
|
+
} else {
|
|
18
|
+
plugins[at] = plugin
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
list: () => [...plugins],
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TaxType } from '@owlmeans/payment'
|
|
2
|
+
import type { DisputePhase } from '../types.js'
|
|
3
|
+
|
|
4
|
+
export const NON_SCALABLE_REASONS = new Set([
|
|
5
|
+
'portion_product_exempt', 'portion_reduced_rated', 'portion_standard_rated', 'taxable_basis_reduced',
|
|
6
|
+
'proportionally_rated',
|
|
7
|
+
])
|
|
8
|
+
|
|
9
|
+
export const TAX_TYPE_MAP: Readonly<Record<string, TaxType>> = Object.freeze({
|
|
10
|
+
vat: TaxType.Vat, gst: TaxType.Gst, sales_tax: TaxType.SalesTax,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export const RESYNC_PAGE = 200
|
|
14
|
+
|
|
15
|
+
export const DISPUTE_PHASES: Record<string, DisputePhase> = {
|
|
16
|
+
'charge.dispute.created': 'opened',
|
|
17
|
+
'charge.dispute.funds_withdrawn': 'funds-withdrawn',
|
|
18
|
+
'charge.dispute.funds_reinstated': 'funds-reinstated',
|
|
19
|
+
'charge.dispute.closed': 'closed',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Stripe's limit on every `custom_text` message. */
|
|
23
|
+
export const CUSTOM_TEXT_MAX = 1200
|
|
24
|
+
|
|
25
|
+
export const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
|
26
|
+
|
|
27
|
+
/** Countries where Stripe Tax cannot place a customer from the country alone (docs: tax/customer-locations). */
|
|
28
|
+
export const NEEDS_POSTAL_CODE = new Set(['US'])
|
|
29
|
+
|
|
30
|
+
export const NEEDS_POSTAL_CODE_OR_STATE = new Set(['CA', 'IN'])
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Serialized work per paygate customer, within this process. */
|
|
2
|
+
export interface CustomerLockHelper {
|
|
3
|
+
/** Serialize the work on one paygate customer within this process. */
|
|
4
|
+
withCustomerLock: <T>(customerId: string | undefined, fn: () => Promise<T>) => Promise<T>
|
|
5
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Mutex } from 'async-mutex'
|
|
2
|
+
import type { CustomerLockHelper } from './customer-lock/types.js'
|
|
3
|
+
|
|
4
|
+
export const createCustomerLockHelper = (): CustomerLockHelper => {
|
|
5
|
+
const customerMutex: Record<string, Mutex> = {}
|
|
6
|
+
|
|
7
|
+
const withCustomerLock = async <T>(customerId: string | undefined, fn: () => Promise<T>): Promise<T> => {
|
|
8
|
+
const key = customerId ?? ''
|
|
9
|
+
const mutex = customerMutex[key] = customerMutex[key] ?? new Mutex()
|
|
10
|
+
const release = await mutex.acquire()
|
|
11
|
+
try {
|
|
12
|
+
return await fn()
|
|
13
|
+
} finally {
|
|
14
|
+
release()
|
|
15
|
+
if (!mutex.isLocked()) {
|
|
16
|
+
delete customerMutex[key]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return { withCustomerLock }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The process's customer locks — one set shared by every caller. */
|
|
25
|
+
export const customerLockHelper = createCustomerLockHelper()
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EstimateCache } from './types.js'
|
|
2
|
+
|
|
3
|
+
// One instance per gateway service, never module-level (a test builds many contexts in one process,
|
|
4
|
+
// and a module-level cache would make "no Stripe call" assertions order-dependent).
|
|
5
|
+
|
|
6
|
+
/** @param taxTtlMs default 24h; @param fxTtlMs default 1h; @param customerTtlMs default 5min. */
|
|
7
|
+
export const makeEstimateCache = (
|
|
8
|
+
taxTtlMs: number = 24 * 60 * 60 * 1_000, fxTtlMs: number = 60 * 60 * 1_000,
|
|
9
|
+
customerTtlMs: number = 5 * 60 * 1_000,
|
|
10
|
+
): EstimateCache => ({
|
|
11
|
+
taxTtlMs, fxTtlMs, customerTtlMs, tax: new Map(), fx: new Map(), customer: new Map(), inflight: new Map(),
|
|
12
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type Stripe from 'stripe'
|
|
2
|
+
import type { PriceEstimate } from '@owlmeans/payment'
|
|
3
|
+
import type { PriceEstimateParams } from '../../types.js'
|
|
4
|
+
import type { CacheEntry, FxOutcome, TaxOutcome } from '../types.local.js'
|
|
5
|
+
|
|
6
|
+
export interface EstimateCache {
|
|
7
|
+
taxTtlMs: number
|
|
8
|
+
fxTtlMs: number
|
|
9
|
+
customerTtlMs: number
|
|
10
|
+
tax: Map<string, CacheEntry<TaxOutcome>>
|
|
11
|
+
fx: Map<string, CacheEntry<FxOutcome>>
|
|
12
|
+
customer: Map<string, CacheEntry<Stripe.Customer | null>>
|
|
13
|
+
inflight: Map<string, Promise<unknown>>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Price estimates of a context: Stripe Tax and the local-currency line. */
|
|
17
|
+
export interface EstimateHelper {
|
|
18
|
+
/**
|
|
19
|
+
* A Stripe Tax estimate (and, when the pricing policy asks for it, a local-currency conversion) for
|
|
20
|
+
* one product/plan, at a billing country the request names or the entity's paygate customer does.
|
|
21
|
+
*
|
|
22
|
+
* Costs one Tax Calculation API call ($0.05) per distinct (currency, country, amount, tax code,
|
|
23
|
+
* behavior, matching tax ids) within `cache`'s TTL, and one free FX Quotes call per distinct
|
|
24
|
+
* (currency, local currency) — never more, and never for a rate-limit or connection error, which is
|
|
25
|
+
* never cached.
|
|
26
|
+
*/
|
|
27
|
+
estimateStripePrice: (stripe: Stripe, params: PriceEstimateParams, cache: EstimateCache) => Promise<PriceEstimate>
|
|
28
|
+
}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import type Stripe from 'stripe'
|
|
2
|
+
import { CheckoutPricingMode, currencyOfCountry, ProductError, TaxBehavior, TaxEstimateStatus, TaxType, UnknownProduct, type PriceEstimate, type TaxEstimate, type TaxRateEstimate, checkoutPricingHelper, consumerRegionHelper, priceEstimateHelper } from '@owlmeans/payment'
|
|
3
|
+
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
4
|
+
import { memoHelper } from '@owlmeans/context'
|
|
5
|
+
import { STRIPE_FX_QUOTES_API_VERSION, STRIPE_PAYGATE_ALIAS } from '../consts.js'
|
|
6
|
+
import type { PaymentPlan, PaymentProduct, PriceEstimateParams } from '../types.js'
|
|
7
|
+
import { NON_SCALABLE_REASONS, TAX_TYPE_MAP } from './consts.local.js'
|
|
8
|
+
import type { CacheEntry, FxOutcome, TaxOutcome } from './types.local.js'
|
|
9
|
+
import type { EstimateCache, EstimateHelper } from './estimate/types.js'
|
|
10
|
+
import { fxOf } from './fx.js'
|
|
11
|
+
import { paymentAccessOf } from '../access.js'
|
|
12
|
+
import { paymentUtils } from '../utils.js'
|
|
13
|
+
import { catalogueOf } from '../catalogue.js'
|
|
14
|
+
import { planHelper } from '../plan.js'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A keyed value cached for `ttlMs`, with in-flight requests shared across concurrent callers. Only
|
|
18
|
+
* a settled (resolved) outcome is cached — a thrown error (a rate limit, a dropped connection) never
|
|
19
|
+
* is, so the next call simply tries again.
|
|
20
|
+
*/
|
|
21
|
+
const cached = async <T>(
|
|
22
|
+
store: Map<string, CacheEntry<T>>, inflight: Map<string, Promise<unknown>>,
|
|
23
|
+
key: string, ttlMs: number, factory: () => Promise<T>,
|
|
24
|
+
): Promise<T> => {
|
|
25
|
+
const now = Date.now()
|
|
26
|
+
const hit = store.get(key)
|
|
27
|
+
if (hit != null && hit.expiresAt > now) {
|
|
28
|
+
return hit.value
|
|
29
|
+
}
|
|
30
|
+
const pending = inflight.get(key) as Promise<T> | undefined
|
|
31
|
+
if (pending != null) {
|
|
32
|
+
return pending
|
|
33
|
+
}
|
|
34
|
+
const promise = factory().then(value => {
|
|
35
|
+
store.set(key, { value, expiresAt: Date.now() + ttlMs })
|
|
36
|
+
inflight.delete(key)
|
|
37
|
+
return value
|
|
38
|
+
}).catch(error => {
|
|
39
|
+
inflight.delete(key)
|
|
40
|
+
throw error
|
|
41
|
+
})
|
|
42
|
+
inflight.set(key, promise)
|
|
43
|
+
return promise
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// -------------------------------------------------------------------------------------------
|
|
47
|
+
// Tax
|
|
48
|
+
// -------------------------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
/** A duck-typed check, matching `isMissingObject` above: the installed SDK's own error classes. */
|
|
51
|
+
const isInvalidRequest = (error: unknown): error is { code?: string } =>
|
|
52
|
+
(error as { type?: unknown } | null)?.type === 'StripeInvalidRequestError'
|
|
53
|
+
|
|
54
|
+
/** A linear percentage rate scales with the amount; a flat fee, a partial exemption, or several inclusive rates do not. */
|
|
55
|
+
const scalableOf = (breakdown: Stripe.Tax.Calculation.TaxBreakdown[], behavior: TaxBehavior): boolean => {
|
|
56
|
+
if (breakdown.some(row => row.tax_rate_details?.rate_type === 'flat_amount')) return false
|
|
57
|
+
if (breakdown.some(row => NON_SCALABLE_REASONS.has(row.taxability_reason))) return false
|
|
58
|
+
if (behavior === TaxBehavior.Inclusive && breakdown.length > 1) return false
|
|
59
|
+
return true
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const statusOf = (breakdown: Stripe.Tax.Calculation.TaxBreakdown[], taxMinor: number): TaxEstimateStatus => {
|
|
63
|
+
if (breakdown.some(row => row.taxability_reason === 'reverse_charge')) return TaxEstimateStatus.ReverseCharge
|
|
64
|
+
if (taxMinor > 0) return TaxEstimateStatus.Taxed
|
|
65
|
+
if (breakdown.some(row => row.taxability_reason === 'not_supported')) return TaxEstimateStatus.AtCheckout
|
|
66
|
+
return TaxEstimateStatus.None
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const taxTypeOf = (raw: string | null | undefined): TaxType => raw != null && raw in TAX_TYPE_MAP ? TAX_TYPE_MAP[raw] : TaxType.Tax
|
|
70
|
+
|
|
71
|
+
const ratesOf = (breakdown: Stripe.Tax.Calculation.TaxBreakdown[]): TaxRateEstimate[] => breakdown
|
|
72
|
+
.filter((row): row is Stripe.Tax.Calculation.TaxBreakdown & {
|
|
73
|
+
tax_rate_details: NonNullable<Stripe.Tax.Calculation.TaxBreakdown['tax_rate_details']>
|
|
74
|
+
} => row.tax_rate_details != null)
|
|
75
|
+
.map(row => ({
|
|
76
|
+
type: taxTypeOf(row.tax_rate_details.tax_type),
|
|
77
|
+
percentage: row.tax_rate_details.percentage_decimal,
|
|
78
|
+
ratePpm: priceEstimateHelper.ratePpmOf(row.tax_rate_details.percentage_decimal),
|
|
79
|
+
...(row.tax_rate_details.country != null ? { country: row.tax_rate_details.country } : {}),
|
|
80
|
+
...(row.tax_rate_details.state != null ? { state: row.tax_rate_details.state } : {}),
|
|
81
|
+
}))
|
|
82
|
+
|
|
83
|
+
const taxEstimateOf = (calculation: Stripe.Tax.Calculation, behavior: TaxBehavior, subtotalMinor: number): TaxEstimate => {
|
|
84
|
+
const breakdown = calculation.tax_breakdown ?? []
|
|
85
|
+
const taxMinor = calculation.tax_amount_exclusive + calculation.tax_amount_inclusive
|
|
86
|
+
const status = statusOf(breakdown, taxMinor)
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
status, subtotalMinor, taxMinor, totalMinor: calculation.amount_total,
|
|
90
|
+
scalable: scalableOf(breakdown, behavior), rates: ratesOf(breakdown),
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The reference amount and currency of the estimate: an amount plan's default preset, else the plan's own price. */
|
|
95
|
+
const referenceOf = (plan: PaymentPlan): { subtotalMinor: number; currency: string } => {
|
|
96
|
+
if (plan.pricingMode === CheckoutPricingMode.Amount) {
|
|
97
|
+
if (plan.amountPolicy == null) throw new ProductError(`amount-policy:${plan.sku}`)
|
|
98
|
+
return {
|
|
99
|
+
subtotalMinor: checkoutPricingHelper.chargeAmountMinor(plan.amountPolicy.defaultMinor, plan.amountPolicy),
|
|
100
|
+
currency: plan.amountPolicy.currency.toLowerCase(),
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { subtotalMinor: Math.round(plan.price * 100), currency: (plan.currency ?? 'usd').toLowerCase() }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** A placeholder estimate — no known tax, shown by its `status`, never by its zeroed numbers. */
|
|
107
|
+
const unresolvedEstimate = (status: TaxEstimateStatus, subtotalMinor: number): TaxEstimate => ({
|
|
108
|
+
status, subtotalMinor, taxMinor: 0, totalMinor: subtotalMinor, scalable: false, rates: [],
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
export const makeEstimateHelper = (ctx: ApiContext): EstimateHelper => {
|
|
112
|
+
const access = paymentAccessOf(ctx)
|
|
113
|
+
|
|
114
|
+
// Customer lookup — the fallback country and the tax ids a request-given country still checks.
|
|
115
|
+
const cachedCustomer = async (
|
|
116
|
+
stripe: Stripe, entityId: string, cache: EstimateCache,
|
|
117
|
+
): Promise<Stripe.Customer | null> => cached(cache.customer, cache.inflight, `customer:${entityId}`, cache.customerTtlMs, async () => {
|
|
118
|
+
const record = await access.paygateCustomers().byEntity(entityId, STRIPE_PAYGATE_ALIAS)
|
|
119
|
+
if (record == null || record.deletedAt != null) {
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const retrieved = await stripe.customers.retrieve(record.externalId, { expand: ['tax_ids'] })
|
|
124
|
+
return (retrieved as Stripe.DeletedCustomer).deleted ? null : retrieved as Stripe.Customer
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (paymentUtils.isMissingObject(error)) return null
|
|
127
|
+
throw error
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The reference amount in the currency the buyer is charged in: a recurring or quantity plan's
|
|
133
|
+
* synced price in that currency (its default or an option — no paygate call), else the plan's own
|
|
134
|
+
* catalogue reference. An amount plan keeps its policy currency.
|
|
135
|
+
*/
|
|
136
|
+
const chargedReferenceOf = async (
|
|
137
|
+
product: PaymentProduct, plan: PaymentPlan, chargeCurrency: string | null,
|
|
138
|
+
): Promise<{ subtotalMinor: number; currency: string }> => {
|
|
139
|
+
const reference = referenceOf(plan)
|
|
140
|
+
if (chargeCurrency == null || plan.pricingMode === CheckoutPricingMode.Amount || chargeCurrency === reference.currency && plan.currencyPrices == null) {
|
|
141
|
+
return reference
|
|
142
|
+
}
|
|
143
|
+
const synced = (await access.fingerprints().bySku(product.sku))?.prices?.find(price => price.planSku === plan.sku)
|
|
144
|
+
if (synced == null) {
|
|
145
|
+
return reference
|
|
146
|
+
}
|
|
147
|
+
if (synced.currency === chargeCurrency) {
|
|
148
|
+
return { subtotalMinor: synced.unitAmount, currency: chargeCurrency }
|
|
149
|
+
}
|
|
150
|
+
const option = synced.options.find(entry => entry.currency === chargeCurrency)
|
|
151
|
+
|
|
152
|
+
return option != null ? { subtotalMinor: option.unitAmount, currency: chargeCurrency } : reference
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Currency: Stripe FX Quotes, a PREVIEW endpoint — see `STRIPE_FX_QUOTES_API_VERSION`. A buyer's
|
|
156
|
+
// local currency is priced by Adaptive Pricing at the BASE rate plus its own conversion fee
|
|
157
|
+
// (`price × (1 + fee)`, 2–4% as Stripe decides), which the quote's fee-inclusive `exchange_rate`
|
|
158
|
+
// (base × (1 − `fx_fee_rate`), 2%) understates; a policy declaring `adaptiveFeeRate` is estimated
|
|
159
|
+
// the way Checkout prices it, one without keeps the quote's rate.
|
|
160
|
+
const fetchFxRate = async (
|
|
161
|
+
stripe: Stripe, currency: string, localCurrency: string, apiVersion: string,
|
|
162
|
+
settlementCurrency: string = currency, adaptiveFeeRate?: number,
|
|
163
|
+
): Promise<FxOutcome> => {
|
|
164
|
+
const settlement = settlementCurrency.toLowerCase()
|
|
165
|
+
const sourceRate = settlement === currency
|
|
166
|
+
? { referenceRate: 1 }
|
|
167
|
+
: await fxOf(ctx).stripeFxRate(stripe, currency, settlement, apiVersion)
|
|
168
|
+
if (sourceRate == null) return null
|
|
169
|
+
if (localCurrency === settlement) {
|
|
170
|
+
return { currency: localCurrency, exchangeRate: 1 / sourceRate.referenceRate }
|
|
171
|
+
}
|
|
172
|
+
const localRate = await fxOf(ctx).stripeFxRate(stripe, localCurrency, settlement, apiVersion)
|
|
173
|
+
if (localRate == null) return null
|
|
174
|
+
const settlementPerLocal = adaptiveFeeRate != null ? localRate.baseRate / (1 + adaptiveFeeRate) : localRate.exchangeRate
|
|
175
|
+
const feeRate = adaptiveFeeRate ?? localRate.fxFeeRate
|
|
176
|
+
return {
|
|
177
|
+
currency: localCurrency, exchangeRate: settlementPerLocal / sourceRate.referenceRate,
|
|
178
|
+
...(feeRate != null ? { fxFeeRate: feeRate } : {}),
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const estimateStripePrice = async (
|
|
183
|
+
stripe: Stripe, params: PriceEstimateParams, cache: EstimateCache,
|
|
184
|
+
): Promise<PriceEstimate> => {
|
|
185
|
+
const product = await catalogueOf(ctx).findProduct(params.productSku) as PaymentProduct | null
|
|
186
|
+
if (product == null) throw new UnknownProduct(params.productSku)
|
|
187
|
+
const plans = (await access.payment().allPlans(product.sku) as PaymentPlan[])
|
|
188
|
+
.filter(plan => planHelper.isSoldThrough(product, plan, STRIPE_PAYGATE_ALIAS))
|
|
189
|
+
const plan = params.planSku != null
|
|
190
|
+
? plans.find(item => item.sku === params.planSku)
|
|
191
|
+
: plans.find(item => item.recurring != null) ?? plans[0]
|
|
192
|
+
if (plan == null) throw new ProductError(params.planSku != null ? `plan:${params.planSku}` : 'plan')
|
|
193
|
+
|
|
194
|
+
const pricing = await access.payment().pricingPolicy()
|
|
195
|
+
const behavior = pricing.tax.behavior ?? TaxBehavior.Exclusive
|
|
196
|
+
const rights = await access.payment().consumerRightsPolicy()
|
|
197
|
+
// A locked billing country overrides whatever the request names: a picker shows it, locked.
|
|
198
|
+
const profile = rights != null ? await access.consumerRightsOf()?.profile(params.entityId) ?? null : null
|
|
199
|
+
const locked = profile?.locked === true && profile.country != null
|
|
200
|
+
|
|
201
|
+
let country = locked ? profile.country as string : params.country?.toUpperCase()
|
|
202
|
+
let source: 'request' | 'customer' | 'profile' | undefined = locked ? 'profile' : country != null ? 'request' : undefined
|
|
203
|
+
let matchingTaxIds: Array<{ type: string; value: string }> = []
|
|
204
|
+
let taxabilityOverride: 'customer_exempt' | 'reverse_charge' | undefined
|
|
205
|
+
|
|
206
|
+
const customer = await cachedCustomer(stripe, params.entityId, cache)
|
|
207
|
+
if (customer != null) {
|
|
208
|
+
if (country == null && customer.address?.country != null) {
|
|
209
|
+
country = customer.address.country
|
|
210
|
+
source = 'customer'
|
|
211
|
+
}
|
|
212
|
+
if (country != null) {
|
|
213
|
+
matchingTaxIds = (customer.tax_ids?.data ?? [])
|
|
214
|
+
.filter(taxId => taxId.country === country)
|
|
215
|
+
.map(taxId => ({ type: taxId.type, value: taxId.value }))
|
|
216
|
+
if (customer.tax_exempt === 'exempt') taxabilityOverride = 'customer_exempt'
|
|
217
|
+
else if (customer.tax_exempt === 'reverse') taxabilityOverride = 'reverse_charge'
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const region = rights != null ? consumerRegionHelper.regionOf(country, rights) : null
|
|
222
|
+
const settlementCurrency = (await access.stripePricingConfig())?.settlementCurrency?.toLowerCase()
|
|
223
|
+
// The currency the checkout session charges: the region's (or the locked profile's) under a policy
|
|
224
|
+
// with region currencies, else none forced.
|
|
225
|
+
const chargeCurrency = rights != null && rights.currencies != null && Object.keys(rights.currencies).length > 0
|
|
226
|
+
? (profile?.currency ?? consumerRegionHelper.chargeCurrencyOf(region, rights, settlementCurrency ?? (plan.currency ?? 'usd'))).toLowerCase()
|
|
227
|
+
: null
|
|
228
|
+
const { subtotalMinor, currency } = await chargedReferenceOf(product, plan, chargeCurrency)
|
|
229
|
+
const where = { ...(region != null ? { region } : {}), ...(locked ? { locked: true } : {}) }
|
|
230
|
+
|
|
231
|
+
if (country == null) {
|
|
232
|
+
return { currency, behavior, tax: unresolvedEstimate(TaxEstimateStatus.LocationRequired, subtotalMinor), ...where }
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const cacheKey = JSON.stringify([
|
|
236
|
+
currency, country, subtotalMinor, product.taxCode ?? null, behavior,
|
|
237
|
+
matchingTaxIds.map(id => `${id.type}:${id.value}`).sort(), taxabilityOverride ?? null,
|
|
238
|
+
])
|
|
239
|
+
const outcome = await cached(cache.tax, cache.inflight, `tax:${cacheKey}`, cache.taxTtlMs, async (): Promise<TaxOutcome> => {
|
|
240
|
+
try {
|
|
241
|
+
const calculation = await stripe.tax.calculations.create({
|
|
242
|
+
currency,
|
|
243
|
+
line_items: [{
|
|
244
|
+
amount: subtotalMinor, reference: plan.sku, tax_behavior: behavior,
|
|
245
|
+
...(product.taxCode != null ? { tax_code: product.taxCode } : {}),
|
|
246
|
+
}],
|
|
247
|
+
customer_details: {
|
|
248
|
+
address: { country },
|
|
249
|
+
address_source: 'billing',
|
|
250
|
+
// Cast: `Stripe.TaxId.type` (the customer's saved tax id) and the Tax Calculation
|
|
251
|
+
// parameter's own tax-id-type enum are independently generated from Stripe's OpenAPI
|
|
252
|
+
// spec and can drift apart in this pinned SDK; every value here still came from a real
|
|
253
|
+
// Stripe `TaxId` record, so it is valid at the API even where the two types disagree.
|
|
254
|
+
...(matchingTaxIds.length > 0
|
|
255
|
+
? { tax_ids: matchingTaxIds as Stripe.Tax.CalculationCreateParams.CustomerDetails['tax_ids'] }
|
|
256
|
+
: {}),
|
|
257
|
+
...(taxabilityOverride != null ? { taxability_override: taxabilityOverride } : {}),
|
|
258
|
+
},
|
|
259
|
+
})
|
|
260
|
+
return { ok: true, calculation }
|
|
261
|
+
} catch (error) {
|
|
262
|
+
if (isInvalidRequest(error)) return { ok: false, code: error.code }
|
|
263
|
+
throw error
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
const tax = outcome.ok
|
|
268
|
+
? taxEstimateOf(outcome.calculation, behavior, subtotalMinor)
|
|
269
|
+
: unresolvedEstimate(TaxEstimateStatus.AtCheckout, subtotalMinor)
|
|
270
|
+
|
|
271
|
+
const result: PriceEstimate = { country, source, currency, behavior, tax, ...where }
|
|
272
|
+
// Adaptive Pricing — and so a local-currency line — applies only to a session CHARGED in the
|
|
273
|
+
// settlement currency; a forced region currency (exact USD) is shown as it is. An amount plan is
|
|
274
|
+
// estimated in its policy currency but charged in the region's currency (converted per session,
|
|
275
|
+
// `chargeAmount`), so the session's currency decides, never the reference's: a EUR-charged top-up
|
|
276
|
+
// gets its local line through the same USD → settlement → local chain the session takes.
|
|
277
|
+
const charged = chargeCurrency ?? currency
|
|
278
|
+
const adaptive = rights?.currencies == null || charged === (settlementCurrency ?? charged)
|
|
279
|
+
|
|
280
|
+
if (pricing.currency.estimate && pricing.currency.adaptive === true && adaptive) {
|
|
281
|
+
const localCurrency = currencyOfCountry(country)
|
|
282
|
+
if (localCurrency != null && localCurrency !== currency) {
|
|
283
|
+
const stripePricing = await access.stripePricingConfig()
|
|
284
|
+
const apiVersion = stripePricing?.fxApiVersion ?? STRIPE_FX_QUOTES_API_VERSION
|
|
285
|
+
const settlementCurrency = stripePricing?.settlementCurrency?.toLowerCase() ?? currency
|
|
286
|
+
// A preview endpoint: unreachable or erroring never fails the estimate, it only drops `local`.
|
|
287
|
+
const feeRate = pricing.currency.adaptiveFeeRate
|
|
288
|
+
const fx = await cached(
|
|
289
|
+
cache.fx, cache.inflight, `fx:${currency}:${settlementCurrency}:${localCurrency}:${apiVersion}:${feeRate ?? ''}`, cache.fxTtlMs,
|
|
290
|
+
() => fetchFxRate(stripe, currency, localCurrency, apiVersion, settlementCurrency, feeRate),
|
|
291
|
+
).catch(() => null)
|
|
292
|
+
if (fx != null) {
|
|
293
|
+
result.local = { currency: fx.currency, exchangeRate: fx.exchangeRate, ...(fx.fxFeeRate != null ? { fxFeeRate: fx.fxFeeRate } : {}) }
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return result
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return { estimateStripePrice }
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** The price estimates of a context — one per context. */
|
|
305
|
+
export const estimateOf = memoHelper.oncePer(makeEstimateHelper)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type Stripe from 'stripe'
|
|
2
|
+
|
|
3
|
+
export interface EventHandler { (event: Stripe.Event): Promise<void> }
|
|
4
|
+
|
|
5
|
+
/** The Stripe event dispatch table of one context and client. */
|
|
6
|
+
export interface StripeEventHandler {
|
|
7
|
+
/** The handler of each event type this package processes. */
|
|
8
|
+
handlers: Record<string, EventHandler>
|
|
9
|
+
/** Run the handler of an event's type; every other type is ignored. A throw escapes so Stripe delivers again. */
|
|
10
|
+
process: (event: Stripe.Event) => Promise<void>
|
|
11
|
+
}
|