@owlmeans/server-payment 0.1.22-rc.0 → 0.2.0-alpha.1

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.
Files changed (296) hide show
  1. package/README.md +52 -54
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/server-payment/SKILL.md +272 -330
  4. package/agent-meta/skills/server-payment/parts/reference.md +3 -3
  5. package/build/access/types.d.ts +7 -16
  6. package/build/access/types.d.ts.map +1 -1
  7. package/build/access.d.ts.map +1 -1
  8. package/build/access.js +6 -8
  9. package/build/access.js.map +1 -1
  10. package/build/actions/resync.d.ts +3 -3
  11. package/build/actions/resync.js +5 -5
  12. package/build/actions/resync.js.map +1 -1
  13. package/build/actions/webhook.d.ts +4 -1
  14. package/build/actions/webhook.d.ts.map +1 -1
  15. package/build/actions/webhook.js +8 -4
  16. package/build/actions/webhook.js.map +1 -1
  17. package/build/bootstrap/types.d.ts +13 -7
  18. package/build/bootstrap/types.d.ts.map +1 -1
  19. package/build/bootstrap.d.ts +4 -4
  20. package/build/bootstrap.d.ts.map +1 -1
  21. package/build/bootstrap.js +19 -10
  22. package/build/bootstrap.js.map +1 -1
  23. package/build/catalogue/types.d.ts +3 -3
  24. package/build/catalogue/types.d.ts.map +1 -1
  25. package/build/catalogue.d.ts.map +1 -1
  26. package/build/catalogue.js +4 -8
  27. package/build/catalogue.js.map +1 -1
  28. package/build/checkout/types.d.ts +21 -0
  29. package/build/checkout/types.d.ts.map +1 -0
  30. package/build/{plugins/stripe → checkout}/types.js.map +1 -1
  31. package/build/checkout.d.ts +6 -0
  32. package/build/checkout.d.ts.map +1 -0
  33. package/build/checkout.js +374 -0
  34. package/build/checkout.js.map +1 -0
  35. package/build/config.d.ts +10 -16
  36. package/build/config.d.ts.map +1 -1
  37. package/build/config.js +18 -59
  38. package/build/config.js.map +1 -1
  39. package/build/consts.d.ts +3 -49
  40. package/build/consts.d.ts.map +1 -1
  41. package/build/consts.js +3 -61
  42. package/build/consts.js.map +1 -1
  43. package/build/consumer/cancellation/types.d.ts +6 -4
  44. package/build/consumer/cancellation/types.d.ts.map +1 -1
  45. package/build/consumer/cancellation.d.ts.map +1 -1
  46. package/build/consumer/cancellation.js +11 -5
  47. package/build/consumer/cancellation.js.map +1 -1
  48. package/build/consumer/capture/types.d.ts +8 -12
  49. package/build/consumer/capture/types.d.ts.map +1 -1
  50. package/build/consumer/capture.d.ts.map +1 -1
  51. package/build/consumer/capture.js +48 -53
  52. package/build/consumer/capture.js.map +1 -1
  53. package/build/consumer/index.d.ts +4 -0
  54. package/build/consumer/index.d.ts.map +1 -1
  55. package/build/consumer/index.js +2 -0
  56. package/build/consumer/index.js.map +1 -1
  57. package/build/consumer/reconcile.d.ts.map +1 -1
  58. package/build/consumer/reconcile.js +82 -72
  59. package/build/consumer/reconcile.js.map +1 -1
  60. package/build/consumer/records/types.d.ts +4 -4
  61. package/build/consumer/records/types.d.ts.map +1 -1
  62. package/build/consumer/records.d.ts.map +1 -1
  63. package/build/consumer/records.js +16 -13
  64. package/build/consumer/records.js.map +1 -1
  65. package/build/consumer/service.d.ts +2 -2
  66. package/build/consumer/service.d.ts.map +1 -1
  67. package/build/consumer/service.js +28 -21
  68. package/build/consumer/service.js.map +1 -1
  69. package/build/consumer/types.d.ts +1 -4
  70. package/build/consumer/types.d.ts.map +1 -1
  71. package/build/consumer/types.local.d.ts +1 -9
  72. package/build/consumer/types.local.d.ts.map +1 -1
  73. package/build/consumer/withdrawal/types.d.ts +14 -12
  74. package/build/consumer/withdrawal/types.d.ts.map +1 -1
  75. package/build/consumer/withdrawal.d.ts.map +1 -1
  76. package/build/consumer/withdrawal.js +55 -71
  77. package/build/consumer/withdrawal.js.map +1 -1
  78. package/build/index.d.ts +12 -6
  79. package/build/index.d.ts.map +1 -1
  80. package/build/index.js +7 -4
  81. package/build/index.js.map +1 -1
  82. package/build/paygate/providers.d.ts +13 -0
  83. package/build/paygate/providers.d.ts.map +1 -0
  84. package/build/paygate/providers.js +38 -0
  85. package/build/paygate/providers.js.map +1 -0
  86. package/build/paygate/registry.d.ts +6 -0
  87. package/build/paygate/registry.d.ts.map +1 -0
  88. package/build/paygate/registry.js +37 -0
  89. package/build/paygate/registry.js.map +1 -0
  90. package/build/paygate/types.d.ts +577 -0
  91. package/build/paygate/types.d.ts.map +1 -0
  92. package/build/{plugins/session → paygate}/types.js.map +1 -1
  93. package/build/plan/types.d.ts +6 -1
  94. package/build/plan/types.d.ts.map +1 -1
  95. package/build/plan.d.ts.map +1 -1
  96. package/build/plan.js +16 -2
  97. package/build/plan.js.map +1 -1
  98. package/build/plugins/checkout-policy/types.d.ts +5 -3
  99. package/build/plugins/checkout-policy/types.d.ts.map +1 -1
  100. package/build/plugins/checkout-policy.d.ts.map +1 -1
  101. package/build/plugins/checkout-policy.js +5 -3
  102. package/build/plugins/checkout-policy.js.map +1 -1
  103. package/build/plugins/consts.local.d.ts +8 -10
  104. package/build/plugins/consts.local.d.ts.map +1 -1
  105. package/build/plugins/consts.local.js +2 -19
  106. package/build/plugins/consts.local.js.map +1 -1
  107. package/build/plugins/customer-lock/types.d.ts +2 -2
  108. package/build/plugins/customer-lock/types.d.ts.map +1 -1
  109. package/build/plugins/customer-lock.js +2 -2
  110. package/build/plugins/customer-lock.js.map +1 -1
  111. package/build/plugins/estimate/cache.js +1 -1
  112. package/build/plugins/estimate/cache.js.map +1 -1
  113. package/build/plugins/estimate/types.d.ts +10 -10
  114. package/build/plugins/estimate/types.d.ts.map +1 -1
  115. package/build/plugins/estimate.d.ts.map +1 -1
  116. package/build/plugins/estimate.js +48 -122
  117. package/build/plugins/estimate.js.map +1 -1
  118. package/build/plugins/events/types.d.ts +17 -10
  119. package/build/plugins/events/types.d.ts.map +1 -1
  120. package/build/plugins/events.d.ts +6 -5
  121. package/build/plugins/events.d.ts.map +1 -1
  122. package/build/plugins/events.js +162 -173
  123. package/build/plugins/events.js.map +1 -1
  124. package/build/plugins/fx/types.d.ts +10 -21
  125. package/build/plugins/fx/types.d.ts.map +1 -1
  126. package/build/plugins/fx.d.ts +1 -1
  127. package/build/plugins/fx.d.ts.map +1 -1
  128. package/build/plugins/fx.js +17 -54
  129. package/build/plugins/fx.js.map +1 -1
  130. package/build/plugins/portal/types.d.ts +8 -37
  131. package/build/plugins/portal/types.d.ts.map +1 -1
  132. package/build/plugins/portal.d.ts.map +1 -1
  133. package/build/plugins/portal.js +38 -208
  134. package/build/plugins/portal.js.map +1 -1
  135. package/build/plugins/refunds/types.d.ts +11 -11
  136. package/build/plugins/refunds/types.d.ts.map +1 -1
  137. package/build/plugins/refunds.d.ts.map +1 -1
  138. package/build/plugins/refunds.js +14 -39
  139. package/build/plugins/refunds.js.map +1 -1
  140. package/build/plugins/snapshot/types.d.ts +11 -0
  141. package/build/plugins/snapshot/types.d.ts.map +1 -0
  142. package/build/plugins/snapshot/types.js +2 -0
  143. package/build/plugins/snapshot/types.js.map +1 -0
  144. package/build/plugins/snapshot.d.ts +4 -0
  145. package/build/plugins/snapshot.d.ts.map +1 -0
  146. package/build/plugins/snapshot.js +19 -0
  147. package/build/plugins/snapshot.js.map +1 -0
  148. package/build/plugins/subscriptions/types.d.ts +17 -17
  149. package/build/plugins/subscriptions/types.d.ts.map +1 -1
  150. package/build/plugins/subscriptions.d.ts +4 -4
  151. package/build/plugins/subscriptions.d.ts.map +1 -1
  152. package/build/plugins/subscriptions.js +69 -77
  153. package/build/plugins/subscriptions.js.map +1 -1
  154. package/build/plugins/types.local.d.ts +9 -43
  155. package/build/plugins/types.local.d.ts.map +1 -1
  156. package/build/plugins/webhook-manager/types.d.ts +15 -43
  157. package/build/plugins/webhook-manager/types.d.ts.map +1 -1
  158. package/build/plugins/webhook-manager.d.ts +3 -3
  159. package/build/plugins/webhook-manager.d.ts.map +1 -1
  160. package/build/plugins/webhook-manager.js +21 -199
  161. package/build/plugins/webhook-manager.js.map +1 -1
  162. package/build/protocol.d.ts +1 -1
  163. package/build/protocol.d.ts.map +1 -1
  164. package/build/protocol.js +1 -1
  165. package/build/protocol.js.map +1 -1
  166. package/build/service.d.ts +11 -11
  167. package/build/service.d.ts.map +1 -1
  168. package/build/service.js +59 -23
  169. package/build/service.js.map +1 -1
  170. package/build/sync/types.d.ts +17 -13
  171. package/build/sync/types.d.ts.map +1 -1
  172. package/build/sync.d.ts.map +1 -1
  173. package/build/sync.js +22 -122
  174. package/build/sync.js.map +1 -1
  175. package/build/types.d.ts +46 -101
  176. package/build/types.d.ts.map +1 -1
  177. package/build/utils/types.d.ts +0 -8
  178. package/build/utils/types.d.ts.map +1 -1
  179. package/build/utils.d.ts +1 -4
  180. package/build/utils.d.ts.map +1 -1
  181. package/build/utils.js +1 -15
  182. package/build/utils.js.map +1 -1
  183. package/package.json +20 -22
  184. package/src/access/types.ts +7 -16
  185. package/src/access.ts +7 -15
  186. package/src/actions/resync.ts +5 -5
  187. package/src/actions/webhook.ts +8 -4
  188. package/src/bootstrap/types.ts +13 -7
  189. package/src/bootstrap.ts +23 -13
  190. package/src/catalogue/types.ts +3 -3
  191. package/src/catalogue.ts +4 -8
  192. package/src/checkout/types.ts +21 -0
  193. package/src/checkout.ts +414 -0
  194. package/src/config.ts +19 -66
  195. package/src/consts.ts +3 -69
  196. package/src/consumer/cancellation/types.ts +6 -4
  197. package/src/consumer/cancellation.ts +13 -7
  198. package/src/consumer/capture/types.ts +8 -12
  199. package/src/consumer/capture.ts +50 -59
  200. package/src/consumer/index.ts +4 -0
  201. package/src/consumer/reconcile.ts +69 -68
  202. package/src/consumer/records/types.ts +4 -4
  203. package/src/consumer/records.ts +19 -14
  204. package/src/consumer/service.ts +35 -22
  205. package/src/consumer/types.local.ts +1 -8
  206. package/src/consumer/types.ts +1 -4
  207. package/src/consumer/withdrawal/types.ts +14 -12
  208. package/src/consumer/withdrawal.ts +61 -77
  209. package/src/index.ts +12 -6
  210. package/src/paygate/providers.ts +48 -0
  211. package/src/paygate/registry.ts +53 -0
  212. package/src/paygate/types.ts +640 -0
  213. package/src/plan/types.ts +6 -1
  214. package/src/plan.ts +21 -3
  215. package/src/plugins/checkout-policy/types.ts +5 -3
  216. package/src/plugins/checkout-policy.ts +6 -5
  217. package/src/plugins/consts.local.ts +2 -26
  218. package/src/plugins/customer-lock/types.ts +2 -2
  219. package/src/plugins/customer-lock.ts +2 -2
  220. package/src/plugins/estimate/cache.ts +1 -1
  221. package/src/plugins/estimate/types.ts +10 -10
  222. package/src/plugins/estimate.ts +52 -128
  223. package/src/plugins/events/types.ts +17 -9
  224. package/src/plugins/events.ts +172 -190
  225. package/src/plugins/fx/types.ts +10 -23
  226. package/src/plugins/fx.ts +28 -64
  227. package/src/plugins/portal/types.ts +8 -38
  228. package/src/plugins/portal.ts +48 -229
  229. package/src/plugins/refunds/types.ts +11 -11
  230. package/src/plugins/refunds.ts +16 -40
  231. package/src/plugins/snapshot/types.ts +11 -0
  232. package/src/plugins/snapshot.ts +22 -0
  233. package/src/plugins/subscriptions/types.ts +17 -17
  234. package/src/plugins/subscriptions.ts +81 -81
  235. package/src/plugins/types.local.ts +9 -33
  236. package/src/plugins/webhook-manager/types.ts +15 -43
  237. package/src/plugins/webhook-manager.ts +24 -220
  238. package/src/protocol.ts +1 -1
  239. package/src/service.ts +66 -30
  240. package/src/sync/types.ts +17 -13
  241. package/src/sync.ts +25 -143
  242. package/src/types.ts +47 -97
  243. package/src/utils/types.ts +0 -9
  244. package/src/utils.ts +2 -20
  245. package/tests/capabilities.spec.ts +219 -0
  246. package/tests/entitlement.spec.ts +4 -4
  247. package/tests/gate-handlers.spec.ts +6 -6
  248. package/tests/gate.spec.ts +2 -2
  249. package/tests/grants.spec.ts +2 -2
  250. package/tests/internal-plan.spec.ts +2 -2
  251. package/tests/limit-gate.spec.ts +2 -2
  252. package/tests/paygates.spec.ts +132 -0
  253. package/tests/protocol.spec.ts +4 -5
  254. package/tests/usage.spec.ts +2 -2
  255. package/tests/webhook.spec.ts +137 -0
  256. package/build/plugins/session/types.d.ts +0 -34
  257. package/build/plugins/session/types.d.ts.map +0 -1
  258. package/build/plugins/session.d.ts +0 -4
  259. package/build/plugins/session.d.ts.map +0 -1
  260. package/build/plugins/session.js +0 -71
  261. package/build/plugins/session.js.map +0 -1
  262. package/build/plugins/status.d.ts +0 -8
  263. package/build/plugins/status.d.ts.map +0 -1
  264. package/build/plugins/status.js +0 -21
  265. package/build/plugins/status.js.map +0 -1
  266. package/build/plugins/stripe/types.d.ts +0 -20
  267. package/build/plugins/stripe/types.d.ts.map +0 -1
  268. package/build/plugins/stripe.d.ts +0 -6
  269. package/build/plugins/stripe.d.ts.map +0 -1
  270. package/build/plugins/stripe.js +0 -518
  271. package/build/plugins/stripe.js.map +0 -1
  272. package/src/plugins/session/types.ts +0 -30
  273. package/src/plugins/session.ts +0 -86
  274. package/src/plugins/status.ts +0 -22
  275. package/src/plugins/stripe/types.ts +0 -20
  276. package/src/plugins/stripe.ts +0 -571
  277. package/tests/checkout-consumer.spec.ts +0 -366
  278. package/tests/checkout-locks.spec.ts +0 -161
  279. package/tests/checkout-plugins.spec.ts +0 -164
  280. package/tests/checkout.spec.ts +0 -313
  281. package/tests/consumer-events.spec.ts +0 -215
  282. package/tests/consumer-fixtures.ts +0 -141
  283. package/tests/consumer-ops.spec.ts +0 -361
  284. package/tests/consumer-rights.integration.spec.ts +0 -147
  285. package/tests/consumer-rights.spec.ts +0 -606
  286. package/tests/context.ts +0 -110
  287. package/tests/estimate.spec.ts +0 -350
  288. package/tests/events.spec.ts +0 -367
  289. package/tests/fake-stripe.ts +0 -1004
  290. package/tests/gateway-options.spec.ts +0 -180
  291. package/tests/portal.spec.ts +0 -202
  292. package/tests/sync.spec.ts +0 -114
  293. package/tests/usage.integration.spec.ts +0 -165
  294. package/tests/webhook-manager.spec.ts +0 -149
  295. /package/build/{plugins/session → checkout}/types.js +0 -0
  296. /package/build/{plugins/stripe → paygate}/types.js +0 -0
@@ -1,180 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
- import { PaygateError, PortalFlow, WebhookSetupError } from '@owlmeans/payment'
3
- import { RES_PAYMENT_FINGERPRINT, RES_PAYMENT_WEBHOOK } from '../src/consts.js'
4
- import { makeGatewayService } from '../src/service.js'
5
- import { makeFakeContext, SERVICE, type FakeContext, type FakeContextOptions } from './fake-stripe.js'
6
- import type { GatewayServiceOptions } from '../src/types.js'
7
- import { paymentAccessOf } from '../src/access.js'
8
- import { stripeBootstrapOf } from '../src/bootstrap.js'
9
- import { portalOf } from '../src/plugins/portal.js'
10
- import { webhookOf } from '../src/plugins/webhook-manager.js'
11
-
12
- const WEB = 'app.example.com'
13
- const HOOKS = 'hooks.example.com'
14
- const HOOK_SERVICE = 'hooks'
15
- const WEB_URL = `https://${WEB}/api/payment-gate/webhook/stripe`
16
- const HOOK_URL = `https://${HOOKS}/payment-gate/webhook/stripe`
17
- const PORTAL = { returnUrl: `https://${WEB}/billing` }
18
- const labelOf = (owner: string) => ({ owlmeans: 'payment', service: owner })
19
-
20
- /** Poll until `ready` holds — a boot bootstrap runs once the context is initialized, unawaited. */
21
- const until = async (ready: () => boolean, ms = 3000): Promise<void> => {
22
- const deadline = Date.now() + ms
23
- while (!ready()) {
24
- if (Date.now() > deadline) throw new Error('condition not reached')
25
- await Bun.sleep(5)
26
- }
27
- }
28
-
29
- /**
30
- * The two managed processes of one deployment sharing a database and a Stripe account: the manager
31
- * (`cfg.service` = SERVICE, on the web host under `/api`) and the hook receiver (its own host) — both
32
- * with `owner` SERVICE and `webhookService` the hook receiver.
33
- */
34
- const managerProcess = async (gatewayOpts: GatewayServiceOptions = {}, extra: FakeContextOptions = {}): Promise<FakeContext> =>
35
- await makeFakeContext({
36
- service: SERVICE, host: WEB, base: 'api', services: { [HOOK_SERVICE]: { host: HOOKS } }, portal: PORTAL,
37
- ...extra, gateway: { owner: SERVICE, webhookService: HOOK_SERVICE, ...gatewayOpts },
38
- })
39
- const hookProcess = async (gatewayOpts: GatewayServiceOptions = {}, extra: FakeContextOptions = {}): Promise<FakeContext> =>
40
- await makeFakeContext({
41
- service: HOOK_SERVICE, host: HOOKS, services: { [SERVICE]: { host: WEB, base: 'api' } }, portal: PORTAL,
42
- ...extra, gateway: { manage: true, owner: SERVICE, webhookService: HOOK_SERVICE, ...gatewayOpts },
43
- })
44
-
45
- /** A boot bootstrap is done once the webhook step has left exactly one endpoint and one row. */
46
- const bootstrapped = (fake: FakeContext, url: string) => (): boolean =>
47
- fake.state.webhookEndpoints.length === 1 && fake.state.webhookEndpoints[0].url === url
48
- && fake.stores[RES_PAYMENT_WEBHOOK].rows.length === 1 && fake.stores[RES_PAYMENT_WEBHOOK].rows[0].url === url
49
-
50
- describe('@owlmeans/server-payment — gateway options: defaults', () => {
51
- test('without options the URL, the row key and the portal key are this service\'s own, and bootstrap follows manage', async () => {
52
- const reader = await makeFakeContext({ host: WEB, base: 'api' })
53
- expect(paymentAccessOf(reader.ctx).gateway()).toEqual(expect.objectContaining({
54
- managed: false, bootstrap: false, owner: SERVICE, webhookService: SERVICE,
55
- }))
56
- expect(webhookOf(reader.ctx).webhookUrlOf()).toBe(WEB_URL)
57
-
58
- const owner = await makeFakeContext({ host: WEB, base: 'api', portal: PORTAL, gateway: { manage: true } })
59
- expect(paymentAccessOf(owner.ctx).gateway().bootstrap).toBe(true)
60
- await until(bootstrapped(owner, WEB_URL))
61
- expect(owner.state.webhookEndpoints[0]).toEqual(expect.objectContaining({
62
- metadata: labelOf(SERVICE), description: `owlmeans:${SERVICE}`,
63
- }))
64
- expect(owner.stores[RES_PAYMENT_WEBHOOK].rows).toEqual([expect.objectContaining({ service: SERVICE, url: WEB_URL })])
65
- expect(owner.stores[RES_PAYMENT_FINGERPRINT].rows).toContainEqual(expect.objectContaining({ sku: `portal:${SERVICE}` }))
66
- })
67
- })
68
-
69
- describe('@owlmeans/server-payment — gateway options: webhookService and owner', () => {
70
- test('webhookService forms the URL on its own host; owner keys the rows, the secret, the labels and the portal', async () => {
71
- const hook = await hookProcess({ bootstrap: false })
72
- expect(webhookOf(hook.ctx).webhookServiceOf()).toBe(HOOK_SERVICE)
73
- expect(webhookOf(hook.ctx).gatewayOwnerOf()).toBe(SERVICE)
74
- expect(webhookOf(hook.ctx).webhookUrlOf()).toBe(HOOK_URL)
75
-
76
- const row = await webhookOf(hook.ctx).ensureWebhookEndpoint(hook.stripe)
77
- const [endpoint] = hook.state.webhookEndpoints
78
- expect(endpoint).toEqual(expect.objectContaining({
79
- url: HOOK_URL, metadata: labelOf(SERVICE), description: `owlmeans:${SERVICE}`,
80
- }))
81
- expect(row).toEqual(expect.objectContaining({ service: SERVICE, url: HOOK_URL, externalId: endpoint.id }))
82
- expect(await webhookOf(hook.ctx).stripeWebhookSecret()).toBe(endpoint.secret)
83
-
84
- const configuration = await portalOf(hook.ctx).ensurePortalConfiguration(hook.stripe)
85
- expect(hook.state.portalConfigurations[0]).toEqual(expect.objectContaining({
86
- id: configuration, metadata: { ...labelOf(SERVICE), deployment: HOOK_URL },
87
- }))
88
- expect(hook.stores[RES_PAYMENT_FINGERPRINT].rows).toContainEqual(
89
- expect.objectContaining({ sku: `portal:${SERVICE}`, externalId: configuration }),
90
- )
91
- })
92
-
93
- test('the manager and the hook process share the rows: one URL, one secret, and a forced run from the manager creates nothing', async () => {
94
- const hook = await hookProcess({ bootstrap: false })
95
- const manager = await managerProcess({ manage: true, bootstrap: false })
96
- expect(webhookOf(manager.ctx).webhookUrlOf()).toBe(webhookOf(hook.ctx).webhookUrlOf())
97
-
98
- await stripeBootstrapOf(hook.ctx).bootstrapStripe(hook.stripe)
99
- for (const alias of [RES_PAYMENT_WEBHOOK, RES_PAYMENT_FINGERPRINT]) {
100
- manager.stores[alias].rows.push(...structuredClone(hook.stores[alias].rows))
101
- }
102
- expect(await webhookOf(manager.ctx).stripeWebhookSecret()).toBe(hook.state.webhookEndpoints[0].secret)
103
-
104
- hook.state.calls.length = 0
105
- await stripeBootstrapOf(manager.ctx).bootstrapStripe(hook.stripe, { force: true })
106
- expect(hook.state.calls).not.toContain('webhookEndpoints.create')
107
- expect(hook.state.calls).not.toContain('webhookEndpoints.del')
108
- expect(hook.state.calls).not.toContain('billingPortal.configurations.create')
109
- expect(hook.state.webhookEndpoints.map(({ url }) => url)).toEqual([HOOK_URL])
110
- expect(hook.state.portalConfigurations).toHaveLength(1)
111
- })
112
-
113
- test('a process booting with a new webhookService moves the owner\'s endpoint and re-creates the portal for the new key', async () => {
114
- const before = await makeFakeContext({ host: WEB, base: 'api', portal: PORTAL })
115
- const former = await webhookOf(before.ctx).ensureWebhookEndpoint(before.stripe)
116
- const formerPortal = await portalOf(before.ctx).ensurePortalConfiguration(before.stripe)
117
- expect(former?.url).toBe(WEB_URL)
118
-
119
- const hook = await hookProcess({}, {
120
- seed: {
121
- [RES_PAYMENT_WEBHOOK]: before.stores[RES_PAYMENT_WEBHOOK].rows,
122
- [RES_PAYMENT_FINGERPRINT]: before.stores[RES_PAYMENT_FINGERPRINT].rows,
123
- },
124
- stripe: {
125
- seq: before.state.seq,
126
- webhookEndpoints: structuredClone(before.state.webhookEndpoints),
127
- portalConfigurations: structuredClone(before.state.portalConfigurations),
128
- },
129
- })
130
- await until(bootstrapped(hook, HOOK_URL))
131
-
132
- expect(hook.state.webhookEndpoints).toEqual([expect.objectContaining({ url: HOOK_URL, metadata: labelOf(SERVICE) })])
133
- expect(hook.state.webhookEndpoints[0].id).not.toBe(former?.externalId)
134
- expect(hook.stores[RES_PAYMENT_WEBHOOK].rows).toEqual([expect.objectContaining({ service: SERVICE, url: HOOK_URL })])
135
- expect(await webhookOf(hook.ctx).stripeWebhookSecret()).toBe(hook.state.webhookEndpoints[0].secret)
136
-
137
- const portal = hook.stores[RES_PAYMENT_FINGERPRINT].rows.find(row => row.sku === `portal:${SERVICE}`)
138
- expect(portal?.externalId).not.toBe(formerPortal)
139
- expect(hook.state.portalConfigurations.map(({ id, metadata }) => ({ id, metadata }))).toEqual([
140
- { id: formerPortal, metadata: { ...labelOf(SERVICE), deployment: WEB_URL } },
141
- { id: portal?.externalId, metadata: { ...labelOf(SERVICE), deployment: HOOK_URL } },
142
- ])
143
- })
144
- })
145
-
146
- describe('@owlmeans/server-payment — gateway options: bootstrap', () => {
147
- test('bootstrap: false skips the boot bootstrap, serves the portal, and still runs a forced bootstrap', async () => {
148
- const manager = await managerProcess({ manage: true, bootstrap: false })
149
- expect(paymentAccessOf(manager.ctx).gateway()).toEqual(expect.objectContaining({ managed: true, bootstrap: false }))
150
- // A bootstrapping process booted after it is the clock: once it is done, the manager's would be too.
151
- const clock = await hookProcess()
152
- await until(bootstrapped(clock, HOOK_URL))
153
- expect(manager.state.calls).toEqual([])
154
-
155
- await paymentAccessOf(manager.ctx).paygateCustomers().create({ paygate: 'stripe', externalId: 'cus_1', entityId: 'entity-1' })
156
- const link = await paymentAccessOf(manager.ctx).gateway().portalLink(manager.ctx, 'entity-1', {
157
- flow: PortalFlow.Manage, returnUrl: PORTAL.returnUrl,
158
- })
159
- expect(link).toStartWith('https://billing.example.test/')
160
- expect(manager.state.portalConfigurations[0].metadata).toEqual({ ...labelOf(SERVICE), deployment: HOOK_URL })
161
-
162
- await stripeBootstrapOf(manager.ctx).bootstrapStripe(await paymentAccessOf(manager.ctx).gateway().stripe(manager.ctx), { force: true })
163
- expect(manager.state.webhookEndpoints).toEqual([expect.objectContaining({ url: HOOK_URL, metadata: labelOf(SERVICE) })])
164
- expect(manager.stores[RES_PAYMENT_WEBHOOK].rows).toEqual([expect.objectContaining({ service: SERVICE, url: HOOK_URL })])
165
- })
166
-
167
- test('refuses contradictory options at construction, and an undeclared webhook service only when bootstrapping', async () => {
168
- expect(() => makeGatewayService(undefined, { manage: false, bootstrap: true })).toThrow(PaygateError)
169
- expect(() => makeGatewayService(undefined, { owner: '' })).toThrow(PaygateError)
170
- expect(() => makeGatewayService(undefined, { webhookService: ' ' })).toThrow(PaygateError)
171
-
172
- await expect(makeFakeContext({ gateway: { manage: true, webhookService: HOOK_SERVICE } }))
173
- .rejects.toBeInstanceOf(WebhookSetupError)
174
-
175
- const quiet = await makeFakeContext({ gateway: { manage: true, bootstrap: false, webhookService: HOOK_SERVICE } })
176
- expect(() => webhookOf(quiet.ctx).webhookUrlOf()).toThrow(WebhookSetupError)
177
- const reader = await makeFakeContext({ gateway: { webhookService: HOOK_SERVICE } })
178
- expect(paymentAccessOf(reader.ctx).gateway().webhookService).toBe(HOOK_SERVICE)
179
- })
180
- })
@@ -1,202 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
- import {
3
- PortalFlow, PortalUnavailable, ProductType, PlanDuration, SubscriptionStatus, TaxBehavior,
4
- } from '@owlmeans/payment'
5
- import { declarePaymentPlan, declarePaymentPricing, declarePaymentProduct } from '../src/config.js'
6
- import { makeFakeContext, PLANS_PRODUCT, PRO, SERVICE, TEAM } from './fake-stripe.js'
7
- import type { FakeContextOptions } from './fake-stripe.js'
8
- import { paymentAccessOf } from '../src/access.js'
9
- import { portalOf } from '../src/plugins/portal.js'
10
-
11
- const RETURN = 'https://app.example.com/billing'
12
- const hookOf = (host: string): string => `https://${host}/payment-gate/webhook/stripe`
13
- const tagOf = (host: string) => ({ owlmeans: 'payment', service: SERVICE, deployment: hookOf(host) })
14
- const prices = [
15
- { id: 'price_pro', product: PLANS_PRODUCT, lookup_key: PRO, active: true, recurring: { interval: 'month' } },
16
- { id: 'price_team', product: PLANS_PRODUCT, lookup_key: TEAM, active: true, recurring: { interval: 'month' } },
17
- { id: 'price_old', product: PLANS_PRODUCT, lookup_key: null, active: false, recurring: { interval: 'month' } },
18
- { id: 'price_once', product: PLANS_PRODUCT, lookup_key: 'once', active: true, recurring: null },
19
- ]
20
-
21
- const withPortal = async (opts: FakeContextOptions = {}) => await makeFakeContext({
22
- portal: { returnUrl: RETURN, headline: 'Plans', privacyPolicyUrl: 'https://example.com/privacy' },
23
- ...opts, stripe: { prices: structuredClone(prices), ...opts.stripe },
24
- })
25
-
26
- describe('@owlmeans/server-payment — portal configuration', () => {
27
- test('offers switching between active recurring prices and cancellation at period end; unchanged means no call', async () => {
28
- const fake = await withPortal()
29
- const id = await portalOf(fake.ctx).ensurePortalConfiguration(fake.stripe)
30
- const [configuration] = fake.state.portalConfigurations
31
-
32
- expect(configuration.id).toBe(id)
33
- expect(configuration.features.subscription_update).toEqual({
34
- enabled: true, default_allowed_updates: ['price'], proration_behavior: 'create_prorations',
35
- products: [{ product: PLANS_PRODUCT, prices: ['price_pro', 'price_team'] }],
36
- })
37
- expect(configuration.features.subscription_cancel).toEqual({ enabled: true, mode: 'at_period_end', proration_behavior: 'none' })
38
- expect(configuration.features.customer_update).toEqual({ enabled: true, allowed_updates: ['email', 'address', 'tax_id'] })
39
- expect(configuration).toEqual(expect.objectContaining({
40
- default_return_url: RETURN, metadata: tagOf('api.example.com'),
41
- business_profile: { headline: 'Plans', privacy_policy_url: 'https://example.com/privacy' },
42
- }))
43
-
44
- fake.state.calls.length = 0
45
- expect(await portalOf(fake.ctx).ensurePortalConfiguration(fake.stripe)).toBe(id)
46
- expect(fake.state.calls).toEqual([])
47
- })
48
-
49
- test('re-adopts its own untracked configuration, and never an untagged one or one tagged for another deployment', async () => {
50
- const fake = await withPortal({
51
- stripe: {
52
- prices: structuredClone(prices),
53
- portalConfigurations: [
54
- { id: 'bpc_service_only', active: true, metadata: { owlmeans: 'payment', service: SERVICE } },
55
- { id: 'bpc_other', active: true, metadata: tagOf('other.example.com') },
56
- ],
57
- },
58
- })
59
- const id = await portalOf(fake.ctx).ensurePortalConfiguration(fake.stripe)
60
- expect(id).not.toBe('bpc_service_only')
61
- expect(id).not.toBe('bpc_other')
62
-
63
- await paymentAccessOf(fake.ctx).fingerprints().clear()
64
- fake.state.calls.length = 0
65
- expect(await portalOf(fake.ctx).ensurePortalConfiguration(fake.stripe, { force: true })).toBe(id)
66
- expect(fake.state.calls).toEqual(['prices.list', 'billingPortal.configurations.list', 'billingPortal.configurations.update'])
67
- expect(fake.stores['payment-fingerprint'].rows).toEqual([
68
- expect.objectContaining({ sku: `portal:${SERVICE}`, externalId: id }),
69
- ])
70
- expect(fake.state.portalConfigurations.map(({ id, metadata, features }) => ({ id, metadata, features: features != null })))
71
- .toEqual([
72
- { id: 'bpc_service_only', metadata: { owlmeans: 'payment', service: SERVICE }, features: false },
73
- { id: 'bpc_other', metadata: tagOf('other.example.com'), features: false },
74
- { id, metadata: tagOf('api.example.com'), features: true },
75
- ])
76
- })
77
-
78
- test('a declared tax behavior is hashed: changing it re-hashes and updates the configuration', async () => {
79
- const fake = await withPortal({
80
- pricing: { tax: { automatic: true, collectTaxId: true, estimate: false, behavior: TaxBehavior.Exclusive }, currency: { estimate: false } },
81
- })
82
- const id = await portalOf(fake.ctx).ensurePortalConfiguration(fake.stripe)
83
- fake.state.calls.length = 0
84
- expect(await portalOf(fake.ctx).ensurePortalConfiguration(fake.stripe)).toBe(id)
85
- expect(fake.state.calls).toEqual([])
86
-
87
- declarePaymentPricing(fake.ctx.cfg as never, {
88
- tax: { automatic: true, collectTaxId: true, estimate: false, behavior: TaxBehavior.Inclusive },
89
- currency: { estimate: false },
90
- })
91
- expect(await portalOf(fake.ctx).ensurePortalConfiguration(fake.stripe)).toBe(id)
92
- expect(fake.state.calls).toContain('billingPortal.configurations.update')
93
- })
94
-
95
- test('two deployments on one Stripe account keep separate configurations, even when both rows name one', async () => {
96
- const shared = { owlmeans: 'payment', service: SERVICE }
97
- const stage = await withPortal({
98
- host: 'stage.example.com',
99
- stripe: { prices: structuredClone(prices), portalConfigurations: [{ id: 'bpc_shared', active: true, metadata: shared }] },
100
- })
101
- const staging = await withPortal({ host: 'staging.example.com' })
102
- for (const deployment of [stage, staging]) {
103
- await paymentAccessOf(deployment.ctx).fingerprints().create({ sku: `portal:${SERVICE}`, hash: 'legacy', externalId: 'bpc_shared', updatedAt: new Date() })
104
- }
105
-
106
- expect(await portalOf(stage.ctx).ensurePortalConfiguration(stage.stripe)).toBe('bpc_shared')
107
- const stagingId = await portalOf(staging.ctx).ensurePortalConfiguration(stage.stripe)
108
- expect(stagingId).not.toBe('bpc_shared')
109
- expect(stage.state.portalConfigurations.map(({ id, metadata }) => ({ id, metadata }))).toEqual([
110
- { id: 'bpc_shared', metadata: tagOf('stage.example.com') },
111
- { id: stagingId, metadata: tagOf('staging.example.com') },
112
- ])
113
-
114
- for (const deployment of [stage, staging]) {
115
- await paymentAccessOf(deployment.ctx).fingerprints().clear()
116
- }
117
- expect(await portalOf(staging.ctx).ensurePortalConfiguration(stage.stripe, { force: true })).toBe(stagingId)
118
- expect(await portalOf(stage.ctx).ensurePortalConfiguration(stage.stripe, { force: true })).toBe('bpc_shared')
119
- expect(stage.state.portalConfigurations).toHaveLength(2)
120
-
121
- const local = await withPortal({ host: 'localhost' })
122
- const localId = await portalOf(local.ctx).ensurePortalConfiguration(stage.stripe)
123
- expect(stage.state.portalConfigurations.find(configuration => configuration.id === localId)?.metadata)
124
- .toEqual(tagOf('localhost'))
125
- expect(stage.state.portalConfigurations).toHaveLength(3)
126
- })
127
-
128
- test('disables both subscription features when nothing recurring is sold', async () => {
129
- const fake = await makeFakeContext({
130
- declare: cfg => {
131
- declarePaymentProduct(cfg, { sku: 'kit', type: ProductType.Simple, services: [SERVICE], name: 'Kit' })
132
- declarePaymentPlan(cfg, { productSku: 'kit', sku: 'kit-once', duration: PlanDuration.Lifetime, price: 5 })
133
- },
134
- })
135
- await portalOf(fake.ctx).ensurePortalConfiguration(fake.stripe)
136
- expect(fake.state.portalConfigurations[0].features.subscription_update).toEqual({ enabled: false })
137
- expect(fake.state.portalConfigurations[0].features.subscription_cancel).toEqual({ enabled: false })
138
- })
139
- })
140
-
141
- describe('@owlmeans/server-payment — portal links', () => {
142
- const subscribed = async () => {
143
- const fake = await withPortal()
144
- await paymentAccessOf(fake.ctx).paygateCustomers().create({ paygate: 'stripe', externalId: 'cus_1', entityId: 'entity-1' })
145
- await paymentAccessOf(fake.ctx).subscriptions().create({
146
- entityId: 'entity-1', planSku: PRO, productSku: PLANS_PRODUCT, service: SERVICE, paygate: 'stripe',
147
- externalId: 'sub_1', itemId: 'si_1', status: SubscriptionStatus.Active, rank: 10, createdAt: new Date(),
148
- })
149
- return fake
150
- }
151
-
152
- test('needs a customer; Manage opens the portal home on the managed configuration', async () => {
153
- const empty = await withPortal()
154
- await expect(portalOf(empty.ctx).createPortalLink(empty.stripe, 'entity-1', { flow: PortalFlow.Manage, returnUrl: RETURN }))
155
- .rejects.toBeInstanceOf(PortalUnavailable)
156
-
157
- const fake = await subscribed()
158
- const url = await portalOf(fake.ctx).createPortalLink(fake.stripe, 'entity-1', { flow: PortalFlow.Manage, returnUrl: RETURN })
159
- expect(url).toStartWith('https://billing.example.test/')
160
- expect(fake.state.portalSessions[0]).toEqual({
161
- customer: 'cus_1', return_url: RETURN, configuration: fake.state.portalConfigurations[0].id,
162
- })
163
- })
164
-
165
- test('PaymentMethod, Cancel and Update deep-link with a redirect back', async () => {
166
- const fake = await subscribed()
167
- const after = { type: 'redirect', redirect: { return_url: RETURN } }
168
- for (const flow of [PortalFlow.PaymentMethod, PortalFlow.Cancel, PortalFlow.Update]) {
169
- await portalOf(fake.ctx).createPortalLink(fake.stripe, 'entity-1', { flow, returnUrl: RETURN })
170
- }
171
- expect(fake.state.portalSessions.map(session => session.flow_data)).toEqual([
172
- { type: 'payment_method_update', after_completion: after },
173
- { type: 'subscription_cancel', subscription_cancel: { subscription: 'sub_1' }, after_completion: after },
174
- { type: 'subscription_update', subscription_update: { subscription: 'sub_1' }, after_completion: after },
175
- ])
176
- })
177
-
178
- test('Change confirms the stored item switching to the target plan price, as one item', async () => {
179
- const fake = await subscribed()
180
- await portalOf(fake.ctx).createPortalLink(fake.stripe, 'entity-1', { flow: PortalFlow.Change, planSku: TEAM, returnUrl: RETURN })
181
- expect(fake.state.portalSessions[0].flow_data).toEqual({
182
- type: 'subscription_update_confirm',
183
- subscription_update_confirm: { subscription: 'sub_1', items: [{ id: 'si_1', price: 'price_team', quantity: 1 }] },
184
- after_completion: { type: 'redirect', redirect: { return_url: RETURN } },
185
- })
186
- await expect(portalOf(fake.ctx).createPortalLink(fake.stripe, 'entity-1', { flow: PortalFlow.Change, returnUrl: RETURN }))
187
- .rejects.toBeInstanceOf(PortalUnavailable)
188
- })
189
-
190
- test('a subscription flow without an entitling paygate subscription is unavailable', async () => {
191
- const fake = await withPortal()
192
- await paymentAccessOf(fake.ctx).paygateCustomers().create({ paygate: 'stripe', externalId: 'cus_1', entityId: 'entity-1' })
193
- await paymentAccessOf(fake.ctx).subscriptions().create({
194
- entityId: 'entity-1', planSku: PRO, productSku: PLANS_PRODUCT, service: SERVICE, paygate: 'stripe',
195
- externalId: 'sub_1', itemId: 'si_1', status: SubscriptionStatus.Canceled, rank: 10, createdAt: new Date(),
196
- })
197
- const refusal = await portalOf(fake.ctx).createPortalLink(fake.stripe, 'entity-1', { flow: PortalFlow.Cancel, returnUrl: RETURN })
198
- .catch(error => error)
199
- expect(refusal).toBeInstanceOf(PortalUnavailable)
200
- expect(refusal.message).toContain('subscription')
201
- })
202
- })
@@ -1,114 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
- import { TaxBehavior } from '@owlmeans/payment'
3
- import type { PricingDef } from '../src/types.js'
4
- import { makeFakeContext, PLANS_PRODUCT, PRO } from './fake-stripe.js'
5
- import type { FakeContextOptions } from './fake-stripe.js'
6
- import { productSyncOf } from '../src/sync.js'
7
-
8
- const exclusive: PricingDef = {
9
- tax: { automatic: true, collectTaxId: true, estimate: false, behavior: TaxBehavior.Exclusive },
10
- currency: { estimate: false },
11
- }
12
-
13
- const inclusiveAccountDefault = {
14
- defaults: { tax_behavior: 'inclusive' as const, tax_code: null }, head_office: null,
15
- status: 'active' as const, status_details: {},
16
- }
17
-
18
- /** A price already in place, matching PRO's lookup key, amount, currency and interval. */
19
- const existingProPrice = (taxBehavior: string, id = 'price_pro_existing') => ({
20
- id, product: PLANS_PRODUCT, lookup_key: PRO, active: true, unit_amount: 2_000, currency: 'usd',
21
- recurring: { interval: 'month' }, tax_behavior: taxBehavior,
22
- })
23
-
24
- const withProProduct = async (opts: FakeContextOptions = {}) => await makeFakeContext(opts)
25
- const proPrice = (fake: Awaited<ReturnType<typeof withProProduct>>) =>
26
- fake.state.prices.find(item => item.lookup_key === PRO && item.active)
27
-
28
- describe('@owlmeans/server-payment — price tax_behavior sync', () => {
29
- test('an undeclared policy creates a price with no forced tax_behavior (Stripe defaults it to unspecified)', async () => {
30
- const fake = await withProProduct()
31
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
32
- expect(proPrice(fake)?.tax_behavior).toBe('unspecified')
33
- })
34
-
35
- test('re-syncing an unchanged, undeclared catalogue makes no paygate call', async () => {
36
- const fake = await withProProduct()
37
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
38
- fake.state.calls.length = 0
39
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
40
- expect(fake.state.calls).toEqual([])
41
- })
42
-
43
- test('a declared behavior sets tax_behavior on a freshly created price', async () => {
44
- const fake = await withProProduct({ pricing: exclusive })
45
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
46
- expect(proPrice(fake)?.tax_behavior).toBe('exclusive')
47
- })
48
-
49
- test("a declared behavior updates a pre-existing 'unspecified' price IN PLACE — the id is kept", async () => {
50
- const fake = await withProProduct({ pricing: exclusive, stripe: { prices: [existingProPrice('unspecified')] } })
51
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
52
- expect(fake.state.calls).toContain('prices.update')
53
- // PRO's own price keeps its id (an update, not a replacement) — TEAM's plan has no price
54
- // fixture, so it legitimately goes through `prices.create` alongside it.
55
- expect(proPrice(fake)).toEqual(expect.objectContaining({ id: 'price_pro_existing', tax_behavior: 'exclusive' }))
56
- })
57
-
58
- test("an inclusive account default skips the in-place update and leaves the price 'unspecified'", async () => {
59
- const fake = await withProProduct({
60
- pricing: exclusive, stripe: { prices: [existingProPrice('unspecified')], taxSettings: inclusiveAccountDefault },
61
- })
62
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
63
- expect(fake.state.calls).toContain('tax.settings.retrieve')
64
- expect(fake.state.calls).not.toContain('prices.update')
65
- expect(proPrice(fake)?.tax_behavior).toBe('unspecified')
66
- })
67
-
68
- test("'stripe.migrateUnspecifiedPrices' overrides the account-default guard, without even checking it", async () => {
69
- const fake = await withProProduct({
70
- pricing: { ...exclusive, stripe: { migrateUnspecifiedPrices: true } },
71
- stripe: { prices: [existingProPrice('unspecified')], taxSettings: inclusiveAccountDefault },
72
- })
73
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
74
- expect(fake.state.calls).not.toContain('tax.settings.retrieve')
75
- expect(proPrice(fake)?.tax_behavior).toBe('exclusive')
76
- })
77
-
78
- test('a price already carrying the OPPOSITE behavior is deactivated and replaced, never mutated', async () => {
79
- const fake = await withProProduct({ pricing: exclusive, stripe: { prices: [existingProPrice('inclusive')] } })
80
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
81
- const old = fake.state.prices.find(item => item.id === 'price_pro_existing')
82
- const fresh = proPrice(fake)
83
- expect(old?.active).toBe(false)
84
- expect(old?.tax_behavior).toBe('inclusive')
85
- expect(fresh?.id).not.toBe('price_pro_existing')
86
- expect(fresh).toEqual(expect.objectContaining({ tax_behavior: 'exclusive', lookup_key: PRO }))
87
- })
88
-
89
- test('recurring USD catalogue prices are synchronized as EUR settlement prices', async () => {
90
- const fake = await withProProduct({
91
- pricing: { ...exclusive, stripe: { settlementCurrency: 'eur' } },
92
- stripe: { fxRates: { usd: { exchangeRate: 0.853568, referenceRate: 0.8726 } } },
93
- })
94
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
95
- expect(proPrice(fake)).toEqual(expect.objectContaining({ currency: 'eur', unit_amount: 1_746 }))
96
- expect(fake.state.rawRequests).toContainEqual(expect.objectContaining({
97
- params: { to_currency: 'eur', 'from_currencies[]': 'usd', lock_duration: 'none' },
98
- }))
99
- })
100
-
101
- test('a changed reference rate replaces a recurring settlement price on the next sync', async () => {
102
- const fake = await withProProduct({
103
- pricing: { ...exclusive, stripe: { settlementCurrency: 'eur' } },
104
- stripe: { fxRates: { usd: { exchangeRate: 0.853568, referenceRate: 0.8726 } } },
105
- })
106
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
107
- const first = proPrice(fake)
108
- fake.state.fxRates.usd = { exchangeRate: 0.88, referenceRate: 0.9 }
109
- await productSyncOf(fake.ctx).syncStripeProducts(fake.stripe)
110
- expect(first?.active).toBe(false)
111
- expect(proPrice(fake)).toEqual(expect.objectContaining({ currency: 'eur', unit_amount: 1_800 }))
112
- expect(proPrice(fake)?.id).not.toBe(first?.id)
113
- })
114
- })