@owlmeans/server-payment 0.1.18-rc.8 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -26
- package/agent-meta/manifest.json +30 -4
- package/agent-meta/skills/server-payment/SKILL.md +613 -54
- package/agent-meta/skills/server-payment/parts/reference.md +174 -0
- package/build/access/types.d.ts +46 -0
- package/build/access/types.d.ts.map +1 -0
- package/build/access/types.js +2 -0
- package/build/access/types.js.map +1 -0
- package/build/access.d.ts +6 -0
- package/build/access.d.ts.map +1 -0
- package/build/access.js +45 -0
- package/build/access.js.map +1 -0
- package/build/actions/index.d.ts +1 -0
- package/build/actions/index.d.ts.map +1 -1
- package/build/actions/index.js +1 -0
- package/build/actions/index.js.map +1 -1
- package/build/actions/resync-subscriptions.d.ts +3 -0
- package/build/actions/resync-subscriptions.d.ts.map +1 -0
- package/build/actions/resync-subscriptions.js +7 -0
- package/build/actions/resync-subscriptions.js.map +1 -0
- package/build/actions/resync.d.ts +6 -1
- package/build/actions/resync.d.ts.map +1 -1
- package/build/actions/resync.js +15 -5
- package/build/actions/resync.js.map +1 -1
- package/build/actions/webhook.d.ts +2 -1
- package/build/actions/webhook.d.ts.map +1 -1
- package/build/actions/webhook.js +10 -4
- package/build/actions/webhook.js.map +1 -1
- package/build/bootstrap/types.d.ts +16 -0
- package/build/bootstrap/types.d.ts.map +1 -0
- package/build/bootstrap/types.js +2 -0
- package/build/bootstrap/types.js.map +1 -0
- package/build/bootstrap.d.ts +6 -0
- package/build/bootstrap.d.ts.map +1 -0
- package/build/bootstrap.js +26 -0
- package/build/bootstrap.js.map +1 -0
- package/build/catalogue/types.d.ts +38 -0
- package/build/catalogue/types.d.ts.map +1 -0
- package/build/catalogue/types.js +2 -0
- package/build/catalogue/types.js.map +1 -0
- package/build/catalogue.d.ts +6 -0
- package/build/catalogue.d.ts.map +1 -0
- package/build/catalogue.js +110 -0
- package/build/catalogue.js.map +1 -0
- package/build/commit/types.d.ts +22 -0
- package/build/commit/types.d.ts.map +1 -0
- package/build/commit/types.js +2 -0
- package/build/commit/types.js.map +1 -0
- package/build/commit.d.ts +6 -0
- package/build/commit.d.ts.map +1 -0
- package/build/commit.js +125 -0
- package/build/commit.js.map +1 -0
- package/build/config.d.ts +44 -5
- package/build/config.d.ts.map +1 -1
- package/build/config.js +216 -10
- package/build/config.js.map +1 -1
- package/build/consts.d.ts +74 -16
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +86 -23
- package/build/consts.js.map +1 -1
- package/build/consts.local.d.ts +94 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +44 -0
- package/build/consts.local.js.map +1 -0
- package/build/consumer/cancellation/types.d.ts +11 -0
- package/build/consumer/cancellation/types.d.ts.map +1 -0
- package/build/consumer/cancellation/types.js +2 -0
- package/build/consumer/cancellation/types.js.map +1 -0
- package/build/consumer/cancellation.d.ts +6 -0
- package/build/consumer/cancellation.d.ts.map +1 -0
- package/build/consumer/cancellation.js +33 -0
- package/build/consumer/cancellation.js.map +1 -0
- package/build/consumer/capture/types.d.ts +50 -0
- package/build/consumer/capture/types.d.ts.map +1 -0
- package/build/consumer/capture/types.js +2 -0
- package/build/consumer/capture/types.js.map +1 -0
- package/build/consumer/capture.d.ts +6 -0
- package/build/consumer/capture.d.ts.map +1 -0
- package/build/consumer/capture.js +284 -0
- package/build/consumer/capture.js.map +1 -0
- package/build/consumer/consts.local.d.ts +10 -0
- package/build/consumer/consts.local.d.ts.map +1 -0
- package/build/consumer/consts.local.js +11 -0
- package/build/consumer/consts.local.js.map +1 -0
- package/build/consumer/format/types.d.ts +30 -0
- package/build/consumer/format/types.d.ts.map +1 -0
- package/build/consumer/format/types.js +2 -0
- package/build/consumer/format/types.js.map +1 -0
- package/build/consumer/format.d.ts +4 -0
- package/build/consumer/format.d.ts.map +1 -0
- package/build/consumer/format.js +73 -0
- package/build/consumer/format.js.map +1 -0
- package/build/consumer/handlers.d.ts +21 -0
- package/build/consumer/handlers.d.ts.map +1 -0
- package/build/consumer/handlers.js +174 -0
- package/build/consumer/handlers.js.map +1 -0
- package/build/consumer/index.d.ts +10 -0
- package/build/consumer/index.d.ts.map +1 -0
- package/build/consumer/index.js +6 -0
- package/build/consumer/index.js.map +1 -0
- package/build/consumer/mail/types.d.ts +29 -0
- package/build/consumer/mail/types.d.ts.map +1 -0
- package/build/consumer/mail/types.js +2 -0
- package/build/consumer/mail/types.js.map +1 -0
- package/build/consumer/mail.d.ts +6 -0
- package/build/consumer/mail.d.ts.map +1 -0
- package/build/consumer/mail.js +313 -0
- package/build/consumer/mail.js.map +1 -0
- package/build/consumer/observers/types.d.ts +15 -0
- package/build/consumer/observers/types.d.ts.map +1 -0
- package/build/consumer/observers/types.js +2 -0
- package/build/consumer/observers/types.js.map +1 -0
- package/build/consumer/observers.d.ts +6 -0
- package/build/consumer/observers.d.ts.map +1 -0
- package/build/consumer/observers.js +74 -0
- package/build/consumer/observers.js.map +1 -0
- package/build/consumer/origin/types.d.ts +17 -0
- package/build/consumer/origin/types.d.ts.map +1 -0
- package/build/consumer/origin/types.js +2 -0
- package/build/consumer/origin/types.js.map +1 -0
- package/build/consumer/origin.d.ts +8 -0
- package/build/consumer/origin.d.ts.map +1 -0
- package/build/consumer/origin.js +43 -0
- package/build/consumer/origin.js.map +1 -0
- package/build/consumer/reconcile/types.d.ts +13 -0
- package/build/consumer/reconcile/types.d.ts.map +1 -0
- package/build/consumer/reconcile/types.js +2 -0
- package/build/consumer/reconcile/types.js.map +1 -0
- package/build/consumer/reconcile.d.ts +5 -0
- package/build/consumer/reconcile.d.ts.map +1 -0
- package/build/consumer/reconcile.js +320 -0
- package/build/consumer/reconcile.js.map +1 -0
- package/build/consumer/records/types.d.ts +66 -0
- package/build/consumer/records/types.d.ts.map +1 -0
- package/build/consumer/records/types.js +2 -0
- package/build/consumer/records/types.js.map +1 -0
- package/build/consumer/records.d.ts +6 -0
- package/build/consumer/records.d.ts.map +1 -0
- package/build/consumer/records.js +243 -0
- package/build/consumer/records.js.map +1 -0
- package/build/consumer/service.d.ts +28 -0
- package/build/consumer/service.d.ts.map +1 -0
- package/build/consumer/service.js +706 -0
- package/build/consumer/service.js.map +1 -0
- package/build/consumer/types.d.ts +84 -0
- package/build/consumer/types.d.ts.map +1 -0
- package/build/consumer/types.js +2 -0
- package/build/consumer/types.js.map +1 -0
- package/build/consumer/types.local.d.ts +26 -0
- package/build/consumer/types.local.d.ts.map +1 -0
- package/build/consumer/types.local.js +2 -0
- package/build/consumer/types.local.js.map +1 -0
- package/build/consumer/withdrawal/types.d.ts +36 -0
- package/build/consumer/withdrawal/types.d.ts.map +1 -0
- package/build/consumer/withdrawal/types.js +2 -0
- package/build/consumer/withdrawal/types.js.map +1 -0
- package/build/consumer/withdrawal.d.ts +6 -0
- package/build/consumer/withdrawal.d.ts.map +1 -0
- package/build/consumer/withdrawal.js +237 -0
- package/build/consumer/withdrawal.js.map +1 -0
- package/build/entitlement.d.ts +4 -0
- package/build/entitlement.d.ts.map +1 -0
- package/build/entitlement.js +72 -0
- package/build/entitlement.js.map +1 -0
- package/build/entrypoints.d.ts +19 -2
- package/build/entrypoints.d.ts.map +1 -1
- package/build/entrypoints.js +16 -4
- package/build/entrypoints.js.map +1 -1
- package/build/gate/request.d.ts +4 -0
- package/build/gate/request.d.ts.map +1 -0
- package/build/gate/request.js +17 -0
- package/build/gate/request.js.map +1 -0
- package/build/gate/types.d.ts +15 -0
- package/build/gate/types.d.ts.map +1 -0
- package/build/gate/types.js +2 -0
- package/build/gate/types.js.map +1 -0
- package/build/gate.d.ts +13 -9
- package/build/gate.d.ts.map +1 -1
- package/build/gate.js +36 -21
- package/build/gate.js.map +1 -1
- package/build/index.d.ts +50 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +29 -3
- package/build/index.js.map +1 -1
- package/build/limit.d.ts +11 -0
- package/build/limit.d.ts.map +1 -0
- package/build/limit.js +48 -0
- package/build/limit.js.map +1 -0
- package/build/log.d.ts +3 -0
- package/build/log.d.ts.map +1 -0
- package/build/log.js +4 -0
- package/build/log.js.map +1 -0
- package/build/models/declarations/types.d.ts +22 -0
- package/build/models/declarations/types.d.ts.map +1 -0
- package/build/models/declarations/types.js +2 -0
- package/build/models/declarations/types.js.map +1 -0
- package/build/models/declarations.d.ts +4 -0
- package/build/models/declarations.d.ts.map +1 -0
- package/build/models/declarations.js +26 -0
- package/build/models/declarations.js.map +1 -0
- package/build/models/purchase/types.d.ts +13 -0
- package/build/models/purchase/types.d.ts.map +1 -0
- package/build/models/purchase/types.js +2 -0
- package/build/models/purchase/types.js.map +1 -0
- package/build/models/purchase.d.ts +4 -0
- package/build/models/purchase.d.ts.map +1 -0
- package/build/models/purchase.js +37 -0
- package/build/models/purchase.js.map +1 -0
- package/build/observer.d.ts +9 -0
- package/build/observer.d.ts.map +1 -1
- package/build/observer.js +38 -12
- package/build/observer.js.map +1 -1
- package/build/plan/types.d.ts +21 -0
- package/build/plan/types.d.ts.map +1 -0
- package/build/plan/types.js +2 -0
- package/build/plan/types.js.map +1 -0
- package/build/plan.d.ts +7 -0
- package/build/plan.d.ts.map +1 -0
- package/build/plan.js +29 -0
- package/build/plan.js.map +1 -0
- package/build/plugins/checkout-plugins/types.d.ts +25 -0
- package/build/plugins/checkout-plugins/types.d.ts.map +1 -0
- package/build/plugins/checkout-plugins/types.js +2 -0
- package/build/plugins/checkout-plugins/types.js.map +1 -0
- package/build/plugins/checkout-plugins.d.ts +12 -0
- package/build/plugins/checkout-plugins.d.ts.map +1 -0
- package/build/plugins/checkout-plugins.js +72 -0
- package/build/plugins/checkout-plugins.js.map +1 -0
- package/build/plugins/checkout-policy/types.d.ts +18 -0
- package/build/plugins/checkout-policy/types.d.ts.map +1 -0
- package/build/plugins/checkout-policy/types.js +2 -0
- package/build/plugins/checkout-policy/types.js.map +1 -0
- package/build/plugins/checkout-policy.d.ts +4 -0
- package/build/plugins/checkout-policy.d.ts.map +1 -0
- package/build/plugins/checkout-policy.js +26 -0
- package/build/plugins/checkout-policy.js.map +1 -0
- package/build/plugins/checkout-registry/types.d.ts +7 -0
- package/build/plugins/checkout-registry/types.d.ts.map +1 -0
- package/build/plugins/checkout-registry/types.js +2 -0
- package/build/plugins/checkout-registry/types.js.map +1 -0
- package/build/plugins/checkout-registry.d.ts +8 -0
- package/build/plugins/checkout-registry.d.ts.map +1 -0
- package/build/plugins/checkout-registry.js +21 -0
- package/build/plugins/checkout-registry.js.map +1 -0
- package/build/plugins/consts.local.d.ts +13 -0
- package/build/plugins/consts.local.d.ts.map +1 -0
- package/build/plugins/consts.local.js +22 -0
- package/build/plugins/consts.local.js.map +1 -0
- package/build/plugins/customer-lock/types.d.ts +6 -0
- package/build/plugins/customer-lock/types.d.ts.map +1 -0
- package/build/plugins/customer-lock/types.js +2 -0
- package/build/plugins/customer-lock/types.js.map +1 -0
- package/build/plugins/customer-lock.d.ts +5 -0
- package/build/plugins/customer-lock.d.ts.map +1 -0
- package/build/plugins/customer-lock.js +22 -0
- package/build/plugins/customer-lock.js.map +1 -0
- package/build/plugins/estimate/cache.d.ts +4 -0
- package/build/plugins/estimate/cache.d.ts.map +1 -0
- package/build/plugins/estimate/cache.js +7 -0
- package/build/plugins/estimate/cache.js.map +1 -0
- package/build/plugins/estimate/types.d.ts +27 -0
- package/build/plugins/estimate/types.d.ts.map +1 -0
- package/build/plugins/estimate/types.js +2 -0
- package/build/plugins/estimate/types.js.map +1 -0
- package/build/plugins/estimate.d.ts +6 -0
- package/build/plugins/estimate.d.ts.map +1 -0
- package/build/plugins/estimate.js +271 -0
- package/build/plugins/estimate.js.map +1 -0
- package/build/plugins/events/types.d.ts +12 -0
- package/build/plugins/events/types.d.ts.map +1 -0
- package/build/plugins/events/types.js +2 -0
- package/build/plugins/events/types.js.map +1 -0
- package/build/plugins/events.d.ts +6 -13
- package/build/plugins/events.d.ts.map +1 -1
- package/build/plugins/events.js +441 -144
- package/build/plugins/events.js.map +1 -1
- package/build/plugins/fx/types.d.ts +33 -0
- package/build/plugins/fx/types.d.ts.map +1 -0
- package/build/plugins/fx/types.js +2 -0
- package/build/plugins/fx/types.js.map +1 -0
- package/build/plugins/fx.d.ts +6 -0
- package/build/plugins/fx.d.ts.map +1 -0
- package/build/plugins/fx.js +83 -0
- package/build/plugins/fx.js.map +1 -0
- package/build/plugins/portal/types.d.ts +44 -0
- package/build/plugins/portal/types.d.ts.map +1 -0
- package/build/plugins/portal/types.js +2 -0
- package/build/plugins/portal/types.js.map +1 -0
- package/build/plugins/portal.d.ts +6 -0
- package/build/plugins/portal.d.ts.map +1 -0
- package/build/plugins/portal.js +255 -0
- package/build/plugins/portal.js.map +1 -0
- package/build/plugins/refunds/types.d.ts +35 -0
- package/build/plugins/refunds/types.d.ts.map +1 -0
- package/build/plugins/refunds/types.js +2 -0
- package/build/plugins/refunds/types.js.map +1 -0
- package/build/plugins/refunds.d.ts +6 -0
- package/build/plugins/refunds.d.ts.map +1 -0
- package/build/plugins/refunds.js +81 -0
- package/build/plugins/refunds.js.map +1 -0
- package/build/plugins/session/types.d.ts +32 -0
- package/build/plugins/session/types.d.ts.map +1 -0
- package/build/plugins/session/types.js +2 -0
- package/build/plugins/session/types.js.map +1 -0
- package/build/plugins/session.d.ts +4 -0
- package/build/plugins/session.d.ts.map +1 -0
- package/build/plugins/session.js +58 -0
- package/build/plugins/session.js.map +1 -0
- package/build/plugins/status.d.ts +8 -0
- package/build/plugins/status.d.ts.map +1 -0
- package/build/plugins/status.js +21 -0
- package/build/plugins/status.js.map +1 -0
- package/build/plugins/stripe/types.d.ts +20 -0
- package/build/plugins/stripe/types.d.ts.map +1 -0
- package/build/plugins/stripe/types.js +2 -0
- package/build/plugins/stripe/types.js.map +1 -0
- package/build/plugins/stripe.d.ts +5 -13
- package/build/plugins/stripe.d.ts.map +1 -1
- package/build/plugins/stripe.js +481 -129
- package/build/plugins/stripe.js.map +1 -1
- package/build/plugins/subscriptions/types.d.ts +41 -0
- package/build/plugins/subscriptions/types.d.ts.map +1 -0
- package/build/plugins/subscriptions/types.js +2 -0
- package/build/plugins/subscriptions/types.js.map +1 -0
- package/build/plugins/subscriptions.d.ts +6 -0
- package/build/plugins/subscriptions.d.ts.map +1 -0
- package/build/plugins/subscriptions.js +169 -0
- package/build/plugins/subscriptions.js.map +1 -0
- package/build/plugins/types.d.ts +7 -0
- package/build/plugins/types.d.ts.map +1 -0
- package/build/plugins/types.js +2 -0
- package/build/plugins/types.js.map +1 -0
- package/build/plugins/types.local.d.ts +75 -0
- package/build/plugins/types.local.d.ts.map +1 -0
- package/build/plugins/types.local.js +2 -0
- package/build/plugins/types.local.js.map +1 -0
- package/build/plugins/webhook-manager/types.d.ts +62 -0
- package/build/plugins/webhook-manager/types.d.ts.map +1 -0
- package/build/plugins/webhook-manager/types.js +2 -0
- package/build/plugins/webhook-manager/types.js.map +1 -0
- package/build/plugins/webhook-manager.d.ts +8 -0
- package/build/plugins/webhook-manager.d.ts.map +1 -0
- package/build/plugins/webhook-manager.js +245 -0
- package/build/plugins/webhook-manager.js.map +1 -0
- package/build/protocol.d.ts +13 -0
- package/build/protocol.d.ts.map +1 -0
- package/build/protocol.js +17 -0
- package/build/protocol.js.map +1 -0
- package/build/reconcile/types.d.ts +17 -0
- package/build/reconcile/types.d.ts.map +1 -0
- package/build/reconcile/types.js +2 -0
- package/build/reconcile/types.js.map +1 -0
- package/build/reconcile.d.ts +12 -0
- package/build/reconcile.d.ts.map +1 -0
- package/build/reconcile.js +91 -0
- package/build/reconcile.js.map +1 -0
- package/build/resource.d.ts +12 -1
- package/build/resource.d.ts.map +1 -1
- package/build/resource.js +97 -6
- package/build/resource.js.map +1 -1
- package/build/schemas.d.ts +19 -0
- package/build/schemas.d.ts.map +1 -0
- package/build/schemas.js +244 -0
- package/build/schemas.js.map +1 -0
- package/build/service.d.ts +28 -3
- package/build/service.d.ts.map +1 -1
- package/build/service.js +140 -19
- package/build/service.js.map +1 -1
- package/build/subscription/types.d.ts +21 -0
- package/build/subscription/types.d.ts.map +1 -0
- package/build/subscription/types.js +2 -0
- package/build/subscription/types.js.map +1 -0
- package/build/subscription.d.ts +4 -0
- package/build/subscription.d.ts.map +1 -0
- package/build/subscription.js +84 -0
- package/build/subscription.js.map +1 -0
- package/build/sync/types.d.ts +25 -0
- package/build/sync/types.d.ts.map +1 -0
- package/build/sync/types.js +2 -0
- package/build/sync/types.js.map +1 -0
- package/build/sync.d.ts +4 -3
- package/build/sync.d.ts.map +1 -1
- package/build/sync.js +231 -79
- package/build/sync.js.map +1 -1
- package/build/types.d.ts +1258 -36
- package/build/types.d.ts.map +1 -1
- package/build/types.local.d.ts +22 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/build/usage/types.d.ts +56 -0
- package/build/usage/types.d.ts.map +1 -0
- package/build/usage/types.js +2 -0
- package/build/usage/types.js.map +1 -0
- package/build/usage.d.ts +6 -0
- package/build/usage.d.ts.map +1 -0
- package/build/usage.js +365 -0
- package/build/usage.js.map +1 -0
- package/build/utils/types.d.ts +31 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/utils/types.js +2 -0
- package/build/utils/types.js.map +1 -0
- package/build/utils.d.ts +21 -7
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +56 -17
- package/build/utils.js.map +1 -1
- package/package.json +22 -17
- package/src/access/types.ts +52 -0
- package/src/access.ts +86 -0
- package/src/actions/index.ts +1 -0
- package/src/actions/resync-subscriptions.ts +10 -0
- package/src/actions/resync.ts +14 -5
- package/src/actions/webhook.ts +9 -4
- package/src/bootstrap/types.ts +16 -0
- package/src/bootstrap.ts +31 -0
- package/src/catalogue/types.ts +32 -0
- package/src/catalogue.ts +135 -0
- package/src/commit/types.ts +27 -0
- package/src/commit.ts +152 -0
- package/src/config.ts +234 -14
- package/src/consts.local.ts +62 -0
- package/src/consts.ts +100 -36
- package/src/consumer/cancellation/types.ts +13 -0
- package/src/consumer/cancellation.ts +43 -0
- package/src/consumer/capture/types.ts +53 -0
- package/src/consumer/capture.ts +321 -0
- package/src/consumer/consts.local.ts +18 -0
- package/src/consumer/format/types.ts +29 -0
- package/src/consumer/format.ts +85 -0
- package/src/consumer/handlers.ts +204 -0
- package/src/consumer/index.ts +9 -0
- package/src/consumer/mail/types.ts +31 -0
- package/src/consumer/mail.ts +353 -0
- package/src/consumer/observers/types.ts +22 -0
- package/src/consumer/observers.ts +97 -0
- package/src/consumer/origin/types.ts +17 -0
- package/src/consumer/origin.ts +61 -0
- package/src/consumer/reconcile/types.ts +13 -0
- package/src/consumer/reconcile.ts +330 -0
- package/src/consumer/records/types.ts +64 -0
- package/src/consumer/records.ts +288 -0
- package/src/consumer/service.ts +768 -0
- package/src/consumer/types.local.ts +22 -0
- package/src/consumer/types.ts +96 -0
- package/src/consumer/withdrawal/types.ts +37 -0
- package/src/consumer/withdrawal.ts +268 -0
- package/src/entitlement.ts +85 -0
- package/src/entrypoints.ts +17 -4
- package/src/gate/request.ts +24 -0
- package/src/gate/types.ts +13 -0
- package/src/gate.ts +47 -30
- package/src/index.ts +55 -3
- package/src/limit.ts +54 -0
- package/src/log.ts +4 -0
- package/src/models/declarations/types.ts +22 -0
- package/src/models/declarations.ts +30 -0
- package/src/models/purchase/types.ts +13 -0
- package/src/models/purchase.ts +43 -0
- package/src/observer.ts +44 -11
- package/src/plan/types.ts +21 -0
- package/src/plan.ts +46 -0
- package/src/plugins/checkout-plugins/types.ts +25 -0
- package/src/plugins/checkout-plugins.ts +90 -0
- package/src/plugins/checkout-policy/types.ts +18 -0
- package/src/plugins/checkout-policy.ts +34 -0
- package/src/plugins/checkout-registry/types.ts +7 -0
- package/src/plugins/checkout-registry.ts +23 -0
- package/src/plugins/consts.local.ts +30 -0
- package/src/plugins/customer-lock/types.ts +5 -0
- package/src/plugins/customer-lock.ts +25 -0
- package/src/plugins/estimate/cache.ts +12 -0
- package/src/plugins/estimate/types.ts +28 -0
- package/src/plugins/estimate.ts +305 -0
- package/src/plugins/events/types.ts +11 -0
- package/src/plugins/events.ts +466 -132
- package/src/plugins/fx/types.ts +40 -0
- package/src/plugins/fx.ts +101 -0
- package/src/plugins/portal/types.ts +45 -0
- package/src/plugins/portal.ts +284 -0
- package/src/plugins/refunds/types.ts +31 -0
- package/src/plugins/refunds.ts +95 -0
- package/src/plugins/session/types.ts +28 -0
- package/src/plugins/session.ts +73 -0
- package/src/plugins/status.ts +22 -0
- package/src/plugins/stripe/types.ts +20 -0
- package/src/plugins/stripe.ts +523 -135
- package/src/plugins/subscriptions/types.ts +39 -0
- package/src/plugins/subscriptions.ts +195 -0
- package/src/plugins/types.local.ts +61 -0
- package/src/plugins/types.ts +7 -0
- package/src/plugins/webhook-manager/types.ts +63 -0
- package/src/plugins/webhook-manager.ts +288 -0
- package/src/protocol.ts +29 -0
- package/src/reconcile/types.ts +17 -0
- package/src/reconcile.ts +110 -0
- package/src/resource.ts +158 -11
- package/src/schemas.ts +271 -0
- package/src/service.ts +161 -19
- package/src/subscription/types.ts +23 -0
- package/src/subscription.ts +104 -0
- package/src/sync/types.ts +25 -0
- package/src/sync.ts +255 -72
- package/src/types.local.ts +18 -0
- package/src/types.ts +1365 -32
- package/src/usage/types.ts +51 -0
- package/src/usage.ts +432 -0
- package/src/utils/types.ts +30 -0
- package/src/utils.ts +94 -29
- package/tests/checkout-consumer.spec.ts +366 -0
- package/tests/checkout-locks.spec.ts +161 -0
- package/tests/checkout-plugins.spec.ts +164 -0
- package/tests/checkout.spec.ts +209 -93
- package/tests/consumer-events.spec.ts +215 -0
- package/tests/consumer-fixtures.ts +134 -0
- package/tests/consumer-ops.spec.ts +350 -0
- package/tests/consumer-rights.integration.spec.ts +147 -0
- package/tests/consumer-rights.spec.ts +572 -0
- package/tests/context.ts +110 -0
- package/tests/entitlement.spec.ts +139 -0
- package/tests/estimate.spec.ts +350 -0
- package/tests/events.spec.ts +357 -0
- package/tests/fake-stripe.ts +981 -0
- package/tests/gate-handlers.spec.ts +120 -0
- package/tests/gate.spec.ts +63 -72
- package/tests/gateway-options.spec.ts +180 -0
- package/tests/limit-gate.spec.ts +66 -0
- package/tests/portal.spec.ts +202 -0
- package/tests/protocol.spec.ts +17 -3
- package/tests/sync.spec.ts +114 -0
- package/tests/usage.integration.spec.ts +133 -0
- package/tests/usage.spec.ts +169 -0
- package/tests/webhook-manager.spec.ts +149 -0
- package/build/model.d.ts +0 -6
- package/build/model.d.ts.map +0 -1
- package/build/model.js +0 -33
- package/build/model.js.map +0 -1
- package/src/model.ts +0 -37
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { PurchaseKind, withdrawalDeadlineHelper } from '@owlmeans/payment'
|
|
3
|
+
import {
|
|
4
|
+
buyTopUp, ENTITY, invoiceOf, makeRightsContext, paidSession, PRO, requestStart, send,
|
|
5
|
+
} from './consumer-fixtures.js'
|
|
6
|
+
import { subscriptionOf, type FakeContext } from './fake-stripe.js'
|
|
7
|
+
import { paymentAccessOf } from '../src/access.js'
|
|
8
|
+
import { captureOf } from '../src/consumer/capture.js'
|
|
9
|
+
|
|
10
|
+
const proSubscription = (startRequestId?: string, overrides: Record<string, unknown> = {}) => {
|
|
11
|
+
const subscription = subscriptionOf({ id: 'sub_pro', customer: 'cus_1', latestInvoice: 'in_sub' }) as unknown as Record<string, any>
|
|
12
|
+
subscription.currency = 'eur'
|
|
13
|
+
subscription.items.data[0].price = { id: 'price_pro', lookup_key: PRO, unit_amount: 1_800, currency: 'eur', tax_behavior: 'exclusive' }
|
|
14
|
+
subscription.items.data[0].quantity = 1
|
|
15
|
+
subscription.metadata = {
|
|
16
|
+
entityId: ENTITY, planSku: PRO, productSku: 'app-plans', service: 'app', country: 'DE', language: 'de',
|
|
17
|
+
...(startRequestId != null ? { startRequestId } : {}),
|
|
18
|
+
}
|
|
19
|
+
return { ...subscription, ...overrides }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const subscriptionSession = (overrides: Record<string, unknown> = {}) => paidSession({
|
|
23
|
+
id: 'cs_sub', mode: 'subscription', subscription: 'sub_pro', invoice: 'in_sub', payment_intent: null,
|
|
24
|
+
amount_subtotal: 1_800, amount_total: 2_142, total_details: { amount_tax: 342 },
|
|
25
|
+
customer_details: { address: { country: 'DE' }, email: 'owner@shop.eu', name: 'Anna', tax_ids: [] },
|
|
26
|
+
metadata: { pricingMode: 'quantity', planSku: PRO, productSku: 'app-plans', country: 'DE', language: 'de' },
|
|
27
|
+
...overrides,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const withSubInvoice = (fake: FakeContext) => {
|
|
31
|
+
fake.state.invoices.in_sub = invoiceOf('in_sub', {
|
|
32
|
+
number: 'INV-SUB-1', subtotal: 1_800, tax: 342, total: 2_142, payment_intent: 'pi_sub',
|
|
33
|
+
lines: { object: 'list', data: [{ id: 'il_sub', amount: 1_800 }] }, customer_address: { country: 'DE' },
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('webhook capture — one-time purchases', () => {
|
|
38
|
+
test('the purchase row exists before the credits are granted, with its window and evidence', async () => {
|
|
39
|
+
const fake = await makeRightsContext()
|
|
40
|
+
const seen: unknown[] = []
|
|
41
|
+
fake.observed.onTopUp = async () => { seen.push(await paymentAccessOf(fake.ctx).purchases().load({ sessionId: 'cs_pl' })) }
|
|
42
|
+
const purchase = await buyTopUp(fake)
|
|
43
|
+
|
|
44
|
+
expect(seen[0]).toEqual(expect.objectContaining({ purchaseId: 'stripe:cs_pl' }))
|
|
45
|
+
expect(purchase).toEqual(expect.objectContaining({
|
|
46
|
+
purchaseId: 'stripe:cs_pl', kind: PurchaseKind.TopUp, entityId: ENTITY, country: 'PL', region: 'eu', inScope: true,
|
|
47
|
+
language: 'pl', currency: 'eur', amountSubtotalMinor: 919, amountTaxMinor: 211, amountTotalMinor: 1_130,
|
|
48
|
+
netAmountMinor: 1_000, amountCurrency: 'usd', paymentIntentId: 'pi_pl', invoiceId: 'in_pl',
|
|
49
|
+
invoiceNumber: 'INV-0001', invoiceLineId: 'il_pl', termsAccepted: true, ipCountry: 'PL', email: 'buyer@shop.eu',
|
|
50
|
+
textVersion: 'terms-v1',
|
|
51
|
+
}))
|
|
52
|
+
expect(purchase.contractRef).toMatch(/^CR-\d{6}-[2-9A-HJKMNP-Z]{6}$/)
|
|
53
|
+
expect(purchase.deadline).toEqual(withdrawalDeadlineHelper.withdrawalDeadlineOf(new Date(purchase.purchasedAt), { marginDays: 5 }))
|
|
54
|
+
expect((await paymentAccessOf(fake.ctx).fulfillments().byExternalId('cs_pl', 'stripe'))).toEqual(expect.objectContaining({
|
|
55
|
+
country: 'PL', email: 'buyer@shop.eu', amountTotalMinor: 1_130, amountTaxMinor: 211, termsAccepted: true,
|
|
56
|
+
purchaseId: 'stripe:cs_pl',
|
|
57
|
+
}))
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('the first purchase locks the country; a later one elsewhere is only a lock-mismatch event', async () => {
|
|
61
|
+
const fake = await makeRightsContext()
|
|
62
|
+
await buyTopUp(fake)
|
|
63
|
+
expect(await paymentAccessOf(fake.ctx).billingProfiles().byEntity(ENTITY)).toEqual(expect.objectContaining({
|
|
64
|
+
country: 'PL', region: 'eu', currency: 'eur', language: 'pl', source: 'checkout', ipCountry: 'PL',
|
|
65
|
+
email: 'buyer@shop.eu', sessionId: 'cs_pl',
|
|
66
|
+
}))
|
|
67
|
+
const second = await buyTopUp(fake, {
|
|
68
|
+
id: 'cs_de', invoice: 'in_de', customer_details: { address: { country: 'DE' }, email: 'buyer@shop.eu' },
|
|
69
|
+
metadata: { ipCountry: 'AT' },
|
|
70
|
+
})
|
|
71
|
+
expect(second.country).toBe('DE')
|
|
72
|
+
expect((await paymentAccessOf(fake.ctx).billingProfiles().byEntity(ENTITY))?.country).toBe('PL')
|
|
73
|
+
const mismatch = (await paymentAccessOf(fake.ctx).consumerEvents().list({ action: 'lock-mismatch' })).items
|
|
74
|
+
expect(mismatch).toHaveLength(1)
|
|
75
|
+
expect(JSON.parse(mismatch[0].detail ?? '{}')).toEqual(expect.objectContaining({ locked: 'PL', observed: 'DE', sessionId: 'cs_de' }))
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('the confirmation is mailed once, in the billing language, with the withdrawal information and an archive copy', async () => {
|
|
79
|
+
const fake = await makeRightsContext()
|
|
80
|
+
await buyTopUp(fake, { customer_details: { address: { country: 'PL' }, email: 'buyer@shop.eu', name: 'Jan <b>K</b>' } })
|
|
81
|
+
await send(fake, 'checkout.session.completed', paidSession())
|
|
82
|
+
const mails = fake.mails.filter(mail => mail.subject.includes('CR-'))
|
|
83
|
+
expect(mails.map(mail => mail.to)).toEqual(['buyer@shop.eu', 'archive@example.com'])
|
|
84
|
+
const [mail] = mails
|
|
85
|
+
expect(mail.from).toBe('billing@example.com')
|
|
86
|
+
expect(mail.text).toContain('Example Trading Ltd, 1 Example Street, 00-001 Example, support@example.com')
|
|
87
|
+
expect(mail.text).toContain('https://app.example.com/legal/withdraw')
|
|
88
|
+
expect(mail.text).toContain('Odstąp od umowy tutaj')
|
|
89
|
+
expect(mail.html).toContain('Jan <b>K</b>')
|
|
90
|
+
expect(mail.html).not.toContain('<b>K</b>')
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('concurrent deliveries in several processes mail the confirmation once', async () => {
|
|
94
|
+
const fake = await makeRightsContext()
|
|
95
|
+
fake.state.invoices.in_pl = invoiceOf()
|
|
96
|
+
const session = paidSession() as never
|
|
97
|
+
// Not through the webhook handler, whose per-customer lock serializes one process: two processes race here.
|
|
98
|
+
await Promise.all([
|
|
99
|
+
captureOf(fake.ctx).capturePaymentPurchase(fake.stripe, session), captureOf(fake.ctx).capturePaymentPurchase(fake.stripe, session),
|
|
100
|
+
])
|
|
101
|
+
await send(fake, 'checkout.session.completed', paidSession())
|
|
102
|
+
expect(fake.mails.filter(mail => mail.subject.includes('CR-')).map(mail => mail.to)).toEqual(['buyer@shop.eu', 'archive@example.com'])
|
|
103
|
+
expect(await paymentAccessOf(fake.ctx).consumerEvents().count({ action: 'mail', step: 'purchase' })).toBe(1)
|
|
104
|
+
expect((await paymentAccessOf(fake.ctx).purchases().load({ sessionId: 'cs_pl' }))?.confirmationMailAt).toBeInstanceOf(Date)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('a checkout that collected no terms records no acceptance', async () => {
|
|
108
|
+
const fake = await makeRightsContext()
|
|
109
|
+
const purchase = await buyTopUp(fake, { consent: null, metadata: { termsCollected: 'false' } })
|
|
110
|
+
expect(purchase.termsAccepted).toBeUndefined()
|
|
111
|
+
expect((await paymentAccessOf(fake.ctx).fulfillments().byExternalId('cs_pl', 'stripe'))?.termsAccepted).toBeUndefined()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('a purchase outside the territories has no window and no confirmation', async () => {
|
|
115
|
+
const fake = await makeRightsContext()
|
|
116
|
+
const purchase = await buyTopUp(fake, {
|
|
117
|
+
id: 'cs_us', invoice: 'in_us', currency: 'usd', amount_subtotal: 1_021, amount_total: 1_021, total_details: { amount_tax: 0 },
|
|
118
|
+
customer_details: { address: { country: 'US' }, email: 'buyer@shop.us' },
|
|
119
|
+
metadata: { country: 'US', currency: 'usd', chargeAmountMinor: '1021', language: 'en' },
|
|
120
|
+
})
|
|
121
|
+
expect(purchase).toEqual(expect.objectContaining({ inScope: false, region: 'other', country: 'US' }))
|
|
122
|
+
expect(purchase.deadline).toBeUndefined()
|
|
123
|
+
expect(fake.mails).toHaveLength(0)
|
|
124
|
+
expect((await paymentAccessOf(fake.ctx).billingProfiles().byEntity(ENTITY))?.currency).toBe('usd')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('customer webhooks store the paygate country and currency', async () => {
|
|
128
|
+
const fake = await makeRightsContext()
|
|
129
|
+
await send(fake, 'customer.updated', { id: 'cus_9', email: 'a@shop.eu', address: { country: 'fr' }, currency: 'EUR', metadata: { entityId: ENTITY } })
|
|
130
|
+
expect(await paymentAccessOf(fake.ctx).paygateCustomers().loadByPgId('cus_9', 'stripe')).toEqual(expect.objectContaining({ country: 'FR', currency: 'eur' }))
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe('webhook capture — subscriptions', () => {
|
|
135
|
+
test('the first commit writes the purchase before the created observers; the checkout refines it', async () => {
|
|
136
|
+
const fake = await makeRightsContext()
|
|
137
|
+
withSubInvoice(fake)
|
|
138
|
+
const startRequestId = await requestStart(fake)
|
|
139
|
+
const seen: unknown[] = []
|
|
140
|
+
fake.observed.onSubscription = async event => {
|
|
141
|
+
if (event.change === 'created') seen.push(await paymentAccessOf(fake.ctx).purchases().byPurchaseId('stripe:sub_pro'))
|
|
142
|
+
}
|
|
143
|
+
const subscription = proSubscription(startRequestId)
|
|
144
|
+
fake.state.subscriptions.sub_pro = subscription as never
|
|
145
|
+
await send(fake, 'customer.subscription.created', subscription)
|
|
146
|
+
|
|
147
|
+
expect(seen[0]).toEqual(expect.objectContaining({
|
|
148
|
+
purchaseId: 'stripe:sub_pro', kind: PurchaseKind.Subscription, subscriptionId: 'sub_pro', invoiceId: 'in_sub',
|
|
149
|
+
invoiceNumber: 'INV-SUB-1', invoiceLineId: 'il_sub', paymentIntentId: 'pi_sub', currency: 'eur',
|
|
150
|
+
amountSubtotalMinor: 1_800, amountTaxMinor: 342, amountTotalMinor: 2_142, startRequestId, consentId: startRequestId,
|
|
151
|
+
country: 'DE', inScope: true,
|
|
152
|
+
}))
|
|
153
|
+
const stored = seen[0] as { servicesStartedAt: Date, consentedAt: Date }
|
|
154
|
+
expect(stored.servicesStartedAt).toBeInstanceOf(Date)
|
|
155
|
+
expect(stored.consentedAt).toEqual(stored.servicesStartedAt)
|
|
156
|
+
|
|
157
|
+
await send(fake, 'checkout.session.completed', subscriptionSession({ customer_details: { address: { country: 'AT' }, email: 'owner@shop.eu', name: 'Anna' } }))
|
|
158
|
+
expect(await paymentAccessOf(fake.ctx).purchases().byPurchaseId('stripe:sub_pro')).toEqual(expect.objectContaining({
|
|
159
|
+
sessionId: 'cs_sub', country: 'AT', email: 'owner@shop.eu', termsAccepted: true, amountTotalMinor: 2_142,
|
|
160
|
+
}))
|
|
161
|
+
expect(await paymentAccessOf(fake.ctx).subscriptions().byExternalId('sub_pro', 'stripe')).toEqual(expect.objectContaining({
|
|
162
|
+
checkoutSessionId: 'cs_sub', purchaseId: 'stripe:sub_pro', firstInvoiceId: 'in_sub', currency: 'eur', country: 'AT',
|
|
163
|
+
email: 'owner@shop.eu', amountTotalMinor: 2_142, amountTaxMinor: 342, termsAccepted: true, startRequestId,
|
|
164
|
+
}))
|
|
165
|
+
expect((await paymentAccessOf(fake.ctx).billingProfiles().byEntity(ENTITY))?.country).toBe('AT')
|
|
166
|
+
const confirmation = fake.mails.find(mail => mail.to === 'owner@shop.eu' && mail.subject.includes('CR-'))
|
|
167
|
+
// The order confirmation is in the billing language; the start request is repeated verbatim, as shown (en).
|
|
168
|
+
expect(confirmation?.subject).toStartWith('Bestellbestätigung')
|
|
169
|
+
expect(confirmation?.text).toContain('I expressly request and agree that Example starts the Pro services — including the AI work')
|
|
170
|
+
expect(confirmation?.text).toContain('https://app.example.com/legal/cancel')
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test('a completed subscription checkout that arrives first applies the subscription itself', async () => {
|
|
174
|
+
const fake = await makeRightsContext()
|
|
175
|
+
withSubInvoice(fake)
|
|
176
|
+
fake.state.subscriptions.sub_pro = proSubscription() as never
|
|
177
|
+
await send(fake, 'checkout.session.completed', subscriptionSession())
|
|
178
|
+
expect(fake.observed.subscription.map(event => event.change)).toEqual(['created'])
|
|
179
|
+
expect(await paymentAccessOf(fake.ctx).purchases().byPurchaseId('stripe:sub_pro')).toEqual(expect.objectContaining({ sessionId: 'cs_sub', country: 'DE' }))
|
|
180
|
+
// Renewals are not purchases.
|
|
181
|
+
await send(fake, 'invoice.paid', { id: 'in_renew', object: 'invoice', subscription: 'sub_pro', customer: 'cus_1', billing_reason: 'subscription_cycle' })
|
|
182
|
+
expect(fake.stores['payment-purchase'].rows).toHaveLength(1)
|
|
183
|
+
})
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
describe('webhook capture — refunds', () => {
|
|
187
|
+
const charge = { id: 'ch_pl', amount: 1_130, amount_refunded: 1_130, payment_intent: 'pi_pl', invoice: null }
|
|
188
|
+
|
|
189
|
+
test('a withdrawal refund carries its id to the refund observers; a whole refund closes the window', async () => {
|
|
190
|
+
const fake = await makeRightsContext({ stripe: { charges: { ch_pl: charge } } })
|
|
191
|
+
await buyTopUp(fake)
|
|
192
|
+
await send(fake, 'refund.created', {
|
|
193
|
+
id: 're_w', object: 'refund', amount: 1_130, currency: 'eur', status: 'succeeded', payment_intent: 'pi_pl',
|
|
194
|
+
charge: 'ch_pl', metadata: { owlmeans: 'payment', withdrawalId: 'decl_1', purchaseId: 'stripe:cs_pl' },
|
|
195
|
+
})
|
|
196
|
+
expect(fake.observed.refund[0]).toEqual(expect.objectContaining({
|
|
197
|
+
withdrawalId: 'decl_1', metadata: expect.objectContaining({ withdrawalId: 'decl_1' }), partial: false,
|
|
198
|
+
}))
|
|
199
|
+
const purchase = await paymentAccessOf(fake.ctx).purchases().byPurchaseId('stripe:cs_pl')
|
|
200
|
+
expect(purchase?.refundedMinor).toBe(1_130)
|
|
201
|
+
expect(purchase?.refundedAt).toBeInstanceOf(Date)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
test('an ordinary partial refund carries no withdrawal id and keeps the window open', async () => {
|
|
205
|
+
const fake = await makeRightsContext({ stripe: { charges: { ch_pl: { ...charge, amount_refunded: 300 } } } })
|
|
206
|
+
await buyTopUp(fake)
|
|
207
|
+
await send(fake, 'refund.created', {
|
|
208
|
+
id: 're_p', object: 'refund', amount: 300, currency: 'eur', status: 'succeeded', payment_intent: 'pi_pl', charge: 'ch_pl',
|
|
209
|
+
})
|
|
210
|
+
expect(fake.observed.refund[0].withdrawalId).toBeUndefined()
|
|
211
|
+
const purchase = await paymentAccessOf(fake.ctx).purchases().byPurchaseId('stripe:cs_pl')
|
|
212
|
+
expect(purchase?.refundedMinor).toBe(300)
|
|
213
|
+
expect(purchase?.refundedAt).toBeUndefined()
|
|
214
|
+
})
|
|
215
|
+
})
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ConsentKind } from '@owlmeans/payment'
|
|
2
|
+
import { createEventHandler } from '../src/plugins/events.js'
|
|
3
|
+
import type {
|
|
4
|
+
ConsumerRightsDef, PricingDef, PurchaseRecord, UsageMeter, UsageQuery, UsageReading,
|
|
5
|
+
} from '../src/types.js'
|
|
6
|
+
import { CREDIT_UNIT, CREDITS_PRODUCT, makeFakeContext, PLANS_PRODUCT, PRO } from './fake-stripe.js'
|
|
7
|
+
import type { FakeContext, FakeContextOptions } from './fake-stripe.js'
|
|
8
|
+
import { paymentAccessOf } from '../src/access.js'
|
|
9
|
+
|
|
10
|
+
type Rec = Record<string, any>
|
|
11
|
+
|
|
12
|
+
export const ENTITY = 'entity-1'
|
|
13
|
+
export const TEXT_VERSION = 'terms-v1'
|
|
14
|
+
export const epoch = (date: Date): number => Math.floor(date.getTime() / 1000)
|
|
15
|
+
|
|
16
|
+
export const LINKS = {
|
|
17
|
+
en: {
|
|
18
|
+
billingTerms: 'https://legal.example.com/en/billing',
|
|
19
|
+
withdrawalInformation: 'https://legal.example.com/en/withdrawal',
|
|
20
|
+
withdrawalForm: 'https://legal.example.com/en/withdrawal-form',
|
|
21
|
+
withdrawalFunction: 'https://app.example.com/legal/withdraw',
|
|
22
|
+
cancellation: 'https://app.example.com/legal/cancel',
|
|
23
|
+
},
|
|
24
|
+
de: { billingTerms: 'https://legal.example.com/de/billing', withdrawalInformation: 'https://legal.example.com/de/withdrawal' },
|
|
25
|
+
pl: { billingTerms: 'https://legal.example.com/pl/billing', withdrawalInformation: 'https://legal.example.com/pl/withdrawal' },
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const ALL_ON = {
|
|
29
|
+
countryLock: true, checkoutTerms: false, performanceConsent: true, subscriptionStart: true, withdrawal: true,
|
|
30
|
+
automaticRefunds: true, cancellation: true, purchaseConfirmation: true,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const TRADER = {
|
|
34
|
+
name: 'Example', legalName: 'Example Trading Ltd', address: '1 Example Street, 00-001 Example',
|
|
35
|
+
email: 'support@example.com',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const rightsOf = (patch: Partial<ConsumerRightsDef> = {}): ConsumerRightsDef => ({
|
|
39
|
+
textVersion: TEXT_VERSION,
|
|
40
|
+
links: LINKS,
|
|
41
|
+
currencies: { eu: 'eur', other: 'usd' },
|
|
42
|
+
mechanisms: ALL_ON,
|
|
43
|
+
trader: TRADER,
|
|
44
|
+
mail: { from: 'billing@example.com', bcc: ['archive@example.com'] },
|
|
45
|
+
...patch,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
/** The pricing a EUR-settling account with USD catalogue prices declares. */
|
|
49
|
+
export const EUR_SETTLEMENT: PricingDef = {
|
|
50
|
+
tax: { automatic: true, collectTaxId: true, estimate: true },
|
|
51
|
+
currency: { adaptive: true, estimate: false },
|
|
52
|
+
stripe: { settlementCurrency: 'eur' },
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 1 USD = 0.9 EUR at the reference rate. */
|
|
56
|
+
export const FX = { usd: { exchangeRate: 0.88, referenceRate: 0.9 } }
|
|
57
|
+
|
|
58
|
+
export const makeRightsContext = async (opts: FakeContextOptions = {}): Promise<FakeContext> =>
|
|
59
|
+
await makeFakeContext({
|
|
60
|
+
pricing: EUR_SETTLEMENT,
|
|
61
|
+
consumerRights: rightsOf(),
|
|
62
|
+
...opts,
|
|
63
|
+
stripe: { fxRates: FX, ...opts.stripe },
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
export interface RecordingMeter extends UsageMeter {
|
|
67
|
+
queries: UsageQuery[]
|
|
68
|
+
reading: Partial<UsageReading> & { granted: number }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A usage meter answering one fixed reading (mutable through `reading`). */
|
|
72
|
+
export const fixedMeter = (reading: Partial<UsageReading> & { granted: number }): RecordingMeter => {
|
|
73
|
+
const meter: RecordingMeter = {
|
|
74
|
+
queries: [],
|
|
75
|
+
reading,
|
|
76
|
+
used: async (_ctx, query) => {
|
|
77
|
+
meter.queries.push(query)
|
|
78
|
+
return { used: 0, usedAfter: 0, ...meter.reading }
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return meter
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const send = async (fake: FakeContext, type: string, object: unknown): Promise<void> => {
|
|
86
|
+
await createEventHandler(fake.ctx, fake.stripe).process({ id: `evt_${type}_${Math.random()}`, type, created: epoch(new Date()), data: { object } } as never)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A completed, paid amount checkout: 10.00 USD of credit charged as 9.19 EUR + 23 % VAT, bought from Poland. */
|
|
90
|
+
export const paidSession = (overrides: Rec = {}): Rec => ({
|
|
91
|
+
id: 'cs_pl', object: 'checkout.session', mode: 'payment', payment_status: 'paid', status: 'complete',
|
|
92
|
+
customer: 'cus_1', currency: 'eur', amount_subtotal: 919, amount_total: 1130, total_details: { amount_tax: 211 },
|
|
93
|
+
payment_intent: 'pi_pl', invoice: 'in_pl', created: epoch(new Date()),
|
|
94
|
+
customer_details: {
|
|
95
|
+
address: { country: 'PL' }, email: 'buyer@shop.eu', name: 'Jan Kowalski', tax_ids: [], tax_exempt: 'none',
|
|
96
|
+
},
|
|
97
|
+
consent: { terms_of_service: 'accepted' },
|
|
98
|
+
...overrides,
|
|
99
|
+
metadata: {
|
|
100
|
+
pricingMode: 'amount', amountMinor: '1000', sourceChargeAmountMinor: '1021', amountCurrency: 'usd',
|
|
101
|
+
chargeAmountMinor: '919', currency: 'eur', entityId: ENTITY, service: 'app', productSku: CREDITS_PRODUCT,
|
|
102
|
+
planSku: CREDIT_UNIT, country: 'PL', language: 'pl', termsVersion: TEXT_VERSION, ipCountry: 'PL',
|
|
103
|
+
...overrides.metadata,
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
/** The post-payment invoice of `paidSession`. */
|
|
108
|
+
export const invoiceOf = (id = 'in_pl', overrides: Rec = {}): Rec => ({
|
|
109
|
+
id, object: 'invoice', number: 'INV-0001', subtotal: 919, tax: 211, total: 1130, currency: 'eur',
|
|
110
|
+
payment_intent: 'pi_pl', lines: { object: 'list', data: [{ id: 'il_pl', amount: 919 }] },
|
|
111
|
+
customer_address: { country: 'PL' }, ...overrides,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
/** Complete a top-up: the webhook captures the purchase (and locks the country). */
|
|
115
|
+
export const buyTopUp = async (fake: FakeContext, overrides: Rec = {}): Promise<PurchaseRecord> => {
|
|
116
|
+
const session = paidSession(overrides)
|
|
117
|
+
fake.state.invoices[session.invoice as string] = fake.state.invoices[session.invoice as string] ?? invoiceOf(session.invoice as string)
|
|
118
|
+
await send(fake, 'checkout.session.completed', session)
|
|
119
|
+
const purchase = await paymentAccessOf(fake.ctx).purchases().load({ sessionId: session.id as string })
|
|
120
|
+
if (purchase == null) throw new Error('no purchase captured')
|
|
121
|
+
|
|
122
|
+
return purchase
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** A start request of `ENTITY` for the pro plan. */
|
|
126
|
+
export const requestStart = async (fake: FakeContext, patch: Rec = {}): Promise<string> =>
|
|
127
|
+
(await paymentAccessOf(fake.ctx).consumerRights().recordStartRequest(
|
|
128
|
+
{ entityId: ENTITY, email: 'owner@shop.eu', name: 'Anna' },
|
|
129
|
+
{ planSku: PRO, textVersion: TEXT_VERSION, language: 'en', acknowledged: true, ...patch },
|
|
130
|
+
{ ip: '203.0.113.7' },
|
|
131
|
+
{ plan: 'Pro' },
|
|
132
|
+
)).startRequestId
|
|
133
|
+
|
|
134
|
+
export { ConsentKind, CREDITS_PRODUCT, CREDIT_UNIT, PLANS_PRODUCT, PRO }
|