@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
package/build/types.d.ts CHANGED
@@ -1,10 +1,13 @@
1
+ import type Stripe from 'stripe';
1
2
  import type { InitializedService, LazyService } from '@owlmeans/context';
2
3
  import type { ResourceRecord } from '@owlmeans/resource';
3
4
  import type { MongoResource } from '@owlmeans/mongo-resource';
4
5
  import type { PluginConfig } from '@owlmeans/config';
5
6
  import type { PermissionSet } from '@owlmeans/auth';
7
+ import type { AbstractRequest } from '@owlmeans/entrypoint';
8
+ import type { MailMessage } from '@owlmeans/mailer';
6
9
  import type { Config as ApiConfig, Context as ApiContext } from '@owlmeans/server-api';
7
- import type { AmountCheckoutPolicy, CheckoutPricingMode, LimitConfig, PlanDuration, Product, ProductPlan, ProductType, QuantityCheckoutPolicy, SubscriptionStatus } from '@owlmeans/payment';
10
+ import type { AmountCheckoutPolicy, AmountNarrowing, AmountPolicyView, BillingProfileView, CancellationBody, CancellationKind, CancellationReceipt, CancellationStatus, CheckoutPricingMode, ConsentKind, ConsumerRegion, ConsumerRightsDeclaration, ConsumerRightsLinks, ConsumerRightsPolicy, DeclarationChannel, DeclarationKind, EntitlementView, LimitDeclaration, LimitView, PerformanceConsentBody, PerformanceConsentResponse, PerformanceConsentView, PlanCapability, PlanDuration, PlanPriceView, PlanWithdrawalComponent, PortalFlow, PriceEstimate, PricingPolicy, Product, ProductPlan, ProductType, PurchaseKind, PurchaseView, QuantityCheckoutPolicy, SubscriptionStartBody, SubscriptionStartResponse, SubscriptionStartView, SubscriptionStatus, WithdrawalBody, WithdrawalCandidateList, WithdrawalReceipt, WithdrawalStatus } from '@owlmeans/payment';
8
11
  export interface Config extends ApiConfig {
9
12
  }
10
13
  export interface Context<C extends Config = Config> extends ApiContext<C> {
@@ -23,6 +26,11 @@ export interface PaymentPlan extends ProductPlan {
23
26
  pricingMode?: CheckoutPricingMode;
24
27
  amountPolicy?: AmountCheckoutPolicy;
25
28
  quantityPolicy?: QuantityCheckoutPolicy;
29
+ /**
30
+ * Exact prices in further currencies, major units by lowercase ISO 4217 code (`{ usd: 20 }`).
31
+ * Synced as the reusable Price's `currency_options`, never converted.
32
+ */
33
+ currencyPrices?: Record<string, number>;
26
34
  }
27
35
  export interface PaymentProductDef {
28
36
  sku: string;
@@ -40,6 +48,12 @@ export interface PaymentPlanDef {
40
48
  productSku: string;
41
49
  sku: string;
42
50
  duration: PlanDuration;
51
+ /** Position among the plans of one product; a higher rank is an upgrade. Absent reads as `0`. */
52
+ rank?: number;
53
+ /** Held without paying: `price: 0` and no gateway. */
54
+ free?: boolean;
55
+ /** Paygates the plan is sold through. Absent: the product's gateways. A free plan has none. */
56
+ gateways?: string[];
43
57
  /** Reference unit price in major units; amount checkout uses it only for fulfillment conversion. */
44
58
  price: number;
45
59
  currency?: string;
@@ -48,9 +62,9 @@ export interface PaymentPlanDef {
48
62
  };
49
63
  order?: number;
50
64
  title?: string;
51
- capabilities?: PermissionSet[];
65
+ capabilities?: PlanCapability[];
52
66
  limits?: {
53
- [key: string]: LimitConfig;
67
+ [key: string]: LimitDeclaration;
54
68
  };
55
69
  pricingMode?: CheckoutPricingMode;
56
70
  amountPolicy?: AmountCheckoutPolicy;
@@ -59,10 +73,112 @@ export interface PaymentPlanDef {
59
73
  minQuantity?: number;
60
74
  maxQuantity?: number;
61
75
  defaultQuantity?: number;
76
+ /**
77
+ * Exact prices in further currencies, major units by ISO 4217 code (`{ usd: 20 }`): a recurring
78
+ * or quantity plan's synced Price carries each as a `currency_options` entry at exactly this
79
+ * amount, while its default currency (the settlement currency) is converted as before.
80
+ */
81
+ currencyPrices?: Record<string, number>;
82
+ /**
83
+ * The separately priced parts of a subscription for a withdrawal (CJEU C-641/19): their
84
+ * `shareMinor` sum to `round(price × 100)`. Absent: the whole price is one `time` component.
85
+ */
86
+ withdrawal?: {
87
+ components: PlanWithdrawalComponent[];
88
+ };
89
+ }
90
+ /** File paths (or values) of the Stripe secrets. The webhook secret is an optional override. */
91
+ export interface StripeSecretsDef {
92
+ api: string;
93
+ webhook?: string;
62
94
  }
63
95
  export interface StripePluginConfig extends PluginConfig {
64
96
  api: string;
65
- webhook: string;
97
+ webhook?: string;
98
+ }
99
+ /** Stripe-only pricing settings — never a browser-visible field (see `PricingPolicy` for those). */
100
+ export interface StripePricingDef {
101
+ /** Overrides `STRIPE_FX_QUOTES_API_VERSION`, when Stripe moves or renames the preview. */
102
+ fxApiVersion?: string;
103
+ /**
104
+ * Stripe settlement currency used when a catalogue price is declared in another currency.
105
+ * Recurring prices are converted during product sync; amount checkout is converted per session.
106
+ */
107
+ settlementCurrency?: string;
108
+ /** Explicit Stripe payment methods for subscription Checkout; absent keeps Stripe's dynamic selection. */
109
+ subscriptionPaymentMethodTypes?: string[];
110
+ /** Payment methods for a specific subscription charge currency; overrides the default list. */
111
+ subscriptionPaymentMethodTypesByCurrency?: Record<string, string[]>;
112
+ /**
113
+ * Let a matching `unspecified` price take the declared `tax.behavior` even when the Stripe
114
+ * account's own tax-settings default resolves to the opposite one — which changes what an
115
+ * existing subscriber is charged at their next renewal. Absent/`false`: such a price is left
116
+ * `unspecified` and a `log.error` explains why.
117
+ */
118
+ migrateUnspecifiedPrices?: boolean;
119
+ /**
120
+ * The Stripe customer's e-mail is the application's: every checkout must pass
121
+ * `CreateLinkParams.email` (else `PaygateError('customer-email')`), which is written to the
122
+ * customer before the session — Checkout shows a customer's valid e-mail read-only, so no other
123
+ * address can be typed — and the portal configuration never offers to edit it.
124
+ */
125
+ lockCustomerEmail?: boolean;
126
+ /**
127
+ * The billing country a checkout knows — the locked profile's, else `CreateLinkParams.country` —
128
+ * is pinned on the Stripe customer (replacing a saved address of another country before any lock)
129
+ * and Checkout never collects another (`customer_update.address: 'never'`, collection `'auto'`):
130
+ * tax is calculated on it whatever the card form's "Country or region" says, the first completed
131
+ * purchase locks it, and the portal never offers to edit the address. Where Stripe Tax needs more
132
+ * than a country (US: a postal code; CA, IN: a postal code or province) and the customer carries
133
+ * none, Checkout still collects the address — Stripe refuses a session otherwise.
134
+ */
135
+ lockCustomerCountry?: boolean;
136
+ }
137
+ export interface StripePricingPluginConfig extends PluginConfig, StripePricingDef {
138
+ }
139
+ /** `declarePaymentPricing`'s argument: the browser-safe `PricingPolicy` plus Stripe-only settings. */
140
+ export interface PricingDef extends PricingPolicy {
141
+ stripe?: StripePricingDef;
142
+ }
143
+ /**
144
+ * The business the consumer contracts with — backend only, never advertised. `name` is what the
145
+ * express statements say (`{{trader}}` in a consent or start request); the mails' identity line,
146
+ * the withdrawal information and the model form ("To: …") say `legalName`, `address` and `email`.
147
+ */
148
+ export type TraderDef = {
149
+ name: string;
150
+ legalName: string;
151
+ /** Postal address; without it (or `email`) the mails render without it and the boot warns. */
152
+ address?: string;
153
+ email?: string;
154
+ website?: string;
155
+ };
156
+ /** The consumer-rights mail options — backend only, never advertised. */
157
+ export interface ConsumerMailDef {
158
+ /** The mailer service alias. Default `MAILER_SERVICE`. */
159
+ alias?: string;
160
+ from?: string;
161
+ replyTo?: string;
162
+ /** Evidence archive addresses: each receives its own copy of every consumer-rights mail. */
163
+ bcc?: string[];
164
+ }
165
+ export interface ConsumerMailPluginConfig extends PluginConfig, ConsumerMailDef {
166
+ trader?: TraderDef;
167
+ }
168
+ /** `declareConsumerRights`'s argument: the advertised policy plus the backend-only trader and mail options. */
169
+ export interface ConsumerRightsDef extends ConsumerRightsDeclaration {
170
+ trader?: TraderDef;
171
+ mail?: ConsumerMailDef;
172
+ }
173
+ /** What the managed customer portal configuration shows. */
174
+ export interface PortalBrandingDef {
175
+ headline?: string;
176
+ privacyPolicyUrl?: string;
177
+ termsOfServiceUrl?: string;
178
+ /** Where the portal's "return" link leads when a session names none. Absolute URL. */
179
+ returnUrl: string;
180
+ }
181
+ export interface PortalBrandingConfig extends PluginConfig, PortalBrandingDef {
66
182
  }
67
183
  export interface CreateLinkParams {
68
184
  productSku: string;
@@ -72,29 +188,221 @@ export interface CreateLinkParams {
72
188
  service: string;
73
189
  planSku?: string;
74
190
  amountMinor?: number;
191
+ /** Stripe Checkout and future paid-invoice language. Caller supplies a Stripe-supported locale. */
192
+ locale?: string;
193
+ /**
194
+ * Trusted application copy shown beside the Checkout confirmation button — never caller-provided
195
+ * text. A function receives the charge currency and the price the session charges.
196
+ */
197
+ submitText?: string | ((context: CheckoutTextContext) => string);
75
198
  successUrl?: string;
76
199
  cancelUrl?: string;
200
+ /** The billing country the buyer declared (ISO 3166-1 alpha-2). A locked profile overrides it. */
201
+ country?: string;
202
+ /** The subscription start request recorded right before a subscription checkout. */
203
+ startRequestId?: string;
204
+ /** The language the buyer is shown legal copy in; default: the billing country's. */
205
+ consumerLanguage?: string;
206
+ /** The request's geolocated country (`cf-ipcountry`) — second location evidence, stored at lock. */
207
+ ipCountry?: string;
208
+ /**
209
+ * The buyer's e-mail as the application verified it (the signed-in person's account). Read only
210
+ * under `stripe.lockCustomerEmail`, where it is required and pinned on the Stripe customer.
211
+ */
212
+ email?: string;
77
213
  }
78
- export interface PaymentPlugin {
79
- createLink: (ctx: ApiContext, params: CreateLinkParams) => Promise<string>;
80
- handleWebhook: (request: unknown, ctx: ApiContext) => Promise<void>;
81
- initialize?: (ctx: ApiContext) => Promise<void>;
82
- manageSubscription: (ctx: ApiContext, entityId: string, returnUrl: string) => Promise<string>;
214
+ /** What a submit-text function is told about the session it labels. */
215
+ export interface CheckoutTextContext {
216
+ language: string;
217
+ /** The charge currency, lowercase. */
218
+ currency: string;
219
+ /** A subscription's unit price in the charge currency; an amount checkout's pre-tax charge. */
220
+ unitAmountMinor?: number;
221
+ interval?: 'month' | 'year';
222
+ region: ConsumerRegion | null;
223
+ country?: string;
224
+ }
225
+ /** What a plugin narrows: one entity's amount checkout of one plan, at one instant. */
226
+ export interface CheckoutNarrowInput {
227
+ entityId: string;
228
+ productSku: string;
229
+ planSku?: string;
230
+ /** The plan's own amount policy — the same for everyone. */
231
+ base: AmountCheckoutPolicy;
232
+ at: Date;
233
+ }
234
+ /** A checkout about to be created — what `admit` may veto. */
235
+ export interface CheckoutAttempt {
236
+ entityId: string;
237
+ productSku: string;
238
+ planSku?: string;
239
+ mode: 'amount' | 'quantity' | 'subscription';
240
+ /** Amount mode: the net value bought, in the amount policy's currency. */
241
+ amountMinor?: number;
242
+ /** The amount policy's currency (amount mode), else the charge currency. */
243
+ amountCurrency?: string;
244
+ /** Amount mode: the pre-tax charge in `currency`. */
245
+ chargeMinor?: number;
246
+ currency: string;
247
+ /** The session lifetime the gateway will set; absent: Stripe's default (24 h). */
248
+ sessionTtlSeconds?: number;
249
+ expiresAt?: Date;
250
+ at: Date;
251
+ }
252
+ /** A plugin's admission: an optional reservation it binds to the session in `created`. */
253
+ export interface CheckoutAdmission {
254
+ reservationId?: string;
255
+ }
256
+ /** The session a checkout became. */
257
+ export interface CheckoutCreated extends CheckoutAttempt {
258
+ sessionId: string;
259
+ url: string;
260
+ /** What this plugin's own `admit` answered. */
261
+ reservationId?: string;
262
+ }
263
+ export type CheckoutOutcome = 'paid' | 'expired' | 'failed';
264
+ /**
265
+ * How a checkout ended: `paid` (completed and paid), `expired`, or `failed` — an asynchronous
266
+ * payment failure, or a session that never became usable (a later plugin vetoed, Stripe refused,
267
+ * a `created` threw; then `sessionId` may be absent and `reservationId` names the hold to release).
268
+ */
269
+ export interface CheckoutSettled {
270
+ entityId: string;
271
+ productSku?: string;
272
+ planSku?: string;
273
+ sessionId?: string;
274
+ reservationId?: string;
275
+ outcome: CheckoutOutcome;
276
+ amountMinor?: number;
277
+ at: Date;
278
+ }
279
+ /**
280
+ * A seam around amount and subscription checkout, registered with
281
+ * `paymentAccessOf(ctx).gateway().use(plugin)` (a plugin with an `alias` registered twice replaces
282
+ * the first). Errors from `narrow` and `admit` propagate — a plugin fails closed; `settled` errors
283
+ * are logged, since holds carry their own TTL.
284
+ */
285
+ export interface CheckoutPlugin {
286
+ alias?: string;
287
+ /** Lower what this entity may buy now; `null` for no opinion. */
288
+ narrow?: (ctx: ApiContext, input: CheckoutNarrowInput) => Promise<AmountNarrowing | null>;
289
+ /** Veto (throw, e.g. `CheckoutLimitExceeded`) or hold a reservation for the session. */
290
+ admit?: (ctx: ApiContext, attempt: CheckoutAttempt) => Promise<CheckoutAdmission | void>;
291
+ /** The session exists — bind the reservation. A throw expires the session and rethrows. */
292
+ created?: (ctx: ApiContext, created: CheckoutCreated) => Promise<void>;
293
+ /** From the webhook (paid, expired, failed) or from a checkout that never became usable. */
294
+ settled?: (ctx: ApiContext, settled: CheckoutSettled) => Promise<void>;
295
+ /** The longest a session may stay open; the gateway uses the smallest, clamped to 30 min–24 h. */
296
+ sessionTtlSeconds?: number;
297
+ }
298
+ export interface PortalLinkOptions {
299
+ flow: PortalFlow;
300
+ /** The target plan of `PortalFlow.Change`. */
301
+ planSku?: string;
302
+ returnUrl: string;
303
+ }
304
+ export interface PriceEstimateParams {
305
+ productSku: string;
306
+ /** Stable database key resolved by the application before this in-process call. */
307
+ entityId: string;
308
+ /** Absent: the product's own reference plan (an amount-priced consumable). */
309
+ planSku?: string;
310
+ /** ISO 3166-1 alpha-2. Absent: taken from the entity's paygate customer address. */
311
+ country?: string;
312
+ }
313
+ export interface GrantInternalPlanOptions {
314
+ /** Required to grant a plan that is not `free`. */
315
+ force?: boolean;
316
+ /** When the grant stops entitling. Absent: never. */
317
+ periodEnd?: Date;
318
+ }
319
+ export interface SubscriptionRef {
320
+ entityId?: string;
321
+ /** The paygate subscription id (`sub_…`). */
322
+ subscriptionId?: string;
83
323
  }
84
324
  export interface GatewayService extends InitializedService {
85
- createLink: PaymentPlugin['createLink'];
86
- manageSubscription: PaymentPlugin['manageSubscription'];
325
+ /** `false` when registered with `manage: false`: every Stripe-calling method throws. */
326
+ managed: boolean;
327
+ /** Whether the boot-time `bootstrapStripe` runs: the `bootstrap` option, else `managed`. */
328
+ bootstrap: boolean;
329
+ /** The alias whose host and base form the webhook URL: the `webhookService` option, else `cfg.service`. */
330
+ readonly webhookService: string;
331
+ /** The key of this deployment's Stripe rows: the `owner` option, else `cfg.service`. */
332
+ readonly owner: string;
333
+ /** The Stripe client every paygate call of this gateway uses: the `stripe` option, else the configured secret. */
334
+ stripe: StripeFactory;
335
+ createLink: (ctx: ApiContext, params: CreateLinkParams) => Promise<string>;
336
+ portalLink: (ctx: ApiContext, entityId: string, opts: PortalLinkOptions) => Promise<string>;
337
+ /** @throws PaygateError('unmanaged') when `managed` is `false`. */
338
+ estimatePrice: (ctx: ApiContext, params: PriceEstimateParams) => Promise<PriceEstimate>;
339
+ grantInternalPlan: (ctx: ApiContext, entityId: string, planSku: string, opts?: GrantInternalPlanOptions) => Promise<PaymentSubscriptionRecord>;
340
+ /** @returns how many subscription rows changed */
341
+ resyncSubscription: (ctx: ApiContext, ref: SubscriptionRef) => Promise<number>;
342
+ resyncAll: (ctx: ApiContext) => Promise<{
343
+ scanned: number;
344
+ updated: number;
345
+ }>;
346
+ /** Register a checkout plugin; one with an `alias` already registered replaces it. */
347
+ use: (plugin: CheckoutPlugin) => void;
348
+ /** The registered checkout plugins, in registration order. */
349
+ checkoutPlugins: () => readonly CheckoutPlugin[];
350
+ /**
351
+ * The entity's amount policy of an amount plan as narrowed NOW — the very computation
352
+ * `createLink` enforces. Mongo and plugins only; works unmanaged.
353
+ */
354
+ amountPolicy: (ctx: ApiContext, entityId: string, productSku: string, planSku?: string) => Promise<AmountPolicyView>;
355
+ /** The synced prices of a product's plans, per currency — stored rows, no Stripe call. */
356
+ planPrices: (ctx: ApiContext, productSku: string) => Promise<PlanPriceView[]>;
87
357
  }
88
- export interface PaymentResourceOptions {
358
+ export interface PaymentGatewayOptions {
89
359
  dbAlias?: string;
90
360
  serviceAlias?: string;
361
+ /**
362
+ * `false` for a process that must read entitlements but never talk to Stripe: no Stripe
363
+ * bootstrap at init, and `createLink` / `portalLink` / `resync*` / the webhook route throw
364
+ * `PaygateError('unmanaged')`.
365
+ */
366
+ manage?: boolean;
367
+ /**
368
+ * Whether this process brings Stripe to the declared state at boot (`bootstrapStripe`: products,
369
+ * portal configuration, webhook endpoint). Default: `manage`. A managed process with `false`
370
+ * still serves checkout, the portal, estimates and the resyncs, and still runs a FORCED
371
+ * bootstrap (`resync`, an application's `stripeBootstrapOf(ctx).bootstrapStripe(stripe, { force: true })`).
372
+ * `true` on an unmanaged gateway is refused at construction.
373
+ */
374
+ bootstrap?: boolean;
375
+ /**
376
+ * The alias (in `cfg.services`) whose host and base form the webhook URL (`webhookUrlOf`) — also
377
+ * the portal configuration's deployment key. Default: `cfg.service`. Name the process that
378
+ * RECEIVES the webhook, in every process of the deployment, so every bootstrap computes one URL.
379
+ * A managed, bootstrapping gateway refuses to initialize when the alias is not declared.
380
+ */
381
+ webhookService?: string;
382
+ /**
383
+ * The key this deployment's Stripe rows are stored under: the `payment-webhook` rows' `service`,
384
+ * the signing-secret lookup, the endpoint's `owlmeans:<owner>` description and `service`
385
+ * metadata, the `portal:<owner>` fingerprint and the portal configuration's `service` metadata.
386
+ * Default: `cfg.service`. Give every process sharing the database the same value, so they read
387
+ * and replace one another's rows.
388
+ */
389
+ owner?: string;
390
+ /** The Stripe client for this gateway's paygate calls. Default: the configured secret (`stripeClient`). */
391
+ stripe?: StripeFactory;
91
392
  }
393
+ /** A Stripe client for one context — the default reads the configured secret. */
394
+ export interface StripeFactory {
395
+ (ctx: ApiContext): Promise<Stripe>;
396
+ }
397
+ /** @deprecated use `PaymentGatewayOptions` */
398
+ export type PaymentResourceOptions = PaymentGatewayOptions;
92
399
  interface TopUpBase {
93
400
  entityId: string;
94
401
  productSku: string;
95
402
  planSku?: string;
96
403
  service: string;
97
404
  paygate: string;
405
+ /** The checkout session id — the consumer's idempotency key (`payment:<externalId>`). */
98
406
  externalId: string;
99
407
  }
100
408
  export interface QuantityTopUpCompletion extends TopUpBase {
@@ -103,36 +411,218 @@ export interface QuantityTopUpCompletion extends TopUpBase {
103
411
  }
104
412
  export interface AmountTopUpCompletion extends TopUpBase {
105
413
  mode: 'amount';
414
+ /** Net value in the amount policy's catalogue currency. */
106
415
  amountMinor: number;
416
+ /** Grossed-up value in the amount policy's catalogue currency, before settlement conversion. */
417
+ sourceChargeAmountMinor: number;
418
+ /** The amount policy's catalogue currency. */
419
+ amountCurrency: string;
420
+ /** Pre-tax subtotal actually charged by Stripe, in `currency`. */
107
421
  chargeAmountMinor: number;
422
+ /** Stripe integration/settlement currency. */
108
423
  currency: string;
109
424
  }
110
425
  export type TopUpCompletion = QuantityTopUpCompletion | AmountTopUpCompletion;
111
- export interface SubscriptionCompletion {
426
+ export type SubscriptionChange = 'created' | 'renewed' | 'upgraded' | 'downgraded' | 'cancel-scheduled' | 'cancel-undone' | 'canceled' | 'paused' | 'resumed' | 'past-due' | 'suspended' | 'trial-ending';
427
+ export interface SubscriptionSnapshot {
112
428
  entityId: string;
113
- status: SubscriptionStatus;
114
- productSku: string;
115
429
  planSku: string;
116
- service: string;
430
+ productSku: string;
431
+ rank: number;
432
+ status: SubscriptionStatus;
117
433
  paygate: string;
118
- externalId: string;
119
- isNew: boolean;
120
- capabilities?: PermissionSet[];
434
+ /** The subscription row's `externalId`. */
435
+ subscriptionId: string;
436
+ service: string;
437
+ periodStart?: Date;
438
+ periodEnd?: Date;
439
+ cancelAtPeriodEnd?: boolean;
440
+ trialEnd?: Date;
441
+ pausedAt?: Date;
442
+ createdAt?: Date;
443
+ capabilities?: PlanCapability[];
121
444
  limits?: {
122
- [key: string]: LimitConfig;
445
+ [key: string]: LimitDeclaration;
123
446
  };
124
447
  }
448
+ export interface SubscriptionEvent {
449
+ change: SubscriptionChange;
450
+ /** The state last propagated to observers; `null` for `created`. */
451
+ previous: SubscriptionSnapshot | null;
452
+ current: SubscriptionSnapshot;
453
+ /** `ENTITLING_STATUSES.includes(current.status)`. */
454
+ active: boolean;
455
+ eventKey: string;
456
+ invoiceId?: string;
457
+ externalEventId?: string;
458
+ }
459
+ export type PaymentTargetKind = 'fulfillment' | 'subscription';
460
+ export interface RefundEvent {
461
+ entityId: string;
462
+ target: PaymentTargetKind;
463
+ productSku?: string;
464
+ planSku?: string;
465
+ /** The target row's `externalId` (checkout session or subscription). */
466
+ externalId: string;
467
+ refundId: string;
468
+ paymentIntentId?: string;
469
+ invoiceId?: string;
470
+ /** This refund. */
471
+ amountMinor: number;
472
+ /** Everything refunded on the charge so far, this refund included. */
473
+ refundedTotalMinor: number;
474
+ /** What the customer paid on the refunded charge, tax included. */
475
+ paidMinor?: number;
476
+ currency: string;
477
+ /** Less than the whole charge has been refunded. */
478
+ partial: boolean;
479
+ eventKey: string;
480
+ /** Fulfillment targets: the net value credited at checkout. */
481
+ netAmountMinor?: number;
482
+ /** Fulfillment targets: the pre-tax subtotal charged at checkout. */
483
+ chargeAmountMinor?: number;
484
+ /** The refund's own metadata. */
485
+ metadata?: Record<string, string>;
486
+ /**
487
+ * Set when the refund executes a withdrawal (`refund.metadata.withdrawalId`): the `onWithdrawal`
488
+ * observer takes back exactly the unused units — an `onRefund` observer must skip its own
489
+ * claw-back for such a refund, or the units are taken back twice.
490
+ */
491
+ withdrawalId?: string;
492
+ }
493
+ export type DisputePhase = 'opened' | 'funds-withdrawn' | 'funds-reinstated' | 'closed';
494
+ export interface DisputeEvent {
495
+ entityId: string;
496
+ target: PaymentTargetKind;
497
+ productSku?: string;
498
+ planSku?: string;
499
+ externalId: string;
500
+ disputeId: string;
501
+ phase: DisputePhase;
502
+ /** The paygate's dispute status (`needs_response`, `won`, `lost`, …). */
503
+ status: string;
504
+ amountMinor: number;
505
+ currency: string;
506
+ eventKey: string;
507
+ netAmountMinor?: number;
508
+ chargeAmountMinor?: number;
509
+ }
510
+ export interface PaymentFailedEvent {
511
+ entityId: string;
512
+ kind: 'checkout' | 'invoice';
513
+ /** The checkout session or invoice id. */
514
+ externalId: string;
515
+ subscriptionId?: string;
516
+ invoiceId?: string;
517
+ attempt?: number;
518
+ actionRequired?: boolean;
519
+ nextAttemptAt?: Date;
520
+ eventKey: string;
521
+ }
522
+ /** A consumer's express request was recorded (performance consent or subscription start). */
523
+ export interface ConsentEvent {
524
+ kind: ConsentKind;
525
+ consentId: string;
526
+ entityId: string;
527
+ profileId?: string;
528
+ /** The purchases the consent covers (none for a start request, which precedes its purchase). */
529
+ purchaseIds: string[];
530
+ planSku?: string;
531
+ textVersion: string;
532
+ language: string;
533
+ decidedAt: Date;
534
+ expiresAt?: Date;
535
+ /** `consent:<consentId>`. */
536
+ eventKey: string;
537
+ }
538
+ /** A withdrawal executed (`refunded`) or left to an operator (`review`). */
539
+ export interface WithdrawalEvent {
540
+ withdrawalId: string;
541
+ /** `withdrawal:<withdrawalId>`. */
542
+ eventKey: string;
543
+ entityId: string;
544
+ channel: DeclarationChannel;
545
+ purchase: PurchaseRef;
546
+ declaredAt: Date;
547
+ status: WithdrawalStatus;
548
+ refund: {
549
+ amountMinor: number;
550
+ currency: string;
551
+ netMinor?: number;
552
+ refundId?: string;
553
+ creditNoteId?: string;
554
+ };
555
+ /**
556
+ * The purchase's units as the usage meter read them: `returned` is what the application takes
557
+ * back (`granted − used`), `null` without a meter.
558
+ */
559
+ units: {
560
+ granted: number;
561
+ used: number;
562
+ returned: number;
563
+ } | null;
564
+ subscriptionCanceled: boolean;
565
+ }
566
+ /** A cancellation was declared (matched to a subscription or not). */
567
+ export interface CancellationEvent {
568
+ cancellationId: string;
569
+ /** `cancellation:<cancellationId>`. */
570
+ eventKey: string;
571
+ entityId?: string;
572
+ matched: boolean;
573
+ channel: DeclarationChannel;
574
+ kind: CancellationKind;
575
+ status: CancellationStatus;
576
+ subscriptionId?: string;
577
+ effectiveAt?: Date;
578
+ declaredAt: Date;
579
+ }
125
580
  export interface TopUpCallback {
126
581
  (completion: TopUpCompletion, ctx: ApiContext): Promise<void>;
127
582
  }
128
583
  export interface SubscriptionCallback {
129
- (completion: SubscriptionCompletion, ctx: ApiContext): Promise<void>;
584
+ (event: SubscriptionEvent, ctx: ApiContext): Promise<void>;
585
+ }
586
+ export interface RefundCallback {
587
+ (event: RefundEvent, ctx: ApiContext): Promise<void>;
588
+ }
589
+ export interface DisputeCallback {
590
+ (event: DisputeEvent, ctx: ApiContext): Promise<void>;
130
591
  }
592
+ export interface PaymentFailedCallback {
593
+ (event: PaymentFailedEvent, ctx: ApiContext): Promise<void>;
594
+ }
595
+ export interface ConsentCallback {
596
+ (event: ConsentEvent, ctx: ApiContext): Promise<void>;
597
+ }
598
+ export interface WithdrawalCallback {
599
+ (event: WithdrawalEvent, ctx: ApiContext): Promise<void>;
600
+ }
601
+ export interface CancellationCallback {
602
+ (event: CancellationEvent, ctx: ApiContext): Promise<void>;
603
+ }
604
+ /**
605
+ * Callbacks run sequentially and are awaited. A paygate callback's throw escapes so the paygate
606
+ * retries; a consumer-rights callback (`onConsent`, `onWithdrawal`, `onCancellation`) runs AFTER
607
+ * the records and the paygate steps, and its throw is recorded and retried by `reconcile()`.
608
+ */
131
609
  export interface CompletionObserver extends LazyService {
132
610
  onTopUp: (cb: TopUpCallback) => void;
133
611
  onSubscription: (cb: SubscriptionCallback) => void;
612
+ onRefund: (cb: RefundCallback) => void;
613
+ onDispute: (cb: DisputeCallback) => void;
614
+ onPaymentFailed: (cb: PaymentFailedCallback) => void;
615
+ onConsent: (cb: ConsentCallback) => void;
616
+ onWithdrawal: (cb: WithdrawalCallback) => void;
617
+ onCancellation: (cb: CancellationCallback) => void;
134
618
  propagateTopUp: (completion: TopUpCompletion, ctx: ApiContext) => Promise<void>;
135
- propagateSubscription: (completion: SubscriptionCompletion, ctx: ApiContext) => Promise<void>;
619
+ propagateSubscription: (event: SubscriptionEvent, ctx: ApiContext) => Promise<void>;
620
+ propagateRefund: (event: RefundEvent, ctx: ApiContext) => Promise<void>;
621
+ propagateDispute: (event: DisputeEvent, ctx: ApiContext) => Promise<void>;
622
+ propagatePaymentFailed: (event: PaymentFailedEvent, ctx: ApiContext) => Promise<void>;
623
+ propagateConsent: (event: ConsentEvent, ctx: ApiContext) => Promise<void>;
624
+ propagateWithdrawal: (event: WithdrawalEvent, ctx: ApiContext) => Promise<void>;
625
+ propagateCancellation: (event: CancellationEvent, ctx: ApiContext) => Promise<void>;
136
626
  }
137
627
  export interface PaygateCustomerRecord extends ResourceRecord {
138
628
  paygate: string;
@@ -142,48 +632,780 @@ export interface PaygateCustomerRecord extends ResourceRecord {
142
632
  email?: string;
143
633
  name?: string;
144
634
  taxId?: string;
635
+ /** The paygate customer's billing address country, as its last webhook stated it. */
636
+ country?: string;
637
+ /** The paygate customer's own currency (set by its first subscription or invoice). */
638
+ currency?: string;
639
+ deletedAt?: Date;
145
640
  }
146
641
  export interface PaygateCustomerResource extends MongoResource<PaygateCustomerRecord> {
147
642
  loadByPgId: (externalId: string, paygate: string) => Promise<PaygateCustomerRecord | null>;
148
643
  byEntity: (entityId: string, paygate: string) => Promise<PaygateCustomerRecord | null>;
149
644
  }
645
+ /** The classification inputs last propagated to observers. */
646
+ export interface PropagatedState {
647
+ planSku: string;
648
+ rank: number;
649
+ status: SubscriptionStatus;
650
+ cancelAtPeriodEnd?: boolean;
651
+ pausedAt?: Date;
652
+ /** The renewal invoice last reported as `renewed` — a renewal is reported once per invoice. */
653
+ renewedInvoiceId?: string;
654
+ }
655
+ /**
656
+ * What ONE subscription holds instead of its plan's static declaration. Written by an operator,
657
+ * never by the paygate: every sync and re-grant carries it over with the rest of the row.
658
+ */
659
+ export interface SubscriptionOverrides {
660
+ /** By limit key: the ceiling in force for this subscription, whatever the plan or its promo says. */
661
+ limits?: {
662
+ [key: string]: {
663
+ limit: number;
664
+ };
665
+ };
666
+ }
667
+ /** One row per subscription — paygate (`sub_…`) or internal (`free:<entityId>`, `internal:<planSku>:<entityId>`). */
150
668
  export interface PaymentSubscriptionRecord extends ResourceRecord {
151
- sku: string;
152
- productSku: string;
153
669
  entityId: string;
670
+ planSku: string;
671
+ productSku: string;
154
672
  service: string;
155
673
  paygate: string;
156
674
  externalId: string;
675
+ itemId?: string;
676
+ priceId?: string;
157
677
  status: SubscriptionStatus;
158
- kind: 'consumable' | 'subscription';
159
- capabilities?: PermissionSet[];
160
- limits?: {
161
- [key: string]: LimitConfig;
162
- };
163
- pricingMode?: CheckoutPricingMode;
678
+ externalStatus?: string;
679
+ rank: number;
680
+ periodStart?: Date;
681
+ periodEnd?: Date;
682
+ cancelAtPeriodEnd?: boolean;
683
+ canceledAt?: Date;
684
+ endedAt?: Date;
685
+ pausedAt?: Date;
686
+ trialEnd?: Date;
687
+ latestInvoiceId?: string;
688
+ customerId?: string;
689
+ disputedAt?: Date;
690
+ disputeStatus?: string;
691
+ createdAt: Date;
692
+ updatedAt?: Date;
693
+ /** The paygate-side instant of the state stored; an older event payload is not applied. */
694
+ syncedAt?: Date;
695
+ lastEventId?: string;
696
+ initialPropagatedAt?: Date;
697
+ propagated?: PropagatedState;
698
+ /** The subscription's currency (lowercase). */
699
+ currency?: string;
700
+ checkoutSessionId?: string;
701
+ purchaseId?: string;
702
+ firstInvoiceId?: string;
703
+ country?: string;
704
+ email?: string;
705
+ amountTotalMinor?: number;
706
+ amountTaxMinor?: number;
707
+ termsAccepted?: boolean;
708
+ startRequestId?: string;
709
+ withdrawnAt?: Date;
710
+ /** This subscription's own plan parameters — `resolveEffectivePlan` answers the plan with them applied. */
711
+ overrides?: SubscriptionOverrides;
712
+ }
713
+ export interface PaymentSubscriptionResource extends MongoResource<PaymentSubscriptionRecord> {
714
+ byExternalId: (externalId: string, paygate: string) => Promise<PaymentSubscriptionRecord | null>;
715
+ byItemId: (itemId: string, paygate: string) => Promise<PaymentSubscriptionRecord | null>;
716
+ }
717
+ /** A one-time checkout session: pending until observers succeed, then `fulfilledAt`. */
718
+ export interface PaymentFulfillmentRecord extends ResourceRecord {
719
+ entityId: string;
720
+ productSku: string;
721
+ planSku?: string;
722
+ service: string;
723
+ paygate: string;
724
+ externalId: string;
725
+ paymentIntentId?: string;
726
+ chargeId?: string;
727
+ invoiceId?: string;
728
+ mode: CheckoutPricingMode;
164
729
  units?: number;
165
730
  amountMinor?: number;
731
+ sourceChargeAmountMinor?: number;
732
+ amountCurrency?: string;
166
733
  chargeAmountMinor?: number;
167
734
  currency?: string;
168
735
  createdAt: Date;
169
- endsAt?: Date;
170
- trialUntil?: Date;
171
- canceledAt?: Date;
172
736
  fulfilledAt?: Date;
173
- initialPropagatedAt?: Date;
737
+ failedAt?: Date;
738
+ refundedMinor?: number;
739
+ refundedAt?: Date;
740
+ disputedAt?: Date;
741
+ disputeStatus?: string;
742
+ country?: string;
743
+ email?: string;
744
+ profileId?: string;
745
+ amountTotalMinor?: number;
746
+ amountTaxMinor?: number;
747
+ termsAccepted?: boolean;
748
+ purchaseId?: string;
174
749
  }
175
- export interface PaymentSubscriptionResource extends MongoResource<PaymentSubscriptionRecord> {
176
- byExternalId: (externalId: string, paygate: string) => Promise<PaymentSubscriptionRecord | null>;
750
+ export interface PaymentFulfillmentResource extends MongoResource<PaymentFulfillmentRecord> {
751
+ byExternalId: (externalId: string, paygate: string) => Promise<PaymentFulfillmentRecord | null>;
752
+ }
753
+ /** The paygate webhook endpoint this deployment owns, with its signing secret. */
754
+ export interface PaymentWebhookRecord extends ResourceRecord {
755
+ paygate: string;
756
+ /** The gateway's `owner` (default `cfg.service`) — the key every process of one owner shares. */
757
+ service: string;
758
+ /** The endpoint's URL (`webhookUrlOf`: the `webhookService` alias's host and base). */
759
+ url: string;
760
+ externalId: string;
761
+ secret: string;
762
+ apiVersion: string;
763
+ events: string[];
764
+ hash: string;
765
+ createdAt: Date;
766
+ updatedAt?: Date;
767
+ }
768
+ export interface PaymentWebhookResource extends MongoResource<PaymentWebhookRecord> {
769
+ }
770
+ /** A usage event — the source of truth of every limit counter. */
771
+ export interface PaymentUsageRecord extends ResourceRecord {
772
+ entityId: string;
773
+ limitKey: string;
774
+ /** `windowKeyOf` of the limit when the event was written. */
775
+ window: string;
776
+ /** `+n` consumed, `-n` released, any sign for a reconciliation adjustment. */
777
+ delta: number;
778
+ eventKey: string;
779
+ ref?: string;
780
+ reason?: string;
781
+ planSku?: string;
782
+ createdAt: Date;
783
+ releasedAt?: Date;
784
+ }
785
+ export interface PaymentUsageResource extends MongoResource<PaymentUsageRecord> {
786
+ }
787
+ /** The projection of the usage ledger per (entity, limit, window). */
788
+ export interface PaymentUsageCounterRecord extends ResourceRecord {
789
+ entityId: string;
790
+ limitKey: string;
791
+ window: string;
792
+ used: number;
793
+ limit: number;
794
+ planSku?: string;
795
+ overSince?: Date;
796
+ updatedAt: Date;
797
+ reconciledAt?: Date;
798
+ }
799
+ export interface PaymentUsageCounterResource extends MongoResource<PaymentUsageCounterRecord> {
800
+ }
801
+ /** One currency option of a synced price. */
802
+ export interface SyncedPriceOption {
803
+ currency: string;
804
+ unitAmount: number;
805
+ }
806
+ /** A reusable price as the last sync left it — what `planPrices` and checkout read without Stripe. */
807
+ export interface SyncedPrice {
808
+ planSku: string;
809
+ priceId: string;
810
+ lookupKey: string;
811
+ /** The default currency and its amount. */
812
+ currency: string;
813
+ unitAmount: number;
814
+ /** `currency_options` besides the default currency. */
815
+ options: SyncedPriceOption[];
816
+ taxBehavior?: string;
817
+ interval?: 'month' | 'year';
818
+ sourceUnitAmount: number;
819
+ sourceCurrency: string;
820
+ syncedAt: Date;
177
821
  }
178
822
  export interface FingerprintRecord extends ResourceRecord {
179
823
  sku: string;
180
824
  hash: string;
181
825
  productId?: string;
826
+ /** The paygate object the fingerprint describes (a portal configuration id). */
827
+ externalId?: string;
828
+ /** A product's synced reusable prices. */
829
+ prices?: SyncedPrice[];
182
830
  updatedAt: Date;
183
831
  }
184
832
  export interface FingerprintResource extends MongoResource<FingerprintRecord> {
185
833
  bySku: (sku: string) => Promise<FingerprintRecord | null>;
186
834
  clear: () => Promise<void>;
187
835
  }
836
+ export interface EffectivePlan {
837
+ plan: PaymentPlan;
838
+ /** The entitling row behind the plan; `null` when the entity falls back to the free plan. */
839
+ subscription: PaymentSubscriptionRecord | null;
840
+ /** The declared free plan, when one exists. */
841
+ fallback: PaymentPlan | null;
842
+ }
843
+ export interface ConsumeRequest {
844
+ entityId: string;
845
+ limitKey: string;
846
+ /** Idempotency key — key it by the record the unit pays for. */
847
+ eventKey: string;
848
+ /** Positive safe integer; default `1`. */
849
+ amount?: number;
850
+ ref?: string;
851
+ reason?: string;
852
+ }
853
+ export interface ReleaseRequest {
854
+ entityId: string;
855
+ limitKey: string;
856
+ /** The event key the unit was consumed under. */
857
+ eventKey: string;
858
+ /** Default: the consumed amount. */
859
+ amount?: number;
860
+ }
861
+ export interface LimitOutcome {
862
+ /** A consume: the unit is held. A release: the release is in effect. */
863
+ admitted: boolean;
864
+ /** The event key had been seen before; nothing new was written. */
865
+ replayed: boolean;
866
+ limitKey: string;
867
+ window: string;
868
+ used: number;
869
+ limit: number;
870
+ remaining: number;
871
+ resetsAt?: Date;
872
+ eventKey: string;
873
+ }
874
+ export interface OccupancyOutcome {
875
+ limitKey: string;
876
+ used: number;
877
+ limit: number;
878
+ /** `max(0, used - limit)`. */
879
+ over: number;
880
+ /** When the entity first went over; absent while it is within the limit. */
881
+ overSince?: Date;
882
+ }
883
+ export interface CounterReconciliation {
884
+ counters: number;
885
+ repaired: number;
886
+ }
887
+ export interface EntitlementService extends InitializedService {
888
+ effectivePlan: (entityId: string) => Promise<EffectivePlan>;
889
+ entitlements: (entityId: string) => Promise<EntitlementView>;
890
+ hasCapability: (entityId: string, param: string) => Promise<boolean>;
891
+ /** @throws LimitUnknown */
892
+ limitState: (entityId: string, key: string) => Promise<LimitView>;
893
+ /** @throws LimitExhausted | LimitUnknown */
894
+ consume: (req: ConsumeRequest) => Promise<LimitOutcome>;
895
+ release: (req: ReleaseRequest) => Promise<LimitOutcome>;
896
+ /** @throws LimitUnknown | LimitMisdeclared */
897
+ reconcileOccupancy: (entityId: string, limitKey: string, actual: number) => Promise<OccupancyOutcome>;
898
+ reconcileCounters: (entityId?: string) => Promise<CounterReconciliation>;
899
+ /**
900
+ * The ACTIVE consume event for this key (not released), or null. This is how a consumer asks
901
+ * "was a unit already spent on this record?" — a consumer keys allowances by the record they pay
902
+ * for (`eventKey = <anything>:<recordId>`, `ref = recordId`) instead of writing a marker onto
903
+ * the record, so a retry replays the same event and a resumed run can re-derive that it is free.
904
+ */
905
+ consumption: (entityId: string, limitKey: string, eventKey: string) => Promise<PaymentUsageRecord | null>;
906
+ /**
907
+ * The newest ACTIVE consume event (not released) whose `ref` is this record, or null. For a unit
908
+ * consumed under a fresh event key per cycle (`<key>:<recordId>:<timestamp>`, `ref = recordId`):
909
+ * whether the record holds a unit now, and the event key to release it by.
910
+ */
911
+ consumptionByRef: (entityId: string, limitKey: string, ref: string) => Promise<PaymentUsageRecord | null>;
912
+ }
913
+ export interface ReconcileEntityOptions {
914
+ /** Grant this plan (an internal row) when the entity holds no entitling subscription. */
915
+ freePlanSku?: string;
916
+ /** Re-read the entity's paygate subscriptions first (managed gateways only). */
917
+ resync?: boolean;
918
+ }
919
+ export interface ReconcileAllOptions extends ReconcileEntityOptions {
920
+ /** Entities to cover besides those the payment store already knows. */
921
+ entities?: Iterable<string> | AsyncIterable<string>;
922
+ }
923
+ export interface ReconcileAllResult {
924
+ entities: number;
925
+ granted: number;
926
+ counters: number;
927
+ repaired: number;
928
+ failed: number;
929
+ }
930
+ /** Where a billing profile's country came from. */
931
+ export type BillingProfileSource = 'checkout' | 'customer' | 'manual';
932
+ /** One per organization: the billing country fixed at the first purchase (first write wins). */
933
+ export interface BillingProfileRecord extends ResourceRecord {
934
+ entityId: string;
935
+ country: string;
936
+ region: ConsumerRegion;
937
+ /** The charge currency, fixed with the country. */
938
+ currency: string;
939
+ /** The language of the legal copy. */
940
+ language: string;
941
+ source: BillingProfileSource;
942
+ paygate: string;
943
+ customerId?: string;
944
+ sessionId?: string;
945
+ /** The geolocated country of the request that started the locking checkout — VAT evidence. */
946
+ ipCountry?: string;
947
+ email?: string;
948
+ name?: string;
949
+ /** A business tax id was given at the locking checkout. */
950
+ business?: boolean;
951
+ lockedAt: Date;
952
+ createdAt: Date;
953
+ updatedAt?: Date;
954
+ }
955
+ export interface BillingProfileResource extends MongoResource<BillingProfileRecord> {
956
+ byEntity: (entityId: string) => Promise<BillingProfileRecord | null>;
957
+ }
958
+ /**
959
+ * One purchase — a contract and its withdrawal window: a paid one-time checkout (`top-up`) or a
960
+ * subscription's first invoice (`subscription`). Renewals are not purchases.
961
+ */
962
+ export interface PurchaseRecord extends ResourceRecord {
963
+ /** `stripe:<session id>` (one-time) or `stripe:<subscription id>`. */
964
+ purchaseId: string;
965
+ /** `CR-YYMMDD-XXXXXX` — what a consumer quotes. */
966
+ contractRef: string;
967
+ entityId: string;
968
+ kind: PurchaseKind;
969
+ paygate: string;
970
+ sessionId?: string;
971
+ subscriptionId?: string;
972
+ paymentIntentId?: string;
973
+ invoiceId?: string;
974
+ invoiceNumber?: string;
975
+ invoiceLineId?: string;
976
+ productSku: string;
977
+ planSku?: string;
978
+ profileId?: string;
979
+ country?: string;
980
+ region?: ConsumerRegion;
981
+ ipCountry?: string;
982
+ inScope: boolean;
983
+ language: string;
984
+ email?: string;
985
+ name?: string;
986
+ business?: boolean;
987
+ /** The charge currency. */
988
+ currency: string;
989
+ amountSubtotalMinor: number;
990
+ amountTaxMinor: number;
991
+ amountTotalMinor: number;
992
+ presentmentCurrency?: string;
993
+ presentmentAmountMinor?: number;
994
+ /** Amount checkout: the net value credited, in `amountCurrency`. */
995
+ netAmountMinor?: number;
996
+ amountCurrency?: string;
997
+ /** Quantity checkout: the units bought. */
998
+ units?: number;
999
+ taxBehavior?: string;
1000
+ /**
1001
+ * Stripe's own `consent.terms_of_service` of the checkout — absent when the session did not
1002
+ * collect it (the policy's `checkoutTerms` off, or the fallback of a Dashboard without a terms URL).
1003
+ */
1004
+ termsAccepted?: boolean;
1005
+ textVersion?: string;
1006
+ copyVersion?: string;
1007
+ startRequestId?: string;
1008
+ /** When the consumer expressly requested the services (the start request) — time deductions count from here. */
1009
+ servicesStartedAt?: Date;
1010
+ /** When the confirmation mail was claimed — one claim per purchase, whatever the outcome of the send. */
1011
+ confirmationMailAt?: Date;
1012
+ purchasedAt: Date;
1013
+ /** Exclusive end of the withdrawal window; absent outside the consumer-rights territories. */
1014
+ deadline?: Date;
1015
+ consentId?: string;
1016
+ consentedAt?: Date;
1017
+ withdrawalId?: string;
1018
+ withdrawnAt?: Date;
1019
+ /** Refunded so far on this purchase's payment, tax included. */
1020
+ refundedMinor?: number;
1021
+ /** Set once the whole payment is refunded — the window closes. */
1022
+ refundedAt?: Date;
1023
+ cancellationId?: string;
1024
+ cancelEffectiveAt?: Date;
1025
+ createdAt: Date;
1026
+ updatedAt?: Date;
1027
+ }
1028
+ export interface PurchaseResource extends MongoResource<PurchaseRecord> {
1029
+ byPurchaseId: (purchaseId: string) => Promise<PurchaseRecord | null>;
1030
+ }
1031
+ /** The request evidence a consumer act is recorded with (`requestOriginOf`). */
1032
+ export interface RequestOrigin {
1033
+ /** `cf-connecting-ip`, else the LAST `x-forwarded-for` entry, else `x-real-ip`, else the socket. */
1034
+ ip?: string;
1035
+ /** The raw `x-forwarded-for` header. */
1036
+ forwardedFor?: string;
1037
+ /** `user-agent`, at most 512 characters. */
1038
+ userAgent?: string;
1039
+ /** `cf-ipcountry`. */
1040
+ ipCountry?: string;
1041
+ acceptLanguage?: string;
1042
+ /** The channel the request came through (`http`, `mcp`, …), when the application knows. */
1043
+ via?: string;
1044
+ }
1045
+ /** Append-only: one express request — a performance consent or a subscription start request. */
1046
+ export interface ConsumerConsentRecord extends ResourceRecord, RequestOrigin {
1047
+ kind: ConsentKind;
1048
+ entityId: string;
1049
+ profileId?: string;
1050
+ /** The person who gave it — the confirmation is mailed here. */
1051
+ name?: string;
1052
+ email?: string;
1053
+ purchaseIds: string[];
1054
+ planSku?: string;
1055
+ /** The plan's name as the statement said it (`{{plan}}`). */
1056
+ planName?: string;
1057
+ textVersion: string;
1058
+ copyVersion: string;
1059
+ /** The language the statement was shown in. */
1060
+ language: string;
1061
+ uiLanguage?: string;
1062
+ trader: string;
1063
+ /**
1064
+ * The copy variant the statement was rendered with: the policy's `consentContext` for a
1065
+ * performance consent, `startContextOf(plan)` (`'units'`) for a start request; absent for the base.
1066
+ */
1067
+ context?: string;
1068
+ /** The statement exactly as rendered and recorded. */
1069
+ text: {
1070
+ request: string;
1071
+ acknowledgement: string;
1072
+ checkbox: string;
1073
+ };
1074
+ links: ConsumerRightsLinks;
1075
+ /** The latest deadline among the covered purchases. */
1076
+ deadline?: Date;
1077
+ decidedAt: Date;
1078
+ /** A start request stops being usable at this instant. */
1079
+ expiresAt?: Date;
1080
+ }
1081
+ export interface ConsumerConsentResource extends MongoResource<ConsumerConsentRecord> {
1082
+ }
1083
+ /** Append-only: one withdrawal or cancellation declaration, matched to a contract or not. */
1084
+ export interface ConsumerDeclarationRecord extends ResourceRecord, RequestOrigin {
1085
+ kind: DeclarationKind;
1086
+ channel: DeclarationChannel;
1087
+ entityId?: string;
1088
+ purchaseId?: string;
1089
+ subscriptionId?: string;
1090
+ /** The contract as the consumer named it. */
1091
+ contractRef?: string;
1092
+ name: string;
1093
+ email: string;
1094
+ cancellationKind?: CancellationKind;
1095
+ reason?: string;
1096
+ effective?: 'earliest' | 'date';
1097
+ requestedDate?: string;
1098
+ language: string;
1099
+ textVersion?: string;
1100
+ copyVersion: string;
1101
+ receivedAt: Date;
1102
+ matched: boolean;
1103
+ profileId?: string;
1104
+ /** A repeated declaration of a contract already withdrawn from: the original's id. */
1105
+ duplicateOf?: string;
1106
+ /** The status decided on receipt (`WithdrawalStatus` / `CancellationStatus`); execution steps are events. */
1107
+ status: string;
1108
+ refundMinor?: number;
1109
+ currency?: string;
1110
+ effectiveAt?: Date;
1111
+ }
1112
+ export interface ConsumerDeclarationResource extends MongoResource<ConsumerDeclarationRecord> {
1113
+ }
1114
+ export type ConsumerEventAction = 'mail' | 'computed' | 'meter' | 'refund' | 'credit-note' | 'subscription-cancel' | 'cancel-scheduled' | 'observers' | 'lock' | 'lock-mismatch' | 'relock' | 'unlock' | 'duplicate' | 'checkout-terms-fallback';
1115
+ export type ConsumerRecordKind = 'purchase' | 'consent' | 'declaration' | 'profile' | 'checkout';
1116
+ /** Append-only: one execution or audit step. */
1117
+ export interface ConsumerEventRecord extends ResourceRecord {
1118
+ /** The purchase id, consent id, declaration id, or the entity id of a profile or a checkout. */
1119
+ recordId: string;
1120
+ recordKind: ConsumerRecordKind;
1121
+ entityId?: string;
1122
+ action: ConsumerEventAction;
1123
+ /** The mail kind of a `mail` event; the observer family of an `observers` one. */
1124
+ step?: string;
1125
+ ok: boolean;
1126
+ /** A mail deliberately not sent (a reserved domain, a renderer that suppressed it). */
1127
+ skipped?: boolean;
1128
+ externalId?: string;
1129
+ amountMinor?: number;
1130
+ currency?: string;
1131
+ /** JSON. */
1132
+ detail?: string;
1133
+ error?: string;
1134
+ at: Date;
1135
+ }
1136
+ export interface ConsumerEventResource extends MongoResource<ConsumerEventRecord> {
1137
+ }
1138
+ /** What a usage meter is told about the purchase it reads. */
1139
+ export interface PurchaseRef {
1140
+ purchaseId: string;
1141
+ kind: PurchaseKind;
1142
+ entityId: string;
1143
+ contractRef: string;
1144
+ productSku: string;
1145
+ planSku?: string;
1146
+ /** One-time purchases: the checkout session id. */
1147
+ sessionId?: string;
1148
+ /** Subscription purchases: the paygate subscription id. */
1149
+ subscriptionId?: string;
1150
+ invoiceId?: string;
1151
+ purchasedAt: Date;
1152
+ }
1153
+ export interface UsageQuery {
1154
+ entityId: string;
1155
+ purchase: PurchaseRef;
1156
+ /** The purchase's consent — before it the consumer bears no cost; absent: nothing is deductible. */
1157
+ after?: Date;
1158
+ at: Date;
1159
+ }
1160
+ export interface UsageReading {
1161
+ /** Units the purchase granted. */
1162
+ granted: number;
1163
+ /** Units of it used so far. */
1164
+ used: number;
1165
+ /** Units of it used strictly after `after` (0 without `after`). */
1166
+ usedAfter: number;
1167
+ /** Units of it that paid off an earlier overdraft when it was granted. */
1168
+ settled?: number;
1169
+ /** Units of it already taken back by an earlier (money) refund. */
1170
+ clawed?: number;
1171
+ remaining?: number;
1172
+ }
1173
+ /**
1174
+ * The application's reading of how much of one purchase was used — for a withdrawal's refund.
1175
+ * The deduction is `usedAfter + settled + clawed`.
1176
+ */
1177
+ export interface UsageMeter {
1178
+ used: (ctx: ApiContext, query: UsageQuery) => Promise<UsageReading>;
1179
+ }
1180
+ /** Who acts: the organization, and the person's prefill. */
1181
+ export interface ConsumerSubject {
1182
+ entityId: string;
1183
+ profileId?: string;
1184
+ name?: string;
1185
+ email?: string;
1186
+ /** `public` when an application matched a public declaration to this organization itself. */
1187
+ channel?: DeclarationChannel;
1188
+ }
1189
+ export type ConsumerMailKind = 'purchase' | 'consent' | 'start' | 'withdrawal' | 'cancellation';
1190
+ /** What a consumer-rights mail is rendered from. */
1191
+ export interface ConsumerMailData {
1192
+ kind: ConsumerMailKind;
1193
+ /** The purchase id, consent id or declaration id. */
1194
+ recordId: string;
1195
+ entityId?: string;
1196
+ language: string;
1197
+ to: string;
1198
+ name?: string;
1199
+ trader: TraderDef;
1200
+ links: ConsumerRightsLinks;
1201
+ purchase?: PurchaseRecord;
1202
+ purchases?: PurchaseRecord[];
1203
+ consent?: ConsumerConsentRecord;
1204
+ declaration?: ConsumerDeclarationRecord;
1205
+ }
1206
+ /**
1207
+ * Replace or suppress a consumer-rights mail: answer a message to send it instead, `null` to send
1208
+ * nothing (recorded as skipped), `undefined` to send the rendered one.
1209
+ */
1210
+ export interface ConsumerMailRenderer {
1211
+ (kind: ConsumerMailKind, data: ConsumerMailData, rendered: MailMessage): MailMessage | null | undefined | Promise<MailMessage | null | undefined>;
1212
+ }
1213
+ export interface LockOptions {
1214
+ customerId?: string;
1215
+ sessionId?: string;
1216
+ ipCountry?: string;
1217
+ email?: string;
1218
+ name?: string;
1219
+ business?: boolean;
1220
+ /** The charge currency; default: an active subscription's, else the region's. */
1221
+ currency?: string;
1222
+ language?: string;
1223
+ /** `manual` only: replace an existing lock (audited as a `relock` event). */
1224
+ force?: boolean;
1225
+ by?: string;
1226
+ reason?: string;
1227
+ }
1228
+ /** Who removes a lock, and why — kept on the `unlock` event. */
1229
+ export interface UnlockOptions {
1230
+ by?: string;
1231
+ reason?: string;
1232
+ }
1233
+ export interface ConsumerReconcileOptions {
1234
+ /** How far back declarations, mails and observers are retried. Default 30 days. */
1235
+ since?: Date;
1236
+ /** The most items per step. Default 50. */
1237
+ limit?: number;
1238
+ }
1239
+ export interface ConsumerReconcileResult {
1240
+ retried: number;
1241
+ mailed: number;
1242
+ observed: number;
1243
+ backfilled: number;
1244
+ locked: number;
1245
+ failed: number;
1246
+ }
1247
+ /**
1248
+ * Lazy: reachable while the application is still being wired (`useMeter`, `useMailRenderer` before
1249
+ * the context initializes); the gateway's initialization initializes it at boot.
1250
+ */
1251
+ export interface ConsumerRightsService extends LazyService {
1252
+ /**
1253
+ * `false`: every paygate-calling method (`withdraw`, `cancel`, `reconcile`'s paygate steps) refuses.
1254
+ * An explicit `manage` of `appendConsumerRights` wins over the gateway's, whatever the order.
1255
+ */
1256
+ readonly managed: boolean;
1257
+ policy: () => Promise<ConsumerRightsPolicy | null>;
1258
+ /** The locked billing profile, or `null`. */
1259
+ profile: (entityId: string) => Promise<BillingProfileView | null>;
1260
+ /** Lock the billing country; the first write wins unless a `manual` lock is `force`d. */
1261
+ lock: (entityId: string, country: string, source: BillingProfileSource, opts?: LockOptions) => Promise<BillingProfileView>;
1262
+ /**
1263
+ * An operator removes the lock: the profile is deleted and an `unlock` event keeps it. No lazy lock
1264
+ * from the paygate customer follows (checkout, reconcile); the next completed purchase locks again.
1265
+ * @returns the profile as it was, or `null` when nothing was locked
1266
+ */
1267
+ unlock: (entityId: string, opts?: UnlockOptions) => Promise<BillingProfileView | null>;
1268
+ purchases: (entityId: string, opts?: {
1269
+ open?: boolean;
1270
+ at?: Date;
1271
+ }) => Promise<PurchaseView[]>;
1272
+ consentView: (entityId: string, at?: Date) => Promise<PerformanceConsentView>;
1273
+ /** @throws PerformanceConsentRequired (428) for a stale text version */
1274
+ recordConsent: (subject: ConsumerSubject, body: PerformanceConsentBody, origin?: RequestOrigin) => Promise<PerformanceConsentResponse>;
1275
+ /** @throws PerformanceConsentRequired while an open in-scope window has no consent */
1276
+ assertConsent: (entityId: string, at?: Date) => Promise<void>;
1277
+ /** `context` = `startContextOf(plan)`: the statement variant the dialog shows and the request records. */
1278
+ startView: (entityId: string, planSku: string, opts?: {
1279
+ language?: string;
1280
+ }) => Promise<SubscriptionStartView>;
1281
+ /**
1282
+ * Records the statement in the variant of the plan (`startContextOf`), the one the start view
1283
+ * named. `plan`: the plan's short name the statement says (default: its localized catalogue title).
1284
+ * @throws SubscriptionStartRequired (428) for a stale text version
1285
+ */
1286
+ recordStartRequest: (subject: ConsumerSubject, body: SubscriptionStartBody, origin?: RequestOrigin, opts?: {
1287
+ plan?: string;
1288
+ }) => Promise<SubscriptionStartResponse>;
1289
+ /**
1290
+ * The fresh start request bound to this entity and plan, or `null` when none is required.
1291
+ * @throws SubscriptionStartRequired
1292
+ */
1293
+ assertStartRequest: (entityId: string, planSku: string, startRequestId?: string) => Promise<ConsumerConsentRecord | null>;
1294
+ withdrawalCandidates: (entityId: string, subject?: Partial<ConsumerSubject>) => Promise<WithdrawalCandidateList>;
1295
+ /** `subject: null` — the public function: matched by contract reference and e-mail, never disclosed. */
1296
+ withdraw: (subject: ConsumerSubject | null, body: WithdrawalBody, origin?: RequestOrigin) => Promise<WithdrawalReceipt>;
1297
+ cancel: (subject: ConsumerSubject | null, body: CancellationBody, origin?: RequestOrigin) => Promise<CancellationReceipt>;
1298
+ useMeter: (meter: UsageMeter | null) => void;
1299
+ useMailRenderer: (renderer: ConsumerMailRenderer | null) => void;
1300
+ usageMeter: () => UsageMeter | null;
1301
+ mailRenderer: () => ConsumerMailRenderer | null;
1302
+ /** Retry refunds, credit notes, cancellations, mails and observers; backfill purchases and legacy locks. */
1303
+ reconcile: (opts?: ConsumerReconcileOptions) => Promise<ConsumerReconcileResult>;
1304
+ }
1305
+ /**
1306
+ * `appendConsumerRights` options. `manage`, `usage` and `stripe` apply to the service whenever the
1307
+ * call comes — before or after the gateway registered it; the resources' `dbAlias` / `serviceAlias`
1308
+ * are those of the first registration.
1309
+ */
1310
+ export interface ConsumerRightsOptions {
1311
+ /**
1312
+ * `false` in a process that never talks to the paygate (reads and consent asserts only). Absent:
1313
+ * the gateway's `manage`, else managed.
1314
+ */
1315
+ manage?: boolean;
1316
+ /** The application's usage meter; without one a withdrawal is left to an operator (`review`). */
1317
+ usage?: UsageMeter;
1318
+ alias?: string;
1319
+ /** The paygate client; default: the configured Stripe secret. */
1320
+ stripe?: StripeFactory;
1321
+ dbAlias?: string;
1322
+ serviceAlias?: string;
1323
+ }
1324
+ /** What a public declaration is throttled by. */
1325
+ export interface ConsumerThrottleKey {
1326
+ action: 'withdrawal' | 'cancellation';
1327
+ email: string;
1328
+ ip?: string;
1329
+ }
1330
+ /**
1331
+ * The hooks of `consumerRightsEntrypoints`. Every hook gets the request's context last, so an
1332
+ * application keeps its counters and lookups on the context, never in module state.
1333
+ */
1334
+ export interface ConsumerRightsHandlerOptions {
1335
+ /** The organization a signed-in request acts for. Default: `req.entity.id`. */
1336
+ resolveEntity?: (req: AbstractRequest, ctx: ApiContext) => string | null | undefined;
1337
+ /** The person's profile id and prefill. */
1338
+ subjectOf?: (req: AbstractRequest, ctx: ApiContext) => Partial<ConsumerSubject> | Promise<Partial<ConsumerSubject>>;
1339
+ /** Refuse a money-moving act (consent, start, withdraw, cancel) — e.g. an API-key request. */
1340
+ guardMoney?: (req: AbstractRequest, action: string, ctx: ApiContext) => void | Promise<void>;
1341
+ /** REQUIRED when the public subtree is bound: throw (e.g. 429) to refuse a public declaration. */
1342
+ throttle?: (req: AbstractRequest, key: ConsumerThrottleKey, ctx: ApiContext) => void | Promise<void>;
1343
+ /** The request evidence; default `requestOriginOf`. */
1344
+ metaOf?: (req: AbstractRequest, ctx: ApiContext) => RequestOrigin;
1345
+ /** The least time a public declaration takes to answer, matched or not. Default 1000 ms. */
1346
+ publicMinMs?: number;
1347
+ /** The plan's short name a start request's statement says (default: its localized catalogue title). */
1348
+ planNameOf?: (planSku: string, language: string, req: AbstractRequest, ctx: ApiContext) => string | undefined | Promise<string | undefined>;
1349
+ serviceAlias?: string;
1350
+ }
1351
+ export interface CheckoutReadHandlerOptions {
1352
+ resolveEntity?: (req: AbstractRequest, ctx: ApiContext) => string | null | undefined;
1353
+ gatewayAlias?: string;
1354
+ }
1355
+ export interface PaygateParams {
1356
+ paygate: string;
1357
+ }
1358
+ export interface ResyncResult {
1359
+ ok: boolean;
1360
+ }
1361
+ export interface ResyncSubscriptionsResult {
1362
+ scanned: number;
1363
+ updated: number;
1364
+ }
1365
+ export interface EntityResolverOption {
1366
+ /** The stable organization id a request acts for. Default: `req.entity.id`, else the token's entity. */
1367
+ resolveEntity?: (req: AbstractRequest) => string | null;
1368
+ }
1369
+ export interface CapabilityGateOptions extends EntityResolverOption {
1370
+ /** Refuse unless the effective plan belongs to one of these products. */
1371
+ productSkus?: string[];
1372
+ /**
1373
+ * Also require the token to grant the permission (IAM `hasPermission`). Off by default: a
1374
+ * platform token carries no permissions, and the subscription is the authority.
1375
+ */
1376
+ requirePermission?: boolean;
1377
+ }
1378
+ /** @deprecated use `CapabilityGateOptions` */
1379
+ export type EntitlementGateOptions = CapabilityGateOptions;
1380
+ export interface LimitGateOptions extends EntityResolverOption {
1381
+ }
1382
+ export interface StripeBootstrapOptions {
1383
+ /** Re-verify what the stored fingerprints say is in place. */
1384
+ force?: boolean;
1385
+ }
1386
+ /** The gateway options a service instance takes — the resource aliases belong to the registration. */
1387
+ export interface GatewayServiceOptions extends Omit<PaymentGatewayOptions, 'dbAlias' | 'serviceAlias'> {
1388
+ }
1389
+ export interface CommitOptions {
1390
+ /** The paygate event being applied; a repeat of the last applied one is ignored. */
1391
+ eventId?: string;
1392
+ /** A paid renewal invoice. */
1393
+ renewal?: boolean;
1394
+ invoiceId?: string;
1395
+ /** The paygate announced the trial ends soon. */
1396
+ trialEnding?: boolean;
1397
+ /**
1398
+ * Runs after the new state is written and BEFORE observers hear the change — what must exist
1399
+ * before an observer grants anything (a subscription's purchase row). A throw propagates: the
1400
+ * observers are not told and the paygate retries.
1401
+ */
1402
+ beforePropagate?: (record: PaymentSubscriptionRecord, change: SubscriptionChange) => Promise<void>;
1403
+ }
1404
+ export interface CommitResult {
1405
+ record: PaymentSubscriptionRecord | null;
1406
+ change: SubscriptionChange | null;
1407
+ /** The stored subscription state changed. */
1408
+ updated: boolean;
1409
+ }
188
1410
  export {};
189
1411
  //# sourceMappingURL=types.d.ts.map