@owlmeans/server-payment 0.1.18-rc.9 → 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/src/consts.ts
CHANGED
|
@@ -1,45 +1,109 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { GUARD_ED25519 } from '@owlmeans/server-app'
|
|
4
|
-
import type { JSONSchemaType } from 'ajv'
|
|
1
|
+
import { INTERNAL_PAYGATE, LIMIT_GATE } from '@owlmeans/payment'
|
|
2
|
+
export { INTERNAL_PAYGATE, LIMIT_GATE }
|
|
5
3
|
|
|
6
4
|
export const STRIPE_PAYGATE_ALIAS = 'stripe'
|
|
7
5
|
export const STRIPE_PLUGIN_CONFIG = '_external:stripe'
|
|
6
|
+
export const STRIPE_PORTAL_PLUGIN_CONFIG = '_external:stripe-portal'
|
|
7
|
+
/** Stripe-only pricing settings (FX Quotes API version, the unspecified-price migration switch) — never advertised to the browser, unlike the `PricingPolicy` record itself. */
|
|
8
|
+
export const STRIPE_PRICING_PLUGIN_CONFIG = '_external:stripe-pricing'
|
|
8
9
|
export const STRIPE_SIGNATURE = 'Stripe-Signature'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The FX Quotes API is a Stripe PREVIEW endpoint as of this writing: it answers only a
|
|
13
|
+
* `Stripe-Version` header naming a preview version, never the SDK's pinned stable one. Verify this
|
|
14
|
+
* string against https://docs.stripe.com/api/fx_quotes/create before relying on it, and override it
|
|
15
|
+
* with `declarePaymentPricing({ stripe: { fxApiVersion } })` once Stripe moves the API or renames
|
|
16
|
+
* the preview.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The Stripe API version every client of this package is pinned to (the one stripe-node 17 defaulted to).
|
|
20
|
+
* Moving it re-creates the stored webhook endpoints with their payload shapes, so it moves together with
|
|
21
|
+
* the readers of `current_period_*`, an invoice's subscription and a credit note's refund.
|
|
22
|
+
*/
|
|
23
|
+
export const STRIPE_PINNED_API_VERSION = '2025-02-24.acacia'
|
|
24
|
+
|
|
25
|
+
export const STRIPE_FX_QUOTES_API_VERSION = '2025-07-30.preview'
|
|
9
26
|
export const GATEWAY_SERVICE = 'payment-gateway'
|
|
10
27
|
export const PAYMENT_OBSERVER = 'payment-observer'
|
|
28
|
+
export const ENTITLEMENT_SERVICE = 'payment-entitlement'
|
|
29
|
+
|
|
11
30
|
export const RES_PAYGATE_CUSTOMER = 'payment-paygate-customer'
|
|
12
31
|
export const RES_PAYMENT_SUBSCRIPTION = 'payment-subscription'
|
|
32
|
+
export const RES_PAYMENT_FULFILLMENT = 'payment-fulfillment'
|
|
33
|
+
export const RES_PAYMENT_WEBHOOK = 'payment-webhook'
|
|
34
|
+
export const RES_PAYMENT_USAGE = 'payment-usage'
|
|
35
|
+
export const RES_PAYMENT_USAGE_COUNTER = 'payment-usage-counter'
|
|
13
36
|
export const RES_PAYMENT_FINGERPRINT = 'payment-fingerprint'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
|
|
38
|
+
/** One per organization: the billing country fixed at the first purchase. */
|
|
39
|
+
export const RES_BILLING_PROFILE = 'payment-billing-profile'
|
|
40
|
+
/** One per paid checkout (a top-up, a subscription's first invoice): the contract and its window. */
|
|
41
|
+
export const RES_PAYMENT_PURCHASE = 'payment-purchase'
|
|
42
|
+
/** Append-only: express consents to early performance and subscription start requests. */
|
|
43
|
+
export const RES_CONSUMER_CONSENT = 'payment-consumer-consent'
|
|
44
|
+
/** Append-only: withdrawal and cancellation declarations. */
|
|
45
|
+
export const RES_CONSUMER_DECLARATION = 'payment-consumer-declaration'
|
|
46
|
+
/** Append-only: every execution and audit step of the consumer-rights flows. */
|
|
47
|
+
export const RES_CONSUMER_EVENT = 'payment-consumer-event'
|
|
48
|
+
|
|
49
|
+
export const CONSUMER_RIGHTS_SERVICE = 'payment-consumer-rights'
|
|
50
|
+
/** The consumer-rights mail options (trader, sender, archive copies) — never advertised. */
|
|
51
|
+
export const CONSUMER_RIGHTS_MAIL_PLUGIN_CONFIG = '_external:payment-consumer-mail'
|
|
52
|
+
|
|
53
|
+
/** Stripe's own bounds of a Checkout Session's `expires_at`, from now. */
|
|
54
|
+
export const STRIPE_SESSION_TTL_MIN_SECONDS = 30 * 60
|
|
55
|
+
export const STRIPE_SESSION_TTL_MAX_SECONDS = 24 * 60 * 60
|
|
56
|
+
|
|
57
|
+
/** How far back `reconcile` looks for completed sessions that have no purchase row. */
|
|
58
|
+
export const PURCHASE_BACKFILL_DAYS = 16
|
|
59
|
+
|
|
60
|
+
/** Top-level domains that never receive mail (RFC 2606 / 6761) — e2e addresses are recorded as skipped. */
|
|
61
|
+
export const RESERVED_MAIL_TLDS: readonly string[] = Object.freeze(['test', 'example', 'invalid', 'localhost'])
|
|
62
|
+
|
|
63
|
+
/** The purchase id prefix of a Stripe purchase: `stripe:<session id>` or `stripe:<subscription id>`. */
|
|
64
|
+
export const PURCHASE_ID_PREFIX = 'stripe'
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The contract reference alphabet: digits and capitals without the look-alikes 0/O, 1/I/L, so a
|
|
68
|
+
* reference read aloud or typed from paper is never ambiguous.
|
|
69
|
+
*/
|
|
70
|
+
export const CONTRACT_REF_ALPHABET = '23456789ABCDEFGHJKMNPQRSTUVWXYZ'
|
|
71
|
+
|
|
72
|
+
/** Fingerprint sku prefix of a portal configuration: `portal:<owner>` (the gateway's `owner`). */
|
|
73
|
+
export const FINGERPRINT_PORTAL = 'portal'
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The metadata every Stripe object this package creates carries (`{ owlmeans: 'payment', service }`,
|
|
77
|
+
* `service` valued with the gateway's `owner`). It labels the object for an operator; several
|
|
78
|
+
* deployments of one owner share it, so it never decides on its own that an object belongs to this
|
|
79
|
+
* deployment.
|
|
80
|
+
*/
|
|
81
|
+
export const STRIPE_OWNER_KEY = 'owlmeans'
|
|
82
|
+
export const STRIPE_OWNER_VALUE = 'payment'
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The metadata key naming the ONE deployment a portal configuration belongs to, valued with that
|
|
86
|
+
* deployment's webhook URL (`webhookUrlOf`). Only an exact match lets a deployment adopt a
|
|
87
|
+
* configuration it holds no fingerprint row for.
|
|
88
|
+
*/
|
|
89
|
+
export const STRIPE_DEPLOYMENT_KEY = 'deployment'
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Every Stripe event the managed webhook endpoint subscribes to.
|
|
93
|
+
*
|
|
94
|
+
* `invoice.upcoming` is enabled although nothing handles it (it carries no invoice id and nothing
|
|
95
|
+
* is due), so an application can observe it without a Stripe dashboard change.
|
|
96
|
+
*/
|
|
97
|
+
export const WEBHOOK_EVENTS: readonly string[] = Object.freeze([
|
|
98
|
+
'checkout.session.completed', 'checkout.session.async_payment_succeeded',
|
|
99
|
+
'checkout.session.async_payment_failed', 'checkout.session.expired',
|
|
100
|
+
'customer.created', 'customer.updated', 'customer.deleted',
|
|
101
|
+
'customer.subscription.created', 'customer.subscription.updated', 'customer.subscription.deleted',
|
|
102
|
+
'customer.subscription.paused', 'customer.subscription.resumed', 'customer.subscription.trial_will_end',
|
|
103
|
+
'customer.subscription.pending_update_applied', 'customer.subscription.pending_update_expired',
|
|
104
|
+
'invoice.paid', 'invoice.payment_failed', 'invoice.payment_action_required', 'invoice.upcoming',
|
|
105
|
+
'invoice.marked_uncollectible', 'invoice.voided',
|
|
106
|
+
'charge.refunded', 'refund.created', 'refund.updated', 'refund.failed',
|
|
107
|
+
'charge.dispute.created', 'charge.dispute.closed', 'charge.dispute.funds_withdrawn',
|
|
108
|
+
'charge.dispute.funds_reinstated',
|
|
109
|
+
])
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type Stripe from 'stripe'
|
|
2
|
+
import type { ConsumerDeclarationRecord, PaymentSubscriptionRecord } from '../../types.js'
|
|
3
|
+
|
|
4
|
+
/** The paygate step of a declared cancellation. */
|
|
5
|
+
export interface CancellationHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Schedule an ordinary cancellation at the paygate: at the period end (`cancel_at_period_end`), or
|
|
8
|
+
* at a later boundary (`cancel_at`, no proration). Recorded as a `cancel-scheduled` event.
|
|
9
|
+
*/
|
|
10
|
+
scheduleCancellation: (
|
|
11
|
+
stripe: Stripe, declaration: ConsumerDeclarationRecord, row: PaymentSubscriptionRecord, attempt?: number,
|
|
12
|
+
) => Promise<boolean>
|
|
13
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type Stripe from 'stripe'
|
|
2
|
+
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
3
|
+
import { memoHelper } from '@owlmeans/context'
|
|
4
|
+
import type { ConsumerDeclarationRecord, PaymentSubscriptionRecord } from '../types.js'
|
|
5
|
+
import { paymentUtils } from '../utils.js'
|
|
6
|
+
import { consumerRecordsOf } from './records.js'
|
|
7
|
+
import type { CancellationHelper } from './cancellation/types.js'
|
|
8
|
+
|
|
9
|
+
export const makeCancellationHelper = (ctx: ApiContext): CancellationHelper => {
|
|
10
|
+
const scheduleCancellation = async (
|
|
11
|
+
stripe: Stripe, declaration: ConsumerDeclarationRecord, row: PaymentSubscriptionRecord, attempt: number = 0,
|
|
12
|
+
): Promise<boolean> => {
|
|
13
|
+
const id = declaration.id as string
|
|
14
|
+
const effectiveAt = declaration.effectiveAt != null ? new Date(declaration.effectiveAt) : null
|
|
15
|
+
const atPeriodEnd = effectiveAt == null || row.periodEnd == null
|
|
16
|
+
|| effectiveAt.getTime() === new Date(row.periodEnd).getTime()
|
|
17
|
+
const details = { comment: `cancellation:${id}` }
|
|
18
|
+
try {
|
|
19
|
+
await stripe.subscriptions.update(row.externalId, atPeriodEnd
|
|
20
|
+
? { cancel_at_period_end: true, cancellation_details: details }
|
|
21
|
+
: { cancel_at: Math.floor((effectiveAt as Date).getTime() / 1000), proration_behavior: 'none', cancellation_details: details },
|
|
22
|
+
{ idempotencyKey: attempt > 0 ? `cancellation:${id}:schedule:${attempt}` : `cancellation:${id}:schedule` })
|
|
23
|
+
await consumerRecordsOf(ctx).recordEvent({
|
|
24
|
+
recordId: id, recordKind: 'declaration', entityId: row.entityId, action: 'cancel-scheduled', ok: true,
|
|
25
|
+
externalId: row.externalId, detail: JSON.stringify({ atPeriodEnd, effectiveAt: effectiveAt?.toISOString() }),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
return true
|
|
29
|
+
} catch (error) {
|
|
30
|
+
await consumerRecordsOf(ctx).recordEvent({
|
|
31
|
+
recordId: id, recordKind: 'declaration', entityId: row.entityId, action: 'cancel-scheduled', ok: false,
|
|
32
|
+
externalId: row.externalId, error: paymentUtils.errorText(error),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return { scheduleCancellation }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The paygate cancellations of a context — one per context. */
|
|
43
|
+
export const cancellationOf = memoHelper.oncePer(makeCancellationHelper)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type Stripe from 'stripe'
|
|
2
|
+
import type { PaymentSubscriptionRecord, PurchaseRecord } from '../../types.js'
|
|
3
|
+
import type { CapturedPurchase, InvoiceEvidence, SessionEvidence } from '../types.js'
|
|
4
|
+
|
|
5
|
+
/** What a one-time checkout or a subscription's first invoice extra-records of its purchase. */
|
|
6
|
+
export interface CapturedPaymentExtra {
|
|
7
|
+
netAmountMinor?: number
|
|
8
|
+
amountCurrency?: string
|
|
9
|
+
units?: number
|
|
10
|
+
taxBehavior?: string
|
|
11
|
+
at?: Date
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Paid checkouts and first invoices of a context, captured as purchases. */
|
|
15
|
+
export interface CaptureHelper {
|
|
16
|
+
/**
|
|
17
|
+
* The buyer and totals of a Checkout Session. `presentment_details` (Adaptive Pricing) is not typed
|
|
18
|
+
* by the pinned SDK, hence the narrow accessor.
|
|
19
|
+
*/
|
|
20
|
+
sessionEvidenceOf: (session: Stripe.Checkout.Session) => SessionEvidence
|
|
21
|
+
/**
|
|
22
|
+
* An invoice's evidence, best effort: an unreachable invoice is logged and yields nothing — the
|
|
23
|
+
* withdrawal reads it again when it needs it. `invoice.payment_intent` is top-level on the pinned
|
|
24
|
+
* API version.
|
|
25
|
+
*/
|
|
26
|
+
invoiceEvidenceOf: (stripe: Stripe | null | undefined, invoiceId: string | undefined) => Promise<InvoiceEvidence>
|
|
27
|
+
/**
|
|
28
|
+
* A completed, paid ONE-TIME checkout as a purchase — the window and the contract registry. Runs
|
|
29
|
+
* BEFORE the credits are granted: the billing country is locked first (first write wins; another
|
|
30
|
+
* country is a `lock-mismatch` event), then the purchase row is written, then its confirmation is
|
|
31
|
+
* mailed. `null` when no consumer-rights policy is declared.
|
|
32
|
+
*/
|
|
33
|
+
capturePaymentPurchase: (
|
|
34
|
+
stripe: Stripe | null, session: Stripe.Checkout.Session, extra?: CapturedPaymentExtra, opts?: { mail?: boolean },
|
|
35
|
+
) => Promise<CapturedPurchase | null>
|
|
36
|
+
/**
|
|
37
|
+
* A subscription's FIRST invoice as a purchase — called while the subscription is committed, BEFORE
|
|
38
|
+
* the `created` observers grant anything, so the window exists before the bundle can be spent. The
|
|
39
|
+
* buyer's country and totals are refined when the checkout completes. The start request (when the
|
|
40
|
+
* metadata names one) is the purchase's consent: `servicesStartedAt` and `consentedAt`.
|
|
41
|
+
*/
|
|
42
|
+
captureSubscriptionPurchase: (
|
|
43
|
+
stripe: Stripe | null, subscription: Stripe.Subscription, row: PaymentSubscriptionRecord,
|
|
44
|
+
) => Promise<CapturedPurchase | null>
|
|
45
|
+
/**
|
|
46
|
+
* Refine a subscription purchase with its completed checkout: the buyer's own country (and so the
|
|
47
|
+
* scope and deadline), e-mail, the charged totals, the terms acceptance and the session id; lock
|
|
48
|
+
* the billing country; mail the confirmation once.
|
|
49
|
+
*/
|
|
50
|
+
completeSubscriptionPurchase: (
|
|
51
|
+
stripe: Stripe | null, session: Stripe.Checkout.Session, purchase: PurchaseRecord, opts?: { mail?: boolean },
|
|
52
|
+
) => Promise<PurchaseRecord>
|
|
53
|
+
}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import type Stripe from 'stripe'
|
|
2
|
+
import { ConsentKind, CONSUMER_RIGHTS_COPY_VERSION, PurchaseKind, type ConsumerRightsPolicy, consumerRegionHelper, withdrawalDeadlineHelper } from '@owlmeans/payment'
|
|
3
|
+
import type { Context as ApiContext } from '@owlmeans/server-api'
|
|
4
|
+
import { memoHelper } from '@owlmeans/context'
|
|
5
|
+
import { STRIPE_PAYGATE_ALIAS } from '../consts.js'
|
|
6
|
+
import type { PurchaseDraft, CapturedPurchase, InvoiceEvidence, SessionEvidence } from './types.js'
|
|
7
|
+
import type {
|
|
8
|
+
BillingProfileRecord, PaymentSubscriptionRecord, PurchaseRecord, ConsumerConsentRecord,
|
|
9
|
+
} from '../types.js'
|
|
10
|
+
import { log } from '../log.js'
|
|
11
|
+
import { paymentAccessOf } from '../access.js'
|
|
12
|
+
import { paymentUtils } from '../utils.js'
|
|
13
|
+
import { consumerRecordsOf } from './records.js'
|
|
14
|
+
import type { CapturedPaymentExtra, CaptureHelper } from './capture/types.js'
|
|
15
|
+
import { consumerMailOf } from './mail.js'
|
|
16
|
+
|
|
17
|
+
const deadlineOf = (policy: ConsumerRightsPolicy, scoped: boolean, purchasedAt: Date): Date | undefined =>
|
|
18
|
+
scoped ? withdrawalDeadlineHelper.withdrawalDeadlineOf(purchasedAt, policy) : undefined
|
|
19
|
+
|
|
20
|
+
export const makeCaptureHelper = (ctx: ApiContext): CaptureHelper => {
|
|
21
|
+
const access = paymentAccessOf(ctx)
|
|
22
|
+
const records = consumerRecordsOf(ctx)
|
|
23
|
+
|
|
24
|
+
const sessionEvidenceOf = (session: Stripe.Checkout.Session): SessionEvidence => {
|
|
25
|
+
const details = session.customer_details
|
|
26
|
+
const presentment = (session as unknown as {
|
|
27
|
+
presentment_details?: { presentment_amount?: number, presentment_currency?: string } | null
|
|
28
|
+
}).presentment_details
|
|
29
|
+
const subtotal = session.amount_subtotal ?? 0
|
|
30
|
+
const tax = session.total_details?.amount_tax ?? 0
|
|
31
|
+
|
|
32
|
+
return paymentUtils.compact({
|
|
33
|
+
country: details?.address?.country?.toUpperCase() ?? undefined,
|
|
34
|
+
email: details?.email ?? undefined,
|
|
35
|
+
name: details?.name ?? undefined,
|
|
36
|
+
business: (details?.tax_ids?.length ?? 0) > 0 || details?.tax_exempt === 'reverse' ? true : undefined,
|
|
37
|
+
currency: (session.currency ?? '').toLowerCase(),
|
|
38
|
+
subtotalMinor: subtotal,
|
|
39
|
+
taxMinor: tax,
|
|
40
|
+
totalMinor: session.amount_total ?? subtotal + tax,
|
|
41
|
+
presentmentCurrency: presentment?.presentment_currency?.toLowerCase(),
|
|
42
|
+
presentmentAmountMinor: presentment?.presentment_amount,
|
|
43
|
+
termsAccepted: session.consent?.terms_of_service === 'accepted' ? true
|
|
44
|
+
: session.consent?.terms_of_service != null ? false : undefined,
|
|
45
|
+
}) as SessionEvidence
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const invoiceEvidenceOf = async (
|
|
49
|
+
stripe: Stripe | null | undefined, invoiceId: string | undefined,
|
|
50
|
+
): Promise<InvoiceEvidence> => {
|
|
51
|
+
if (stripe == null || invoiceId == null) {
|
|
52
|
+
return {}
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const invoice = await stripe.invoices.retrieve(invoiceId)
|
|
56
|
+
const typed = invoice as unknown as { payment_intent?: string | { id?: string } | null, tax?: number | null }
|
|
57
|
+
|
|
58
|
+
return paymentUtils.compact({
|
|
59
|
+
invoiceNumber: invoice.number ?? undefined,
|
|
60
|
+
invoiceLineId: invoice.lines?.data?.[0]?.id,
|
|
61
|
+
paymentIntentId: paymentUtils.idOf(typed.payment_intent),
|
|
62
|
+
country: invoice.customer_address?.country?.toUpperCase() ?? undefined,
|
|
63
|
+
subtotalMinor: invoice.subtotal ?? undefined,
|
|
64
|
+
taxMinor: typed.tax ?? undefined,
|
|
65
|
+
totalMinor: invoice.total ?? undefined,
|
|
66
|
+
currency: invoice.currency ?? undefined,
|
|
67
|
+
}) as InvoiceEvidence
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (!paymentUtils.isMissingObject(error)) {
|
|
70
|
+
log.warn('Invoice unreadable for its purchase', { invoiceId, error })
|
|
71
|
+
}
|
|
72
|
+
return {}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Lock the entity's billing country from a completed checkout, when the policy locks countries: the
|
|
78
|
+
* buyer's address at Stripe, else the declared country — the pinned one first when the session held
|
|
79
|
+
* it (`countryPinned`: tax was calculated on it, the card form's country moved nothing).
|
|
80
|
+
*/
|
|
81
|
+
const lockFromSession = async (
|
|
82
|
+
policy: ConsumerRightsPolicy, entityId: string, session: Stripe.Checkout.Session,
|
|
83
|
+
evidence: SessionEvidence,
|
|
84
|
+
): Promise<BillingProfileRecord | null> => {
|
|
85
|
+
const metadata = session.metadata ?? {}
|
|
86
|
+
const country = metadata.countryPinned === 'true'
|
|
87
|
+
? metadata.country ?? evidence.country
|
|
88
|
+
: evidence.country ?? metadata.country
|
|
89
|
+
if (!policy.mechanisms.countryLock || country == null || country === '') {
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
const { record } = await records.lockProfile(policy, {
|
|
93
|
+
entityId, country, source: 'checkout', customerId: paymentUtils.idOf(session.customer), sessionId: session.id,
|
|
94
|
+
ipCountry: metadata.ipCountry, email: evidence.email, name: evidence.name, business: evidence.business,
|
|
95
|
+
currency: evidence.currency, language: metadata.language,
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
return record
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Mail the purchase confirmation once per purchase: only the delivery that claims the purchase's
|
|
103
|
+
* `confirmationMailAt` (a conditional write — concurrent deliveries in several processes, a
|
|
104
|
+
* redelivery, the checkout refining a subscription) sends it; one that failed is retried by
|
|
105
|
+
* `reconcile`, never here. A purchase mailed before the claim existed is recognised by its event.
|
|
106
|
+
*/
|
|
107
|
+
const confirmPurchase = async (policy: ConsumerRightsPolicy, purchase: PurchaseRecord): Promise<void> => {
|
|
108
|
+
if (!policy.mechanisms.purchaseConfirmation || !purchase.inScope) {
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
if (await records.hasEvent(purchase.purchaseId, 'mail', 'purchase')) {
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
const claimed = await paymentUtils.conditionalSet(access.purchases(), { purchaseId: purchase.purchaseId, confirmationMailAt: null }, {
|
|
115
|
+
confirmationMailAt: new Date(),
|
|
116
|
+
})
|
|
117
|
+
if (!claimed) {
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
await consumerMailOf(ctx).sendConsumerMail(policy, 'purchase', purchase.purchaseId)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const capturePaymentPurchase = async (
|
|
124
|
+
stripe: Stripe | null, session: Stripe.Checkout.Session, extra: CapturedPaymentExtra = {}, opts: { mail?: boolean } = {},
|
|
125
|
+
): Promise<CapturedPurchase | null> => {
|
|
126
|
+
const policy = await access.payment().consumerRightsPolicy()
|
|
127
|
+
if (policy == null) {
|
|
128
|
+
return null
|
|
129
|
+
}
|
|
130
|
+
const metadata = session.metadata ?? {}
|
|
131
|
+
const entityId = metadata.entityId
|
|
132
|
+
if (entityId == null || metadata.productSku == null) {
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
const evidence = sessionEvidenceOf(session)
|
|
136
|
+
const profile = await lockFromSession(policy, entityId, session, evidence)
|
|
137
|
+
const existing = await access.purchases().byPurchaseId(records.purchaseIdOf(session.id))
|
|
138
|
+
if (existing != null) {
|
|
139
|
+
if (opts.mail !== false) await confirmPurchase(policy, existing)
|
|
140
|
+
return { purchase: existing, created: false }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const country = evidence.country ?? metadata.country ?? profile?.country
|
|
144
|
+
const region = consumerRegionHelper.regionOf(country, policy)
|
|
145
|
+
// Protected when either the buyer's own address or the organization's locked country is in scope.
|
|
146
|
+
const scoped = consumerRegionHelper.inScope(region, country, policy) || (profile != null && consumerRegionHelper.inScope(profile.region, profile.country, policy))
|
|
147
|
+
const invoice = await invoiceEvidenceOf(stripe, paymentUtils.idOf(session.invoice))
|
|
148
|
+
const purchasedAt = extra.at ?? new Date()
|
|
149
|
+
const draft = paymentUtils.compact({
|
|
150
|
+
purchaseId: records.purchaseIdOf(session.id),
|
|
151
|
+
entityId,
|
|
152
|
+
kind: PurchaseKind.TopUp,
|
|
153
|
+
paygate: STRIPE_PAYGATE_ALIAS,
|
|
154
|
+
sessionId: session.id,
|
|
155
|
+
paymentIntentId: paymentUtils.idOf(session.payment_intent) ?? invoice.paymentIntentId,
|
|
156
|
+
invoiceId: paymentUtils.idOf(session.invoice),
|
|
157
|
+
invoiceNumber: invoice.invoiceNumber,
|
|
158
|
+
invoiceLineId: invoice.invoiceLineId,
|
|
159
|
+
productSku: metadata.productSku,
|
|
160
|
+
planSku: metadata.planSku,
|
|
161
|
+
profileId: metadata.profileId,
|
|
162
|
+
country,
|
|
163
|
+
region: region ?? undefined,
|
|
164
|
+
ipCountry: metadata.ipCountry,
|
|
165
|
+
inScope: scoped,
|
|
166
|
+
language: profile?.language ?? metadata.language ?? consumerRegionHelper.billingLanguageOf(country, policy),
|
|
167
|
+
email: evidence.email,
|
|
168
|
+
name: evidence.name,
|
|
169
|
+
business: evidence.business,
|
|
170
|
+
currency: evidence.currency,
|
|
171
|
+
amountSubtotalMinor: evidence.subtotalMinor,
|
|
172
|
+
amountTaxMinor: evidence.taxMinor,
|
|
173
|
+
amountTotalMinor: evidence.totalMinor,
|
|
174
|
+
presentmentCurrency: evidence.presentmentCurrency,
|
|
175
|
+
presentmentAmountMinor: evidence.presentmentAmountMinor,
|
|
176
|
+
netAmountMinor: extra.netAmountMinor,
|
|
177
|
+
amountCurrency: extra.amountCurrency,
|
|
178
|
+
units: extra.units,
|
|
179
|
+
taxBehavior: extra.taxBehavior,
|
|
180
|
+
termsAccepted: evidence.termsAccepted,
|
|
181
|
+
textVersion: metadata.termsVersion ?? policy.textVersion,
|
|
182
|
+
copyVersion: metadata.copyVersion ?? CONSUMER_RIGHTS_COPY_VERSION,
|
|
183
|
+
purchasedAt,
|
|
184
|
+
deadline: deadlineOf(policy, scoped, purchasedAt),
|
|
185
|
+
}) as PurchaseDraft
|
|
186
|
+
const { record, created } = await records.createPurchase(draft)
|
|
187
|
+
if (opts.mail !== false) await confirmPurchase(policy, record)
|
|
188
|
+
|
|
189
|
+
return { purchase: record, created }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The start request a subscription's metadata names, when it is a real start request of that entity. */
|
|
193
|
+
const startRequestOf = async (entityId: string, id: string | undefined): Promise<ConsumerConsentRecord | null> => {
|
|
194
|
+
if (id == null || id === '') {
|
|
195
|
+
return null
|
|
196
|
+
}
|
|
197
|
+
const consent = await access.consumerConsents().load(id).catch(() => null)
|
|
198
|
+
|
|
199
|
+
return consent != null && consent.kind === ConsentKind.SubscriptionStart && consent.entityId === entityId ? consent : null
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const captureSubscriptionPurchase = async (
|
|
203
|
+
stripe: Stripe | null, subscription: Stripe.Subscription, row: PaymentSubscriptionRecord,
|
|
204
|
+
): Promise<CapturedPurchase | null> => {
|
|
205
|
+
const policy = await access.payment().consumerRightsPolicy()
|
|
206
|
+
if (policy == null) {
|
|
207
|
+
return null
|
|
208
|
+
}
|
|
209
|
+
const purchaseId = records.purchaseIdOf(subscription.id)
|
|
210
|
+
const existing = await access.purchases().byPurchaseId(purchaseId)
|
|
211
|
+
if (existing != null) {
|
|
212
|
+
return { purchase: existing, created: false }
|
|
213
|
+
}
|
|
214
|
+
const metadata = subscription.metadata ?? {}
|
|
215
|
+
const item = subscription.items?.data?.[0]
|
|
216
|
+
const invoiceId = paymentUtils.idOf(subscription.latest_invoice)
|
|
217
|
+
const invoice = await invoiceEvidenceOf(stripe, invoiceId)
|
|
218
|
+
const profile = await access.billingProfiles().byEntity(row.entityId)
|
|
219
|
+
const country = invoice.country ?? profile?.country ?? metadata.country
|
|
220
|
+
const region = consumerRegionHelper.regionOf(country, policy)
|
|
221
|
+
const scoped = consumerRegionHelper.inScope(region, country, policy) || (profile != null && consumerRegionHelper.inScope(profile.region, profile.country, policy))
|
|
222
|
+
const start = await startRequestOf(row.entityId, metadata.startRequestId)
|
|
223
|
+
const subtotal = invoice.subtotalMinor ?? (item?.price?.unit_amount ?? 0) * (item?.quantity ?? 1)
|
|
224
|
+
const tax = invoice.taxMinor ?? 0
|
|
225
|
+
const purchasedAt = paymentUtils.dateOf(subscription.created) ?? new Date()
|
|
226
|
+
const draft = paymentUtils.compact({
|
|
227
|
+
purchaseId,
|
|
228
|
+
entityId: row.entityId,
|
|
229
|
+
kind: PurchaseKind.Subscription,
|
|
230
|
+
paygate: STRIPE_PAYGATE_ALIAS,
|
|
231
|
+
subscriptionId: subscription.id,
|
|
232
|
+
paymentIntentId: invoice.paymentIntentId,
|
|
233
|
+
invoiceId,
|
|
234
|
+
invoiceNumber: invoice.invoiceNumber,
|
|
235
|
+
invoiceLineId: invoice.invoiceLineId,
|
|
236
|
+
productSku: row.productSku,
|
|
237
|
+
planSku: row.planSku,
|
|
238
|
+
profileId: metadata.profileId,
|
|
239
|
+
country,
|
|
240
|
+
region: region ?? undefined,
|
|
241
|
+
ipCountry: metadata.ipCountry,
|
|
242
|
+
inScope: scoped,
|
|
243
|
+
language: profile?.language ?? metadata.language ?? consumerRegionHelper.billingLanguageOf(country, policy),
|
|
244
|
+
currency: (invoice.currency ?? subscription.currency ?? item?.price?.currency ?? 'usd').toLowerCase(),
|
|
245
|
+
amountSubtotalMinor: subtotal,
|
|
246
|
+
amountTaxMinor: tax,
|
|
247
|
+
amountTotalMinor: invoice.totalMinor ?? subtotal + tax,
|
|
248
|
+
taxBehavior: item?.price?.tax_behavior ?? undefined,
|
|
249
|
+
textVersion: metadata.termsVersion ?? policy.textVersion,
|
|
250
|
+
copyVersion: metadata.copyVersion ?? CONSUMER_RIGHTS_COPY_VERSION,
|
|
251
|
+
startRequestId: start?.id,
|
|
252
|
+
servicesStartedAt: start?.decidedAt,
|
|
253
|
+
consentId: start?.id,
|
|
254
|
+
consentedAt: start?.decidedAt,
|
|
255
|
+
purchasedAt,
|
|
256
|
+
deadline: deadlineOf(policy, scoped, purchasedAt),
|
|
257
|
+
}) as PurchaseDraft
|
|
258
|
+
const { record, created } = await records.createPurchase(draft)
|
|
259
|
+
|
|
260
|
+
return { purchase: record, created }
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const completeSubscriptionPurchase = async (
|
|
264
|
+
stripe: Stripe | null, session: Stripe.Checkout.Session, purchase: PurchaseRecord,
|
|
265
|
+
opts: { mail?: boolean } = {},
|
|
266
|
+
): Promise<PurchaseRecord> => {
|
|
267
|
+
const policy = await access.payment().consumerRightsPolicy()
|
|
268
|
+
if (policy == null) {
|
|
269
|
+
return purchase
|
|
270
|
+
}
|
|
271
|
+
const evidence = sessionEvidenceOf(session)
|
|
272
|
+
const profile = await lockFromSession(policy, purchase.entityId, session, evidence)
|
|
273
|
+
const country = evidence.country ?? purchase.country ?? profile?.country
|
|
274
|
+
const region = consumerRegionHelper.regionOf(country, policy)
|
|
275
|
+
const scoped = consumerRegionHelper.inScope(region, country, policy) || (profile != null && consumerRegionHelper.inScope(profile.region, profile.country, policy))
|
|
276
|
+
const invoice = purchase.invoiceLineId == null || purchase.paymentIntentId == null
|
|
277
|
+
? await invoiceEvidenceOf(stripe, purchase.invoiceId ?? paymentUtils.idOf(session.invoice)) : {}
|
|
278
|
+
const purchasedAt = new Date(purchase.purchasedAt)
|
|
279
|
+
const fields = paymentUtils.compact({
|
|
280
|
+
sessionId: session.id,
|
|
281
|
+
invoiceId: purchase.invoiceId ?? paymentUtils.idOf(session.invoice),
|
|
282
|
+
invoiceNumber: purchase.invoiceNumber ?? invoice.invoiceNumber,
|
|
283
|
+
invoiceLineId: purchase.invoiceLineId ?? invoice.invoiceLineId,
|
|
284
|
+
paymentIntentId: purchase.paymentIntentId ?? invoice.paymentIntentId,
|
|
285
|
+
country,
|
|
286
|
+
region: region ?? undefined,
|
|
287
|
+
inScope: scoped,
|
|
288
|
+
deadline: scoped ? purchase.deadline ?? withdrawalDeadlineHelper.withdrawalDeadlineOf(purchasedAt, policy) : undefined,
|
|
289
|
+
email: evidence.email ?? purchase.email,
|
|
290
|
+
name: evidence.name ?? purchase.name,
|
|
291
|
+
business: evidence.business ?? purchase.business,
|
|
292
|
+
currency: evidence.currency !== '' ? evidence.currency : purchase.currency,
|
|
293
|
+
amountSubtotalMinor: evidence.subtotalMinor,
|
|
294
|
+
amountTaxMinor: evidence.taxMinor,
|
|
295
|
+
amountTotalMinor: evidence.totalMinor,
|
|
296
|
+
presentmentCurrency: evidence.presentmentCurrency,
|
|
297
|
+
presentmentAmountMinor: evidence.presentmentAmountMinor,
|
|
298
|
+
termsAccepted: evidence.termsAccepted,
|
|
299
|
+
ipCountry: purchase.ipCountry ?? session.metadata?.ipCountry,
|
|
300
|
+
language: profile?.language ?? purchase.language,
|
|
301
|
+
}) as Partial<PurchaseRecord>
|
|
302
|
+
await records.patchPurchase(purchase.purchaseId, fields)
|
|
303
|
+
const updated = { ...purchase, ...fields } as PurchaseRecord
|
|
304
|
+
if (!scoped && purchase.deadline != null) {
|
|
305
|
+
// Out of scope after all (the buyer's own country): no window.
|
|
306
|
+
await records.patchPurchase(purchase.purchaseId, { deadline: null as unknown as undefined })
|
|
307
|
+
delete updated.deadline
|
|
308
|
+
}
|
|
309
|
+
if (opts.mail !== false) await confirmPurchase(policy, updated)
|
|
310
|
+
|
|
311
|
+
return updated
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return {
|
|
315
|
+
sessionEvidenceOf, invoiceEvidenceOf, capturePaymentPurchase, captureSubscriptionPurchase,
|
|
316
|
+
completeSubscriptionPurchase,
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** The purchase capture of a context — one per context. */
|
|
321
|
+
export const captureOf = memoHelper.oncePer(makeCaptureHelper)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ConsumerMailKind, ConsumerRecordKind } from '../types.js'
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_PUBLIC_MIN_MS = 1000
|
|
4
|
+
|
|
5
|
+
export const RECORD_KIND: Record<ConsumerMailKind, ConsumerRecordKind> = {
|
|
6
|
+
purchase: 'purchase', consent: 'consent', start: 'consent', withdrawal: 'declaration', cancellation: 'declaration',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const USER_AGENT_MAX = 512
|
|
10
|
+
|
|
11
|
+
export const HEADER_MAX = 1024
|
|
12
|
+
|
|
13
|
+
export const DAY_MS = 86_400_000
|
|
14
|
+
|
|
15
|
+
/** A paygate step failed this often is left to an operator. */
|
|
16
|
+
export const MAX_ATTEMPTS = 5
|
|
17
|
+
|
|
18
|
+
export const CONTRACT_REF_ATTEMPTS = 6
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** How the consumer-rights flows write and read references, addresses, amounts and dates — pure. */
|
|
2
|
+
export interface ConsumerFormatHelper {
|
|
3
|
+
/** `CR-YYMMDD-XXXXXX` — the purchase's UTC date and six characters of an unambiguous alphabet. */
|
|
4
|
+
newContractRef: (at?: Date) => string
|
|
5
|
+
/** A contract reference as a person may type it: trimmed, upper-cased, look-alike dashes unified. */
|
|
6
|
+
normalizeContractRef: (value: string) => string
|
|
7
|
+
normalizeEmail: (value: string | null | undefined) => string
|
|
8
|
+
/**
|
|
9
|
+
* Whether an address is on a reserved top-level domain (`.test`, `.example`, `.invalid`,
|
|
10
|
+
* `.localhost` — RFC 2606 / 6761), any subdomain included: `a@shop.test`, `a@mail.shop.test`,
|
|
11
|
+
* `a@localhost`. Case, surrounding spaces, a display-name form (`Name <a@shop.test>`) and a
|
|
12
|
+
* trailing root dot are all read through.
|
|
13
|
+
*/
|
|
14
|
+
isReservedAddress: (address: string) => boolean
|
|
15
|
+
escapeHtml: (value: string) => string
|
|
16
|
+
/** Minor units as a localized amount with its currency (`12,56 €`, `$12.56`). */
|
|
17
|
+
formatMoney: (amountMinor: number, currency: string, lng: string) => string
|
|
18
|
+
/** A date and time in UTC, localized (`23 September 2026, 14:05`). */
|
|
19
|
+
formatDateTime: (at: Date, lng: string) => string
|
|
20
|
+
/** A calendar date in UTC, localized. */
|
|
21
|
+
formatDate: (at: Date, lng: string) => string
|
|
22
|
+
/**
|
|
23
|
+
* The last included day of a window whose deadline is EXCLUSIVE (the first instant it is over),
|
|
24
|
+
* as a UTC date — the copy says "until the end of <date>": 13 October 00:00 UTC is "12 October".
|
|
25
|
+
*/
|
|
26
|
+
formatDeadline: (deadline: Date, lng: string) => string
|
|
27
|
+
/** A country's name in a language, else its code. */
|
|
28
|
+
countryName: (country: string, lng: string) => string
|
|
29
|
+
}
|