@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
package/build/plugins/stripe.js
CHANGED
|
@@ -1,51 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (prices.data.length === 0)
|
|
42
|
-
throw new ProductError(`price:${lookupKey}`);
|
|
43
|
-
return prices.data[0];
|
|
1
|
+
import { BillingCountryLocked, CheckoutPricingMode, CONSUMER_RIGHTS_COPY_VERSION, ConsumerRightsError, PaygateError, ProductError, ProductType, TaxBehavior, consumerCopyHelper, consumerRegionHelper, consumerRightsPolicyHelper } from '@owlmeans/payment';
|
|
2
|
+
import { memoHelper } from '@owlmeans/context';
|
|
3
|
+
import { STRIPE_PAYGATE_ALIAS } from '../consts.js';
|
|
4
|
+
import { log } from '../log.js';
|
|
5
|
+
import { CUSTOM_TEXT_MAX, EMAIL } from './consts.local.js';
|
|
6
|
+
import { fxOf } from './fx.js';
|
|
7
|
+
import { paymentAccessOf } from '../access.js';
|
|
8
|
+
import { paymentUtils } from '../utils.js';
|
|
9
|
+
import { planHelper } from '../plan.js';
|
|
10
|
+
import { checkoutPluginsOf } from './checkout-plugins.js';
|
|
11
|
+
import { checkoutPolicyHelper } from './checkout-policy.js';
|
|
12
|
+
import { stripeSessionHelper } from './session.js';
|
|
13
|
+
import { consumerFormatHelper } from '../consumer/format.js';
|
|
14
|
+
import { consumerRecordsOf } from '../consumer/records.js';
|
|
15
|
+
/**
|
|
16
|
+
* A Checkout Session's tax and currency options, entirely driven by the declared `PricingPolicy` —
|
|
17
|
+
* an undeclared one (`DEFAULT_PRICING_POLICY`) reproduces exactly what every session hard-coded
|
|
18
|
+
* before this policy existed: automatic tax and tax-id collection on, no Adaptive Pricing.
|
|
19
|
+
*
|
|
20
|
+
* `customer_update.address` lets automatic tax use the billing address Checkout just collected
|
|
21
|
+
* rather than only a previously saved one; `customer_update.name` lets tax-id collection save the
|
|
22
|
+
* business name it collects. Each is included only for the concern that needs it. Under a country
|
|
23
|
+
* lock the saved address is kept (`address: 'never'`, collection `'auto'`), so tax follows the
|
|
24
|
+
* locked country and Checkout cannot move it.
|
|
25
|
+
*/
|
|
26
|
+
const checkoutOptions = (policy, promotions, flags = {}) => {
|
|
27
|
+
const customerUpdate = {};
|
|
28
|
+
if (policy.tax.automatic)
|
|
29
|
+
customerUpdate.address = flags.locked === true ? 'never' : 'auto';
|
|
30
|
+
if (policy.tax.collectTaxId)
|
|
31
|
+
customerUpdate.name = 'auto';
|
|
32
|
+
return {
|
|
33
|
+
...(policy.tax.automatic
|
|
34
|
+
? { automatic_tax: { enabled: true }, billing_address_collection: flags.locked === true ? 'auto' : 'required' }
|
|
35
|
+
: {}),
|
|
36
|
+
...(policy.tax.collectTaxId ? { tax_id_collection: { enabled: true } } : {}),
|
|
37
|
+
...(Object.keys(customerUpdate).length > 0 ? { customer_update: customerUpdate } : {}),
|
|
38
|
+
adaptive_pricing: { enabled: policy.currency.adaptive === true && flags.adaptive !== false },
|
|
39
|
+
allow_promotion_codes: promotions,
|
|
40
|
+
};
|
|
44
41
|
};
|
|
45
42
|
const sharedSession = (customer, params, product, plan, metadata) => ({
|
|
46
43
|
customer: customer.id,
|
|
47
44
|
success_url: params.successUrl,
|
|
48
45
|
cancel_url: params.cancelUrl ?? params.successUrl,
|
|
46
|
+
...(params.locale != null ? { locale: params.locale } : {}),
|
|
49
47
|
metadata: {
|
|
50
48
|
pricingMode: plan.pricingMode ?? CheckoutPricingMode.Quantity,
|
|
51
49
|
currency: (plan.currency ?? 'usd').toLowerCase(),
|
|
@@ -57,110 +55,464 @@ const sharedSession = (customer, params, product, plan, metadata) => ({
|
|
|
57
55
|
...metadata,
|
|
58
56
|
},
|
|
59
57
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
/** A saved address holding only `country` — stale lines and a postal code of another country cleared. */
|
|
59
|
+
const countryOnlyAddress = (country) => ({
|
|
60
|
+
country, line1: '', line2: '', city: '', state: '', postal_code: '',
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* The consumer-rights metadata every session (and its subscription) carries. `termsCollected`
|
|
64
|
+
* says whether Checkout asked for the terms checkbox — `'false'` also after the fallback of a
|
|
65
|
+
* Dashboard without a terms URL; `countryPinned` that tax was calculated on `country`, held on the
|
|
66
|
+
* customer by `stripe.lockCustomerCountry`, so that country is the one the purchase locks.
|
|
67
|
+
*/
|
|
68
|
+
const consumerMetadata = (buyer, params, startRequestId) => buyer.policy == null ? {} : paymentUtils.compact({
|
|
69
|
+
region: buyer.region ?? undefined,
|
|
70
|
+
country: buyer.country,
|
|
71
|
+
language: buyer.language,
|
|
72
|
+
termsVersion: buyer.policy.textVersion,
|
|
73
|
+
copyVersion: CONSUMER_RIGHTS_COPY_VERSION,
|
|
74
|
+
termsCollected: String(buyer.policy.mechanisms.checkoutTerms === true),
|
|
75
|
+
ipCountry: params.ipCountry?.toUpperCase(),
|
|
76
|
+
startRequestId,
|
|
77
|
+
countryPinned: buyer.countryPinned ? 'true' : undefined,
|
|
78
|
+
});
|
|
79
|
+
const limited = (message, field) => {
|
|
80
|
+
if (message.length > CUSTOM_TEXT_MAX) {
|
|
81
|
+
throw new ConsumerRightsError(`copy:length:${field}`);
|
|
82
|
+
}
|
|
83
|
+
return message;
|
|
84
|
+
};
|
|
85
|
+
/** The terms checkbox and its text, when the policy asks for them on every checkout. */
|
|
86
|
+
const termsOptions = (buyer) => {
|
|
87
|
+
const policy = buyer.policy;
|
|
88
|
+
if (policy?.mechanisms.checkoutTerms !== true) {
|
|
89
|
+
return {};
|
|
90
|
+
}
|
|
91
|
+
const links = consumerRightsPolicyHelper.linksOf(policy, buyer.language);
|
|
92
|
+
const withInformation = buyer.inScope && links.withdrawalInformation != null;
|
|
93
|
+
const message = limited(consumerCopyHelper.consumerText(buyer.language, `checkout.terms-acceptance.${withInformation ? 'in-scope' : 'other'}`, {
|
|
94
|
+
billingTerms: links.billingTerms, ...(withInformation ? { withdrawalInformation: links.withdrawalInformation } : {}),
|
|
95
|
+
}), 'terms');
|
|
96
|
+
return { consent_collection: { terms_of_service: 'required' }, terms: message };
|
|
97
|
+
};
|
|
98
|
+
const textContextOf = (buyer, currency, extra = {}) => paymentUtils.compact({
|
|
99
|
+
language: buyer.language, currency, region: buyer.region, country: buyer.country, ...extra,
|
|
100
|
+
});
|
|
101
|
+
const submitTextOf = (params, context) => {
|
|
102
|
+
if (params.submitText == null) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const message = typeof params.submitText === 'function' ? params.submitText(context) : params.submitText;
|
|
106
|
+
return message.trim() === '' ? undefined : message;
|
|
107
|
+
};
|
|
108
|
+
/** The same session without the terms checkbox and its text — and saying so in its metadata. */
|
|
109
|
+
const withoutTerms = (params) => {
|
|
110
|
+
const { consent_collection: consent, custom_text: customText, ...rest } = params;
|
|
111
|
+
const { terms_of_service: _terms, ...otherConsent } = consent ?? {};
|
|
112
|
+
const { terms_of_service_acceptance: _acceptance, ...otherText } = customText ?? {};
|
|
113
|
+
const marked = (metadata) => metadata != null ? { ...metadata, termsCollected: 'false' } : metadata;
|
|
66
114
|
return {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
currency,
|
|
115
|
+
...rest,
|
|
116
|
+
...(Object.keys(otherConsent).length > 0 ? { consent_collection: otherConsent } : {}),
|
|
117
|
+
...(Object.keys(otherText).length > 0 ? { custom_text: otherText } : {}),
|
|
118
|
+
metadata: marked(rest.metadata) ?? { termsCollected: 'false' },
|
|
119
|
+
...(rest.subscription_data != null
|
|
120
|
+
? { subscription_data: { ...rest.subscription_data, metadata: marked(rest.subscription_data.metadata) ?? { termsCollected: 'false' } } }
|
|
121
|
+
: {}),
|
|
75
122
|
};
|
|
76
123
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
124
|
+
/** One console warning per context — a process builds one. */
|
|
125
|
+
const warnedTermsFallback = new WeakSet();
|
|
126
|
+
export const makeStripeCheckoutHelper = (ctx) => {
|
|
127
|
+
const access = paymentAccessOf(ctx);
|
|
128
|
+
/**
|
|
129
|
+
* The e-mail a checkout pins on its Stripe customer: `params.email` under
|
|
130
|
+
* `stripe.lockCustomerEmail`, `undefined` without the lock.
|
|
131
|
+
*
|
|
132
|
+
* @throws PaygateError('customer-email') — the lock is declared and no usable e-mail was passed
|
|
133
|
+
*/
|
|
134
|
+
const lockedEmailOf = async (params) => {
|
|
135
|
+
if ((await access.stripePricingConfig())?.lockCustomerEmail !== true) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
const email = params.email?.trim();
|
|
139
|
+
if (email == null || !EMAIL.test(email)) {
|
|
140
|
+
throw new PaygateError('customer-email');
|
|
141
|
+
}
|
|
142
|
+
return email;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* The entity's Stripe customer, created on first use. Under `stripe.lockCustomerEmail` it carries
|
|
146
|
+
* the buyer's e-mail — written over any other one — because Checkout shows a customer's valid
|
|
147
|
+
* e-mail read-only (and only asks for one, then saves it, while the customer has none).
|
|
148
|
+
*/
|
|
149
|
+
const ensureStripeCustomer = async (stripe, params) => {
|
|
150
|
+
const email = await lockedEmailOf(params);
|
|
151
|
+
const resource = access.paygateCustomers();
|
|
152
|
+
const existing = await resource.byEntity(params.entityId, STRIPE_PAYGATE_ALIAS);
|
|
153
|
+
if (existing != null && existing.deletedAt == null) {
|
|
154
|
+
const retrieved = await stripe.customers.retrieve(existing.externalId);
|
|
155
|
+
if (!retrieved.deleted) {
|
|
156
|
+
const customer = retrieved;
|
|
157
|
+
const update = {
|
|
158
|
+
...(params.locale != null && customer.preferred_locales?.[0] !== params.locale ? { preferred_locales: [params.locale] } : {}),
|
|
159
|
+
...(email != null && customer.email?.toLowerCase() !== email.toLowerCase() ? { email } : {}),
|
|
160
|
+
};
|
|
161
|
+
return Object.keys(update).length > 0 ? await stripe.customers.update(customer.id, update) : customer;
|
|
109
162
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
163
|
+
}
|
|
164
|
+
const created = await stripe.customers.create({
|
|
165
|
+
metadata: {
|
|
166
|
+
entityId: params.entityId, ...(params.profileId && { profileId: params.profileId }),
|
|
167
|
+
service: params.service,
|
|
168
|
+
},
|
|
169
|
+
...(params.locale != null ? { preferred_locales: [params.locale] } : {}),
|
|
170
|
+
...(email != null ? { email } : {}),
|
|
171
|
+
});
|
|
172
|
+
if (existing != null) {
|
|
173
|
+
const { deletedAt: _deleted, ...kept } = existing;
|
|
174
|
+
await resource.update({ ...kept, externalId: created.id });
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
await resource.create({
|
|
178
|
+
paygate: STRIPE_PAYGATE_ALIAS, externalId: created.id, entityId: params.entityId,
|
|
179
|
+
...(params.profileId != null ? { profileId: params.profileId } : {}),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return created;
|
|
183
|
+
};
|
|
184
|
+
const findPrice = async (stripe, productSku, lookupKey) => {
|
|
185
|
+
const prices = await stripe.prices.list({ product: productSku, active: true, lookup_keys: [lookupKey] });
|
|
186
|
+
if (prices.data.length === 0)
|
|
187
|
+
throw new ProductError(`price:${lookupKey}`);
|
|
188
|
+
return prices.data[0];
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* The buyer as the consumer-rights policy sees it — a locked profile overrides the declared
|
|
192
|
+
* country (a different one is `BillingCountryLocked`), an organization that already paid before
|
|
193
|
+
* its country was locked is locked lazily from its paygate customer's address, and a locked
|
|
194
|
+
* customer address that no longer carries the locked country refuses (the operator relocks).
|
|
195
|
+
*
|
|
196
|
+
* Under `stripe.lockCustomerCountry` the known country (the locked one, else the declared one) is
|
|
197
|
+
* written to the customer — over a saved address of another country only before any lock — and
|
|
198
|
+
* Checkout keeps it wherever Stripe Tax can calculate on it.
|
|
199
|
+
*/
|
|
200
|
+
const buyerOf = async (stripe, params, catalogueCurrency) => {
|
|
201
|
+
const policy = await access.payment().consumerRightsPolicy();
|
|
202
|
+
const rights = policy != null ? access.consumerRightsOf() : null;
|
|
203
|
+
let profile = rights != null ? await rights.profile(params.entityId) : null;
|
|
204
|
+
const declared = params.country != null && params.country.trim() !== '' ? params.country.trim().toUpperCase() : undefined;
|
|
205
|
+
if (profile?.locked === true && declared != null && declared !== profile.country) {
|
|
206
|
+
throw new BillingCountryLocked({ country: profile.country, requested: declared });
|
|
207
|
+
}
|
|
208
|
+
let customer = await ensureStripeCustomer(stripe, params);
|
|
209
|
+
const customerCountry = customer.address?.country?.toUpperCase() ?? undefined;
|
|
210
|
+
if (rights != null && policy?.mechanisms.countryLock === true && profile == null && customerCountry != null
|
|
211
|
+
&& await consumerRecordsOf(ctx).hasPaid(params.entityId)
|
|
212
|
+
&& !await consumerRecordsOf(ctx).wasUnlocked(params.entityId)) {
|
|
213
|
+
// An organization that paid before countries were locked: its saved address is its country.
|
|
214
|
+
// One an operator unlocked is locked again by its next completed purchase instead.
|
|
215
|
+
profile = await rights.lock(params.entityId, customerCountry, 'customer', { customerId: customer.id });
|
|
216
|
+
}
|
|
217
|
+
if (profile?.locked === true && declared != null && declared !== profile.country) {
|
|
218
|
+
throw new BillingCountryLocked({ country: profile.country, requested: declared });
|
|
219
|
+
}
|
|
220
|
+
if (profile?.locked === true && customerCountry != null && customerCountry !== profile.country) {
|
|
221
|
+
throw new BillingCountryLocked({ country: profile.country, requested: customerCountry });
|
|
222
|
+
}
|
|
223
|
+
const pinning = (await access.stripePricingConfig())?.lockCustomerCountry === true;
|
|
224
|
+
const country = profile?.country ?? declared;
|
|
225
|
+
if (pinning && country != null && customerCountry !== country) {
|
|
226
|
+
// Pinned: the known country replaces whatever an unlocked customer saved (a locked customer's
|
|
227
|
+
// other country was refused above), so Checkout has nothing else to offer.
|
|
228
|
+
customer = await stripe.customers.update(customer.id, { address: countryOnlyAddress(country) });
|
|
229
|
+
}
|
|
230
|
+
else if (policy != null && profile == null && declared != null && customerCountry == null) {
|
|
231
|
+
// Preselect the declared country on Checkout's address form; never over a saved address.
|
|
232
|
+
customer = await stripe.customers.update(customer.id, { address: { country: declared } });
|
|
233
|
+
}
|
|
234
|
+
const savedCountry = customer.address?.country?.toUpperCase() ?? undefined;
|
|
235
|
+
const kept = savedCountry != null && savedCountry === country && stripeSessionHelper.isTaxLocatable(customer.address);
|
|
236
|
+
const countryPinned = pinning && kept;
|
|
237
|
+
const region = policy != null ? consumerRegionHelper.regionOf(country, policy) : null;
|
|
238
|
+
const settlement = (await access.stripePricingConfig())?.settlementCurrency?.toLowerCase();
|
|
239
|
+
const regional = policy?.currencies != null && Object.keys(policy.currencies).length > 0;
|
|
240
|
+
return {
|
|
241
|
+
customer,
|
|
242
|
+
buyer: {
|
|
243
|
+
policy,
|
|
244
|
+
profile,
|
|
245
|
+
...(country != null ? { country } : {}),
|
|
246
|
+
region,
|
|
247
|
+
inScope: policy != null ? consumerRegionHelper.inScope(region, country, policy) : false,
|
|
248
|
+
language: params.consumerLanguage ?? profile?.language ?? consumerRegionHelper.billingLanguageOf(country, policy),
|
|
249
|
+
chargeCurrency: regional
|
|
250
|
+
? (profile?.currency ?? consumerRegionHelper.chargeCurrencyOf(region, policy, settlement ?? catalogueCurrency)).toLowerCase()
|
|
251
|
+
: null,
|
|
252
|
+
addressLocked: kept && (profile?.locked === true || countryPinned),
|
|
253
|
+
countryPinned,
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
/** Whether the synced reusable price of a plan can be charged in `currency` (its default or an option). */
|
|
258
|
+
const priceCarries = async (product, plan, price, currency) => {
|
|
259
|
+
if (price.currency === currency) {
|
|
260
|
+
return { carries: true, ...(price.unit_amount != null ? { unitAmount: price.unit_amount } : {}) };
|
|
261
|
+
}
|
|
262
|
+
const listed = price.currency_options?.[currency];
|
|
263
|
+
if (listed != null) {
|
|
264
|
+
return { carries: true, ...(listed.unit_amount != null ? { unitAmount: listed.unit_amount } : {}) };
|
|
265
|
+
}
|
|
266
|
+
const synced = (await access.fingerprints().bySku(product.sku))?.prices?.find(entry => entry.planSku === plan.sku && entry.priceId === price.id);
|
|
267
|
+
const option = synced?.options.find(entry => entry.currency === currency);
|
|
268
|
+
return option != null ? { carries: true, unitAmount: option.unitAmount } : { carries: false };
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* A Dashboard without a terms-of-service URL must never stop a payment: the session is created
|
|
272
|
+
* once more without the checkbox, an operator is told (once), and the degraded checkout is audited
|
|
273
|
+
* as a `checkout-terms-fallback` event of the organization (`externalId` = the session).
|
|
274
|
+
*/
|
|
275
|
+
const createWithoutTerms = async (stripe, attempt, params, refusal) => {
|
|
276
|
+
const stripeMessage = paymentUtils.errorText(refusal);
|
|
277
|
+
if (!warnedTermsFallback.has(ctx)) {
|
|
278
|
+
warnedTermsFallback.add(ctx);
|
|
279
|
+
log.warn('Stripe refused the terms-of-service checkbox: this account has no terms of service URL. '
|
|
280
|
+
+ 'Checkouts continue WITHOUT the checkbox (metadata termsCollected=false). Operator: set the Billing Terms URL '
|
|
281
|
+
+ 'in the Stripe Dashboard → Settings → Public details (test and live mode alike).');
|
|
282
|
+
}
|
|
283
|
+
const typed = refusal;
|
|
284
|
+
const detail = JSON.stringify(paymentUtils.compact({
|
|
285
|
+
message: stripeMessage, code: typed.code ?? typed.raw?.code, param: typed.param ?? typed.raw?.param,
|
|
286
|
+
mode: attempt.mode, productSku: attempt.productSku, planSku: attempt.planSku,
|
|
287
|
+
}));
|
|
288
|
+
try {
|
|
289
|
+
const session = await stripe.checkout.sessions.create(withoutTerms(params));
|
|
290
|
+
await consumerRecordsOf(ctx).recordEvent({
|
|
291
|
+
recordId: attempt.entityId, recordKind: 'checkout', entityId: attempt.entityId, action: 'checkout-terms-fallback',
|
|
292
|
+
ok: false, externalId: session.id, detail,
|
|
293
|
+
});
|
|
294
|
+
return session;
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
await consumerRecordsOf(ctx).recordEvent({
|
|
298
|
+
recordId: attempt.entityId, recordKind: 'checkout', entityId: attempt.entityId, action: 'checkout-terms-fallback',
|
|
299
|
+
ok: false, detail, error: paymentUtils.errorText(error),
|
|
300
|
+
});
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Create the session, then tell the plugins it exists. A plugin's `created` that throws expires
|
|
306
|
+
* the fresh session and releases every admission before the error propagates. A session Stripe
|
|
307
|
+
* refuses for the terms checkbox alone (no terms URL in the Dashboard) is created once more
|
|
308
|
+
* without it — under the same admissions.
|
|
309
|
+
*/
|
|
310
|
+
const createSession = async (stripe, plugins, attempt, params) => {
|
|
311
|
+
const admitted = await checkoutPluginsOf(ctx).admitCheckout(plugins, attempt);
|
|
312
|
+
const holders = admitted.filter(entry => entry.plugin.admit != null);
|
|
313
|
+
let session;
|
|
314
|
+
try {
|
|
315
|
+
try {
|
|
316
|
+
session = await stripe.checkout.sessions.create(params);
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
if (params.consent_collection?.terms_of_service !== 'required' || !stripeSessionHelper.isMissingTermsUrl(error)) {
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
session = await createWithoutTerms(stripe, attempt, params, error);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
await checkoutPluginsOf(ctx).releaseAdmitted(holders, attempt);
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
if (session.url == null) {
|
|
330
|
+
await checkoutPluginsOf(ctx).releaseAdmitted(holders, attempt, session.id);
|
|
331
|
+
throw new PaygateError('session');
|
|
332
|
+
}
|
|
333
|
+
for (const { plugin, reservationId } of admitted) {
|
|
334
|
+
if (plugin.created == null) {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
try {
|
|
338
|
+
await plugin.created(ctx, { ...attempt, sessionId: session.id, url: session.url, ...(reservationId != null ? { reservationId } : {}) });
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
try {
|
|
342
|
+
await stripe.checkout.sessions.expire(session.id);
|
|
343
|
+
}
|
|
344
|
+
catch (expireError) {
|
|
345
|
+
log.error('Could not expire a checkout a plugin refused', { sessionId: session.id, error: expireError });
|
|
346
|
+
}
|
|
347
|
+
await checkoutPluginsOf(ctx).releaseAdmitted(holders, attempt, session.id);
|
|
348
|
+
throw error;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return session.url;
|
|
352
|
+
};
|
|
353
|
+
const createCheckoutLink = async (stripe, params, plugins = []) => {
|
|
354
|
+
const product = await access.payment().product(params.productSku);
|
|
355
|
+
const plans = (await access.payment().allPlans(product.sku))
|
|
356
|
+
.filter(plan => planHelper.isSoldThrough(product, plan, STRIPE_PAYGATE_ALIAS));
|
|
357
|
+
if (params.planSku != null && !plans.some(plan => plan.sku === params.planSku)) {
|
|
358
|
+
throw new ProductError(`plan:${params.planSku}`);
|
|
359
|
+
}
|
|
360
|
+
const consumable = product.type === ProductType.Consumable;
|
|
361
|
+
const plan = consumable
|
|
362
|
+
? plans.find(item => item.sku === params.planSku) ?? plans[0]
|
|
363
|
+
: plans.find(item => item.sku === params.planSku) ?? plans.find(item => item.recurring != null) ?? plans[0];
|
|
364
|
+
if (plan == null)
|
|
365
|
+
throw new ProductError('plan');
|
|
366
|
+
const catalogueCurrency = (plan.amountPolicy?.currency ?? plan.currency ?? 'usd').toLowerCase();
|
|
367
|
+
const { buyer, customer } = await buyerOf(stripe, params, catalogueCurrency);
|
|
368
|
+
const pricing = await access.payment().pricingPolicy();
|
|
369
|
+
const settlement = (await access.stripePricingConfig())?.settlementCurrency?.toLowerCase();
|
|
370
|
+
const ttl = checkoutPolicyHelper.sessionTtlOf(plugins);
|
|
371
|
+
const now = new Date();
|
|
372
|
+
const expiresAt = ttl != null ? new Date((Math.floor(now.getTime() / 1000) + ttl) * 1000) : undefined;
|
|
373
|
+
const expiry = expiresAt != null ? { expires_at: Math.floor(expiresAt.getTime() / 1000) } : {};
|
|
374
|
+
const { terms, ...termsParams } = termsOptions(buyer);
|
|
375
|
+
const base = {
|
|
376
|
+
entityId: params.entityId, productSku: product.sku, planSku: plan.sku, at: now,
|
|
377
|
+
...(ttl != null ? { sessionTtlSeconds: ttl } : {}), ...(expiresAt != null ? { expiresAt } : {}),
|
|
378
|
+
};
|
|
379
|
+
if (consumable && plan.pricingMode === CheckoutPricingMode.Amount) {
|
|
380
|
+
if (params.amountMinor == null)
|
|
381
|
+
throw new ProductError('amount');
|
|
382
|
+
const { chargeMinor: sourceChargeMinor, currency: amountCurrency } = stripeSessionHelper.amountCheckoutLineItem(product, plan, params.amountMinor, pricing.tax.behavior);
|
|
383
|
+
const view = await checkoutPluginsOf(ctx).narrowAmountFor(plugins, {
|
|
384
|
+
entityId: params.entityId, productSku: product.sku, planSku: plan.sku,
|
|
385
|
+
base: plan.amountPolicy, at: now,
|
|
386
|
+
});
|
|
387
|
+
checkoutPolicyHelper.assertAmountAllowed(view, params.amountMinor);
|
|
388
|
+
const charged = buyer.chargeCurrency != null
|
|
389
|
+
? await fxOf(ctx).chargeAmount(stripe, sourceChargeMinor, amountCurrency, buyer.chargeCurrency)
|
|
390
|
+
: await fxOf(ctx).settlementAmount(stripe, sourceChargeMinor, amountCurrency);
|
|
391
|
+
const adaptive = buyer.chargeCurrency == null || charged.currency === (settlement ?? amountCurrency);
|
|
392
|
+
const context = textContextOf(buyer, charged.currency, { unitAmountMinor: charged.amountMinor });
|
|
393
|
+
const submit = submitTextOf(params, context)
|
|
394
|
+
?? (buyer.policy != null && buyer.inScope && buyer.country != null
|
|
395
|
+
? consumerCopyHelper.consumerText(buyer.language, 'checkout.top-up', {
|
|
396
|
+
product: product.title, country: consumerFormatHelper.countryName(buyer.country, buyer.language),
|
|
397
|
+
})
|
|
398
|
+
: undefined);
|
|
399
|
+
const customText = paymentUtils.compact({
|
|
400
|
+
...(submit != null ? { submit: { message: limited(submit, 'submit') } } : {}),
|
|
401
|
+
...(terms != null ? { terms_of_service_acceptance: { message: terms } } : {}),
|
|
402
|
+
});
|
|
403
|
+
const lineItem = {
|
|
404
|
+
price_data: {
|
|
405
|
+
product: product.sku, currency: charged.currency, unit_amount: charged.amountMinor,
|
|
406
|
+
tax_behavior: pricing.tax.behavior,
|
|
407
|
+
},
|
|
408
|
+
quantity: 1,
|
|
409
|
+
};
|
|
410
|
+
return await createSession(stripe, plugins, {
|
|
411
|
+
...base, mode: 'amount', amountMinor: params.amountMinor, amountCurrency, chargeMinor: charged.amountMinor,
|
|
412
|
+
currency: charged.currency,
|
|
413
|
+
}, {
|
|
414
|
+
mode: 'payment', line_items: [lineItem], invoice_creation: { enabled: true },
|
|
415
|
+
...checkoutOptions(pricing, false, { locked: buyer.addressLocked, adaptive }),
|
|
416
|
+
...termsParams,
|
|
417
|
+
...(Object.keys(customText).length > 0 ? { custom_text: customText } : {}),
|
|
418
|
+
...expiry,
|
|
419
|
+
...sharedSession(customer, params, product, plan, {
|
|
420
|
+
pricingMode: CheckoutPricingMode.Amount,
|
|
421
|
+
currency: charged.currency,
|
|
422
|
+
amountCurrency,
|
|
423
|
+
amountMinor: String(params.amountMinor),
|
|
424
|
+
sourceChargeAmountMinor: String(sourceChargeMinor),
|
|
425
|
+
chargeAmountMinor: String(charged.amountMinor),
|
|
426
|
+
...consumerMetadata(buyer, params),
|
|
427
|
+
}),
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
const price = await findPrice(stripe, product.sku, planHelper.planLookupKey(product, plan));
|
|
431
|
+
const forced = buyer.chargeCurrency != null
|
|
432
|
+
? await priceCarries(product, plan, price, buyer.chargeCurrency) : { carries: false };
|
|
433
|
+
if (buyer.chargeCurrency != null && !forced.carries) {
|
|
434
|
+
log.warn('Plan has no price in the charge currency; Stripe picks the currency', { plan: plan.sku, currency: buyer.chargeCurrency });
|
|
435
|
+
}
|
|
436
|
+
const currency = forced.carries ? buyer.chargeCurrency : price.currency;
|
|
437
|
+
const adaptive = buyer.chargeCurrency == null || currency === (settlement ?? price.currency);
|
|
438
|
+
// Forced only when the synced price carries it: a session currency the price lacks is refused.
|
|
439
|
+
const currencyParam = forced.carries ? { currency } : {};
|
|
440
|
+
if (consumable) {
|
|
441
|
+
const quantityPolicy = plan.quantityPolicy ?? {
|
|
442
|
+
minimum: plan.minQuantity ?? 1,
|
|
113
443
|
maximum: plan.maxQuantity ?? Math.max(100_000, plan.minQuantity ?? 1),
|
|
114
444
|
default: plan.defaultQuantity ?? plan.minQuantity ?? 1,
|
|
115
445
|
};
|
|
116
|
-
const
|
|
446
|
+
const submit = submitTextOf(params, textContextOf(buyer, currency, paymentUtils.compact({ unitAmountMinor: forced.unitAmount ?? price.unit_amount ?? undefined })));
|
|
447
|
+
const customText = paymentUtils.compact({
|
|
448
|
+
...(submit != null ? { submit: { message: limited(submit, 'submit') } } : {}),
|
|
449
|
+
...(terms != null ? { terms_of_service_acceptance: { message: terms } } : {}),
|
|
450
|
+
});
|
|
451
|
+
return await createSession(stripe, plugins, { ...base, mode: 'quantity', currency }, {
|
|
117
452
|
mode: 'payment',
|
|
118
|
-
line_items: [quantityCheckoutLineItem(price,
|
|
453
|
+
line_items: [stripeSessionHelper.quantityCheckoutLineItem(price, quantityPolicy)],
|
|
119
454
|
invoice_creation: { enabled: true },
|
|
120
|
-
...
|
|
121
|
-
...
|
|
455
|
+
...currencyParam,
|
|
456
|
+
...checkoutOptions(pricing, true, { locked: buyer.addressLocked, adaptive }),
|
|
457
|
+
...termsParams,
|
|
458
|
+
...(Object.keys(customText).length > 0 ? { custom_text: customText } : {}),
|
|
459
|
+
...expiry,
|
|
460
|
+
...sharedSession(customer, params, product, plan, {
|
|
461
|
+
pricingMode: CheckoutPricingMode.Quantity,
|
|
462
|
+
...(forced.carries ? { currency } : {}),
|
|
463
|
+
...consumerMetadata(buyer, params),
|
|
464
|
+
}),
|
|
122
465
|
});
|
|
123
|
-
if (session.url == null)
|
|
124
|
-
throw new PaygateError('session');
|
|
125
|
-
return session.url;
|
|
126
466
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
467
|
+
// A subscription starts services at once: in scope (or unknown and protected) it needs the
|
|
468
|
+
// consumer's express start request, fresh and bound to this organization and plan.
|
|
469
|
+
const start = buyer.policy != null ? await access.consumerRightsOf()?.assertStartRequest(params.entityId, plan.sku, params.startRequestId) ?? null : null;
|
|
470
|
+
const stripePricing = await access.stripePricingConfig();
|
|
471
|
+
const subscriptionPaymentMethodTypes = (stripePricing?.subscriptionPaymentMethodTypesByCurrency?.[currency]
|
|
472
|
+
?? stripePricing?.subscriptionPaymentMethodTypes);
|
|
473
|
+
const unitAmount = forced.unitAmount ?? price.unit_amount ?? undefined;
|
|
474
|
+
const interval = plan.recurring?.interval;
|
|
475
|
+
const context = textContextOf(buyer, currency, paymentUtils.compact({ unitAmountMinor: unitAmount, interval }));
|
|
476
|
+
const renewal = buyer.policy != null && unitAmount != null && interval != null
|
|
477
|
+
? consumerCopyHelper.consumerText(buyer.language, `checkout.renewal.${interval}`, {
|
|
478
|
+
price: consumerCopyHelper.consumerText(buyer.language, `checkout.price.${pricing.tax.behavior === TaxBehavior.Inclusive ? 'inclusive' : 'exclusive'}`, {
|
|
479
|
+
amount: consumerFormatHelper.formatMoney(unitAmount, currency, buyer.language),
|
|
480
|
+
}),
|
|
481
|
+
})
|
|
482
|
+
: undefined;
|
|
483
|
+
const submit = submitTextOf(params, context) ?? renewal;
|
|
484
|
+
const links = buyer.policy != null ? consumerRightsPolicyHelper.linksOf(buyer.policy, buyer.language) : null;
|
|
485
|
+
const afterSubmit = buyer.policy?.mechanisms.cancellation === true && links?.cancellation != null
|
|
486
|
+
? consumerCopyHelper.consumerText(buyer.language, 'checkout.renewal.after-submit', { cancelUrl: links.cancellation })
|
|
487
|
+
: undefined;
|
|
488
|
+
const customText = paymentUtils.compact({
|
|
489
|
+
...(submit != null ? { submit: { message: limited(submit, 'submit') } } : {}),
|
|
490
|
+
...(afterSubmit != null ? { after_submit: { message: limited(afterSubmit, 'after-submit') } } : {}),
|
|
491
|
+
...(terms != null ? { terms_of_service_acceptance: { message: terms } } : {}),
|
|
492
|
+
});
|
|
493
|
+
const startRequestId = start?.id ?? undefined;
|
|
494
|
+
const metadata = consumerMetadata(buyer, params, startRequestId);
|
|
495
|
+
return await createSession(stripe, plugins, { ...base, mode: 'subscription', currency }, {
|
|
133
496
|
mode: 'subscription', line_items: [{ price: price.id, quantity: 1 }],
|
|
497
|
+
...currencyParam,
|
|
498
|
+
...(subscriptionPaymentMethodTypes != null ? { payment_method_types: subscriptionPaymentMethodTypes } : {}),
|
|
499
|
+
...(Object.keys(customText).length > 0 ? { custom_text: customText } : {}),
|
|
134
500
|
subscription_data: {
|
|
135
501
|
metadata: {
|
|
136
502
|
pricingMode: CheckoutPricingMode.Quantity, entityId: params.entityId,
|
|
137
503
|
service: params.service, productSku: product.sku, planSku: plan.sku,
|
|
504
|
+
...(params.profileId != null ? { profileId: params.profileId } : {}),
|
|
505
|
+
...metadata,
|
|
138
506
|
},
|
|
139
507
|
},
|
|
140
|
-
...
|
|
141
|
-
...
|
|
508
|
+
...checkoutOptions(pricing, true, { locked: buyer.addressLocked, adaptive }),
|
|
509
|
+
...termsParams,
|
|
510
|
+
...expiry,
|
|
511
|
+
...sharedSession(customer, params, product, plan, metadata),
|
|
142
512
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return session.url;
|
|
146
|
-
},
|
|
147
|
-
handleWebhook: async (request, ctx) => {
|
|
148
|
-
const config = await stripeConfig(ctx);
|
|
149
|
-
const stripe = await stripeClient(ctx);
|
|
150
|
-
const typed = request;
|
|
151
|
-
const rawBody = typed.original?.rawBody ?? typed.rawBody;
|
|
152
|
-
const signature = typed.headers[STRIPE_SIGNATURE.toLowerCase()];
|
|
153
|
-
if (rawBody == null || typeof signature !== 'string')
|
|
154
|
-
throw new PaygateError('signature');
|
|
155
|
-
const event = await stripe.webhooks.constructEventAsync(rawBody, signature, config.webhook);
|
|
156
|
-
await createEventHandler(ctx, stripe).process(event);
|
|
157
|
-
},
|
|
158
|
-
manageSubscription: async (ctx, entityId, returnUrl) => {
|
|
159
|
-
const stripe = await stripeClient(ctx);
|
|
160
|
-
const customer = await paygateCustomers(ctx).byEntity(entityId, STRIPE_PAYGATE_ALIAS);
|
|
161
|
-
if (customer == null)
|
|
162
|
-
throw new PaygateError('customer');
|
|
163
|
-
return (await stripe.billingPortal.sessions.create({ customer: customer.externalId, return_url: returnUrl })).url;
|
|
164
|
-
},
|
|
513
|
+
};
|
|
514
|
+
return { createCheckoutLink };
|
|
165
515
|
};
|
|
516
|
+
/** The Stripe Checkout of a context — one per context. */
|
|
517
|
+
export const stripeCheckoutOf = memoHelper.oncePer(makeStripeCheckoutHelper);
|
|
166
518
|
//# sourceMappingURL=stripe.js.map
|