@owlmeans/server-payment 0.1.18-rc.9 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (537) hide show
  1. package/README.md +157 -26
  2. package/agent-meta/manifest.json +30 -4
  3. package/agent-meta/skills/server-payment/SKILL.md +613 -54
  4. package/agent-meta/skills/server-payment/parts/reference.md +174 -0
  5. package/build/access/types.d.ts +46 -0
  6. package/build/access/types.d.ts.map +1 -0
  7. package/build/access/types.js +2 -0
  8. package/build/access/types.js.map +1 -0
  9. package/build/access.d.ts +6 -0
  10. package/build/access.d.ts.map +1 -0
  11. package/build/access.js +45 -0
  12. package/build/access.js.map +1 -0
  13. package/build/actions/index.d.ts +1 -0
  14. package/build/actions/index.d.ts.map +1 -1
  15. package/build/actions/index.js +1 -0
  16. package/build/actions/index.js.map +1 -1
  17. package/build/actions/resync-subscriptions.d.ts +3 -0
  18. package/build/actions/resync-subscriptions.d.ts.map +1 -0
  19. package/build/actions/resync-subscriptions.js +7 -0
  20. package/build/actions/resync-subscriptions.js.map +1 -0
  21. package/build/actions/resync.d.ts +6 -1
  22. package/build/actions/resync.d.ts.map +1 -1
  23. package/build/actions/resync.js +15 -5
  24. package/build/actions/resync.js.map +1 -1
  25. package/build/actions/webhook.d.ts +2 -1
  26. package/build/actions/webhook.d.ts.map +1 -1
  27. package/build/actions/webhook.js +10 -4
  28. package/build/actions/webhook.js.map +1 -1
  29. package/build/bootstrap/types.d.ts +16 -0
  30. package/build/bootstrap/types.d.ts.map +1 -0
  31. package/build/bootstrap/types.js +2 -0
  32. package/build/bootstrap/types.js.map +1 -0
  33. package/build/bootstrap.d.ts +6 -0
  34. package/build/bootstrap.d.ts.map +1 -0
  35. package/build/bootstrap.js +26 -0
  36. package/build/bootstrap.js.map +1 -0
  37. package/build/catalogue/types.d.ts +38 -0
  38. package/build/catalogue/types.d.ts.map +1 -0
  39. package/build/catalogue/types.js +2 -0
  40. package/build/catalogue/types.js.map +1 -0
  41. package/build/catalogue.d.ts +6 -0
  42. package/build/catalogue.d.ts.map +1 -0
  43. package/build/catalogue.js +110 -0
  44. package/build/catalogue.js.map +1 -0
  45. package/build/commit/types.d.ts +22 -0
  46. package/build/commit/types.d.ts.map +1 -0
  47. package/build/commit/types.js +2 -0
  48. package/build/commit/types.js.map +1 -0
  49. package/build/commit.d.ts +6 -0
  50. package/build/commit.d.ts.map +1 -0
  51. package/build/commit.js +125 -0
  52. package/build/commit.js.map +1 -0
  53. package/build/config.d.ts +44 -5
  54. package/build/config.d.ts.map +1 -1
  55. package/build/config.js +216 -10
  56. package/build/config.js.map +1 -1
  57. package/build/consts.d.ts +74 -16
  58. package/build/consts.d.ts.map +1 -1
  59. package/build/consts.js +86 -23
  60. package/build/consts.js.map +1 -1
  61. package/build/consts.local.d.ts +94 -0
  62. package/build/consts.local.d.ts.map +1 -0
  63. package/build/consts.local.js +44 -0
  64. package/build/consts.local.js.map +1 -0
  65. package/build/consumer/cancellation/types.d.ts +11 -0
  66. package/build/consumer/cancellation/types.d.ts.map +1 -0
  67. package/build/consumer/cancellation/types.js +2 -0
  68. package/build/consumer/cancellation/types.js.map +1 -0
  69. package/build/consumer/cancellation.d.ts +6 -0
  70. package/build/consumer/cancellation.d.ts.map +1 -0
  71. package/build/consumer/cancellation.js +33 -0
  72. package/build/consumer/cancellation.js.map +1 -0
  73. package/build/consumer/capture/types.d.ts +50 -0
  74. package/build/consumer/capture/types.d.ts.map +1 -0
  75. package/build/consumer/capture/types.js +2 -0
  76. package/build/consumer/capture/types.js.map +1 -0
  77. package/build/consumer/capture.d.ts +6 -0
  78. package/build/consumer/capture.d.ts.map +1 -0
  79. package/build/consumer/capture.js +284 -0
  80. package/build/consumer/capture.js.map +1 -0
  81. package/build/consumer/consts.local.d.ts +10 -0
  82. package/build/consumer/consts.local.d.ts.map +1 -0
  83. package/build/consumer/consts.local.js +11 -0
  84. package/build/consumer/consts.local.js.map +1 -0
  85. package/build/consumer/format/types.d.ts +30 -0
  86. package/build/consumer/format/types.d.ts.map +1 -0
  87. package/build/consumer/format/types.js +2 -0
  88. package/build/consumer/format/types.js.map +1 -0
  89. package/build/consumer/format.d.ts +4 -0
  90. package/build/consumer/format.d.ts.map +1 -0
  91. package/build/consumer/format.js +73 -0
  92. package/build/consumer/format.js.map +1 -0
  93. package/build/consumer/handlers.d.ts +21 -0
  94. package/build/consumer/handlers.d.ts.map +1 -0
  95. package/build/consumer/handlers.js +174 -0
  96. package/build/consumer/handlers.js.map +1 -0
  97. package/build/consumer/index.d.ts +10 -0
  98. package/build/consumer/index.d.ts.map +1 -0
  99. package/build/consumer/index.js +6 -0
  100. package/build/consumer/index.js.map +1 -0
  101. package/build/consumer/mail/types.d.ts +29 -0
  102. package/build/consumer/mail/types.d.ts.map +1 -0
  103. package/build/consumer/mail/types.js +2 -0
  104. package/build/consumer/mail/types.js.map +1 -0
  105. package/build/consumer/mail.d.ts +6 -0
  106. package/build/consumer/mail.d.ts.map +1 -0
  107. package/build/consumer/mail.js +313 -0
  108. package/build/consumer/mail.js.map +1 -0
  109. package/build/consumer/observers/types.d.ts +15 -0
  110. package/build/consumer/observers/types.d.ts.map +1 -0
  111. package/build/consumer/observers/types.js +2 -0
  112. package/build/consumer/observers/types.js.map +1 -0
  113. package/build/consumer/observers.d.ts +6 -0
  114. package/build/consumer/observers.d.ts.map +1 -0
  115. package/build/consumer/observers.js +74 -0
  116. package/build/consumer/observers.js.map +1 -0
  117. package/build/consumer/origin/types.d.ts +17 -0
  118. package/build/consumer/origin/types.d.ts.map +1 -0
  119. package/build/consumer/origin/types.js +2 -0
  120. package/build/consumer/origin/types.js.map +1 -0
  121. package/build/consumer/origin.d.ts +8 -0
  122. package/build/consumer/origin.d.ts.map +1 -0
  123. package/build/consumer/origin.js +43 -0
  124. package/build/consumer/origin.js.map +1 -0
  125. package/build/consumer/reconcile/types.d.ts +13 -0
  126. package/build/consumer/reconcile/types.d.ts.map +1 -0
  127. package/build/consumer/reconcile/types.js +2 -0
  128. package/build/consumer/reconcile/types.js.map +1 -0
  129. package/build/consumer/reconcile.d.ts +5 -0
  130. package/build/consumer/reconcile.d.ts.map +1 -0
  131. package/build/consumer/reconcile.js +320 -0
  132. package/build/consumer/reconcile.js.map +1 -0
  133. package/build/consumer/records/types.d.ts +66 -0
  134. package/build/consumer/records/types.d.ts.map +1 -0
  135. package/build/consumer/records/types.js +2 -0
  136. package/build/consumer/records/types.js.map +1 -0
  137. package/build/consumer/records.d.ts +6 -0
  138. package/build/consumer/records.d.ts.map +1 -0
  139. package/build/consumer/records.js +243 -0
  140. package/build/consumer/records.js.map +1 -0
  141. package/build/consumer/service.d.ts +28 -0
  142. package/build/consumer/service.d.ts.map +1 -0
  143. package/build/consumer/service.js +706 -0
  144. package/build/consumer/service.js.map +1 -0
  145. package/build/consumer/types.d.ts +84 -0
  146. package/build/consumer/types.d.ts.map +1 -0
  147. package/build/consumer/types.js +2 -0
  148. package/build/consumer/types.js.map +1 -0
  149. package/build/consumer/types.local.d.ts +26 -0
  150. package/build/consumer/types.local.d.ts.map +1 -0
  151. package/build/consumer/types.local.js +2 -0
  152. package/build/consumer/types.local.js.map +1 -0
  153. package/build/consumer/withdrawal/types.d.ts +36 -0
  154. package/build/consumer/withdrawal/types.d.ts.map +1 -0
  155. package/build/consumer/withdrawal/types.js +2 -0
  156. package/build/consumer/withdrawal/types.js.map +1 -0
  157. package/build/consumer/withdrawal.d.ts +6 -0
  158. package/build/consumer/withdrawal.d.ts.map +1 -0
  159. package/build/consumer/withdrawal.js +237 -0
  160. package/build/consumer/withdrawal.js.map +1 -0
  161. package/build/entitlement.d.ts +4 -0
  162. package/build/entitlement.d.ts.map +1 -0
  163. package/build/entitlement.js +72 -0
  164. package/build/entitlement.js.map +1 -0
  165. package/build/entrypoints.d.ts +19 -2
  166. package/build/entrypoints.d.ts.map +1 -1
  167. package/build/entrypoints.js +16 -4
  168. package/build/entrypoints.js.map +1 -1
  169. package/build/gate/request.d.ts +4 -0
  170. package/build/gate/request.d.ts.map +1 -0
  171. package/build/gate/request.js +17 -0
  172. package/build/gate/request.js.map +1 -0
  173. package/build/gate/types.d.ts +15 -0
  174. package/build/gate/types.d.ts.map +1 -0
  175. package/build/gate/types.js +2 -0
  176. package/build/gate/types.js.map +1 -0
  177. package/build/gate.d.ts +13 -9
  178. package/build/gate.d.ts.map +1 -1
  179. package/build/gate.js +36 -21
  180. package/build/gate.js.map +1 -1
  181. package/build/index.d.ts +50 -3
  182. package/build/index.d.ts.map +1 -1
  183. package/build/index.js +29 -3
  184. package/build/index.js.map +1 -1
  185. package/build/limit.d.ts +11 -0
  186. package/build/limit.d.ts.map +1 -0
  187. package/build/limit.js +48 -0
  188. package/build/limit.js.map +1 -0
  189. package/build/log.d.ts +3 -0
  190. package/build/log.d.ts.map +1 -0
  191. package/build/log.js +4 -0
  192. package/build/log.js.map +1 -0
  193. package/build/models/declarations/types.d.ts +22 -0
  194. package/build/models/declarations/types.d.ts.map +1 -0
  195. package/build/models/declarations/types.js +2 -0
  196. package/build/models/declarations/types.js.map +1 -0
  197. package/build/models/declarations.d.ts +4 -0
  198. package/build/models/declarations.d.ts.map +1 -0
  199. package/build/models/declarations.js +26 -0
  200. package/build/models/declarations.js.map +1 -0
  201. package/build/models/purchase/types.d.ts +13 -0
  202. package/build/models/purchase/types.d.ts.map +1 -0
  203. package/build/models/purchase/types.js +2 -0
  204. package/build/models/purchase/types.js.map +1 -0
  205. package/build/models/purchase.d.ts +4 -0
  206. package/build/models/purchase.d.ts.map +1 -0
  207. package/build/models/purchase.js +37 -0
  208. package/build/models/purchase.js.map +1 -0
  209. package/build/observer.d.ts +9 -0
  210. package/build/observer.d.ts.map +1 -1
  211. package/build/observer.js +38 -12
  212. package/build/observer.js.map +1 -1
  213. package/build/plan/types.d.ts +21 -0
  214. package/build/plan/types.d.ts.map +1 -0
  215. package/build/plan/types.js +2 -0
  216. package/build/plan/types.js.map +1 -0
  217. package/build/plan.d.ts +7 -0
  218. package/build/plan.d.ts.map +1 -0
  219. package/build/plan.js +29 -0
  220. package/build/plan.js.map +1 -0
  221. package/build/plugins/checkout-plugins/types.d.ts +25 -0
  222. package/build/plugins/checkout-plugins/types.d.ts.map +1 -0
  223. package/build/plugins/checkout-plugins/types.js +2 -0
  224. package/build/plugins/checkout-plugins/types.js.map +1 -0
  225. package/build/plugins/checkout-plugins.d.ts +12 -0
  226. package/build/plugins/checkout-plugins.d.ts.map +1 -0
  227. package/build/plugins/checkout-plugins.js +72 -0
  228. package/build/plugins/checkout-plugins.js.map +1 -0
  229. package/build/plugins/checkout-policy/types.d.ts +18 -0
  230. package/build/plugins/checkout-policy/types.d.ts.map +1 -0
  231. package/build/plugins/checkout-policy/types.js +2 -0
  232. package/build/plugins/checkout-policy/types.js.map +1 -0
  233. package/build/plugins/checkout-policy.d.ts +4 -0
  234. package/build/plugins/checkout-policy.d.ts.map +1 -0
  235. package/build/plugins/checkout-policy.js +26 -0
  236. package/build/plugins/checkout-policy.js.map +1 -0
  237. package/build/plugins/checkout-registry/types.d.ts +7 -0
  238. package/build/plugins/checkout-registry/types.d.ts.map +1 -0
  239. package/build/plugins/checkout-registry/types.js +2 -0
  240. package/build/plugins/checkout-registry/types.js.map +1 -0
  241. package/build/plugins/checkout-registry.d.ts +8 -0
  242. package/build/plugins/checkout-registry.d.ts.map +1 -0
  243. package/build/plugins/checkout-registry.js +21 -0
  244. package/build/plugins/checkout-registry.js.map +1 -0
  245. package/build/plugins/consts.local.d.ts +13 -0
  246. package/build/plugins/consts.local.d.ts.map +1 -0
  247. package/build/plugins/consts.local.js +22 -0
  248. package/build/plugins/consts.local.js.map +1 -0
  249. package/build/plugins/customer-lock/types.d.ts +6 -0
  250. package/build/plugins/customer-lock/types.d.ts.map +1 -0
  251. package/build/plugins/customer-lock/types.js +2 -0
  252. package/build/plugins/customer-lock/types.js.map +1 -0
  253. package/build/plugins/customer-lock.d.ts +5 -0
  254. package/build/plugins/customer-lock.d.ts.map +1 -0
  255. package/build/plugins/customer-lock.js +22 -0
  256. package/build/plugins/customer-lock.js.map +1 -0
  257. package/build/plugins/estimate/cache.d.ts +4 -0
  258. package/build/plugins/estimate/cache.d.ts.map +1 -0
  259. package/build/plugins/estimate/cache.js +7 -0
  260. package/build/plugins/estimate/cache.js.map +1 -0
  261. package/build/plugins/estimate/types.d.ts +27 -0
  262. package/build/plugins/estimate/types.d.ts.map +1 -0
  263. package/build/plugins/estimate/types.js +2 -0
  264. package/build/plugins/estimate/types.js.map +1 -0
  265. package/build/plugins/estimate.d.ts +6 -0
  266. package/build/plugins/estimate.d.ts.map +1 -0
  267. package/build/plugins/estimate.js +271 -0
  268. package/build/plugins/estimate.js.map +1 -0
  269. package/build/plugins/events/types.d.ts +12 -0
  270. package/build/plugins/events/types.d.ts.map +1 -0
  271. package/build/plugins/events/types.js +2 -0
  272. package/build/plugins/events/types.js.map +1 -0
  273. package/build/plugins/events.d.ts +6 -13
  274. package/build/plugins/events.d.ts.map +1 -1
  275. package/build/plugins/events.js +441 -144
  276. package/build/plugins/events.js.map +1 -1
  277. package/build/plugins/fx/types.d.ts +33 -0
  278. package/build/plugins/fx/types.d.ts.map +1 -0
  279. package/build/plugins/fx/types.js +2 -0
  280. package/build/plugins/fx/types.js.map +1 -0
  281. package/build/plugins/fx.d.ts +6 -0
  282. package/build/plugins/fx.d.ts.map +1 -0
  283. package/build/plugins/fx.js +83 -0
  284. package/build/plugins/fx.js.map +1 -0
  285. package/build/plugins/portal/types.d.ts +44 -0
  286. package/build/plugins/portal/types.d.ts.map +1 -0
  287. package/build/plugins/portal/types.js +2 -0
  288. package/build/plugins/portal/types.js.map +1 -0
  289. package/build/plugins/portal.d.ts +6 -0
  290. package/build/plugins/portal.d.ts.map +1 -0
  291. package/build/plugins/portal.js +255 -0
  292. package/build/plugins/portal.js.map +1 -0
  293. package/build/plugins/refunds/types.d.ts +35 -0
  294. package/build/plugins/refunds/types.d.ts.map +1 -0
  295. package/build/plugins/refunds/types.js +2 -0
  296. package/build/plugins/refunds/types.js.map +1 -0
  297. package/build/plugins/refunds.d.ts +6 -0
  298. package/build/plugins/refunds.d.ts.map +1 -0
  299. package/build/plugins/refunds.js +81 -0
  300. package/build/plugins/refunds.js.map +1 -0
  301. package/build/plugins/session/types.d.ts +32 -0
  302. package/build/plugins/session/types.d.ts.map +1 -0
  303. package/build/plugins/session/types.js +2 -0
  304. package/build/plugins/session/types.js.map +1 -0
  305. package/build/plugins/session.d.ts +4 -0
  306. package/build/plugins/session.d.ts.map +1 -0
  307. package/build/plugins/session.js +58 -0
  308. package/build/plugins/session.js.map +1 -0
  309. package/build/plugins/status.d.ts +8 -0
  310. package/build/plugins/status.d.ts.map +1 -0
  311. package/build/plugins/status.js +21 -0
  312. package/build/plugins/status.js.map +1 -0
  313. package/build/plugins/stripe/types.d.ts +20 -0
  314. package/build/plugins/stripe/types.d.ts.map +1 -0
  315. package/build/plugins/stripe/types.js +2 -0
  316. package/build/plugins/stripe/types.js.map +1 -0
  317. package/build/plugins/stripe.d.ts +5 -13
  318. package/build/plugins/stripe.d.ts.map +1 -1
  319. package/build/plugins/stripe.js +481 -129
  320. package/build/plugins/stripe.js.map +1 -1
  321. package/build/plugins/subscriptions/types.d.ts +41 -0
  322. package/build/plugins/subscriptions/types.d.ts.map +1 -0
  323. package/build/plugins/subscriptions/types.js +2 -0
  324. package/build/plugins/subscriptions/types.js.map +1 -0
  325. package/build/plugins/subscriptions.d.ts +6 -0
  326. package/build/plugins/subscriptions.d.ts.map +1 -0
  327. package/build/plugins/subscriptions.js +169 -0
  328. package/build/plugins/subscriptions.js.map +1 -0
  329. package/build/plugins/types.d.ts +7 -0
  330. package/build/plugins/types.d.ts.map +1 -0
  331. package/build/plugins/types.js +2 -0
  332. package/build/plugins/types.js.map +1 -0
  333. package/build/plugins/types.local.d.ts +75 -0
  334. package/build/plugins/types.local.d.ts.map +1 -0
  335. package/build/plugins/types.local.js +2 -0
  336. package/build/plugins/types.local.js.map +1 -0
  337. package/build/plugins/webhook-manager/types.d.ts +62 -0
  338. package/build/plugins/webhook-manager/types.d.ts.map +1 -0
  339. package/build/plugins/webhook-manager/types.js +2 -0
  340. package/build/plugins/webhook-manager/types.js.map +1 -0
  341. package/build/plugins/webhook-manager.d.ts +8 -0
  342. package/build/plugins/webhook-manager.d.ts.map +1 -0
  343. package/build/plugins/webhook-manager.js +245 -0
  344. package/build/plugins/webhook-manager.js.map +1 -0
  345. package/build/protocol.d.ts +13 -0
  346. package/build/protocol.d.ts.map +1 -0
  347. package/build/protocol.js +17 -0
  348. package/build/protocol.js.map +1 -0
  349. package/build/reconcile/types.d.ts +17 -0
  350. package/build/reconcile/types.d.ts.map +1 -0
  351. package/build/reconcile/types.js +2 -0
  352. package/build/reconcile/types.js.map +1 -0
  353. package/build/reconcile.d.ts +12 -0
  354. package/build/reconcile.d.ts.map +1 -0
  355. package/build/reconcile.js +91 -0
  356. package/build/reconcile.js.map +1 -0
  357. package/build/resource.d.ts +12 -1
  358. package/build/resource.d.ts.map +1 -1
  359. package/build/resource.js +97 -6
  360. package/build/resource.js.map +1 -1
  361. package/build/schemas.d.ts +19 -0
  362. package/build/schemas.d.ts.map +1 -0
  363. package/build/schemas.js +244 -0
  364. package/build/schemas.js.map +1 -0
  365. package/build/service.d.ts +28 -3
  366. package/build/service.d.ts.map +1 -1
  367. package/build/service.js +140 -19
  368. package/build/service.js.map +1 -1
  369. package/build/subscription/types.d.ts +21 -0
  370. package/build/subscription/types.d.ts.map +1 -0
  371. package/build/subscription/types.js +2 -0
  372. package/build/subscription/types.js.map +1 -0
  373. package/build/subscription.d.ts +4 -0
  374. package/build/subscription.d.ts.map +1 -0
  375. package/build/subscription.js +84 -0
  376. package/build/subscription.js.map +1 -0
  377. package/build/sync/types.d.ts +25 -0
  378. package/build/sync/types.d.ts.map +1 -0
  379. package/build/sync/types.js +2 -0
  380. package/build/sync/types.js.map +1 -0
  381. package/build/sync.d.ts +4 -3
  382. package/build/sync.d.ts.map +1 -1
  383. package/build/sync.js +231 -79
  384. package/build/sync.js.map +1 -1
  385. package/build/types.d.ts +1258 -36
  386. package/build/types.d.ts.map +1 -1
  387. package/build/types.local.d.ts +22 -0
  388. package/build/types.local.d.ts.map +1 -0
  389. package/build/types.local.js +2 -0
  390. package/build/types.local.js.map +1 -0
  391. package/build/usage/types.d.ts +56 -0
  392. package/build/usage/types.d.ts.map +1 -0
  393. package/build/usage/types.js +2 -0
  394. package/build/usage/types.js.map +1 -0
  395. package/build/usage.d.ts +6 -0
  396. package/build/usage.d.ts.map +1 -0
  397. package/build/usage.js +365 -0
  398. package/build/usage.js.map +1 -0
  399. package/build/utils/types.d.ts +31 -0
  400. package/build/utils/types.d.ts.map +1 -0
  401. package/build/utils/types.js +2 -0
  402. package/build/utils/types.js.map +1 -0
  403. package/build/utils.d.ts +21 -7
  404. package/build/utils.d.ts.map +1 -1
  405. package/build/utils.js +56 -17
  406. package/build/utils.js.map +1 -1
  407. package/package.json +22 -17
  408. package/src/access/types.ts +52 -0
  409. package/src/access.ts +86 -0
  410. package/src/actions/index.ts +1 -0
  411. package/src/actions/resync-subscriptions.ts +10 -0
  412. package/src/actions/resync.ts +14 -5
  413. package/src/actions/webhook.ts +9 -4
  414. package/src/bootstrap/types.ts +16 -0
  415. package/src/bootstrap.ts +31 -0
  416. package/src/catalogue/types.ts +32 -0
  417. package/src/catalogue.ts +135 -0
  418. package/src/commit/types.ts +27 -0
  419. package/src/commit.ts +152 -0
  420. package/src/config.ts +234 -14
  421. package/src/consts.local.ts +62 -0
  422. package/src/consts.ts +100 -36
  423. package/src/consumer/cancellation/types.ts +13 -0
  424. package/src/consumer/cancellation.ts +43 -0
  425. package/src/consumer/capture/types.ts +53 -0
  426. package/src/consumer/capture.ts +321 -0
  427. package/src/consumer/consts.local.ts +18 -0
  428. package/src/consumer/format/types.ts +29 -0
  429. package/src/consumer/format.ts +85 -0
  430. package/src/consumer/handlers.ts +204 -0
  431. package/src/consumer/index.ts +9 -0
  432. package/src/consumer/mail/types.ts +31 -0
  433. package/src/consumer/mail.ts +353 -0
  434. package/src/consumer/observers/types.ts +22 -0
  435. package/src/consumer/observers.ts +97 -0
  436. package/src/consumer/origin/types.ts +17 -0
  437. package/src/consumer/origin.ts +61 -0
  438. package/src/consumer/reconcile/types.ts +13 -0
  439. package/src/consumer/reconcile.ts +330 -0
  440. package/src/consumer/records/types.ts +64 -0
  441. package/src/consumer/records.ts +288 -0
  442. package/src/consumer/service.ts +768 -0
  443. package/src/consumer/types.local.ts +22 -0
  444. package/src/consumer/types.ts +96 -0
  445. package/src/consumer/withdrawal/types.ts +37 -0
  446. package/src/consumer/withdrawal.ts +268 -0
  447. package/src/entitlement.ts +85 -0
  448. package/src/entrypoints.ts +17 -4
  449. package/src/gate/request.ts +24 -0
  450. package/src/gate/types.ts +13 -0
  451. package/src/gate.ts +47 -30
  452. package/src/index.ts +55 -3
  453. package/src/limit.ts +54 -0
  454. package/src/log.ts +4 -0
  455. package/src/models/declarations/types.ts +22 -0
  456. package/src/models/declarations.ts +30 -0
  457. package/src/models/purchase/types.ts +13 -0
  458. package/src/models/purchase.ts +43 -0
  459. package/src/observer.ts +44 -11
  460. package/src/plan/types.ts +21 -0
  461. package/src/plan.ts +46 -0
  462. package/src/plugins/checkout-plugins/types.ts +25 -0
  463. package/src/plugins/checkout-plugins.ts +90 -0
  464. package/src/plugins/checkout-policy/types.ts +18 -0
  465. package/src/plugins/checkout-policy.ts +34 -0
  466. package/src/plugins/checkout-registry/types.ts +7 -0
  467. package/src/plugins/checkout-registry.ts +23 -0
  468. package/src/plugins/consts.local.ts +30 -0
  469. package/src/plugins/customer-lock/types.ts +5 -0
  470. package/src/plugins/customer-lock.ts +25 -0
  471. package/src/plugins/estimate/cache.ts +12 -0
  472. package/src/plugins/estimate/types.ts +28 -0
  473. package/src/plugins/estimate.ts +305 -0
  474. package/src/plugins/events/types.ts +11 -0
  475. package/src/plugins/events.ts +466 -132
  476. package/src/plugins/fx/types.ts +40 -0
  477. package/src/plugins/fx.ts +101 -0
  478. package/src/plugins/portal/types.ts +45 -0
  479. package/src/plugins/portal.ts +284 -0
  480. package/src/plugins/refunds/types.ts +31 -0
  481. package/src/plugins/refunds.ts +95 -0
  482. package/src/plugins/session/types.ts +28 -0
  483. package/src/plugins/session.ts +73 -0
  484. package/src/plugins/status.ts +22 -0
  485. package/src/plugins/stripe/types.ts +20 -0
  486. package/src/plugins/stripe.ts +523 -135
  487. package/src/plugins/subscriptions/types.ts +39 -0
  488. package/src/plugins/subscriptions.ts +195 -0
  489. package/src/plugins/types.local.ts +61 -0
  490. package/src/plugins/types.ts +7 -0
  491. package/src/plugins/webhook-manager/types.ts +63 -0
  492. package/src/plugins/webhook-manager.ts +288 -0
  493. package/src/protocol.ts +29 -0
  494. package/src/reconcile/types.ts +17 -0
  495. package/src/reconcile.ts +110 -0
  496. package/src/resource.ts +158 -11
  497. package/src/schemas.ts +271 -0
  498. package/src/service.ts +161 -19
  499. package/src/subscription/types.ts +23 -0
  500. package/src/subscription.ts +104 -0
  501. package/src/sync/types.ts +25 -0
  502. package/src/sync.ts +255 -72
  503. package/src/types.local.ts +18 -0
  504. package/src/types.ts +1365 -32
  505. package/src/usage/types.ts +51 -0
  506. package/src/usage.ts +432 -0
  507. package/src/utils/types.ts +30 -0
  508. package/src/utils.ts +94 -29
  509. package/tests/checkout-consumer.spec.ts +366 -0
  510. package/tests/checkout-locks.spec.ts +161 -0
  511. package/tests/checkout-plugins.spec.ts +164 -0
  512. package/tests/checkout.spec.ts +209 -93
  513. package/tests/consumer-events.spec.ts +215 -0
  514. package/tests/consumer-fixtures.ts +134 -0
  515. package/tests/consumer-ops.spec.ts +350 -0
  516. package/tests/consumer-rights.integration.spec.ts +147 -0
  517. package/tests/consumer-rights.spec.ts +572 -0
  518. package/tests/context.ts +110 -0
  519. package/tests/entitlement.spec.ts +139 -0
  520. package/tests/estimate.spec.ts +350 -0
  521. package/tests/events.spec.ts +357 -0
  522. package/tests/fake-stripe.ts +981 -0
  523. package/tests/gate-handlers.spec.ts +120 -0
  524. package/tests/gate.spec.ts +63 -72
  525. package/tests/gateway-options.spec.ts +180 -0
  526. package/tests/limit-gate.spec.ts +66 -0
  527. package/tests/portal.spec.ts +202 -0
  528. package/tests/protocol.spec.ts +17 -3
  529. package/tests/sync.spec.ts +114 -0
  530. package/tests/usage.integration.spec.ts +133 -0
  531. package/tests/usage.spec.ts +169 -0
  532. package/tests/webhook-manager.spec.ts +149 -0
  533. package/build/model.d.ts +0 -6
  534. package/build/model.d.ts.map +0 -1
  535. package/build/model.js +0 -33
  536. package/build/model.js.map +0 -1
  537. package/src/model.ts +0 -37
@@ -0,0 +1,202 @@
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,23 +1,37 @@
1
1
  import { describe, expect, test } from 'bun:test'
2
2
  import { protocols } from '@owlmeans/entrypoint'
3
3
  import type { ParamsOf, ResponseOf } from '@owlmeans/entrypoint'
4
+ import { GUARD_ED25519 } from '@owlmeans/server-app'
4
5
  import * as payment from '../src/index.js'
5
- import { paymentGate } from '../src/index.js'
6
+ import { paymentGate, paymentGateEntrypoints, WEBHOOK_EVENTS } from '../src/index.js'
6
7
 
7
8
  describe('server payment protocols', () => {
8
- test('bind webhook params and resync response to their declarations', () => {
9
+ test('bind webhook params and the resync responses to their declarations', () => {
9
10
  const params: ParamsOf<typeof paymentGate.webhook> = { paygate: 'stripe' }
10
11
  const response: ResponseOf<typeof paymentGate.resync> = { ok: true }
12
+ const resynced: ResponseOf<typeof paymentGate.resyncSubscriptions> = { scanned: 3, updated: 1 }
11
13
 
12
14
  expect(params.paygate).toBe('stripe')
13
15
  expect(response.ok).toBe(true)
16
+ expect(resynced.updated).toBe(1)
14
17
  expect(paymentGate.webhook.route.route.parent).toBe(paymentGate.base.alias)
18
+ expect(paymentGate.resyncSubscriptions.route.route.parent).toBe(paymentGate.base.alias)
15
19
  })
16
20
 
17
21
  test('exports an immutable protocol tree without a flattened compatibility list', () => {
18
22
  expect(protocols(paymentGate)).toContain(paymentGate.webhook)
23
+ expect(protocols(paymentGate)).toContain(paymentGate.resyncSubscriptions)
19
24
  expect(protocols(paymentGate).every(item => item.kind === 'entrypoint-protocol')).toBe(true)
20
25
  expect(payment).not.toHaveProperty('paymentGateProtocols')
21
- expect(Object.isFrozen(paymentGate.resync)).toBe(true)
26
+ expect(Object.isFrozen(paymentGate.resyncSubscriptions)).toBe(true)
27
+ expect(paymentGateEntrypoints).toHaveLength(4)
28
+ })
29
+
30
+ test('guards both resync routes with the service signature and leaves the webhook public', () => {
31
+ expect(JSON.stringify(paymentGate.resyncSubscriptions)).toContain(GUARD_ED25519)
32
+ expect(JSON.stringify(paymentGate.resync)).toContain(GUARD_ED25519)
33
+ expect(JSON.stringify(paymentGate.webhook)).not.toContain(GUARD_ED25519)
34
+ expect(Object.isFrozen(WEBHOOK_EVENTS)).toBe(true)
35
+ expect(new Set(WEBHOOK_EVENTS).size).toBe(WEBHOOK_EVENTS.length)
22
36
  })
23
37
  })
@@ -0,0 +1,114 @@
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
+ })
@@ -0,0 +1,133 @@
1
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test'
2
+ import { LimitExhausted, LimitKind, LimitWindow, SUBSCRIPTION_WEEK_MS, planLimitHelper, SubscriptionStatus } from '@owlmeans/payment'
3
+ import { createEventHandler } from '../src/plugins/events.js'
4
+ import { BURST_PLAN, gate, makeSuite } from './context.js'
5
+ import type { Booted } from './context.js'
6
+ import { CREDITS_PRODUCT, eventOf, makeFakeStripe, PRO, subscriptionOf, TEAM } from './fake-stripe.js'
7
+ import { paymentAccessOf } from '../src/access.js'
8
+ import { webhookOf } from '../src/plugins/webhook-manager.js'
9
+
10
+ const suite = makeSuite('payusage')
11
+ const it = gate.skip ? test.skip : test
12
+
13
+ describe('@owlmeans/server-payment — usage ledger on Mongo', () => {
14
+ if (gate.skip) {
15
+ test.skip(gate.reason ?? 'mongo gate closed', () => {})
16
+ return
17
+ }
18
+
19
+ let booted: Booted
20
+ beforeAll(async () => { booted = await suite.boot() }, 60_000)
21
+ afterAll(async () => { await suite.teardown() }, 60_000)
22
+
23
+ it('uses subscription weeks for admission, views, reconciliation, replay and release', async () => {
24
+ const { ctx } = booted
25
+ const access = paymentAccessOf(ctx)
26
+ const service = access.entitlements()
27
+ await access.gateway().grantInternalPlan(ctx, 'weekly-1', BURST_PLAN, { force: true })
28
+ const anchor = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000)
29
+ await access.subscriptions().collection.updateOne({ entityId: 'weekly-1', planSku: BURST_PLAN }, { $set: { createdAt: anchor } })
30
+ const window = planLimitHelper.windowKeyOf(LimitKind.Window, LimitWindow.SubscriptionWeek, new Date(), anchor)
31
+ const outcomes = await Promise.allSettled(Array.from({ length: 8 }, (_, index) =>
32
+ service.consume({ entityId: 'weekly-1', limitKey: 'weekly', eventKey: `weekly:${index}` })))
33
+ expect(outcomes.filter(row => row.status === 'fulfilled')).toHaveLength(1)
34
+ const winner = outcomes.find(row => row.status === 'fulfilled')!
35
+ if (winner.status !== 'fulfilled') throw new Error('No admitted weekly unit')
36
+ expect(winner.value.window).toBe(window)
37
+ expect(winner.value.resetsAt).toEqual(new Date(anchor.getTime() + SUBSCRIPTION_WEEK_MS))
38
+ expect((await service.entitlements('weekly-1')).limits.find(row => row.key === 'weekly')).toMatchObject({ used: 1, remaining: 0, windowStart: anchor })
39
+ await access.usageCounters().collection.updateOne({ entityId: 'weekly-1', limitKey: 'weekly', window }, { $set: { used: 9 } })
40
+ await service.reconcileCounters('weekly-1')
41
+ expect((await service.limitState('weekly-1', 'weekly')).used).toBe(1)
42
+ const request = { entityId: 'weekly-1', limitKey: 'weekly', eventKey: winner.value.eventKey }
43
+ expect((await service.consume(request)).replayed).toBe(true)
44
+ expect((await service.release(request)).remaining).toBe(1)
45
+ expect((await service.consume(request)).admitted).toBe(false)
46
+ const oldStart = new Date(anchor.getTime() - SUBSCRIPTION_WEEK_MS)
47
+ const oldWindow = planLimitHelper.windowKeyOf(LimitKind.Window, LimitWindow.SubscriptionWeek, oldStart, anchor)
48
+ await access.usageEvents().create({ entityId: 'weekly-1', limitKey: 'weekly', window: oldWindow,
49
+ delta: 1, eventKey: 'weekly:past', createdAt: oldStart, planSku: BURST_PLAN })
50
+ await service.reconcileCounters('weekly-1')
51
+ expect((await service.consume({ ...request, eventKey: 'weekly:past' })).resetsAt).toEqual(anchor)
52
+ await service.release({ ...request, eventKey: 'weekly:past' })
53
+ expect((await service.limitState('weekly-1', 'weekly')).used).toBe(0)
54
+ expect((await service.consume({ ...request, eventKey: 'weekly:new' })).admitted).toBe(true)
55
+ }, 60_000)
56
+
57
+ it('admits exactly the limit out of 20 concurrent consumes', async () => {
58
+ const { ctx } = booted
59
+ await paymentAccessOf(ctx).gateway().grantInternalPlan(ctx, 'burst-1', BURST_PLAN, { force: true })
60
+ const results = await Promise.allSettled(Array.from({ length: 20 }, async (_, index) =>
61
+ await paymentAccessOf(ctx).entitlements().consume({ entityId: 'burst-1', limitKey: 'burst', eventKey: `burst:${index}` })))
62
+
63
+ expect(results.filter(result => result.status === 'fulfilled')).toHaveLength(5)
64
+ const refused = results.filter((result): result is PromiseRejectedResult => result.status === 'rejected')
65
+ expect(refused).toHaveLength(15)
66
+ expect(refused.every(result => result.reason instanceof LimitExhausted)).toBe(true)
67
+ expect(await paymentAccessOf(ctx).usageEvents().count({ entityId: 'burst-1', limitKey: 'burst' })).toBe(5)
68
+ expect((await paymentAccessOf(ctx).usageCounters().load({ entityId: 'burst-1', limitKey: 'burst' }))?.used).toBe(5)
69
+ }, 60_000)
70
+
71
+ it('admits a concurrently repeated event key once', async () => {
72
+ const { ctx } = booted
73
+ await paymentAccessOf(ctx).gateway().grantInternalPlan(ctx, 'dup-1', TEAM, { force: true })
74
+ const outcomes = await Promise.all(Array.from({ length: 10 }, async () =>
75
+ await paymentAccessOf(ctx).entitlements().consume({ entityId: 'dup-1', limitKey: 'exports', eventKey: 'export:same', ref: 'same' })))
76
+
77
+ expect(outcomes.every(outcome => outcome.admitted)).toBe(true)
78
+ expect(outcomes.filter(outcome => !outcome.replayed)).toHaveLength(1)
79
+ expect(await paymentAccessOf(ctx).usageEvents().count({ entityId: 'dup-1', limitKey: 'exports' })).toBe(1)
80
+ expect((await paymentAccessOf(ctx).usageCounters().load({ entityId: 'dup-1', limitKey: 'exports' }))?.used).toBe(1)
81
+ expect((await paymentAccessOf(ctx).entitlements().consumptionByRef('dup-1', 'exports', 'same'))?.eventKey).toBe('export:same')
82
+ }, 60_000)
83
+
84
+ it('recomputes counters to the ledger sum and reconciles occupancy', async () => {
85
+ const { ctx } = booted
86
+ await paymentAccessOf(ctx).gateway().grantInternalPlan(ctx, 'rec-1', PRO, { force: true })
87
+ const service = paymentAccessOf(ctx).entitlements()
88
+ for (const key of ['a', 'b', 'c']) {
89
+ await service.consume({ entityId: 'rec-1', limitKey: 'reports', eventKey: `report:${key}` })
90
+ }
91
+ await service.release({ entityId: 'rec-1', limitKey: 'reports', eventKey: 'report:b' })
92
+ await paymentAccessOf(ctx).usageCounters().collection.updateOne({ entityId: 'rec-1', limitKey: 'reports' }, { $set: { used: 7 } })
93
+
94
+ const result = await service.reconcileCounters('rec-1')
95
+ expect(result.repaired).toBeGreaterThanOrEqual(1)
96
+ const { items } = await paymentAccessOf(ctx).usageEvents().list({ entityId: 'rec-1', limitKey: 'reports' }, { size: 0 })
97
+ const sum = items.reduce((total, event) => total + event.delta, 0)
98
+ expect(sum).toBe(2)
99
+ expect((await paymentAccessOf(ctx).usageCounters().load({ entityId: 'rec-1', limitKey: 'reports' }))?.used).toBe(sum)
100
+
101
+ const over = await service.reconcileOccupancy('rec-1', 'seats', 4)
102
+ expect(over.overSince).toBeInstanceOf(Date)
103
+ const within = await service.reconcileOccupancy('rec-1', 'seats', 2)
104
+ expect(within).toEqual({ limitKey: 'seats', used: 2, limit: 2, over: 0 })
105
+ expect((await paymentAccessOf(ctx).usageCounters().load({ entityId: 'rec-1', limitKey: 'seats' }))?.overSince ?? null).toBeNull()
106
+ expect(await paymentAccessOf(ctx).usageEvents().count({ entityId: 'rec-1', limitKey: 'seats' })).toBe(1)
107
+ }, 60_000)
108
+
109
+ it('stores subscriptions, fulfillments and webhook endpoints through their collection validators', async () => {
110
+ const { ctx } = booted
111
+ const { stripe } = makeFakeStripe()
112
+ const handler = createEventHandler(ctx, stripe)
113
+ await handler.process(eventOf('customer.subscription.updated', subscriptionOf({ entityId: 'sub-1' })))
114
+ await handler.process(eventOf('customer.subscription.updated', subscriptionOf({ entityId: 'sub-1', cancelAtPeriodEnd: true })))
115
+ await handler.process(eventOf('checkout.session.completed', {
116
+ id: 'cs_int', mode: 'payment', payment_status: 'paid', customer: 'cus_1', currency: 'usd', amount_subtotal: 1021,
117
+ payment_intent: 'pi_int',
118
+ metadata: {
119
+ pricingMode: 'amount', amountMinor: '1000', chargeAmountMinor: '1021', currency: 'usd',
120
+ entityId: 'sub-1', service: 'app', productSku: CREDITS_PRODUCT,
121
+ },
122
+ }))
123
+ await webhookOf(ctx).ensureWebhookEndpoint(stripe)
124
+
125
+ const row = await paymentAccessOf(ctx).subscriptions().byExternalId('sub_1', 'stripe')
126
+ expect(row).toEqual(expect.objectContaining({ status: SubscriptionStatus.Active, cancelAtPeriodEnd: true, rank: 10 }))
127
+ expect(row?.propagated?.cancelAtPeriodEnd).toBe(true)
128
+ expect(row?.createdAt).toBeInstanceOf(Date)
129
+ expect((await paymentAccessOf(ctx).entitlements().entitlements('sub-1')).plan.sku).toBe(PRO)
130
+ expect((await paymentAccessOf(ctx).fulfillments().byExternalId('cs_int', 'stripe'))?.fulfilledAt).toBeInstanceOf(Date)
131
+ expect((await paymentAccessOf(ctx).paymentWebhooks().load({ service: 'app' }))?.secret).toStartWith('whsec_')
132
+ }, 60_000)
133
+ })