@volter/twin-stripe 2.0.38 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (402) hide show
  1. package/README.md +112 -207
  2. package/dist/generated/pack-facts.json +94 -0
  3. package/dist/journeys/coverage.json +596 -0
  4. package/dist/journeys/customer-life.json +6108 -0
  5. package/dist/journeys/customer-life.outline.md +371 -0
  6. package/dist/journeys/decisions.json +677 -0
  7. package/dist/journeys/demand.json +706 -0
  8. package/dist/journeys/score.json +853 -0
  9. package/dist/journeys/unreachable.json +102 -0
  10. package/dist/journeys/vendor-examples.json +8010 -0
  11. package/dist/spec/SOURCE.md +18 -0
  12. package/dist/spec/doc-examples.json +445 -0
  13. package/dist/spec/fixtures3.json.gz +0 -0
  14. package/dist/spec/openapi.json.gz +0 -0
  15. package/dist/spec/patches.json +34 -0
  16. package/dist/spec/sources.json +306 -0
  17. package/dist/src/cli.d.ts +0 -1
  18. package/dist/src/cli.js +11 -31
  19. package/dist/src/engine/after-payment.d.ts +8 -0
  20. package/dist/src/engine/after-payment.js +27 -0
  21. package/dist/src/engine/apps-secrets.d.ts +1 -0
  22. package/dist/src/engine/apps-secrets.js +3 -0
  23. package/dist/src/engine/balance.d.ts +5 -0
  24. package/dist/src/engine/balance.js +15 -0
  25. package/dist/src/engine/checkout.d.ts +24 -0
  26. package/dist/src/engine/checkout.js +30 -0
  27. package/dist/src/engine/common.d.ts +19 -0
  28. package/dist/src/engine/common.js +34 -0
  29. package/dist/src/engine/connect.d.ts +45 -0
  30. package/dist/src/engine/connect.js +108 -0
  31. package/dist/src/engine/customers.d.ts +4 -0
  32. package/dist/src/engine/customers.js +8 -0
  33. package/dist/src/engine/display.d.ts +11 -0
  34. package/dist/src/engine/display.js +13 -0
  35. package/dist/src/engine/files.d.ts +11 -0
  36. package/dist/src/engine/files.js +23 -0
  37. package/dist/src/engine/invoices.d.ts +21 -0
  38. package/dist/src/engine/invoices.js +84 -0
  39. package/dist/src/engine/issuing.d.ts +33 -0
  40. package/dist/src/engine/issuing.js +54 -0
  41. package/dist/src/engine/ledger.d.ts +8 -0
  42. package/dist/src/engine/ledger.js +8 -0
  43. package/dist/src/engine/oauth.d.ts +4 -0
  44. package/dist/src/engine/oauth.js +24 -0
  45. package/dist/src/engine/onboarding.d.ts +13 -0
  46. package/dist/src/engine/onboarding.js +42 -0
  47. package/dist/src/{stripe-params.d.ts → engine/params.d.ts} +20 -3
  48. package/dist/src/{stripe-params.js → engine/params.js} +7 -60
  49. package/dist/src/engine/payment-intents.d.ts +10 -0
  50. package/dist/src/engine/payment-intents.js +27 -0
  51. package/dist/src/engine/payment-methods.d.ts +16 -0
  52. package/dist/src/engine/payment-methods.js +22 -0
  53. package/dist/src/engine/radar.d.ts +2 -0
  54. package/dist/src/engine/radar.js +5 -0
  55. package/dist/src/engine/refunds.d.ts +1 -0
  56. package/dist/src/engine/refunds.js +3 -0
  57. package/dist/src/engine/renewals.d.ts +36 -0
  58. package/dist/src/engine/renewals.js +65 -0
  59. package/dist/src/{stripe-twin.d.ts → engine/stripe.d.ts} +12 -45
  60. package/dist/src/{stripe-twin.js → engine/stripe.js} +53 -387
  61. package/dist/src/engine/subscriptions.d.ts +11 -0
  62. package/dist/src/engine/subscriptions.js +30 -0
  63. package/dist/src/engine/transfers.d.ts +2 -0
  64. package/dist/src/engine/transfers.js +1 -0
  65. package/dist/src/{stripe-version.d.ts → engine/version.d.ts} +0 -2
  66. package/dist/src/{stripe-version.js → engine/version.js} +21 -9
  67. package/dist/src/engine/webhook-endpoints.d.ts +1 -0
  68. package/dist/src/engine/webhook-endpoints.js +12 -0
  69. package/dist/src/engine/webhooks.d.ts +31 -0
  70. package/dist/src/engine/webhooks.js +68 -0
  71. package/dist/src/fetch.d.ts +2 -0
  72. package/dist/src/fetch.js +26 -0
  73. package/dist/src/generated/surface.gen.json +1 -1
  74. package/dist/src/generated/ui.gen.json +1 -1
  75. package/dist/src/index.d.ts +5 -14
  76. package/dist/src/index.js +10 -75
  77. package/dist/src/manifest.js +478 -876
  78. package/dist/src/screens/billing-portal.d.ts +3 -0
  79. package/dist/src/screens/{portal.js → billing-portal.js} +32 -58
  80. package/dist/src/screens/checkout-js.d.ts +2 -0
  81. package/dist/src/screens/checkout-js.js +84 -0
  82. package/dist/src/screens/checkout.d.ts +2 -31
  83. package/dist/src/screens/checkout.js +32 -121
  84. package/dist/src/screens/connect-onboarding.d.ts +3 -0
  85. package/dist/src/screens/{onboarding.js → connect-onboarding.js} +38 -104
  86. package/dist/src/screens/dashboard.d.ts +3 -0
  87. package/dist/src/screens/dashboard.js +116 -0
  88. package/dist/src/screens/shared.d.ts +27 -0
  89. package/dist/src/screens/shared.js +87 -0
  90. package/dist/src/screens/stripe-js.d.ts +3 -0
  91. package/dist/src/screens/stripe-js.js +95 -0
  92. package/dist/src/semantics/account.d.ts +2 -0
  93. package/dist/src/semantics/account.js +8 -0
  94. package/dist/src/semantics/account_links.d.ts +2 -0
  95. package/dist/src/semantics/account_links.js +22 -0
  96. package/dist/src/semantics/accounts.d.ts +4 -0
  97. package/dist/src/semantics/accounts.js +40 -0
  98. package/dist/src/semantics/apps.d.ts +4 -0
  99. package/dist/src/semantics/{apps-secrets.js → apps.js} +14 -26
  100. package/dist/src/semantics/around.d.ts +2 -0
  101. package/dist/src/semantics/around.js +13 -0
  102. package/dist/src/semantics/balance.d.ts +2 -11
  103. package/dist/src/semantics/balance.js +3 -194
  104. package/dist/src/semantics/balance_transactions.d.ts +2 -0
  105. package/dist/src/semantics/balance_transactions.js +15 -0
  106. package/dist/src/semantics/billing_portal.d.ts +4 -0
  107. package/dist/src/semantics/billing_portal.js +36 -0
  108. package/dist/src/semantics/charges.d.ts +3 -28
  109. package/dist/src/semantics/charges.js +5 -202
  110. package/dist/src/semantics/checkout.d.ts +3 -20
  111. package/dist/src/semantics/checkout.js +21 -271
  112. package/dist/src/semantics/clock.d.ts +2 -0
  113. package/dist/src/semantics/clock.js +15 -0
  114. package/dist/src/semantics/coupons.d.ts +2 -6
  115. package/dist/src/semantics/coupons.js +2 -60
  116. package/dist/src/semantics/customers.d.ts +5 -6
  117. package/dist/src/semantics/customers.js +47 -413
  118. package/dist/src/semantics/doors.d.ts +23 -0
  119. package/dist/src/semantics/doors.js +73 -0
  120. package/dist/src/semantics/entitlements.d.ts +0 -2
  121. package/dist/src/semantics/entitlements.js +4 -95
  122. package/dist/src/semantics/events.d.ts +11 -0
  123. package/dist/src/semantics/events.js +31 -0
  124. package/dist/src/semantics/index.d.ts +2 -0
  125. package/dist/src/semantics/index.js +85 -0
  126. package/dist/src/semantics/invoice_payments.d.ts +2 -0
  127. package/dist/src/semantics/invoice_payments.js +12 -0
  128. package/dist/src/semantics/invoices.d.ts +11 -18
  129. package/dist/src/semantics/invoices.js +121 -440
  130. package/dist/src/semantics/issuing.d.ts +6 -13
  131. package/dist/src/semantics/issuing.js +58 -556
  132. package/dist/src/semantics/payment_intents.d.ts +3 -0
  133. package/dist/src/semantics/payment_intents.js +71 -0
  134. package/dist/src/semantics/payment_methods.d.ts +3 -0
  135. package/dist/src/semantics/payment_methods.js +15 -0
  136. package/dist/src/semantics/payouts.d.ts +3 -0
  137. package/dist/src/semantics/payouts.js +28 -0
  138. package/dist/src/semantics/prices.d.ts +4 -0
  139. package/dist/src/semantics/prices.js +37 -0
  140. package/dist/src/semantics/products.d.ts +4 -2
  141. package/dist/src/semantics/products.js +12 -138
  142. package/dist/src/semantics/promotion_codes.d.ts +3 -0
  143. package/dist/src/semantics/promotion_codes.js +35 -0
  144. package/dist/src/semantics/radar.d.ts +2 -2
  145. package/dist/src/semantics/radar.js +5 -74
  146. package/dist/src/semantics/refunds.d.ts +2 -9
  147. package/dist/src/semantics/refunds.js +3 -193
  148. package/dist/src/semantics/shared.d.ts +558 -55
  149. package/dist/src/semantics/shared.js +2070 -114
  150. package/dist/src/semantics/states.d.ts +462 -0
  151. package/dist/src/semantics/states.js +634 -0
  152. package/dist/src/semantics/subscriptions.d.ts +6 -11
  153. package/dist/src/semantics/subscriptions.js +37 -530
  154. package/dist/src/semantics/test_helpers.d.ts +3 -0
  155. package/dist/src/semantics/test_helpers.js +125 -0
  156. package/dist/src/semantics/transfers.d.ts +2 -2
  157. package/dist/src/semantics/transfers.js +6 -101
  158. package/dist/src/semantics/webhook_endpoints.d.ts +2 -0
  159. package/dist/src/semantics/webhook_endpoints.js +26 -0
  160. package/dist/src/server.d.ts +7 -0
  161. package/dist/src/server.js +7 -0
  162. package/generated/pack-facts.json +94 -0
  163. package/journeys/coverage.json +596 -0
  164. package/journeys/customer-life.json +6108 -0
  165. package/journeys/customer-life.outline.md +371 -0
  166. package/journeys/decisions.json +677 -0
  167. package/journeys/demand.json +706 -0
  168. package/journeys/score.json +853 -0
  169. package/journeys/unreachable.json +102 -0
  170. package/journeys/vendor-examples.json +8010 -0
  171. package/package.json +11 -20
  172. package/spec/SOURCE.md +18 -0
  173. package/spec/doc-examples.json +445 -0
  174. package/spec/fixtures3.json.gz +0 -0
  175. package/spec/openapi.json.gz +0 -0
  176. package/spec/patches.json +34 -0
  177. package/spec/sources.json +306 -0
  178. package/src/cli.ts +11 -28
  179. package/src/engine/after-payment.ts +29 -0
  180. package/src/engine/apps-secrets.ts +4 -0
  181. package/src/engine/balance.ts +32 -0
  182. package/src/engine/checkout.ts +39 -0
  183. package/src/engine/common.ts +49 -0
  184. package/src/engine/connect.ts +106 -0
  185. package/src/engine/customers.ts +10 -0
  186. package/src/engine/display.ts +18 -0
  187. package/src/engine/files.ts +28 -0
  188. package/src/engine/invoices.ts +102 -0
  189. package/src/engine/issuing.ts +66 -0
  190. package/src/engine/ledger.ts +48 -0
  191. package/src/engine/oauth.ts +18 -0
  192. package/src/engine/onboarding.ts +53 -0
  193. package/src/{stripe-params.ts → engine/params.ts} +7 -56
  194. package/src/engine/payment-intents.ts +32 -0
  195. package/src/engine/payment-methods.ts +24 -0
  196. package/src/engine/radar.ts +6 -0
  197. package/src/engine/refunds.ts +3 -0
  198. package/src/engine/renewals.ts +72 -0
  199. package/src/{stripe-twin.ts → engine/stripe.ts} +57 -400
  200. package/src/engine/subscriptions.ts +37 -0
  201. package/src/engine/transfers.ts +22 -0
  202. package/src/{stripe-version.ts → engine/version.ts} +19 -10
  203. package/src/engine/webhook-endpoints.ts +14 -0
  204. package/src/engine/webhooks.ts +70 -0
  205. package/src/fetch.ts +27 -0
  206. package/src/generated/surface.gen.json +1 -1
  207. package/src/generated/ui.gen.json +1 -1
  208. package/src/index.ts +10 -116
  209. package/src/manifest.ts +480 -904
  210. package/src/screens/{portal.tsx → billing-portal.tsx} +35 -42
  211. package/src/screens/checkout-js.ts +80 -0
  212. package/src/screens/checkout.tsx +32 -96
  213. package/src/screens/{onboarding.tsx → connect-onboarding.tsx} +39 -85
  214. package/src/screens/dashboard.tsx +178 -0
  215. package/src/screens/shared.tsx +84 -0
  216. package/src/screens/stripe-js.ts +102 -0
  217. package/src/semantics/account.ts +10 -0
  218. package/src/semantics/account_links.ts +20 -0
  219. package/src/semantics/accounts.ts +44 -0
  220. package/src/semantics/{apps-secrets.ts → apps.ts} +17 -33
  221. package/src/semantics/around.ts +17 -0
  222. package/src/semantics/balance.ts +6 -208
  223. package/src/semantics/balance_transactions.ts +18 -0
  224. package/src/semantics/billing_portal.ts +45 -0
  225. package/src/semantics/charges.ts +8 -212
  226. package/src/semantics/checkout.ts +25 -276
  227. package/src/semantics/clock.ts +19 -0
  228. package/src/semantics/coupons.ts +5 -68
  229. package/src/semantics/customers.ts +48 -414
  230. package/src/semantics/doors.ts +79 -0
  231. package/src/semantics/entitlements.ts +3 -94
  232. package/src/semantics/events.ts +37 -0
  233. package/src/semantics/index.ts +89 -0
  234. package/src/semantics/invoice_payments.ts +16 -0
  235. package/src/semantics/invoices.ts +112 -441
  236. package/src/semantics/issuing.ts +57 -573
  237. package/src/semantics/payment_intents.ts +76 -0
  238. package/src/semantics/payment_methods.ts +20 -0
  239. package/src/semantics/payouts.ts +29 -0
  240. package/src/semantics/prices.ts +41 -0
  241. package/src/semantics/products.ts +12 -146
  242. package/src/semantics/promotion_codes.ts +38 -0
  243. package/src/semantics/radar.ts +8 -79
  244. package/src/semantics/refunds.ts +4 -216
  245. package/src/semantics/shared.ts +2089 -135
  246. package/src/semantics/states.ts +662 -0
  247. package/src/semantics/subscriptions.ts +39 -542
  248. package/src/semantics/test_helpers.ts +119 -0
  249. package/src/semantics/transfers.ts +10 -132
  250. package/src/semantics/webhook_endpoints.ts +27 -0
  251. package/src/server.ts +7 -0
  252. package/client/dashboard-api.ts +0 -286
  253. package/client/stripe-mirror.css +0 -277
  254. package/client/stripe-mirror.tsx +0 -1559
  255. package/dist/client/dashboard-api.d.ts +0 -107
  256. package/dist/client/dashboard-api.js +0 -238
  257. package/dist/client/dashboard-api.ts +0 -286
  258. package/dist/client/stripe-mirror.bundle.js +0 -236
  259. package/dist/client/stripe-mirror.css +0 -277
  260. package/dist/client/stripe-mirror.d.ts +0 -134
  261. package/dist/client/stripe-mirror.js +0 -859
  262. package/dist/client/stripe-mirror.tsx +0 -1559
  263. package/dist/src/screens/connect-oauth.d.ts +0 -27
  264. package/dist/src/screens/connect-oauth.js +0 -414
  265. package/dist/src/screens/connect-settings.d.ts +0 -22
  266. package/dist/src/screens/connect-settings.js +0 -103
  267. package/dist/src/screens/consent-skin.d.ts +0 -4
  268. package/dist/src/screens/consent-skin.js +0 -18
  269. package/dist/src/screens/financial-connections.d.ts +0 -5
  270. package/dist/src/screens/financial-connections.js +0 -90
  271. package/dist/src/screens/identity.d.ts +0 -5
  272. package/dist/src/screens/identity.js +0 -86
  273. package/dist/src/screens/onboarding.d.ts +0 -13
  274. package/dist/src/screens/portal.d.ts +0 -5
  275. package/dist/src/screens/public-details.d.ts +0 -5
  276. package/dist/src/screens/public-details.js +0 -90
  277. package/dist/src/semantics/after-payment.d.ts +0 -22
  278. package/dist/src/semantics/after-payment.js +0 -99
  279. package/dist/src/semantics/apps-secrets.d.ts +0 -2
  280. package/dist/src/semantics/billing.d.ts +0 -2
  281. package/dist/src/semantics/billing.js +0 -220
  282. package/dist/src/semantics/connect.d.ts +0 -5
  283. package/dist/src/semantics/connect.js +0 -493
  284. package/dist/src/semantics/credit-notes.d.ts +0 -2
  285. package/dist/src/semantics/credit-notes.js +0 -172
  286. package/dist/src/semantics/disputes.d.ts +0 -2
  287. package/dist/src/semantics/disputes.js +0 -51
  288. package/dist/src/semantics/ephemeral-keys.d.ts +0 -2
  289. package/dist/src/semantics/ephemeral-keys.js +0 -34
  290. package/dist/src/semantics/files.d.ts +0 -2
  291. package/dist/src/semantics/files.js +0 -125
  292. package/dist/src/semantics/ledger.d.ts +0 -59
  293. package/dist/src/semantics/ledger.js +0 -200
  294. package/dist/src/semantics/payment-intents.d.ts +0 -18
  295. package/dist/src/semantics/payment-intents.js +0 -452
  296. package/dist/src/semantics/payment-links.d.ts +0 -2
  297. package/dist/src/semantics/payment-links.js +0 -133
  298. package/dist/src/semantics/payment-methods.d.ts +0 -20
  299. package/dist/src/semantics/payment-methods.js +0 -140
  300. package/dist/src/semantics/plans.d.ts +0 -5
  301. package/dist/src/semantics/plans.js +0 -121
  302. package/dist/src/semantics/platform.d.ts +0 -9
  303. package/dist/src/semantics/platform.js +0 -206
  304. package/dist/src/semantics/renewals.d.ts +0 -47
  305. package/dist/src/semantics/renewals.js +0 -281
  306. package/dist/src/semantics/setup-intents.d.ts +0 -2
  307. package/dist/src/semantics/setup-intents.js +0 -84
  308. package/dist/src/semantics/subscription-schedules.d.ts +0 -2
  309. package/dist/src/semantics/subscription-schedules.js +0 -119
  310. package/dist/src/semantics/tax.d.ts +0 -2
  311. package/dist/src/semantics/tax.js +0 -197
  312. package/dist/src/semantics/terminal.d.ts +0 -5
  313. package/dist/src/semantics/terminal.js +0 -182
  314. package/dist/src/semantics/test-clocks.d.ts +0 -6
  315. package/dist/src/semantics/test-clocks.js +0 -73
  316. package/dist/src/semantics/tokens.d.ts +0 -4
  317. package/dist/src/semantics/tokens.js +0 -44
  318. package/dist/src/semantics/treasury.d.ts +0 -2
  319. package/dist/src/semantics/treasury.js +0 -377
  320. package/dist/src/semantics/webhook-endpoints.d.ts +0 -3
  321. package/dist/src/semantics/webhook-endpoints.js +0 -85
  322. package/dist/src/stripe-budget.d.ts +0 -55
  323. package/dist/src/stripe-budget.js +0 -155
  324. package/dist/src/stripe-capabilities.d.ts +0 -3
  325. package/dist/src/stripe-capabilities.js +0 -5836
  326. package/dist/src/stripe-conformance.d.ts +0 -43
  327. package/dist/src/stripe-conformance.js +0 -105
  328. package/dist/src/stripe-connector.d.ts +0 -161
  329. package/dist/src/stripe-connector.js +0 -414
  330. package/dist/src/stripe-emit.d.ts +0 -2
  331. package/dist/src/stripe-emit.js +0 -145
  332. package/dist/src/stripe-events.d.ts +0 -93
  333. package/dist/src/stripe-events.js +0 -392
  334. package/dist/src/stripe-js.d.ts +0 -4
  335. package/dist/src/stripe-js.js +0 -70
  336. package/dist/src/stripe-mirror-ui.d.ts +0 -15
  337. package/dist/src/stripe-mirror-ui.js +0 -87
  338. package/dist/src/stripe-perform-harness.d.ts +0 -9
  339. package/dist/src/stripe-perform-harness.js +0 -26
  340. package/dist/src/stripe-server.d.ts +0 -33
  341. package/dist/src/stripe-server.js +0 -429
  342. package/dist/src/stripe-shared.d.ts +0 -109
  343. package/dist/src/stripe-shared.js +0 -276
  344. package/dist/src/stripe-ui-conformance.d.ts +0 -5
  345. package/dist/src/stripe-ui-conformance.js +0 -79
  346. package/dist/src/stripe-ui-structure.d.ts +0 -3
  347. package/dist/src/stripe-ui-structure.js +0 -168
  348. package/dist/test-fixtures/stripe-known-deviations.json +0 -110
  349. package/dist/test-fixtures/stripe-openapi-operations.SOURCE.md +0 -14
  350. package/dist/test-fixtures/stripe-openapi-operations.json +0 -4717
  351. package/dist/test-fixtures/stripe-schemas.SOURCE.md +0 -35
  352. package/dist/test-fixtures/stripe-schemas.json +0 -3813
  353. package/src/screens/connect-oauth.tsx +0 -400
  354. package/src/screens/connect-settings.tsx +0 -121
  355. package/src/screens/consent-skin.ts +0 -20
  356. package/src/screens/financial-connections.tsx +0 -101
  357. package/src/screens/identity.tsx +0 -96
  358. package/src/screens/public-details.tsx +0 -105
  359. package/src/semantics/after-payment.ts +0 -118
  360. package/src/semantics/billing.ts +0 -216
  361. package/src/semantics/connect.ts +0 -487
  362. package/src/semantics/credit-notes.ts +0 -168
  363. package/src/semantics/disputes.ts +0 -62
  364. package/src/semantics/ephemeral-keys.ts +0 -34
  365. package/src/semantics/files.ts +0 -143
  366. package/src/semantics/ledger.ts +0 -253
  367. package/src/semantics/payment-intents.ts +0 -463
  368. package/src/semantics/payment-links.ts +0 -148
  369. package/src/semantics/payment-methods.ts +0 -145
  370. package/src/semantics/plans.ts +0 -131
  371. package/src/semantics/platform.ts +0 -220
  372. package/src/semantics/renewals.ts +0 -279
  373. package/src/semantics/setup-intents.ts +0 -87
  374. package/src/semantics/subscription-schedules.ts +0 -129
  375. package/src/semantics/tax.ts +0 -220
  376. package/src/semantics/terminal.ts +0 -195
  377. package/src/semantics/test-clocks.ts +0 -77
  378. package/src/semantics/tokens.ts +0 -52
  379. package/src/semantics/treasury.ts +0 -383
  380. package/src/semantics/webhook-endpoints.ts +0 -87
  381. package/src/stripe-budget.ts +0 -181
  382. package/src/stripe-capabilities.ts +0 -5651
  383. package/src/stripe-conformance.ts +0 -124
  384. package/src/stripe-connector.ts +0 -462
  385. package/src/stripe-emit.ts +0 -157
  386. package/src/stripe-events.ts +0 -434
  387. package/src/stripe-js.ts +0 -70
  388. package/src/stripe-mirror-ui.ts +0 -90
  389. package/src/stripe-perform-harness.ts +0 -29
  390. package/src/stripe-server.ts +0 -393
  391. package/src/stripe-shared.ts +0 -297
  392. package/src/stripe-ui-conformance.ts +0 -88
  393. package/src/stripe-ui-structure.ts +0 -182
  394. package/test-fixtures/stripe-known-deviations.json +0 -110
  395. package/test-fixtures/stripe-openapi-operations.json +0 -4717
  396. package/test-fixtures/stripe-schemas.json +0 -3813
  397. /package/dist/src/{screens → engine}/industries.d.ts +0 -0
  398. /package/dist/src/{screens → engine}/industries.js +0 -0
  399. /package/dist/src/{semantics → engine}/test-cards.d.ts +0 -0
  400. /package/dist/src/{semantics → engine}/test-cards.js +0 -0
  401. /package/src/{screens → engine}/industries.ts +0 -0
  402. /package/src/{semantics → engine}/test-cards.ts +0 -0
@@ -1,197 +0,0 @@
1
- import { asBool, lineItemEntries, paginate } from "../stripe-twin.js";
2
- import { at, created, fail, list, newest, path, where } from "./shared.js";
3
- const TWIN_TAX_RATE_PCT = 10;
4
- const createRate = async (ctx) => {
5
- const params = ctx.params;
6
- if (params.display_name === undefined || params.display_name === '')
7
- return fail(ctx, 'Missing required param: display_name.', 400, 'parameter_missing');
8
- if (params.percentage === undefined)
9
- return fail(ctx, 'Missing required param: percentage.', 400, 'parameter_missing');
10
- if (params.inclusive === undefined)
11
- return fail(ctx, 'Missing required param: inclusive.', 400, 'parameter_missing');
12
- return ctx.reply(await created(ctx, 'tax_rate', { ...params, inclusive: asBool(params.inclusive), percentage: Number(params.percentage) }, {
13
- active: true, livemode: false, metadata: {},
14
- country: null, state: null, jurisdiction: typeof params.jurisdiction === 'string' ? params.jurisdiction : null,
15
- jurisdiction_level: null, description: params.description ?? null, display_name: params.display_name,
16
- tax_type: null,
17
- }));
18
- };
19
- const listRates = async (ctx) => list(ctx, 'tax_rate', where(ctx, newest(ctx, 'tax_rate'), {
20
- active: (t, v) => asBool(t.active) === asBool(v),
21
- inclusive: (t, v) => asBool(t.inclusive) === asBool(v),
22
- }));
23
- // percentage and inclusive are fixed once created
24
- const updateRate = async (ctx) => {
25
- const id = at(ctx, 'tax_rate');
26
- if (!ctx.get('tax_rate', id))
27
- return ctx.notFound('tax_rate', id);
28
- const { percentage: _p, inclusive: _i, ...rest } = ctx.params;
29
- return ctx.reply(await ctx.write('tax_rate', id, { ...rest, ...('active' in rest ? { active: asBool(rest.active) } : {}) }, 'tax_rate.update'));
30
- };
31
- // ── settings: active once a head office is set; the answer has no id ──
32
- // the defaults' provider: "The tax calculation provider this account uses. Defaults to `stripe` when not using a
33
- // third-party provider" (the served spec's tax settings defaults); the head office's address answers each line, the
34
- // lines not given null (the served spec's address: each "(string, nullable)"; the settings page's example answers
35
- // line2 null)
36
- const ADDRESS_LINES = ['city', 'country', 'line1', 'line2', 'postal_code', 'state'];
37
- function settingsBody(stored) {
38
- const given = (stored?.head_office ?? null);
39
- const address = given && typeof given.address === 'object' && given.address ? given.address : undefined;
40
- const headOffice = given ? { ...given, ...(address ? { address: Object.fromEntries(ADDRESS_LINES.map((k) => [k, address[k] ?? null])) } : {}) } : null;
41
- const active = !!headOffice;
42
- return {
43
- object: 'tax.settings', livemode: false,
44
- defaults: { provider: 'stripe', ...(stored?.defaults ?? { tax_behavior: null, tax_code: null }) }, head_office: headOffice,
45
- status: active ? 'active' : 'pending',
46
- status_details: active ? { active: {} } : { pending: { missing_fields: ['head_office'] } },
47
- };
48
- }
49
- const getSettings = async (ctx) => ctx.reply(settingsBody(ctx.rows('tax.settings')[0]));
50
- const updateSettings = async (ctx) => {
51
- const existing = ctx.rows('tax.settings')[0];
52
- const cur = existing ?? {};
53
- const defaults = ctx.params.defaults && typeof ctx.params.defaults === 'object' ? ctx.params.defaults : {};
54
- const curDefaults = cur.defaults ?? {};
55
- const headOffice = ctx.params.head_office && typeof ctx.params.head_office === 'object' ? ctx.params.head_office : undefined;
56
- const fields = {
57
- defaults: {
58
- tax_behavior: typeof defaults.tax_behavior === 'string' ? defaults.tax_behavior : (curDefaults.tax_behavior ?? null),
59
- tax_code: typeof defaults.tax_code === 'string' ? defaults.tax_code : (curDefaults.tax_code ?? null),
60
- },
61
- head_office: headOffice ?? cur.head_office ?? null,
62
- livemode: false,
63
- };
64
- const body = await ctx.write('tax.settings', existing ? String(existing.id) : 'taxset_twin_1', fields, existing ? 'tax_settings.update' : 'tax_settings.create');
65
- return ctx.reply(settingsBody(body));
66
- };
67
- // ── calculations: each line's tax on top of its amount; no `created`, a tax_date instead ──
68
- const calcMissing = (ctx, id) => fail(ctx, `No such tax calculation: '${id}'`, 404, 'resource_missing');
69
- const calculate = async (ctx) => {
70
- const params = ctx.params;
71
- if (params.currency === undefined || params.currency === '')
72
- return fail(ctx, 'Missing required param: currency.', 400, 'parameter_missing');
73
- const entries = lineItemEntries(params);
74
- if (entries.length === 0)
75
- return fail(ctx, 'Missing required param: line_items.', 400, 'parameter_missing');
76
- const now = Number(ctx.now());
77
- const id = ctx.mint('tax.calculation');
78
- const items = entries.map((e, i) => {
79
- const amount = Math.max(0, Math.trunc(Number(e.amount) || 0));
80
- return {
81
- object: 'tax.calculation_line_item', id: `tax_li_${id}_${i + 1}`,
82
- amount, amount_tax: Math.round((amount * TWIN_TAX_RATE_PCT) / 100), reference: typeof e.reference === 'string' ? e.reference : null,
83
- tax_behavior: 'exclusive', tax_code: typeof e.tax_code === 'string' ? e.tax_code : 'txcd_99999999',
84
- quantity: e.quantity === undefined ? 1 : Math.max(1, Math.trunc(Number(e.quantity) || 1)), livemode: false,
85
- };
86
- });
87
- const amountSubtotal = items.reduce((s, it) => s + it.amount, 0);
88
- const taxExclusive = items.reduce((s, it) => s + it.amount_tax, 0);
89
- const cd = params.customer_details && typeof params.customer_details === 'object' ? params.customer_details : {};
90
- return ctx.reply(await created(ctx, 'tax.calculation', {
91
- id, currency: String(params.currency), amount_total: amountSubtotal + taxExclusive, tax_amount_exclusive: taxExclusive, tax_amount_inclusive: 0,
92
- customer: typeof params.customer === 'string' ? params.customer : null,
93
- customer_details: {
94
- address: cd.address ?? null, address_source: cd.address_source ?? 'shipping', ip_address: cd.ip_address ?? null,
95
- tax_ids: Array.isArray(cd.tax_ids) ? cd.tax_ids : [], taxability_override: cd.taxability_override ?? 'none',
96
- },
97
- line_items: { object: 'list', data: items, has_more: false, url: `/v1/tax/calculations/${id}/line_items` },
98
- shipping_cost: null, tax_date: now,
99
- tax_breakdown: taxExclusive > 0 ? [{
100
- amount: taxExclusive, inclusive: false, taxability_reason: 'standard_rated', taxable_amount: amountSubtotal,
101
- tax_rate_details: { country: null, percentage_decimal: String(TWIN_TAX_RATE_PCT), state: null, tax_type: 'sales_tax' },
102
- }] : [],
103
- expires_at: now + 90 * 24 * 3600, livemode: false,
104
- }, {}, { timeField: 'tax_date' }));
105
- };
106
- /** A page of the line items a stored object carries. */
107
- function linePage(ctx, holder) {
108
- const li = holder.line_items;
109
- const { page, hasMore } = paginate(Array.isArray(li?.data) ? li.data : [], ctx.params);
110
- return ctx.reply({ object: 'list', url: path(ctx), has_more: hasMore, data: page });
111
- }
112
- const calculationLines = async (ctx) => {
113
- const c = ctx.get('tax.calculation', at(ctx, 'calculation'));
114
- return c ? linePage(ctx, c) : calcMissing(ctx, at(ctx, 'calculation'));
115
- };
116
- // ── registrations ──
117
- const register = async (ctx) => {
118
- const params = ctx.params;
119
- if (params.country === undefined || params.country === '')
120
- return fail(ctx, 'Missing required param: country.', 400, 'parameter_missing');
121
- if (params.active_from === undefined)
122
- return fail(ctx, 'Missing required param: active_from.', 400, 'parameter_missing');
123
- const now = Number(ctx.now());
124
- const activeFrom = params.active_from === 'now' ? now : Number(params.active_from) || now;
125
- return ctx.reply(await created(ctx, 'tax.registration', { ...params, active_from: activeFrom }, {
126
- status: 'active', expires_at: null, livemode: false,
127
- country_options: params.country_options && typeof params.country_options === 'object' ? params.country_options : {},
128
- }));
129
- };
130
- // ── transactions: committing a calculation, or reversing a transaction with negated amounts ──
131
- const TX = 'tax.transaction';
132
- const txMissing = (ctx, id, status = 404) => fail(ctx, `No such tax transaction: '${id}'`, status, 'resource_missing');
133
- const txLine = (id, i, l, sign, reversal, type) => ({
134
- object: 'tax.transaction_line_item', id: `tax_li_${id}_${i + 1}`,
135
- amount: sign === 1 ? l.amount : -(Number(l.amount) || 0), amount_tax: sign === 1 ? l.amount_tax : -(Number(l.amount_tax) || 0),
136
- reference: l.reference ?? null, tax_behavior: l.tax_behavior ?? 'exclusive', tax_code: l.tax_code ?? 'txcd_99999999',
137
- quantity: l.quantity ?? 1, reversal, type, livemode: false, metadata: {},
138
- });
139
- const linesOf = (holder) => holder.line_items?.data ?? [];
140
- const fromCalculation = async (ctx) => {
141
- const calcId = typeof ctx.params.calculation === 'string' ? ctx.params.calculation : '';
142
- if (!calcId)
143
- return fail(ctx, 'Missing required param: calculation.', 400, 'parameter_missing');
144
- if (ctx.params.reference === undefined || ctx.params.reference === '')
145
- return fail(ctx, 'Missing required param: reference.', 400, 'parameter_missing');
146
- const calc = ctx.get('tax.calculation', calcId);
147
- if (!calc)
148
- return fail(ctx, `No such tax calculation: '${calcId}'`, 400, 'resource_missing');
149
- const id = ctx.mint(TX);
150
- const now = ctx.now();
151
- return ctx.reply(await created(ctx, TX, {
152
- id, _stripe_type: 'transaction', reference: ctx.params.reference, currency: calc.currency,
153
- customer: calc.customer ?? null, customer_details: calc.customer_details ?? {},
154
- tax_date: now, livemode: false, posted_at: now,
155
- line_items: { object: 'list', data: linesOf(calc).map((l, i) => txLine(id, i, l, 1, null, 'transaction')), has_more: false, url: `/v1/tax/transactions/${id}/line_items` },
156
- shipping_cost: calc.shipping_cost ?? null, reversal: null, calculation: calcId, metadata: {},
157
- }, {}));
158
- };
159
- const reversal = async (ctx) => {
160
- const original = typeof ctx.params.original_transaction === 'string' ? ctx.params.original_transaction : '';
161
- if (!original)
162
- return fail(ctx, 'Missing required param: original_transaction.', 400, 'parameter_missing');
163
- if (ctx.params.reference === undefined || ctx.params.reference === '')
164
- return fail(ctx, 'Missing required param: reference.', 400, 'parameter_missing');
165
- const mode = typeof ctx.params.mode === 'string' ? ctx.params.mode : '';
166
- if (mode !== 'full' && mode !== 'partial')
167
- return fail(ctx, 'Missing required param: mode (full or partial).', 400, 'parameter_missing');
168
- const orig = ctx.get(TX, original);
169
- if (!orig)
170
- return txMissing(ctx, original, 400);
171
- const id = ctx.mint(TX);
172
- const now = ctx.now();
173
- return ctx.reply(await created(ctx, TX, {
174
- id, _stripe_type: 'reversal', reference: ctx.params.reference, currency: orig.currency,
175
- customer: orig.customer ?? null, customer_details: orig.customer_details ?? {},
176
- tax_date: now, livemode: false, posted_at: now,
177
- line_items: { object: 'list', data: linesOf(orig).map((l, i) => txLine(id, i, l, -1, { original_line_item: l.id }, 'reversal')), has_more: false, url: `/v1/tax/transactions/${id}/line_items` },
178
- shipping_cost: null, reversal: { original_transaction: original, mode }, metadata: {},
179
- }, {}));
180
- };
181
- const transactionLines = async (ctx) => {
182
- const t = ctx.get(TX, at(ctx, 'transaction'));
183
- return t ? linePage(ctx, t) : txMissing(ctx, at(ctx, 'transaction'));
184
- };
185
- export const tax = {
186
- PostTaxRates: createRate,
187
- GetTaxRates: listRates,
188
- PostTaxRatesTaxRate: updateRate,
189
- GetTaxSettings: getSettings,
190
- PostTaxSettings: updateSettings,
191
- PostTaxCalculations: calculate,
192
- GetTaxCalculationsCalculationLineItems: calculationLines,
193
- PostTaxRegistrations: register,
194
- PostTaxTransactionsCreateFromCalculation: fromCalculation,
195
- PostTaxTransactionsCreateReversal: reversal,
196
- GetTaxTransactionsTransactionLineItems: transactionLines,
197
- };
@@ -1,5 +0,0 @@
1
- import type { Semantics, SemanticsContext } from '@volter/world-core';
2
- /** Time's settling of top-ups, caught up to the World's clock: a pending top-up succeeds on its expected_availability_date,
3
- * its funds entered then in the balance it names. */
4
- export declare function settleTopups(ctx: SemanticsContext): Promise<void>;
5
- export declare const terminal: Record<string, Semantics>;
@@ -1,182 +0,0 @@
1
- import { validateMoney } from "../stripe-twin.js";
2
- import { settleTopup } from "./ledger.js";
3
- import { authorizeCharge, mintCharge } from "./payment-intents.js";
4
- import { at, at_, created, fail, send } from "./shared.js";
5
- const LOC = 'terminal.location';
6
- const READER = 'terminal.reader';
7
- const CONF = 'terminal.configuration';
8
- /** Update and delete by id, finding tombstones as the hand-written routes did, with Stripe's own operation names. */
9
- function patch(resource, param, missing, op) {
10
- return (ctx) => patchRow(ctx, resource, param, missing, op);
11
- }
12
- async function patchRow(ctx, resource, param, missing, op) {
13
- const id = at(ctx, param);
14
- if (!ctx.row(resource, id, { withDeleted: true }))
15
- return fail(ctx, `No such ${missing}: '${id}'`, 404, 'resource_missing');
16
- return ctx.reply(await ctx.write(resource, id, ctx.params, op));
17
- }
18
- // A reader's update takes its label and metadata only; it moves to another location by registering it
19
- // there again (https://docs.stripe.com/api/terminal/readers/update, docs.stripe.com/terminal/fleet/locations-and-zones)
20
- // (the parameter check refuses anything else, as Stripe does: ../stripe-params.ts)
21
- const updateReader = patch(READER, 'reader', 'reader', 'terminal_reader.updated');
22
- function remove(resource, param, missing, op, object) {
23
- return async (ctx) => {
24
- const id = at(ctx, param);
25
- if (!ctx.row(resource, id, { withDeleted: true }))
26
- return fail(ctx, `No such ${missing}: '${id}'`, 404, 'resource_missing');
27
- const row = ctx.get(resource, id);
28
- await ctx.write(resource, id, { deleted: true }, op);
29
- // a deleted reader still says what device it was
30
- return ctx.reply({ id, object, deleted: true, ...(object === 'terminal.reader' && row ? { device_type: row.device_type, serial_number: row.serial_number } : {}) });
31
- };
32
- }
33
- const createLocation = async (ctx) => {
34
- if (ctx.params.display_name === undefined || ctx.params.display_name === '')
35
- return fail(ctx, 'Missing required param: display_name.', 400, 'parameter_missing');
36
- const addr = ctx.params.address && typeof ctx.params.address === 'object' ? ctx.params.address : undefined;
37
- if (!addr || addr.country === undefined || addr.country === '')
38
- return fail(ctx, 'Missing required param: address[country].', 400, 'parameter_missing');
39
- return ctx.reply(await created(ctx, LOC, ctx.params, { livemode: false, metadata: {} }));
40
- };
41
- // a test registration code (simulated-wpe) registers a simulated reader, online
42
- const createReader = async (ctx) => {
43
- if (ctx.params.registration_code === undefined || ctx.params.registration_code === '')
44
- return fail(ctx, 'Missing required param: registration_code.', 400, 'parameter_missing');
45
- return ctx.reply(await created(ctx, READER, ctx.params, {
46
- status: 'online', device_type: 'simulated_wisepos_e', device_sw_version: null, ip_address: '0.0.0.0',
47
- serial_number: `STR-${ctx.rowsRaw(READER, { withDeleted: true }).length + 1}`, action: null,
48
- livemode: false, metadata: {}, label: ctx.params.label ?? 'Twin Reader',
49
- }));
50
- };
51
- const readerMissing = (ctx, id) => fail(ctx, `No such reader: '${id}'`, 404, 'resource_missing');
52
- // handing the reader a PaymentIntent puts it in an in-progress process_payment_intent action
53
- const processPaymentIntent = async (ctx) => {
54
- const id = at(ctx, 'reader');
55
- if (!ctx.get(READER, id))
56
- return readerMissing(ctx, id);
57
- const pi = typeof ctx.params.payment_intent === 'string' ? ctx.params.payment_intent : '';
58
- if (!pi)
59
- return fail(ctx, 'Missing required param: payment_intent.', 400, 'parameter_missing');
60
- if (!ctx.get('payment_intent', pi))
61
- return fail(ctx, `No such payment_intent: '${pi}'`, 400, 'resource_missing');
62
- const action = { type: 'process_payment_intent', status: 'in_progress', failure_code: null, failure_message: null, process_payment_intent: { payment_intent: pi } };
63
- return ctx.reply(await ctx.write(READER, id, { action }, 'terminal_reader.updated'));
64
- };
65
- /** A card presented to a reader with no payment in progress. */
66
- function nothingToPresent(ctx) {
67
- return fail(ctx, 'This reader has no in-progress payment to present a payment method to.', 400, 'terminal_reader_invalid_state');
68
- }
69
- /** Under manual capture the presented card only holds the amount (docs.stripe.com/terminal/payments/collect-card-payment#capture-payment):
70
- * the hold is an uncaptured charge, as an online authorization's is (authorizeCharge), which the intent's capture takes. */
71
- async function holdForCapture(ctx, piId, pi, pm, amount) {
72
- const charge = await authorizeCharge(ctx, piId, { ...pi, payment_method: pm }, amount);
73
- await ctx.write('payment_intent', piId, { status: 'requires_capture', payment_method: pm, amount_capturable: amount, latest_charge: charge }, 'payment_intent.amount_capturable_updated');
74
- }
75
- const presentPaymentMethod = async (ctx) => {
76
- const id = at(ctx, 'reader');
77
- const reader = ctx.get(READER, id);
78
- if (!reader)
79
- return readerMissing(ctx, id);
80
- const action = reader.action;
81
- const piId = String((action?.process_payment_intent?.payment_intent) ?? '');
82
- if (!action || action.type !== 'process_payment_intent' || action.status !== 'in_progress' || !piId)
83
- return nothingToPresent(ctx);
84
- const pi = ctx.get('payment_intent', piId);
85
- if (!pi)
86
- return fail(ctx, `No such payment_intent: '${piId}'`, 400, 'resource_missing');
87
- const manual = pi.capture_method === 'manual' || pi.capture_method === 'manual_preferred';
88
- const to = manual ? 'requires_capture' : 'succeeded';
89
- const refused = ctx.legal('payment_intent', 'status', 'PostTestHelpersTerminalReadersReaderPresentPaymentMethod', pi.status, to, piId);
90
- if (refused)
91
- return ctx.refuse(refused);
92
- const pm = await created(ctx, 'payment_method', {}, {
93
- type: 'card_present', customer: null, livemode: false, billing_details: { address: null, email: null, name: null, phone: null },
94
- card_present: { brand: 'visa', last4: '4242', exp_month: 12, exp_year: 2030, funding: 'credit', country: 'US', read_method: 'contactless_emv', networks: { available: ['visa'], preferred: null } },
95
- });
96
- const amount = Number(pi.amount) || 0;
97
- if (manual)
98
- await holdForCapture(ctx, piId, pi, String(pm.id), amount);
99
- else {
100
- const charge = await mintCharge(ctx, piId, { ...pi, payment_method: pm.id }, amount);
101
- await ctx.write('payment_intent', piId, { status: 'succeeded', payment_method: pm.id, amount_received: amount, latest_charge: charge }, 'payment_intent.succeeded');
102
- }
103
- return ctx.reply(await ctx.write(READER, id, { action: { ...action, status: 'succeeded' } }, 'terminal_reader.action_succeeded'));
104
- };
105
- const cancelAction = async (ctx) => {
106
- const id = at(ctx, 'reader');
107
- if (!ctx.get(READER, id))
108
- return readerMissing(ctx, id);
109
- return ctx.reply(await ctx.write(READER, id, { action: null }, 'terminal_reader.updated'));
110
- };
111
- // a short-lived secret for the reader SDK, answered and not kept
112
- const connectionToken = async (ctx) => {
113
- const loc = typeof ctx.params.location === 'string' ? ctx.params.location : undefined;
114
- return ctx.reply({ object: 'terminal.connection_token', secret: `pst_test_twin_${ctx.rowsRaw(READER, { withDeleted: true }).length + 1}`, ...(loc ? { location: loc } : {}) });
115
- };
116
- const createConfiguration = async (ctx) => ctx.reply(await created(ctx, CONF, ctx.params, { is_account_default: false, livemode: false, tipping: null, name: ctx.params.name ?? null }));
117
- // ── top-ups ──
118
- // a top-up adds money to the balance it names, through the ledger, once its funds arrive: "USA (USD) ACH Debit Transfer
119
- // 5 days" (docs.stripe.com/connect/top-ups), and to the Issuing balance alike: "Top-ups debit your bank account. Your
120
- // top-ups can take up to 5 business days to become available. While they're pending, they won't be added to your
121
- // Issuing balance" (docs.stripe.com/issuing/funding/balance). It is pending until its expected_availability_date, then
122
- // settled by settleTopups. Where the documentation stops and the twin decides: every top-up takes exactly five days,
123
- // whatever its currency and balance, and succeeds.
124
- const TOPUP_DAYS = 5;
125
- const createTopup = async (ctx) => {
126
- const bad = validateMoney(ctx.params);
127
- if (bad)
128
- return send(ctx, bad);
129
- const now = Number(ctx.now());
130
- return ctx.reply(await created(ctx, 'topup', ctx.params, {
131
- status: 'pending', expected_availability_date: now + TOPUP_DAYS * 86_400, livemode: false,
132
- metadata: {}, source: null, statement_descriptor: ctx.params.statement_descriptor ?? null,
133
- balance_transaction: null, failure_code: null, failure_message: null,
134
- }));
135
- };
136
- /** Time's settling of top-ups, caught up to the World's clock: a pending top-up succeeds on its expected_availability_date,
137
- * its funds entered then in the balance it names. */
138
- export async function settleTopups(ctx) {
139
- const now = Number(ctx.now());
140
- for (const t of ctx.rowsRaw('topup')) {
141
- if (t.status !== 'pending' || Number(t.expected_availability_date) > now)
142
- continue;
143
- const c = await at_(ctx)(Number(t.expected_availability_date));
144
- c.legal('topup', 'status', ctx.call.operation.id, 'pending', 'succeeded', String(t.id), 'vendor');
145
- const bt = await settleTopup(c, String(t.id), Number(t.amount), String(t.currency), t.destination_balance === 'issuing' ? 'issuing' : 'payments');
146
- await c.write('topup', String(t.id), { status: 'succeeded', balance_transaction: bt }, 'topup.succeeded');
147
- }
148
- }
149
- const cancelTopup = async (ctx) => {
150
- const id = at(ctx, 'topup');
151
- const t = ctx.get('topup', id);
152
- if (!t)
153
- return fail(ctx, `No such topup: '${id}'`, 404, 'resource_missing');
154
- const refused = ctx.legal('topup', 'status', 'PostTopupsTopupCancel', t.status, undefined, id);
155
- if (refused)
156
- return ctx.refuse(refused);
157
- return ctx.reply(await ctx.write('topup', id, { status: 'canceled' }, 'topup.canceled'));
158
- };
159
- const updateTopup = async (ctx) => {
160
- const id = at(ctx, 'topup');
161
- if (!ctx.get('topup', id))
162
- return fail(ctx, `No such topup: '${id}'`, 404, 'resource_missing');
163
- return ctx.reply(await ctx.write('topup', id, ctx.params, 'topup.updated'));
164
- };
165
- export const terminal = {
166
- PostTerminalLocations: createLocation,
167
- PostTerminalLocationsLocation: patch(LOC, 'location', 'location', 'terminal_location.updated'),
168
- DeleteTerminalLocationsLocation: remove(LOC, 'location', 'location', 'terminal_location.deleted', 'terminal.location'),
169
- PostTerminalReaders: createReader,
170
- PostTerminalReadersReader: updateReader,
171
- DeleteTerminalReadersReader: remove(READER, 'reader', 'reader', 'terminal_reader.deleted', 'terminal.reader'),
172
- PostTerminalReadersReaderProcessPaymentIntent: processPaymentIntent,
173
- PostTerminalReadersReaderCancelAction: cancelAction,
174
- PostTestHelpersTerminalReadersReaderPresentPaymentMethod: presentPaymentMethod,
175
- PostTerminalConnectionTokens: connectionToken,
176
- PostTerminalConfigurations: createConfiguration,
177
- PostTerminalConfigurationsConfiguration: patch(CONF, 'configuration', 'configuration', 'terminal_configuration.updated'),
178
- DeleteTerminalConfigurationsConfiguration: remove(CONF, 'configuration', 'configuration', 'terminal_configuration.deleted', 'terminal.configuration'),
179
- PostTopups: createTopup,
180
- PostTopupsTopupCancel: cancelTopup,
181
- PostTopupsTopup: updateTopup,
182
- };
@@ -1,6 +0,0 @@
1
- import type { Semantics, SemanticsContext } from '@volter/world-core';
2
- /** Each advancing clock whose advance has taken its time reaches its target, caught up before anything is answered:
3
- * its frozen_time moves, it is ready, and its customers' trials and periods that ended by then end
4
- * (./renewals.ts advanceBilling). The advance's own write is when it began (the kernel's updatedAt). */
5
- export declare function finishClockAdvances(ctx: SemanticsContext): Promise<void>;
6
- export declare const testClocks: Record<string, Semantics>;
@@ -1,73 +0,0 @@
1
- import { at, created, fail } from "./shared.js";
2
- import { advanceBilling } from "./renewals.js";
3
- const CLOCK = 'test_helpers.test_clock';
4
- const create = async (ctx) => {
5
- if (ctx.params.frozen_time === undefined)
6
- return fail(ctx, 'Missing required param: frozen_time.', 400, 'parameter_missing');
7
- const frozen = Math.trunc(Number(ctx.params.frozen_time) || 0);
8
- // "Simulations are automatically deleted 30 days after you create them" (docs.stripe.com/billing/testing/test-clocks/
9
- // api-advanced-usage): from its creation on the account's clock, not its frozen time
10
- return ctx.reply(await created(ctx, CLOCK, { name: ctx.params.name ?? null }, { frozen_time: frozen, status: 'ready', status_details: {}, livemode: false, deletes_after: Number(ctx.now()) + 30 * 24 * 3600 }));
11
- };
12
- /** A test clock deleted with what lives on it: "Deleting the simulation also deletes the test customers associated
13
- * with the clock and cancels their subscriptions" (docs.stripe.com/billing/testing/test-clocks/api-advanced-usage). */
14
- const remove = async (ctx) => {
15
- const id = at(ctx, 'test_clock');
16
- if (!ctx.get(CLOCK, id))
17
- return fail(ctx, `No such test clock: '${id}'`, 404, 'resource_missing');
18
- const now = Number(ctx.now());
19
- for (const c of ctx.rows('customer').filter((c) => c.test_clock === id)) {
20
- for (const sub of ctx.rows('subscription').filter((s) => s.customer === c.id && s.status !== 'canceled')) {
21
- ctx.legal('subscription', 'status', 'DeleteTestHelpersTestClocksTestClock', String(sub.status), 'canceled', String(sub.id));
22
- await ctx.write('subscription', String(sub.id), { status: 'canceled', canceled_at: now, ended_at: now }, 'subscription.cancel');
23
- }
24
- await ctx.write('customer', String(c.id), { deleted: true }, 'customer.deleted');
25
- }
26
- await ctx.write(CLOCK, id, { deleted: true }, 'test_clock.deleted');
27
- return ctx.reply({ id, object: 'test_helpers.test_clock', deleted: true });
28
- };
29
- const advance = async (ctx) => {
30
- const id = at(ctx, 'test_clock');
31
- const clock = ctx.get(CLOCK, id);
32
- if (!clock)
33
- return fail(ctx, `No such test clock: '${id}'`, 404, 'resource_missing');
34
- if (ctx.params.frozen_time === undefined)
35
- return fail(ctx, 'Missing required param: frozen_time.', 400, 'parameter_missing');
36
- const to = Math.trunc(Number(ctx.params.frozen_time) || 0);
37
- if (to <= Number(clock.frozen_time))
38
- return fail(ctx, 'frozen_time must be after the current clock time.', 400, 'parameter_invalid');
39
- const refused = ctx.legal(CLOCK, 'status', 'PostTestHelpersTestClocksTestClockAdvance', clock.status, 'advancing', id);
40
- if (refused)
41
- return ctx.refuse(refused);
42
- // "After a successful API request or Dashboard operation, it takes a few seconds to advance to the specified time"
43
- // (docs.stripe.com/billing/testing/test-clocks/api-advanced-usage): the advance answers advancing toward its target,
44
- // and finishClockAdvances completes it ADVANCE_SECONDS of World time later; an advance asked meanwhile is refused
45
- // test_clock_not_ready (the machine's refusal).
46
- return ctx.reply(await ctx.write(CLOCK, id, { status: 'advancing', status_details: { advancing: { target_frozen_time: to } } }, 'test_clock.advancing'));
47
- };
48
- /** How long an advance takes: "it takes a few seconds to advance to the specified time"
49
- * (docs.stripe.com/billing/testing/test-clocks/api-advanced-usage). Where the documentation stops and the twin decides:
50
- * five seconds of World time from the advance. */
51
- const ADVANCE_SECONDS = 5;
52
- /** Each advancing clock whose advance has taken its time reaches its target, caught up before anything is answered:
53
- * its frozen_time moves, it is ready, and its customers' trials and periods that ended by then end
54
- * (./renewals.ts advanceBilling). The advance's own write is when it began (the kernel's updatedAt). */
55
- export async function finishClockAdvances(ctx) {
56
- const now = Number(ctx.now());
57
- for (const clock of ctx.rowsRaw(CLOCK)) {
58
- if (clock.status !== 'advancing')
59
- continue;
60
- if (Date.parse(String(clock.updatedAt)) / 1000 + ADVANCE_SECONDS > now)
61
- continue;
62
- const id = String(clock.id);
63
- const target = Number(clock.status_details?.advancing?.target_frozen_time);
64
- ctx.legal(CLOCK, 'status', ctx.call.operation.id, 'advancing', 'ready', id, 'vendor');
65
- await ctx.write(CLOCK, id, { frozen_time: target, status: 'ready', status_details: {} }, 'test_clock.ready');
66
- await advanceBilling(ctx, (sub) => typeof sub.customer === 'string' && ctx.get('customer', sub.customer)?.test_clock === id);
67
- }
68
- }
69
- export const testClocks = {
70
- PostTestHelpersTestClocks: create,
71
- PostTestHelpersTestClocksTestClockAdvance: advance,
72
- DeleteTestHelpersTestClocksTestClock: remove,
73
- };
@@ -1,4 +0,0 @@
1
- import type { Semantics } from '@volter/world-core';
2
- import { type Row } from './shared.js';
3
- export declare function legacyCard(id: string, card: Row): Row;
4
- export declare const tokens: Record<string, Semantics>;
@@ -1,44 +0,0 @@
1
- import { paymentMethodSubObject } from "../stripe-twin.js";
2
- import { created, fail } from "./shared.js";
3
- /** The Card object a card token carries, as the served spec's `card` describes it: its brand as a name ("Card brand.
4
- * Can be `American Express`, ... `MasterCard`, `UnionPay`, `Visa`, or `Unknown`"), the holder's name and address as
5
- * given ("Cardholder name"), and the CVC's check when one was given ("If a CVC was provided, results of the check:
6
- * pass, fail, unavailable, or unchecked"). Where the documentation stops and the twin decides: a test card's CVC passes. */
7
- const BRAND_NAMES = { amex: 'American Express', cartes_bancaires: 'Cartes Bancaires', diners: 'Diners Club', discover: 'Discover', eftpos_au: 'Eftpos Australia', girocard: 'Girocard', jcb: 'JCB', mastercard: 'MasterCard', unionpay: 'UnionPay', visa: 'Visa' };
8
- export function legacyCard(id, card) {
9
- const pm = paymentMethodSubObject('card', { card }).card;
10
- const given = (k) => (typeof card[k] === 'string' && card[k] !== '' ? card[k] : null);
11
- return {
12
- id, object: 'card', brand: BRAND_NAMES[String(pm.brand)] ?? 'Unknown', last4: pm.last4, exp_month: pm.exp_month, exp_year: pm.exp_year,
13
- funding: pm.funding ?? 'credit', country: pm.country ?? null, fingerprint: pm.fingerprint ?? null, name: given('name'),
14
- address_line1: given('address_line1'), address_line2: given('address_line2'), address_city: given('address_city'), address_state: given('address_state'),
15
- address_zip: given('address_zip'), address_country: given('address_country'), address_line1_check: null, address_zip_check: null,
16
- cvc_check: card.cvc !== undefined && card.cvc !== '' ? 'pass' : null, dynamic_last4: null, tokenization_method: null, metadata: {}, customer: null,
17
- };
18
- }
19
- /** A token asked for none of what a token holds. */
20
- function noTokenSource(ctx) {
21
- return fail(ctx, 'You must provide one of the following parameters: card, bank_account, pii.', 400, 'parameter_missing');
22
- }
23
- /** A bank account token's account, as the legacy BankAccount object holds it. */
24
- function bankAccountOf(ctx, ba) {
25
- const acct = typeof ba.account_number === 'string' ? ba.account_number.replace(/\D/g, '') : '';
26
- return {
27
- id: ctx.mint('external_account'), object: 'bank_account', account_holder_name: ba.account_holder_name ?? null,
28
- account_holder_type: ba.account_holder_type ?? null, bank_name: 'STRIPE TEST BANK',
29
- country: ba.country ?? 'US', currency: ba.currency ?? 'usd', fingerprint: 'twin_ba_fp',
30
- last4: acct ? acct.slice(-4) : '6789', routing_number: ba.routing_number ?? '110000000', status: 'new',
31
- };
32
- }
33
- const create = async (ctx) => {
34
- const params = ctx.params;
35
- const isObject = (v) => !!v && typeof v === 'object';
36
- const type = isObject(params.card) ? 'card' : isObject(params.bank_account) ? 'bank_account' : isObject(params.pii) ? 'pii' : undefined;
37
- if (!type)
38
- return noTokenSource(ctx);
39
- const sub = type === 'card'
40
- ? { card: legacyCard(ctx.mint('payment_method').replace('pm_', 'card_'), params.card) }
41
- : type === 'bank_account' ? { bank_account: bankAccountOf(ctx, params.bank_account) } : {};
42
- return ctx.reply(await created(ctx, 'token', { type }, { ...sub, client_ip: null, used: false, livemode: false }));
43
- };
44
- export const tokens = { PostTokens: create };
@@ -1,2 +0,0 @@
1
- import type { Semantics } from '@volter/world-core';
2
- export declare const treasury: Record<string, Semantics>;