@owlmeans/server-payment 0.1.21 → 0.2.0-alpha.0

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,366 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
- import Stripe from 'stripe'
3
- import { addLogPlugin, memoryPlugin, removeLogPlugin } from '@owlmeans/log'
4
- import { BillingCountryLocked, SubscriptionStartRequired } from '@owlmeans/payment'
5
- import type { CheckoutPlugin } from '../src/types.js'
6
- import {
7
- ALL_ON, CREDITS_PRODUCT, ENTITY, EUR_SETTLEMENT, makeRightsContext, PLANS_PRODUCT, PRO, requestStart, rightsOf,
8
- } from './consumer-fixtures.js'
9
- import { TEAM } from './fake-stripe.js'
10
- import type { FakeContext } from './fake-stripe.js'
11
- import { paymentAccessOf } from '../src/access.js'
12
- import { stripeCheckoutOf } from '../src/plugins/stripe.js'
13
- import { stripeSessionHelper } from '../src/plugins/session.js'
14
-
15
- const successUrl = 'https://app.example.com/ok'
16
- const topUp = (fake: FakeContext, extra: Record<string, unknown> = {}, plugins: CheckoutPlugin[] = []) => stripeCheckoutOf(fake.ctx).createCheckoutLink(fake.stripe, {
17
- productSku: CREDITS_PRODUCT, entityId: ENTITY, service: 'app', amountMinor: 1_000, successUrl, ...extra,
18
- }, plugins)
19
-
20
- /** What Stripe (SDK 17) answers a terms checkbox on an account without a Dashboard terms URL. */
21
- const TERMS_URL_MESSAGE = 'You cannot collect consent to your terms of service unless a URL is set in the Stripe '
22
- + 'Dashboard. Update your public business details at https://dashboard.stripe.com/settings/public to set the URL '
23
- + 'for your terms of service.'
24
- const missingTermsUrl = () => new Stripe.errors.StripeInvalidRequestError({
25
- type: 'invalid_request_error', message: TERMS_URL_MESSAGE, param: 'consent_collection[terms_of_service]', statusCode: 400,
26
- })
27
- const subscribe = (fake: FakeContext, extra: Record<string, unknown> = {}) => stripeCheckoutOf(fake.ctx).createCheckoutLink(fake.stripe, {
28
- productSku: PLANS_PRODUCT, planSku: PRO, entityId: ENTITY, service: 'app', successUrl, ...extra,
29
- })
30
- const session = (fake: FakeContext, index = 0) => fake.state.checkoutSessions[index]
31
-
32
- /** The pro plan synced as EUR 18.00 with an exact USD 20.00 option. */
33
- const PRO_PRICE = {
34
- id: 'price_pro', product: PLANS_PRODUCT, lookup_key: PRO, active: true, recurring: { interval: 'month' },
35
- currency: 'eur', unit_amount: 1_800, tax_behavior: 'exclusive',
36
- currency_options: { eur: { unit_amount: 1_800 }, usd: { unit_amount: 2_000, tax_behavior: 'exclusive' } },
37
- }
38
- const TEAM_PRICE = {
39
- id: 'price_team', product: PLANS_PRODUCT, lookup_key: TEAM, active: true, recurring: { interval: 'month' },
40
- currency: 'eur', unit_amount: 4_500,
41
- }
42
-
43
- const lockTo = async (fake: FakeContext, country: string, customerCountry?: string) => {
44
- await paymentAccessOf(fake.ctx).consumerRights().lock(ENTITY, country, 'manual')
45
- if (customerCountry !== undefined) {
46
- fake.state.customers.cus_locked = { id: 'cus_locked', object: 'customer', address: customerCountry == null ? null : { country: customerCountry } }
47
- await paymentAccessOf(fake.ctx).paygateCustomers().create({ paygate: 'stripe', externalId: 'cus_locked', entityId: ENTITY })
48
- }
49
- }
50
-
51
- describe('checkout under a consumer-rights policy — currency', () => {
52
- test('subscription methods follow the charge currency, with the default list for other currencies', async () => {
53
- for (const country of ['US', 'DE']) {
54
- const fake = await makeRightsContext({
55
- pricing: { ...EUR_SETTLEMENT, stripe: {
56
- ...EUR_SETTLEMENT.stripe, subscriptionPaymentMethodTypes: ['card', 'link', 'klarna'],
57
- subscriptionPaymentMethodTypesByCurrency: { USD: ['CARD', 'link'] },
58
- } },
59
- stripe: { prices: [PRO_PRICE] },
60
- })
61
- const startRequestId = await requestStart(fake)
62
- await subscribe(fake, { country, startRequestId })
63
- expect(session(fake).currency).toBe(country === 'US' ? 'usd' : 'eur')
64
- expect(session(fake).payment_method_types).toEqual(country === 'US'
65
- ? ['card', 'link'] : ['card', 'link', 'klarna'])
66
- }
67
- })
68
-
69
- test('an EU buyer is charged in EUR through the FX reference rate, with Adaptive Pricing', async () => {
70
- const fake = await makeRightsContext()
71
- await topUp(fake, { country: 'pl', ipCountry: 'pl' })
72
- expect(session(fake).line_items[0].price_data).toEqual(expect.objectContaining({ currency: 'eur', unit_amount: 919 }))
73
- expect(fake.state.rawRequests).toHaveLength(1)
74
- expect(session(fake).adaptive_pricing).toEqual({ enabled: true })
75
- expect(session(fake).metadata).toEqual(expect.objectContaining({
76
- currency: 'eur', chargeAmountMinor: '919', amountCurrency: 'usd', amountMinor: '1000', region: 'eu', country: 'PL',
77
- language: 'pl', termsVersion: 'terms-v1', ipCountry: 'PL',
78
- }))
79
- expect(session(fake).metadata.copyVersion).toBeString()
80
- // The declared country is preselected on the new customer's address, never over a saved one.
81
- const customer = Object.values(fake.state.customers)[0]
82
- expect(customer.address).toEqual({ country: 'PL' })
83
- })
84
-
85
- test('a buyer outside the territories is charged exact USD — no FX call, no Adaptive Pricing', async () => {
86
- const fake = await makeRightsContext()
87
- await topUp(fake, { country: 'US' })
88
- expect(session(fake).line_items[0].price_data).toEqual(expect.objectContaining({ currency: 'usd', unit_amount: 1_021 }))
89
- expect(fake.state.rawRequests).toHaveLength(0)
90
- expect(session(fake).adaptive_pricing).toEqual({ enabled: false })
91
- expect(session(fake).metadata).toEqual(expect.objectContaining({ currency: 'usd', chargeAmountMinor: '1021', region: 'other' }))
92
- // No legal submit text for a buyer without the rights.
93
- expect(session(fake).custom_text).toBeUndefined()
94
- })
95
-
96
- test('an in-scope top-up says what it is, in the billing language', async () => {
97
- const fake = await makeRightsContext()
98
- await topUp(fake, { country: 'DE' })
99
- expect(session(fake).custom_text.submit.message).toContain('Deutschland')
100
- expect(session(fake).custom_text.submit.message).toContain('14')
101
- })
102
-
103
- test('without a consumer-rights policy the legacy settlement behaviour is unchanged', async () => {
104
- const fake = await makeRightsContext({ consumerRights: undefined })
105
- await topUp(fake, { country: 'US' })
106
- expect(session(fake).line_items[0].price_data).toEqual(expect.objectContaining({ currency: 'eur', unit_amount: 919 }))
107
- expect(session(fake).metadata.region).toBeUndefined()
108
- })
109
- })
110
-
111
- describe('checkout under a consumer-rights policy — the country lock', () => {
112
- test('a locked country overrides the request; another declared country is refused', async () => {
113
- const fake = await makeRightsContext()
114
- await lockTo(fake, 'DE')
115
- await expect(topUp(fake, { country: 'PL' })).rejects.toBeInstanceOf(BillingCountryLocked)
116
- await topUp(fake)
117
- expect(session(fake).metadata).toEqual(expect.objectContaining({ country: 'DE', currency: 'eur', language: 'de' }))
118
- })
119
-
120
- test('a locked customer keeps its saved address: address never, collection auto, name still auto', async () => {
121
- const fake = await makeRightsContext()
122
- await lockTo(fake, 'DE', 'DE')
123
- await topUp(fake)
124
- expect(session(fake).customer_update).toEqual({ address: 'never', name: 'auto' })
125
- expect(session(fake).billing_address_collection).toBe('auto')
126
- })
127
-
128
- test('a locked customer without a saved address still lets Checkout collect one', async () => {
129
- const fake = await makeRightsContext()
130
- await lockTo(fake, 'DE', null as unknown as string)
131
- await topUp(fake)
132
- expect(session(fake).customer_update).toEqual({ address: 'auto', name: 'auto' })
133
- expect(session(fake).billing_address_collection).toBe('required')
134
- })
135
-
136
- test('a saved customer address that left the locked country is refused', async () => {
137
- const fake = await makeRightsContext()
138
- await lockTo(fake, 'DE', 'FR')
139
- const refusal = await topUp(fake).catch(error => error)
140
- expect(refusal).toBeInstanceOf(BillingCountryLocked)
141
- expect(refusal).toEqual(expect.objectContaining({ country: 'DE', requested: 'FR' }))
142
- })
143
-
144
- test('an organization that paid before the lock is locked lazily from its customer address', async () => {
145
- const fake = await makeRightsContext()
146
- fake.state.customers.cus_old = { id: 'cus_old', object: 'customer', address: { country: 'US' } }
147
- await paymentAccessOf(fake.ctx).paygateCustomers().create({ paygate: 'stripe', externalId: 'cus_old', entityId: ENTITY })
148
- await paymentAccessOf(fake.ctx).fulfillments().create({
149
- entityId: ENTITY, productSku: CREDITS_PRODUCT, service: 'app', paygate: 'stripe', externalId: 'cs_old',
150
- mode: 'amount' as never, createdAt: new Date(), fulfilledAt: new Date(),
151
- })
152
- await topUp(fake)
153
- expect(await paymentAccessOf(fake.ctx).billingProfiles().byEntity(ENTITY)).toEqual(expect.objectContaining({
154
- country: 'US', source: 'customer', currency: 'usd',
155
- }))
156
- expect(session(fake).metadata.currency).toBe('usd')
157
- await expect(topUp(fake, { country: 'PL' })).rejects.toBeInstanceOf(BillingCountryLocked)
158
- expect((await paymentAccessOf(fake.ctx).consumerEvents().list({ action: 'lock' })).items).toHaveLength(1)
159
- })
160
- })
161
-
162
- describe('checkout under a consumer-rights policy — terms', () => {
163
- test('the terms checkbox is off until the policy turns it on', async () => {
164
- const fake = await makeRightsContext()
165
- await topUp(fake, { country: 'PL' })
166
- expect(session(fake).consent_collection).toBeUndefined()
167
- expect(session(fake).custom_text?.terms_of_service_acceptance).toBeUndefined()
168
- })
169
-
170
- test('on, every checkout requires it, with the terms text of the billing language and its links', async () => {
171
- const fake = await makeRightsContext({ consumerRights: rightsOf({ mechanisms: { ...ALL_ON, checkoutTerms: true } }) })
172
- await topUp(fake, { country: 'PL' })
173
- expect(session(fake).consent_collection).toEqual({ terms_of_service: 'required' })
174
- const text = session(fake).custom_text.terms_of_service_acceptance.message as string
175
- expect(text).toContain('https://legal.example.com/pl/billing')
176
- expect(text).toContain('https://legal.example.com/pl/withdrawal')
177
- expect(text.length).toBeLessThanOrEqual(1200)
178
-
179
- await topUp(fake, { country: 'US' })
180
- const other = session(fake, 1).custom_text.terms_of_service_acceptance.message as string
181
- expect(other).toContain('https://legal.example.com/en/billing')
182
- expect(other).not.toContain('withdrawal')
183
- })
184
-
185
- test('the session metadata says whether the checkbox was collected', async () => {
186
- const off = await makeRightsContext()
187
- await topUp(off, { country: 'PL' })
188
- expect(session(off).metadata.termsCollected).toBe('false')
189
- const on = await makeRightsContext({ consumerRights: rightsOf({ mechanisms: { ...ALL_ON, checkoutTerms: true } }) })
190
- await topUp(on, { country: 'PL' })
191
- expect(session(on).metadata.termsCollected).toBe('true')
192
- })
193
-
194
- test('a Dashboard without a terms URL never stops a payment: the session is created again without the checkbox', async () => {
195
- const fake = await makeRightsContext({ consumerRights: rightsOf({ mechanisms: { ...ALL_ON, checkoutTerms: true } }) })
196
- const memory = memoryPlugin('terms-fallback')
197
- addLogPlugin(memory)
198
- try {
199
- fake.state.failures['checkout.sessions.create'] = missingTermsUrl()
200
- const url = await topUp(fake, { country: 'PL' })
201
- expect(url).toStartWith('https://checkout.example.test/')
202
- expect(fake.state.calls.filter(call => call === 'checkout.sessions.create')).toHaveLength(2)
203
- expect(session(fake).consent_collection).toBeUndefined()
204
- expect(session(fake).custom_text.terms_of_service_acceptance).toBeUndefined()
205
- // The legal submit text stays; only the checkbox and its text go.
206
- expect(session(fake).custom_text.submit.message).toContain('Polska')
207
- expect(session(fake).metadata).toEqual(expect.objectContaining({ termsCollected: 'false', termsVersion: 'terms-v1' }))
208
-
209
- const [event] = (await paymentAccessOf(fake.ctx).consumerEvents().list({ action: 'checkout-terms-fallback' })).items
210
- expect(event).toEqual(expect.objectContaining({
211
- recordId: ENTITY, recordKind: 'checkout', entityId: ENTITY, ok: false, externalId: expect.stringMatching(/^cs_\d+$/),
212
- }))
213
- expect(JSON.parse(event.detail ?? '{}')).toEqual(expect.objectContaining({
214
- param: 'consent_collection[terms_of_service]', mode: 'amount', productSku: CREDITS_PRODUCT,
215
- message: expect.stringContaining('terms of service'),
216
- }))
217
-
218
- // Once per process: a second fallback is audited again, but not warned again.
219
- fake.state.failures['checkout.sessions.create'] = missingTermsUrl()
220
- await topUp(fake, { country: 'PL' })
221
- expect((await paymentAccessOf(fake.ctx).consumerEvents().list({ action: 'checkout-terms-fallback' })).items).toHaveLength(2)
222
- const operator = memory.records.filter(record => record.level === 'warn' && record.message.includes('terms of service URL'))
223
- expect(operator).toHaveLength(1)
224
- expect(operator[0].message).toContain('Settings → Public details')
225
- } finally {
226
- removeLogPlugin('terms-fallback')
227
- }
228
- })
229
-
230
- test('a subscription falls back the same way, its subscription metadata marked too', async () => {
231
- const fake = await makeRightsContext({
232
- consumerRights: rightsOf({ mechanisms: { ...ALL_ON, checkoutTerms: true } }), stripe: { prices: [PRO_PRICE] },
233
- })
234
- const startRequestId = await requestStart(fake)
235
- fake.state.failures['checkout.sessions.create'] = missingTermsUrl()
236
- await subscribe(fake, { startRequestId, country: 'DE' })
237
- expect(session(fake).consent_collection).toBeUndefined()
238
- expect(session(fake).custom_text.terms_of_service_acceptance).toBeUndefined()
239
- expect(session(fake).custom_text.after_submit.message).toContain('https://app.example.com/legal/cancel')
240
- expect(session(fake).metadata.termsCollected).toBe('false')
241
- expect(session(fake).subscription_data.metadata).toEqual(expect.objectContaining({ termsCollected: 'false', startRequestId }))
242
- })
243
-
244
- test('the fallback keeps the admissions; a retry that fails too releases them and says why', async () => {
245
- const fake = await makeRightsContext({ consumerRights: rightsOf({ mechanisms: { ...ALL_ON, checkoutTerms: true } }) })
246
- const settled: unknown[] = []
247
- const hold: CheckoutPlugin = {
248
- alias: 'hold',
249
- admit: async () => ({ reservationId: 'hold-1' }),
250
- settled: async (_ctx, event) => { settled.push(event) },
251
- }
252
- fake.state.failures['checkout.sessions.create'] = missingTermsUrl()
253
- await topUp(fake, { country: 'PL' }, [hold])
254
- expect(settled).toHaveLength(0)
255
-
256
- fake.state.failures['checkout.sessions.create'] = [missingTermsUrl(), 'rate limited']
257
- await expect(topUp(fake, { country: 'PL' }, [hold])).rejects.toThrow('rate limited')
258
- expect(settled).toEqual([expect.objectContaining({ outcome: 'failed', reservationId: 'hold-1' })])
259
- const failed = (await paymentAccessOf(fake.ctx).consumerEvents().list({ action: 'checkout-terms-fallback' })).items
260
- .find(event => event.error != null)
261
- expect(failed).toEqual(expect.objectContaining({ ok: false, error: 'rate limited' }))
262
- expect(failed?.externalId).toBeUndefined()
263
- })
264
-
265
- test('any other refusal is not retried', async () => {
266
- const fake = await makeRightsContext({ consumerRights: rightsOf({ mechanisms: { ...ALL_ON, checkoutTerms: true } }) })
267
- fake.state.failures['checkout.sessions.create'] = 'Invalid currency: xyz'
268
- await expect(topUp(fake, { country: 'PL' })).rejects.toThrow('Invalid currency')
269
- expect(fake.state.calls.filter(call => call === 'checkout.sessions.create')).toHaveLength(1)
270
- expect((await paymentAccessOf(fake.ctx).consumerEvents().list({ action: 'checkout-terms-fallback' })).items).toHaveLength(0)
271
- })
272
-
273
- test('only the missing-terms-URL refusal is recognised', () => {
274
- expect(stripeSessionHelper.isMissingTermsUrl(missingTermsUrl())).toBe(true)
275
- // The message alone (no param), as a plain error carries it.
276
- expect(stripeSessionHelper.isMissingTermsUrl(new Error(TERMS_URL_MESSAGE))).toBe(true)
277
- // The param with a terms message.
278
- expect(stripeSessionHelper.isMissingTermsUrl({ type: 'StripeInvalidRequestError', param: 'consent_collection[terms_of_service]', message: 'Terms of service consent is not available.' })).toBe(true)
279
- expect(stripeSessionHelper.isMissingTermsUrl(new Stripe.errors.StripeCardError({ type: 'card_error', message: TERMS_URL_MESSAGE }))).toBe(false)
280
- expect(stripeSessionHelper.isMissingTermsUrl({ type: 'StripeInvalidRequestError', param: 'line_items', message: 'Invalid line items' })).toBe(false)
281
- expect(stripeSessionHelper.isMissingTermsUrl({ message: 'Please accept our terms of service' })).toBe(false)
282
- expect(stripeSessionHelper.isMissingTermsUrl(null)).toBe(false)
283
- })
284
- })
285
-
286
- describe('checkout under a consumer-rights policy — subscriptions', () => {
287
- test('an in-scope (or unknown) buyer needs a fresh start request bound to the plan', async () => {
288
- const fake = await makeRightsContext({ stripe: { prices: [PRO_PRICE, TEAM_PRICE] } })
289
- await expect(subscribe(fake)).rejects.toBeInstanceOf(SubscriptionStartRequired)
290
- await expect(subscribe(fake, { startRequestId: 'nope' })).rejects.toBeInstanceOf(SubscriptionStartRequired)
291
-
292
- const startRequestId = await requestStart(fake)
293
- await expect(stripeCheckoutOf(fake.ctx).createCheckoutLink(fake.stripe, {
294
- productSku: PLANS_PRODUCT, planSku: TEAM, entityId: ENTITY, service: 'app', successUrl, startRequestId,
295
- })).rejects.toBeInstanceOf(SubscriptionStartRequired)
296
-
297
- await subscribe(fake, { startRequestId, country: 'DE' })
298
- expect(session(fake).metadata.startRequestId).toBe(startRequestId)
299
- expect(session(fake).subscription_data.metadata).toEqual(expect.objectContaining({
300
- startRequestId, entityId: ENTITY, planSku: PRO, country: 'DE', region: 'eu',
301
- }))
302
- })
303
-
304
- test('an expired start request, or one of another text version, is asked again', async () => {
305
- const fake = await makeRightsContext({ stripe: { prices: [PRO_PRICE] } })
306
- const startRequestId = await requestStart(fake)
307
- const stored = fake.stores['payment-consumer-consent'].rows.find(row => row.id === startRequestId)!
308
- stored.expiresAt = new Date(Date.now() - 1_000)
309
- await expect(subscribe(fake, { startRequestId })).rejects.toBeInstanceOf(SubscriptionStartRequired)
310
-
311
- const fresh = await requestStart(fake)
312
- fake.stores['payment-consumer-consent'].rows.find(row => row.id === fresh)!.textVersion = 'terms-v0'
313
- await expect(subscribe(fake, { startRequestId: fresh })).rejects.toBeInstanceOf(SubscriptionStartRequired)
314
- })
315
-
316
- test('an organization locked outside the territories subscribes without one, in exact USD', async () => {
317
- const fake = await makeRightsContext({ stripe: { prices: [PRO_PRICE] } })
318
- await paymentAccessOf(fake.ctx).consumerRights().lock(ENTITY, 'US', 'manual')
319
- await subscribe(fake)
320
- expect(session(fake).currency).toBe('usd')
321
- expect(session(fake).adaptive_pricing).toEqual({ enabled: false })
322
- expect(session(fake).custom_text.submit.message).toContain('$20.00')
323
- })
324
-
325
- test('an EU subscription is forced to EUR with the renewal text and the cancellation link', async () => {
326
- const fake = await makeRightsContext({ stripe: { prices: [PRO_PRICE] } })
327
- const startRequestId = await requestStart(fake)
328
- await subscribe(fake, { startRequestId, country: 'DE', consumerLanguage: 'en' })
329
- expect(session(fake).currency).toBe('eur')
330
- expect(session(fake).adaptive_pricing).toEqual({ enabled: true })
331
- expect(session(fake).custom_text.submit.message).toContain('€18.00')
332
- expect(session(fake).custom_text.after_submit.message).toContain('https://app.example.com/legal/cancel')
333
- })
334
-
335
- test('the application submit text is a function of the charge currency and price', async () => {
336
- const fake = await makeRightsContext({ stripe: { prices: [PRO_PRICE] } })
337
- await paymentAccessOf(fake.ctx).consumerRights().lock(ENTITY, 'US', 'manual')
338
- const seen: unknown[] = []
339
- await subscribe(fake, {
340
- submitText: (context: Record<string, unknown>) => { seen.push(context); return `Pay ${String(context.unitAmountMinor)} ${String(context.currency)}` },
341
- })
342
- expect(seen[0]).toEqual(expect.objectContaining({ currency: 'usd', unitAmountMinor: 2_000, interval: 'month', region: 'other' }))
343
- expect(session(fake).custom_text.submit.message).toBe('Pay 2000 usd')
344
- })
345
-
346
- test('a price that does not carry the charge currency leaves the currency to Stripe', async () => {
347
- const fake = await makeRightsContext({
348
- stripe: { prices: [{ ...PRO_PRICE, currency_options: undefined }] },
349
- })
350
- await paymentAccessOf(fake.ctx).consumerRights().lock(ENTITY, 'US', 'manual')
351
- await subscribe(fake)
352
- expect(session(fake).currency).toBeUndefined()
353
- })
354
-
355
- test('the start request records the statement it was shown, with the plan name the application passed', async () => {
356
- const fake = await makeRightsContext({ stripe: { prices: [PRO_PRICE] } })
357
- const startRequestId = await requestStart(fake, { language: 'de' })
358
- const record = await paymentAccessOf(fake.ctx).consumerConsents().load(startRequestId)
359
- expect(record).toEqual(expect.objectContaining({
360
- kind: 'subscription-start', planSku: PRO, planName: 'Pro', language: 'de', trader: 'Example', ip: '203.0.113.7',
361
- }))
362
- expect(record?.text.request).toContain('Ich verlange ausdrücklich')
363
- expect(record?.text.request).toContain('Pro')
364
- expect(record?.expiresAt).toBeInstanceOf(Date)
365
- })
366
- })
@@ -1,161 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
- import { PaygateError } from '@owlmeans/payment'
3
- import type { PricingDef } from '../src/types.js'
4
- import {
5
- ALL_ON, buyTopUp, CREDITS_PRODUCT, ENTITY, EUR_SETTLEMENT, makeRightsContext, rightsOf,
6
- } from './consumer-fixtures.js'
7
- import type { FakeContext } from './fake-stripe.js'
8
- import { paymentAccessOf } from '../src/access.js'
9
- import { portalOf } from '../src/plugins/portal.js'
10
- import { stripeCheckoutOf } from '../src/plugins/stripe.js'
11
- import { stripeSessionHelper } from '../src/plugins/session.js'
12
-
13
- const successUrl = 'https://app.example.com/ok'
14
- const topUp = (fake: FakeContext, extra: Record<string, unknown> = {}) => stripeCheckoutOf(fake.ctx).createCheckoutLink(fake.stripe, {
15
- productSku: CREDITS_PRODUCT, entityId: ENTITY, service: 'app', amountMinor: 1_000, successUrl, ...extra,
16
- })
17
- const session = (fake: FakeContext) => fake.state.checkoutSessions[0]
18
- const customer = (fake: FakeContext) => Object.values(fake.state.customers)[0]
19
- const locks = (stripe: NonNullable<PricingDef['stripe']>): PricingDef => ({
20
- ...EUR_SETTLEMENT, stripe: { ...EUR_SETTLEMENT.stripe, ...stripe },
21
- })
22
- const blank = { line1: '', line2: '', city: '', state: '', postal_code: '' }
23
-
24
- /** An existing paygate customer of `ENTITY`. */
25
- const seedCustomer = async (fake: FakeContext, fields: Record<string, unknown>) => {
26
- fake.state.customers.cus_saved = { id: 'cus_saved', object: 'customer', address: null, ...fields }
27
- await paymentAccessOf(fake.ctx).paygateCustomers().create({ paygate: 'stripe', externalId: 'cus_saved', entityId: ENTITY })
28
- }
29
-
30
- describe('checkout — the locked customer e-mail', () => {
31
- test('without the declaration a passed e-mail is ignored: Checkout asks for one', async () => {
32
- const fake = await makeRightsContext()
33
- await topUp(fake, { email: 'owner@example.com' })
34
- expect(customer(fake).email).toBeUndefined()
35
- })
36
-
37
- test('a new customer is created with the e-mail, so Checkout shows it read-only', async () => {
38
- const fake = await makeRightsContext({ pricing: locks({ lockCustomerEmail: true }) })
39
- await topUp(fake, { email: ' owner@example.com ' })
40
- expect(customer(fake).email).toBe('owner@example.com')
41
- expect(session(fake).customer).toBe(customer(fake).id)
42
- expect(session(fake).customer_email).toBeUndefined()
43
- })
44
-
45
- test('an existing customer with another e-mail is overwritten in one update; the same one is left alone', async () => {
46
- const fake = await makeRightsContext({ pricing: locks({ lockCustomerEmail: true }) })
47
- await seedCustomer(fake, { email: 'typed-at-stripe@example.com', preferred_locales: ['en'] })
48
- await topUp(fake, { email: 'owner@example.com', locale: 'de' })
49
- expect(fake.state.customers.cus_saved).toEqual(expect.objectContaining({ email: 'owner@example.com', preferred_locales: ['de'] }))
50
- expect(fake.state.calls.filter(name => name === 'customers.update')).toHaveLength(1)
51
-
52
- const calls = fake.state.calls.length
53
- await topUp(fake, { email: 'Owner@Example.com', locale: 'de' })
54
- expect(fake.state.calls.slice(calls).filter(name => name === 'customers.update')).toHaveLength(0)
55
- })
56
-
57
- test('under the lock a missing or malformed e-mail is refused before any Stripe call', async () => {
58
- const fake = await makeRightsContext({ pricing: locks({ lockCustomerEmail: true }) })
59
- for (const email of [undefined, '', 'not-an-address']) {
60
- const refusal = await topUp(fake, email != null ? { email } : {}).catch(error => error)
61
- expect(refusal).toBeInstanceOf(PaygateError)
62
- expect(refusal.message).toContain('customer-email')
63
- }
64
- expect(fake.state.calls).toEqual([])
65
- })
66
-
67
- test('the portal never offers to edit a locked e-mail', async () => {
68
- const fake = await makeRightsContext({
69
- pricing: locks({ lockCustomerEmail: true }), portal: { returnUrl: 'https://app.example.com/billing' },
70
- })
71
- await portalOf(fake.ctx).ensurePortalConfiguration(fake.stripe)
72
- expect(fake.state.portalConfigurations[0].features.customer_update).toEqual({ enabled: true, allowed_updates: ['tax_id'] })
73
- const open = await makeRightsContext({
74
- pricing: locks({ lockCustomerEmail: true }), portal: { returnUrl: 'https://app.example.com/billing' },
75
- consumerRights: rightsOf({ mechanisms: { ...ALL_ON, countryLock: false } }),
76
- })
77
- await portalOf(open.ctx).ensurePortalConfiguration(open.stripe)
78
- expect(open.state.portalConfigurations[0].features.customer_update.allowed_updates).toEqual(['address', 'tax_id'])
79
- })
80
- })
81
-
82
- describe('checkout — the pinned country', () => {
83
- test('the declared country is pinned on a new customer and Checkout keeps it', async () => {
84
- const fake = await makeRightsContext({ pricing: locks({ lockCustomerCountry: true }) })
85
- await topUp(fake, { country: 'de' })
86
- expect(customer(fake).address).toEqual({ country: 'DE', ...blank })
87
- expect(session(fake).customer_update).toEqual({ address: 'never', name: 'auto' })
88
- expect(session(fake).billing_address_collection).toBe('auto')
89
- expect(session(fake).metadata).toEqual(expect.objectContaining({ country: 'DE', countryPinned: 'true' }))
90
- })
91
-
92
- test('before any lock a saved address of another country is replaced whole', async () => {
93
- const fake = await makeRightsContext({ pricing: locks({ lockCustomerCountry: true }) })
94
- await seedCustomer(fake, { address: { country: 'US', postal_code: '97712', line1: '27 Fredrick Ave' } })
95
- await topUp(fake, { country: 'FR' })
96
- expect(fake.state.customers.cus_saved.address).toEqual({ country: 'FR', ...blank })
97
- expect(session(fake).customer_update.address).toBe('never')
98
- })
99
-
100
- test('a saved address in the declared country is kept as it is', async () => {
101
- const fake = await makeRightsContext({ pricing: locks({ lockCustomerCountry: true }) })
102
- await seedCustomer(fake, { address: { country: 'US', postal_code: '97712' } })
103
- await topUp(fake, { country: 'US' })
104
- expect(fake.state.customers.cus_saved.address).toEqual({ country: 'US', postal_code: '97712' })
105
- expect(session(fake).customer_update.address).toBe('never')
106
- expect(session(fake).metadata.countryPinned).toBe('true')
107
- })
108
-
109
- test('where Stripe Tax needs more than a country, Checkout still collects the address', async () => {
110
- const fake = await makeRightsContext({ pricing: locks({ lockCustomerCountry: true }) })
111
- await topUp(fake, { country: 'US' })
112
- expect(customer(fake).address).toEqual({ country: 'US', ...blank })
113
- expect(session(fake).customer_update.address).toBe('auto')
114
- expect(session(fake).billing_address_collection).toBe('required')
115
- expect(session(fake).metadata.countryPinned).toBeUndefined()
116
- })
117
-
118
- test('a locked organization whose customer saved no address gets the locked country pinned', async () => {
119
- const fake = await makeRightsContext({ pricing: locks({ lockCustomerCountry: true }) })
120
- await paymentAccessOf(fake.ctx).consumerRights().lock(ENTITY, 'PL', 'manual')
121
- await seedCustomer(fake, {})
122
- await topUp(fake)
123
- expect(fake.state.customers.cus_saved.address).toEqual({ country: 'PL', ...blank })
124
- expect(session(fake).customer_update.address).toBe('never')
125
- })
126
-
127
- test('without a known country nothing is pinned', async () => {
128
- const fake = await makeRightsContext({ pricing: locks({ lockCustomerCountry: true }) })
129
- await topUp(fake)
130
- expect(customer(fake).address).toBeNull()
131
- expect(session(fake).customer_update.address).toBe('auto')
132
- })
133
-
134
- test('a pinned purchase locks the pinned country, whatever the card form said', async () => {
135
- const fake = await makeRightsContext({ pricing: locks({ lockCustomerCountry: true }) })
136
- await buyTopUp(fake, {
137
- id: 'cs_pinned', customer_details: { address: { country: 'US' }, email: 'buyer@shop.eu' },
138
- metadata: { country: 'DE', countryPinned: 'true' },
139
- })
140
- expect((await paymentAccessOf(fake.ctx).billingProfiles().byEntity(ENTITY))?.country).toBe('DE')
141
- })
142
-
143
- test('the portal never offers to edit a pinned address, with or without a consumer-rights policy', async () => {
144
- const fake = await makeRightsContext({
145
- pricing: locks({ lockCustomerCountry: true }), portal: { returnUrl: 'https://app.example.com/billing' },
146
- consumerRights: undefined,
147
- })
148
- await portalOf(fake.ctx).ensurePortalConfiguration(fake.stripe)
149
- expect(fake.state.portalConfigurations[0].features.customer_update.allowed_updates).toEqual(['email', 'tax_id'])
150
- })
151
-
152
- test('tax-locatable addresses follow Stripe Tax: US needs a postal code, CA and IN a postal code or province', () => {
153
- expect(stripeSessionHelper.isTaxLocatable({ country: 'DE' } as never)).toBe(true)
154
- expect(stripeSessionHelper.isTaxLocatable({ country: 'US' } as never)).toBe(false)
155
- expect(stripeSessionHelper.isTaxLocatable({ country: 'US', state: 'OR' } as never)).toBe(false)
156
- expect(stripeSessionHelper.isTaxLocatable({ country: 'US', postal_code: '97712' } as never)).toBe(true)
157
- expect(stripeSessionHelper.isTaxLocatable({ country: 'CA', state: 'BC' } as never)).toBe(true)
158
- expect(stripeSessionHelper.isTaxLocatable({ country: 'IN', postal_code: '' } as never)).toBe(false)
159
- expect(stripeSessionHelper.isTaxLocatable(null)).toBe(false)
160
- })
161
- })