@volter/twin-stripe 2.0.37 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/README.md +82 -207
  2. package/dist/generated/pack-facts.json +94 -0
  3. package/dist/spec/SOURCE.md +14 -0
  4. package/dist/spec/fixtures3.json.gz +0 -0
  5. package/dist/spec/openapi.json.gz +0 -0
  6. package/dist/spec/patches.json +34 -0
  7. package/dist/spec/sources.json +378 -0
  8. package/dist/src/cli.js +12 -30
  9. package/dist/src/engine/after-payment.d.ts +9 -0
  10. package/dist/src/engine/after-payment.js +28 -0
  11. package/dist/src/engine/apps-secrets.d.ts +1 -0
  12. package/dist/src/engine/apps-secrets.js +3 -0
  13. package/dist/src/engine/balance.d.ts +5 -0
  14. package/dist/src/engine/balance.js +15 -0
  15. package/dist/src/engine/billing.d.ts +5 -0
  16. package/dist/src/engine/billing.js +6 -0
  17. package/dist/src/engine/charges.d.ts +6 -0
  18. package/dist/src/engine/charges.js +13 -0
  19. package/dist/src/engine/checkout.d.ts +24 -0
  20. package/dist/src/engine/checkout.js +30 -0
  21. package/dist/src/engine/common.d.ts +19 -0
  22. package/dist/src/engine/common.js +32 -0
  23. package/dist/src/{screens → engine}/connect-settings.d.ts +1 -7
  24. package/dist/src/engine/connect-settings.js +26 -0
  25. package/dist/src/engine/connect.d.ts +66 -0
  26. package/dist/src/engine/connect.js +189 -0
  27. package/dist/src/engine/coupons.d.ts +0 -0
  28. package/dist/src/engine/coupons.js +5 -0
  29. package/dist/src/engine/credit-notes.d.ts +1 -0
  30. package/dist/src/engine/credit-notes.js +5 -0
  31. package/dist/src/engine/customers.d.ts +12 -0
  32. package/dist/src/engine/customers.js +30 -0
  33. package/dist/src/engine/display.d.ts +14 -0
  34. package/dist/src/engine/display.js +16 -0
  35. package/dist/src/engine/disputes.d.ts +0 -0
  36. package/dist/src/engine/disputes.js +9 -0
  37. package/dist/src/engine/entitlements.d.ts +1 -0
  38. package/dist/src/engine/entitlements.js +4 -0
  39. package/dist/src/engine/ephemeral-keys.d.ts +0 -0
  40. package/dist/src/engine/ephemeral-keys.js +4 -0
  41. package/dist/src/engine/files.d.ts +18 -0
  42. package/dist/src/engine/files.js +33 -0
  43. package/dist/src/engine/front.d.ts +5 -0
  44. package/dist/src/engine/front.js +25 -0
  45. package/dist/src/engine/invoices.d.ts +24 -0
  46. package/dist/src/engine/invoices.js +57 -0
  47. package/dist/src/engine/issuing.d.ts +35 -0
  48. package/dist/src/engine/issuing.js +45 -0
  49. package/dist/src/engine/ledger.d.ts +9 -0
  50. package/dist/src/engine/ledger.js +9 -0
  51. package/dist/src/engine/oauth.d.ts +4 -0
  52. package/dist/src/engine/oauth.js +25 -0
  53. package/dist/src/engine/onboarding.d.ts +13 -0
  54. package/dist/src/engine/onboarding.js +42 -0
  55. package/dist/src/{stripe-params.d.ts → engine/params.d.ts} +20 -3
  56. package/dist/src/{stripe-params.js → engine/params.js} +7 -60
  57. package/dist/src/engine/payment-intents.d.ts +10 -0
  58. package/dist/src/engine/payment-intents.js +27 -0
  59. package/dist/src/engine/payment-links.d.ts +1 -0
  60. package/dist/src/engine/payment-links.js +5 -0
  61. package/dist/src/engine/payment-methods.d.ts +16 -0
  62. package/dist/src/engine/payment-methods.js +22 -0
  63. package/dist/src/engine/plans.d.ts +6 -0
  64. package/dist/src/engine/plans.js +26 -0
  65. package/dist/src/engine/platform.d.ts +39 -0
  66. package/dist/src/engine/platform.js +34 -0
  67. package/dist/src/engine/products.d.ts +0 -0
  68. package/dist/src/engine/products.js +4 -0
  69. package/dist/src/engine/radar.d.ts +2 -0
  70. package/dist/src/engine/radar.js +5 -0
  71. package/dist/src/engine/refunds.d.ts +1 -0
  72. package/dist/src/engine/refunds.js +28 -0
  73. package/dist/src/engine/renewals.d.ts +36 -0
  74. package/dist/src/engine/renewals.js +65 -0
  75. package/dist/src/engine/setup-intents.d.ts +1 -0
  76. package/dist/src/engine/setup-intents.js +4 -0
  77. package/dist/src/{stripe-twin.d.ts → engine/stripe.d.ts} +11 -39
  78. package/dist/src/{stripe-twin.js → engine/stripe.js} +25 -310
  79. package/dist/src/engine/subscription-schedules.d.ts +3 -0
  80. package/dist/src/engine/subscription-schedules.js +1 -0
  81. package/dist/src/engine/subscriptions.d.ts +12 -0
  82. package/dist/src/engine/subscriptions.js +31 -0
  83. package/dist/src/engine/tax.d.ts +7 -0
  84. package/dist/src/engine/tax.js +28 -0
  85. package/dist/src/engine/terminal.d.ts +4 -0
  86. package/dist/src/engine/terminal.js +20 -0
  87. package/dist/src/engine/test-clocks.d.ts +5 -0
  88. package/dist/src/engine/test-clocks.js +9 -0
  89. package/dist/src/engine/tokens.d.ts +7 -0
  90. package/dist/src/engine/tokens.js +20 -0
  91. package/dist/src/engine/transfers.d.ts +2 -0
  92. package/dist/src/engine/transfers.js +1 -0
  93. package/dist/src/engine/treasury.d.ts +23 -0
  94. package/dist/src/engine/treasury.js +45 -0
  95. package/dist/src/{stripe-version.js → engine/version.js} +4 -3
  96. package/dist/src/engine/webhook-endpoints.d.ts +1 -0
  97. package/dist/src/engine/webhook-endpoints.js +12 -0
  98. package/dist/src/engine/webhooks.d.ts +31 -0
  99. package/dist/src/engine/webhooks.js +68 -0
  100. package/dist/src/fetch.d.ts +2 -0
  101. package/dist/src/fetch.js +26 -0
  102. package/dist/src/generated/surface.gen.json +1 -1
  103. package/dist/src/generated/ui.gen.json +1 -1
  104. package/dist/src/index.d.ts +5 -14
  105. package/dist/src/index.js +8 -75
  106. package/dist/src/manifest.js +232 -758
  107. package/dist/src/screens/billing-portal.d.ts +3 -0
  108. package/dist/src/screens/{portal.js → billing-portal.js} +28 -54
  109. package/dist/src/screens/checkout.d.ts +2 -31
  110. package/dist/src/screens/checkout.js +32 -121
  111. package/dist/src/screens/connect-oauth.d.ts +3 -27
  112. package/dist/src/screens/connect-oauth.js +51 -132
  113. package/dist/src/screens/connect-onboarding.d.ts +3 -0
  114. package/dist/src/screens/{onboarding.js → connect-onboarding.js} +36 -102
  115. package/dist/src/screens/dashboard.d.ts +3 -0
  116. package/dist/src/screens/dashboard.js +117 -0
  117. package/dist/src/screens/shared.d.ts +27 -0
  118. package/dist/src/screens/shared.js +87 -0
  119. package/dist/src/screens/stripe-js.d.ts +3 -0
  120. package/dist/src/screens/stripe-js.js +135 -0
  121. package/dist/src/semantics/account_links.d.ts +2 -0
  122. package/dist/src/semantics/account_links.js +22 -0
  123. package/dist/src/semantics/accounts.d.ts +4 -0
  124. package/dist/src/semantics/accounts.js +38 -0
  125. package/dist/src/semantics/apps.d.ts +4 -0
  126. package/dist/src/semantics/{apps-secrets.js → apps.js} +14 -26
  127. package/dist/src/semantics/around.d.ts +2 -0
  128. package/dist/src/semantics/around.js +16 -0
  129. package/dist/src/semantics/balance.d.ts +2 -11
  130. package/dist/src/semantics/balance.js +3 -194
  131. package/dist/src/semantics/balance_transactions.d.ts +2 -0
  132. package/dist/src/semantics/balance_transactions.js +15 -0
  133. package/dist/src/semantics/billing_portal.d.ts +5 -0
  134. package/dist/src/semantics/billing_portal.js +42 -0
  135. package/dist/src/semantics/charges.d.ts +3 -28
  136. package/dist/src/semantics/charges.js +5 -202
  137. package/dist/src/semantics/checkout.d.ts +3 -20
  138. package/dist/src/semantics/checkout.js +8 -261
  139. package/dist/src/semantics/clock.d.ts +2 -0
  140. package/dist/src/semantics/clock.js +21 -0
  141. package/dist/src/semantics/coupons.d.ts +2 -6
  142. package/dist/src/semantics/coupons.js +2 -60
  143. package/dist/src/semantics/customers.d.ts +6 -6
  144. package/dist/src/semantics/customers.js +27 -387
  145. package/dist/src/semantics/disputes.d.ts +2 -2
  146. package/dist/src/semantics/disputes.js +3 -49
  147. package/dist/src/semantics/doors.d.ts +23 -0
  148. package/dist/src/semantics/doors.js +73 -0
  149. package/dist/src/semantics/entitlements.d.ts +2 -2
  150. package/dist/src/semantics/entitlements.js +5 -50
  151. package/dist/src/semantics/events.d.ts +12 -0
  152. package/dist/src/semantics/events.js +36 -0
  153. package/dist/src/semantics/index.d.ts +2 -0
  154. package/dist/src/semantics/index.js +107 -0
  155. package/dist/src/semantics/invoice_payments.d.ts +2 -0
  156. package/dist/src/semantics/invoice_payments.js +12 -0
  157. package/dist/src/semantics/invoiceitems.d.ts +3 -0
  158. package/dist/src/semantics/invoiceitems.js +59 -0
  159. package/dist/src/semantics/invoices.d.ts +16 -18
  160. package/dist/src/semantics/invoices.js +118 -444
  161. package/dist/src/semantics/payment_intents.d.ts +4 -0
  162. package/dist/src/semantics/payment_intents.js +79 -0
  163. package/dist/src/semantics/payment_methods.d.ts +5 -0
  164. package/dist/src/semantics/payment_methods.js +39 -0
  165. package/dist/src/semantics/payouts.d.ts +2 -0
  166. package/dist/src/semantics/payouts.js +21 -0
  167. package/dist/src/semantics/prices.d.ts +4 -0
  168. package/dist/src/semantics/prices.js +37 -0
  169. package/dist/src/semantics/products.d.ts +6 -2
  170. package/dist/src/semantics/products.js +15 -130
  171. package/dist/src/semantics/promotion_codes.d.ts +3 -0
  172. package/dist/src/semantics/promotion_codes.js +35 -0
  173. package/dist/src/semantics/radar.d.ts +2 -2
  174. package/dist/src/semantics/radar.js +5 -74
  175. package/dist/src/semantics/refunds.d.ts +3 -9
  176. package/dist/src/semantics/refunds.js +6 -192
  177. package/dist/src/semantics/setup_intents.d.ts +3 -0
  178. package/dist/src/semantics/{setup-intents.js → setup_intents.js} +10 -53
  179. package/dist/src/semantics/shared.d.ts +822 -47
  180. package/dist/src/semantics/shared.js +3044 -78
  181. package/dist/src/semantics/states.d.ts +531 -0
  182. package/dist/src/semantics/states.js +852 -0
  183. package/dist/src/semantics/subscription_items.d.ts +5 -0
  184. package/dist/src/semantics/subscription_items.js +55 -0
  185. package/dist/src/semantics/subscription_schedules.d.ts +4 -0
  186. package/dist/src/semantics/subscription_schedules.js +60 -0
  187. package/dist/src/semantics/subscriptions.d.ts +7 -11
  188. package/dist/src/semantics/subscriptions.js +44 -415
  189. package/dist/src/semantics/test_helpers.d.ts +6 -0
  190. package/dist/src/semantics/{test-clocks.js → test_helpers.js} +14 -40
  191. package/dist/src/semantics/transfers.d.ts +2 -2
  192. package/dist/src/semantics/transfers.js +6 -101
  193. package/dist/src/server.d.ts +7 -0
  194. package/dist/src/server.js +7 -0
  195. package/generated/pack-facts.json +94 -0
  196. package/package.json +10 -20
  197. package/spec/SOURCE.md +14 -0
  198. package/spec/fixtures3.json.gz +0 -0
  199. package/spec/openapi.json.gz +0 -0
  200. package/spec/patches.json +34 -0
  201. package/spec/sources.json +378 -0
  202. package/src/cli.ts +12 -26
  203. package/src/engine/after-payment.ts +31 -0
  204. package/src/engine/apps-secrets.ts +4 -0
  205. package/src/engine/balance.ts +33 -0
  206. package/src/engine/billing.ts +16 -0
  207. package/src/engine/charges.ts +19 -0
  208. package/src/engine/checkout.ts +40 -0
  209. package/src/engine/common.ts +47 -0
  210. package/src/engine/connect-settings.ts +23 -0
  211. package/src/engine/connect.ts +184 -0
  212. package/src/engine/coupons.ts +5 -0
  213. package/src/engine/credit-notes.ts +6 -0
  214. package/src/engine/customers.ts +35 -0
  215. package/src/engine/display.ts +19 -0
  216. package/src/engine/disputes.ts +9 -0
  217. package/src/engine/entitlements.ts +5 -0
  218. package/src/engine/ephemeral-keys.ts +3 -0
  219. package/src/engine/files.ts +41 -0
  220. package/src/engine/front.ts +31 -0
  221. package/src/engine/invoices.ts +71 -0
  222. package/src/engine/issuing.ts +61 -0
  223. package/src/engine/ledger.ts +50 -0
  224. package/src/engine/oauth.ts +19 -0
  225. package/src/engine/onboarding.ts +54 -0
  226. package/src/{stripe-params.ts → engine/params.ts} +8 -56
  227. package/src/engine/payment-intents.ts +33 -0
  228. package/src/engine/payment-links.ts +6 -0
  229. package/src/engine/payment-methods.ts +25 -0
  230. package/src/engine/plans.ts +42 -0
  231. package/src/engine/platform.ts +47 -0
  232. package/src/engine/products.ts +3 -0
  233. package/src/engine/radar.ts +6 -0
  234. package/src/engine/refunds.ts +29 -0
  235. package/src/engine/renewals.ts +73 -0
  236. package/src/engine/setup-intents.ts +5 -0
  237. package/src/{stripe-twin.ts → engine/stripe.ts} +28 -323
  238. package/src/engine/subscription-schedules.ts +10 -0
  239. package/src/engine/subscriptions.ts +40 -0
  240. package/src/engine/tax.ts +39 -0
  241. package/src/engine/terminal.ts +23 -0
  242. package/src/engine/test-clocks.ts +11 -0
  243. package/src/engine/tokens.ts +22 -0
  244. package/src/engine/transfers.ts +23 -0
  245. package/src/engine/treasury.ts +47 -0
  246. package/src/{stripe-version.ts → engine/version.ts} +4 -3
  247. package/src/engine/webhook-endpoints.ts +14 -0
  248. package/src/engine/webhooks.ts +72 -0
  249. package/src/fetch.ts +27 -0
  250. package/src/generated/surface.gen.json +1 -1
  251. package/src/generated/ui.gen.json +1 -1
  252. package/src/index.ts +8 -116
  253. package/src/manifest.ts +234 -786
  254. package/src/screens/{portal.tsx → billing-portal.tsx} +32 -37
  255. package/src/screens/checkout.tsx +33 -95
  256. package/src/screens/connect-oauth.tsx +64 -88
  257. package/src/screens/{onboarding.tsx → connect-onboarding.tsx} +38 -82
  258. package/src/screens/dashboard.tsx +198 -0
  259. package/src/screens/shared.tsx +84 -0
  260. package/src/screens/stripe-js.ts +170 -0
  261. package/src/semantics/account_links.ts +21 -0
  262. package/src/semantics/accounts.ts +43 -0
  263. package/src/semantics/{apps-secrets.ts → apps.ts} +17 -32
  264. package/src/semantics/around.ts +20 -0
  265. package/src/semantics/balance.ts +6 -207
  266. package/src/semantics/balance_transactions.ts +20 -0
  267. package/src/semantics/billing_portal.ts +51 -0
  268. package/src/semantics/charges.ts +12 -211
  269. package/src/semantics/checkout.ts +13 -268
  270. package/src/semantics/clock.ts +26 -0
  271. package/src/semantics/coupons.ts +5 -67
  272. package/src/semantics/customers.ts +29 -392
  273. package/src/semantics/disputes.ts +9 -59
  274. package/src/semantics/doors.ts +80 -0
  275. package/src/semantics/entitlements.ts +9 -56
  276. package/src/semantics/events.ts +44 -0
  277. package/src/semantics/index.ts +111 -0
  278. package/src/semantics/invoice_payments.ts +18 -0
  279. package/src/semantics/invoiceitems.ts +59 -0
  280. package/src/semantics/invoices.ts +109 -443
  281. package/src/semantics/payment_intents.ts +83 -0
  282. package/src/semantics/payment_methods.ts +43 -0
  283. package/src/semantics/payouts.ts +23 -0
  284. package/src/semantics/prices.ts +42 -0
  285. package/src/semantics/products.ts +18 -142
  286. package/src/semantics/promotion_codes.ts +39 -0
  287. package/src/semantics/radar.ts +8 -77
  288. package/src/semantics/refunds.ts +9 -212
  289. package/src/semantics/setup_intents.ts +45 -0
  290. package/src/semantics/shared.ts +3092 -106
  291. package/src/semantics/states.ts +883 -0
  292. package/src/semantics/subscription_items.ts +54 -0
  293. package/src/semantics/subscription_schedules.ts +66 -0
  294. package/src/semantics/subscriptions.ts +49 -432
  295. package/src/semantics/{test-clocks.ts → test_helpers.ts} +23 -47
  296. package/src/semantics/transfers.ts +11 -131
  297. package/src/server.ts +8 -0
  298. package/client/dashboard-api.ts +0 -286
  299. package/client/stripe-mirror.css +0 -277
  300. package/client/stripe-mirror.tsx +0 -1559
  301. package/dist/client/dashboard-api.d.ts +0 -107
  302. package/dist/client/dashboard-api.js +0 -238
  303. package/dist/client/dashboard-api.ts +0 -286
  304. package/dist/client/stripe-mirror.bundle.js +0 -236
  305. package/dist/client/stripe-mirror.css +0 -277
  306. package/dist/client/stripe-mirror.d.ts +0 -134
  307. package/dist/client/stripe-mirror.js +0 -859
  308. package/dist/client/stripe-mirror.tsx +0 -1559
  309. package/dist/src/screens/connect-settings.js +0 -103
  310. package/dist/src/screens/consent-skin.d.ts +0 -4
  311. package/dist/src/screens/consent-skin.js +0 -18
  312. package/dist/src/screens/financial-connections.d.ts +0 -5
  313. package/dist/src/screens/financial-connections.js +0 -90
  314. package/dist/src/screens/identity.d.ts +0 -5
  315. package/dist/src/screens/identity.js +0 -86
  316. package/dist/src/screens/onboarding.d.ts +0 -13
  317. package/dist/src/screens/portal.d.ts +0 -5
  318. package/dist/src/screens/public-details.d.ts +0 -5
  319. package/dist/src/screens/public-details.js +0 -90
  320. package/dist/src/semantics/after-payment.d.ts +0 -22
  321. package/dist/src/semantics/after-payment.js +0 -99
  322. package/dist/src/semantics/apps-secrets.d.ts +0 -2
  323. package/dist/src/semantics/billing.d.ts +0 -2
  324. package/dist/src/semantics/billing.js +0 -220
  325. package/dist/src/semantics/connect.d.ts +0 -5
  326. package/dist/src/semantics/connect.js +0 -493
  327. package/dist/src/semantics/credit-notes.d.ts +0 -2
  328. package/dist/src/semantics/credit-notes.js +0 -172
  329. package/dist/src/semantics/ephemeral-keys.d.ts +0 -2
  330. package/dist/src/semantics/ephemeral-keys.js +0 -34
  331. package/dist/src/semantics/files.d.ts +0 -2
  332. package/dist/src/semantics/files.js +0 -125
  333. package/dist/src/semantics/issuing.d.ts +0 -13
  334. package/dist/src/semantics/issuing.js +0 -575
  335. package/dist/src/semantics/ledger.d.ts +0 -59
  336. package/dist/src/semantics/ledger.js +0 -200
  337. package/dist/src/semantics/payment-intents.d.ts +0 -18
  338. package/dist/src/semantics/payment-intents.js +0 -452
  339. package/dist/src/semantics/payment-links.d.ts +0 -2
  340. package/dist/src/semantics/payment-links.js +0 -133
  341. package/dist/src/semantics/payment-methods.d.ts +0 -20
  342. package/dist/src/semantics/payment-methods.js +0 -140
  343. package/dist/src/semantics/plans.d.ts +0 -5
  344. package/dist/src/semantics/plans.js +0 -121
  345. package/dist/src/semantics/platform.d.ts +0 -9
  346. package/dist/src/semantics/platform.js +0 -206
  347. package/dist/src/semantics/renewals.d.ts +0 -47
  348. package/dist/src/semantics/renewals.js +0 -281
  349. package/dist/src/semantics/setup-intents.d.ts +0 -2
  350. package/dist/src/semantics/subscription-schedules.d.ts +0 -2
  351. package/dist/src/semantics/subscription-schedules.js +0 -119
  352. package/dist/src/semantics/tax.d.ts +0 -2
  353. package/dist/src/semantics/tax.js +0 -197
  354. package/dist/src/semantics/terminal.d.ts +0 -5
  355. package/dist/src/semantics/terminal.js +0 -182
  356. package/dist/src/semantics/test-clocks.d.ts +0 -6
  357. package/dist/src/semantics/tokens.d.ts +0 -4
  358. package/dist/src/semantics/tokens.js +0 -44
  359. package/dist/src/semantics/treasury.d.ts +0 -2
  360. package/dist/src/semantics/treasury.js +0 -377
  361. package/dist/src/semantics/webhook-endpoints.d.ts +0 -3
  362. package/dist/src/semantics/webhook-endpoints.js +0 -85
  363. package/dist/src/stripe-budget.d.ts +0 -55
  364. package/dist/src/stripe-budget.js +0 -155
  365. package/dist/src/stripe-capabilities.d.ts +0 -3
  366. package/dist/src/stripe-capabilities.js +0 -5836
  367. package/dist/src/stripe-conformance.d.ts +0 -43
  368. package/dist/src/stripe-conformance.js +0 -105
  369. package/dist/src/stripe-connector.d.ts +0 -161
  370. package/dist/src/stripe-connector.js +0 -414
  371. package/dist/src/stripe-emit.d.ts +0 -2
  372. package/dist/src/stripe-emit.js +0 -145
  373. package/dist/src/stripe-events.d.ts +0 -93
  374. package/dist/src/stripe-events.js +0 -392
  375. package/dist/src/stripe-js.d.ts +0 -4
  376. package/dist/src/stripe-js.js +0 -70
  377. package/dist/src/stripe-mirror-ui.d.ts +0 -15
  378. package/dist/src/stripe-mirror-ui.js +0 -87
  379. package/dist/src/stripe-perform-harness.d.ts +0 -9
  380. package/dist/src/stripe-perform-harness.js +0 -26
  381. package/dist/src/stripe-server.d.ts +0 -33
  382. package/dist/src/stripe-server.js +0 -429
  383. package/dist/src/stripe-shared.d.ts +0 -109
  384. package/dist/src/stripe-shared.js +0 -276
  385. package/dist/src/stripe-ui-conformance.d.ts +0 -5
  386. package/dist/src/stripe-ui-conformance.js +0 -79
  387. package/dist/src/stripe-ui-structure.d.ts +0 -3
  388. package/dist/src/stripe-ui-structure.js +0 -168
  389. package/dist/test-fixtures/stripe-known-deviations.json +0 -110
  390. package/dist/test-fixtures/stripe-openapi-operations.SOURCE.md +0 -14
  391. package/dist/test-fixtures/stripe-openapi-operations.json +0 -4717
  392. package/dist/test-fixtures/stripe-schemas.SOURCE.md +0 -35
  393. package/dist/test-fixtures/stripe-schemas.json +0 -3813
  394. package/src/screens/connect-settings.tsx +0 -121
  395. package/src/screens/consent-skin.ts +0 -20
  396. package/src/screens/financial-connections.tsx +0 -101
  397. package/src/screens/identity.tsx +0 -96
  398. package/src/screens/public-details.tsx +0 -105
  399. package/src/semantics/after-payment.ts +0 -118
  400. package/src/semantics/billing.ts +0 -216
  401. package/src/semantics/connect.ts +0 -487
  402. package/src/semantics/credit-notes.ts +0 -168
  403. package/src/semantics/ephemeral-keys.ts +0 -34
  404. package/src/semantics/files.ts +0 -143
  405. package/src/semantics/issuing.ts +0 -590
  406. package/src/semantics/ledger.ts +0 -253
  407. package/src/semantics/payment-intents.ts +0 -463
  408. package/src/semantics/payment-links.ts +0 -148
  409. package/src/semantics/payment-methods.ts +0 -145
  410. package/src/semantics/plans.ts +0 -131
  411. package/src/semantics/platform.ts +0 -220
  412. package/src/semantics/renewals.ts +0 -279
  413. package/src/semantics/setup-intents.ts +0 -87
  414. package/src/semantics/subscription-schedules.ts +0 -129
  415. package/src/semantics/tax.ts +0 -220
  416. package/src/semantics/terminal.ts +0 -195
  417. package/src/semantics/tokens.ts +0 -52
  418. package/src/semantics/treasury.ts +0 -383
  419. package/src/semantics/webhook-endpoints.ts +0 -87
  420. package/src/stripe-budget.ts +0 -181
  421. package/src/stripe-capabilities.ts +0 -5651
  422. package/src/stripe-conformance.ts +0 -124
  423. package/src/stripe-connector.ts +0 -462
  424. package/src/stripe-emit.ts +0 -157
  425. package/src/stripe-events.ts +0 -434
  426. package/src/stripe-js.ts +0 -70
  427. package/src/stripe-mirror-ui.ts +0 -90
  428. package/src/stripe-perform-harness.ts +0 -29
  429. package/src/stripe-server.ts +0 -393
  430. package/src/stripe-shared.ts +0 -297
  431. package/src/stripe-ui-conformance.ts +0 -88
  432. package/src/stripe-ui-structure.ts +0 -182
  433. package/test-fixtures/stripe-known-deviations.json +0 -110
  434. package/test-fixtures/stripe-openapi-operations.json +0 -4717
  435. package/test-fixtures/stripe-schemas.json +0 -3813
  436. /package/dist/src/{screens → engine}/industries.d.ts +0 -0
  437. /package/dist/src/{screens → engine}/industries.js +0 -0
  438. /package/dist/src/{semantics → engine}/test-cards.d.ts +0 -0
  439. /package/dist/src/{semantics → engine}/test-cards.js +0 -0
  440. /package/dist/src/{stripe-version.d.ts → engine/version.d.ts} +0 -0
  441. /package/src/{screens → engine}/industries.ts +0 -0
  442. /package/src/{semantics → engine}/test-cards.ts +0 -0
@@ -0,0 +1,883 @@
1
+ // Stripe's state machines and the state candidates it rules not state (docs/contributing/architecture.md, "What an
2
+ // author writes": states), each move cited; the manifest takes each resource's whole.
3
+ import type { StateField, Transition } from '@volter/world-core';
4
+
5
+ const unexpected = (verb: string, allowed: string) => ({
6
+ status: 400,
7
+ code: 'payment_intent_unexpected_state',
8
+ message: `This PaymentIntent could not be ${verb} because it has a status of {from}. ${allowed}`,
9
+ });
10
+ const OPEN = ['requires_payment_method', 'requires_confirmation', 'requires_action', 'requires_capture', 'processing'];
11
+
12
+ /** A move no API call makes: Stripe's own (`vendor`), the clock's (`time`), or the person on a
13
+ * Stripe-hosted page (`external`: Checkout, the billing portal, a hosted invoice or 3DS page). */
14
+ const by = (actor: 'vendor' | 'time' | 'external', from: string[], to: string, source: string): Transition => ({ actor, from, to, source });
15
+ /** A bank account's `status` as a payout or payment destination. Stripe validates its routing number,
16
+ * verifies it (micro-deposits, or instantly) and marks it errored when a payout or debit to it fails
17
+ * (the page each machine cites); no call the twin serves does any of that (the customer-source verify is
18
+ * a gap), so no move of it is the twin's. */
19
+ const bankAccountStatus = (_doc: string): StateField => ({ initial: 'new', transitions: [] });
20
+
21
+ /** A flag an update sets either way. */
22
+ const flag = (operation: string, source: string): Transition[] => ['true', 'false'].map((to) => ({ operation, from: '*' as const, to, source }));
23
+
24
+ /** A PaymentIntent's `status`: which operation may move it from where, and what Stripe answers otherwise. */
25
+ const paymentIntentStatus: StateField = {
26
+ // "After you create the PaymentIntent, its status is `requires_payment_method` until you attach a payment method"
27
+ // (docs.stripe.com/payments/paymentintents/lifecycle)
28
+ initial: 'requires_payment_method',
29
+ transitions: [
30
+ // created with its payment method, it "enters the `requires_confirmation` status and is ready to confirm" (the same page)
31
+ { operation: 'PostPaymentIntents', from: ['requires_payment_method'], to: 'requires_confirmation', source: 'https://docs.stripe.com/payments/paymentintents/lifecycle' },
32
+ // confirm lands on one of its outcomes, decided by the payment method and the capture method
33
+ ...['requires_payment_method', 'requires_action', 'requires_capture', 'succeeded'].map((to) => ({
34
+ operation: 'PostPaymentIntentsIntentConfirm',
35
+ from: ['requires_payment_method', 'requires_confirmation', 'requires_action'],
36
+ to,
37
+ refusal: { status: 400, code: 'payment_intent_unexpected_state', message: 'You cannot confirm this PaymentIntent because it has a status of {from}.' },
38
+ source: 'https://docs.stripe.com/api/payment_intents/confirm',
39
+ })),
40
+ // a bank debit confirmed (created with `confirm`, confirmed, or verified by micro-deposits) is submitted and
41
+ // processes: "The PaymentIntent you create initially has a status of `processing`"; "When the bank account is
42
+ // successfully verified, Stripe returns the PaymentIntent object with a status of `processing`"
43
+ ...['PostPaymentIntents', 'PostPaymentIntentsIntentConfirm'].map((operation) => ({
44
+ operation, from: ['requires_payment_method', 'requires_confirmation', 'requires_action'], to: 'processing',
45
+ source: 'https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment?payment-ui=direct-api',
46
+ })),
47
+ // and succeeds: "After the payment has succeeded, the PaymentIntent status is updated from `processing`
48
+ // to `succeeded`" (../engine/payment-intents.ts settleBankDebits)
49
+ by('vendor', ['processing'], 'succeeded', 'https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment?payment-ui=direct-api'),
50
+ // creating one with `confirm` confirms it at once, landing where a confirm lands
51
+ ...['requires_payment_method', 'requires_action', 'requires_capture', 'succeeded'].map((to) => ({
52
+ operation: 'PostPaymentIntents',
53
+ from: ['requires_payment_method', 'requires_confirmation'],
54
+ to,
55
+ source: 'spec:PostPaymentIntents "Set to `true` to attempt to [confirm this PaymentIntent](https://docs.stripe.com/api/payment_intents/confirm) immediately."',
56
+ })),
57
+ {
58
+ operation: 'PostPaymentIntentsIntentCapture',
59
+ from: ['requires_capture'],
60
+ to: 'succeeded',
61
+ refusal: unexpected('captured', 'Only a PaymentIntent with one of the following statuses may be captured: requires_capture.'),
62
+ source: 'https://docs.stripe.com/api/payment_intents/capture',
63
+ },
64
+ {
65
+ operation: 'PostPaymentIntentsIntentIncrementAuthorization',
66
+ from: ['requires_capture'],
67
+ to: 'requires_capture',
68
+ refusal: unexpected('incremented', 'Only a PaymentIntent with a status of requires_capture may be incremented.'),
69
+ source: 'https://docs.stripe.com/api/payment_intents/increment_authorization',
70
+ },
71
+ {
72
+ operation: 'PostPaymentIntentsIntentCancel',
73
+ from: OPEN,
74
+ to: 'canceled',
75
+ refusal: unexpected('canceled', 'Only a PaymentIntent with one of the following statuses may be canceled: requires_payment_method, requires_capture, requires_confirmation, requires_action, processing.'),
76
+ source: 'https://docs.stripe.com/api/payment_intents/cancel',
77
+ },
78
+ {
79
+ operation: 'PostPaymentIntentsIntentVerifyMicrodeposits',
80
+ from: ['requires_action'],
81
+ to: 'processing',
82
+ refusal: { status: 400, code: 'payment_intent_unexpected_state', message: 'This PaymentIntent could not be verified because it has a status of {from}.' },
83
+ source: 'https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment?payment-ui=direct-api',
84
+ },
85
+ {
86
+ // paying the invoice an intent collects for settles the intent
87
+ operation: 'PostInvoicesInvoicePay',
88
+ from: OPEN,
89
+ to: 'succeeded',
90
+ source: 'https://docs.stripe.com/api/invoices/pay',
91
+ },
92
+ ...['succeeded', 'requires_action'].map((to) => ({
93
+ operation: 'PostPaymentIntentsIntentApplyCustomerBalance',
94
+ from: OPEN,
95
+ to,
96
+ refusal: { status: 400, code: 'payment_intent_unexpected_state', message: 'This PaymentIntent could not be updated because it has a status of {from}.' },
97
+ source: 'https://docs.stripe.com/api/payment_intents/apply_customer_balance',
98
+ })),
99
+ // a card presented to the Terminal reader processing an intent pays it (held, under manual capture)
100
+ ...['succeeded', 'requires_capture'].map((to) => ({
101
+ operation: 'PostTestHelpersTerminalReadersReaderPresentPaymentMethod', from: ['requires_payment_method', 'requires_confirmation'], to,
102
+ source: 'https://docs.stripe.com/api/terminal/readers/present_payment_method',
103
+ })),
104
+ // the customer pays, in the billing portal, the invoice an intent collects for after its charge was declined
105
+ by('external', ['requires_payment_method'], 'succeeded', 'https://docs.stripe.com/customer-management'),
106
+ // Stripe also fails a bank debit back to needing a payment method, completes 3-D Secure on the bank's page and
107
+ // cancels a hold left uncaptured; the twin's bank debits succeed unless their test account stays processing, it has no 3-D Secure page, and it keeps
108
+ // holds until they are captured or canceled
109
+ ],
110
+ };
111
+
112
+ /** A charge's `captured`: an authorization (capture=false) is captured once. */
113
+ const chargeCaptured: StateField = {
114
+ initial: true,
115
+ transitions: [
116
+ {
117
+ operation: 'PostChargesChargeCapture',
118
+ from: ['false'],
119
+ to: 'true',
120
+ refusal: { status: 400, code: 'charge_already_captured', message: 'Charge ch_xxx has already been captured.' },
121
+ source: 'https://docs.stripe.com/api/charges/capture',
122
+ },
123
+ // a manual-capture intent's capture captures the charge its confirm authorized
124
+ { operation: 'PostPaymentIntentsIntentCapture', from: ['false'], to: 'true', source: 'https://docs.stripe.com/api/payment_intents/capture' },
125
+ ],
126
+ };
127
+
128
+ /** A charge's `refunded`: true once refunds take its whole amount, false again when a refund that made it so is
129
+ * canceled. A capture or a cancel never makes it so: "`refunded` will no longer be `true` for payment cancellation
130
+ * flows", and a partial capture makes no Refund (docs.stripe.com/changelog/basil/2025-03-31/remove-refund-from-partial-
131
+ * capture-and-payment-cancellation-flow). */
132
+ const chargeRefunded: StateField = {
133
+ initial: false,
134
+ transitions: [
135
+ ...['PostRefunds', 'PostChargesChargeRefunds', 'PostCreditNotes'].map((operation) => ({ operation, from: ['false'], to: 'true', source: 'https://docs.stripe.com/api/charges/object#charge_object-refunded' })),
136
+ { operation: 'PostRefundsRefundCancel', from: ['true'], to: 'false', source: 'https://docs.stripe.com/api/refunds/cancel' },
137
+ // (an authorization left uncaptured is canceled after seven days, "Uncaptured PaymentIntents are cancelled a set
138
+ // number of days (7 by default) after their creation", docs.stripe.com/api/payment_intents/capture; the twin keeps it)
139
+ ],
140
+ };
141
+
142
+ /** A charge's `status`: the twin settles a charge when it is made (a declined one is never
143
+ * stored); an asynchronous one settles later, on the network's word. */
144
+ const chargeStatus: StateField = {
145
+ initial: 'succeeded',
146
+ transitions: [
147
+ // (an asynchronous charge is pending at Stripe until it settles or fails; the twin's settle when made)
148
+ ],
149
+ };
150
+
151
+ /** A charge's `paid`: true once it succeeded or was authorized; a pending one becomes paid when it settles. */
152
+ const chargePaid: StateField = {
153
+ initial: true,
154
+ // (a charge is paid when it settles; the twin's settle when made)
155
+ transitions: [],
156
+ };
157
+
158
+ /** A refund's `status`: only one waiting on the customer (requires_action) may be canceled; the
159
+ * rest is the network's. */
160
+ const refundStatus: StateField = {
161
+ initial: 'succeeded',
162
+ transitions: [
163
+ {
164
+ operation: 'PostRefundsRefundCancel',
165
+ from: ['requires_action'],
166
+ to: 'canceled',
167
+ refusal: { status: 400, code: 'refund_status_invalid', message: 'Refund {id} cannot be canceled because its status is {from}.' },
168
+ source: 'https://docs.stripe.com/api/refunds/cancel',
169
+ },
170
+ // a card refund the available balance does not cover is held pending, and made once the balance covers it: "Stripe
171
+ // holds the refund as pending for card transactions ... until your Stripe balance becomes sufficient"
172
+ // (docs.stripe.com/refunds; semantics/refunds.ts)
173
+ // (a paid invoice's credit note makes its refund as a refund call does: "Refunds: create a new refund (using
174
+ // refund_amount)", docs.stripe.com/api/credit_notes/create)
175
+ ...['PostRefunds', 'PostChargesChargeRefunds', 'PostCreditNotes'].map((operation) => ({ operation, from: ['succeeded'], to: 'pending', source: 'https://docs.stripe.com/refunds' })),
176
+ by('vendor', ['pending'], 'succeeded', 'https://docs.stripe.com/refunds'),
177
+ // a bank-transfer payment's refund waits in requires_action for the customer's bank details, and is made so
178
+ // (semantics/refunds.ts); (Stripe also fails some refunds; the twin's do not fail)
179
+ ],
180
+ };
181
+
182
+ const SETUP_OPEN = ['requires_payment_method', 'requires_confirmation', 'requires_action'];
183
+ const setupUnexpected = (verb: string) => ({ status: 400, code: 'setup_intent_unexpected_state', message: `You cannot ${verb} this SetupIntent because it has a status of {from}.` });
184
+
185
+ /** A SetupIntent's `status`: confirm settles it (or leaves a bank account awaiting micro-deposits),
186
+ * cancel ends an open one, and verification completes the micro-deposit wait. */
187
+ const setupIntentStatus: StateField = {
188
+ // "After you create the SetupIntent, it has a status of `requires_payment_method` until you attach a payment method"
189
+ // (docs.stripe.com/payments/paymentintents/lifecycle)
190
+ initial: 'requires_payment_method',
191
+ transitions: [
192
+ // created with its payment method, it "enters the `requires_confirmation` status and is ready to confirm" (the same page)
193
+ { operation: 'PostSetupIntents', from: ['requires_payment_method'], to: 'requires_confirmation', source: 'https://docs.stripe.com/payments/paymentintents/lifecycle' },
194
+ ...['requires_action', 'succeeded'].map((to) => ({
195
+ operation: 'PostSetupIntentsIntentConfirm',
196
+ from: SETUP_OPEN,
197
+ to,
198
+ refusal: setupUnexpected('confirm'),
199
+ source: 'https://docs.stripe.com/api/setup_intents/confirm',
200
+ })),
201
+ {
202
+ operation: 'PostSetupIntentsIntentCancel',
203
+ from: SETUP_OPEN,
204
+ to: 'canceled',
205
+ refusal: setupUnexpected('cancel'),
206
+ source: 'https://docs.stripe.com/api/setup_intents/cancel',
207
+ },
208
+ {
209
+ operation: 'PostSetupIntentsIntentVerifyMicrodeposits',
210
+ from: ['requires_action'],
211
+ to: 'succeeded',
212
+ refusal: { status: 400, code: 'setup_intent_unexpected_state', message: 'This SetupIntent could not be verified because it has a status of {from}.' },
213
+ source: 'https://docs.stripe.com/api/setup_intents/verify_microdeposits',
214
+ },
215
+ // (Stripe completes 3-D Secure on the bank's page and settles an asynchronous method from processing; the
216
+ // twin has no such page and settles every method at once)
217
+ ],
218
+ };
219
+
220
+ const invoiceRefusal = (message: string) => ({ status: 400, code: 'invoice_not_editable', message });
221
+
222
+ /** An invoice's `status`: a draft is finalized (or sent, which finalizes it) into open, an open one
223
+ * is paid, written off or voided. Sending leaves any other status where it is. */
224
+ const invoiceStatus: StateField = {
225
+ initial: 'draft',
226
+ transitions: [
227
+ {
228
+ operation: 'PostInvoicesInvoiceFinalize',
229
+ from: ['draft'],
230
+ to: 'open',
231
+ refusal: invoiceRefusal('This invoice cannot be finalized because it has status {from}.'),
232
+ source: 'https://docs.stripe.com/api/invoices/finalize',
233
+ },
234
+ // docs.stripe.com/invoicing/integration: "To finalize a draft invoice, use the Dashboard, send it to the customer, or pay it."
235
+ { operation: 'PostInvoicesInvoiceSend', from: ['draft'], to: 'open', source: 'https://docs.stripe.com/invoicing/integration' },
236
+ { operation: 'PostInvoicesInvoiceSend', from: ['open', 'paid', 'uncollectible', 'void'], source: 'https://docs.stripe.com/api/invoices/send' },
237
+ {
238
+ operation: 'PostInvoicesInvoicePay',
239
+ from: ['open', 'uncollectible'],
240
+ to: 'paid',
241
+ refusal: invoiceRefusal('This invoice cannot be paid because it has status {from}.'),
242
+ refusals: { paid: { status: 400, code: 'invoice_payment_intent_requires_action', message: 'This invoice has already been paid.' } },
243
+ source: 'https://docs.stripe.com/api/invoices/pay',
244
+ },
245
+ {
246
+ operation: 'PostInvoicesInvoiceMarkUncollectible',
247
+ from: ['open'],
248
+ to: 'uncollectible',
249
+ refusal: invoiceRefusal('Only open invoices can be marked uncollectible (this one is {from}).'),
250
+ source: 'https://docs.stripe.com/api/invoices/mark_uncollectible',
251
+ },
252
+ // a guard: only a draft is deleted; a finalized invoice is voided instead
253
+ {
254
+ operation: 'DeleteInvoicesInvoice',
255
+ from: ['draft'],
256
+ refusal: invoiceRefusal('You can only delete draft invoices.'),
257
+ source: 'https://docs.stripe.com/api/invoices/delete',
258
+ },
259
+ {
260
+ // only a finalized invoice is voided; a draft is deleted
261
+ operation: 'PostInvoicesInvoiceVoid',
262
+ from: ['open', 'uncollectible'],
263
+ to: 'void',
264
+ refusal: invoiceRefusal('This invoice cannot be voided because it has status {from}.'),
265
+ source: 'https://docs.stripe.com/api/invoices/void',
266
+ },
267
+ // confirming or capturing the PaymentIntent an invoice collects through pays the invoice
268
+ ...['PostPaymentIntentsIntentConfirm', 'PostPaymentIntentsIntentCapture'].map((operation) => ({
269
+ operation, from: ['draft', 'open', 'uncollectible'], to: 'paid', source: 'https://docs.stripe.com/billing/subscriptions/build-subscriptions',
270
+ })),
271
+ // as does its bank debit succeeding once submitted (../engine/payment-intents.ts settleBankDebits)
272
+ by('vendor', ['draft', 'open', 'uncollectible'], 'paid', 'https://docs.stripe.com/billing/subscriptions/build-subscriptions'),
273
+ // a bank transfer that arrives in the customer's cash balance pays an open invoice that takes transfers
274
+ // (automatic reconciliation; in test mode the funding helper stands in for the transfer)
275
+ { operation: 'PostTestHelpersCustomersCustomerFundCashBalance', from: ['open'], to: 'paid', source: 'https://docs.stripe.com/payments/customer-balance/reconciliation' },
276
+ // a subscription's first invoice is paid on the Checkout page that started it
277
+ by('external', ['draft'], 'paid', 'https://docs.stripe.com/payments/checkout/how-checkout-works'),
278
+ // a subscription's renewal, drafted at its period's end, is finalized about an hour later and charged: paid, or
279
+ // open when the charge is declined (../engine/renewals.ts)
280
+ by('time', ['draft'], 'paid', 'https://docs.stripe.com/invoicing/integration/workflow-transitions#finalized'),
281
+ by('time', ['draft'], 'open', 'https://docs.stripe.com/billing/subscriptions/overview#payment-status'),
282
+ // an update that ends a subscription's trial invoices its new period and attempts payment at once: paid, or open
283
+ // when the charge is declined or not attempted (semantics/subscriptions.ts applyTrialEnd)
284
+ { operation: 'PostSubscriptionsSubscriptionExposedId', from: ['draft'], to: 'paid', source: 'https://docs.stripe.com/billing/subscriptions/upgrade-downgrade#immediate-payment' },
285
+ // a trialing subscription's first invoice, for nothing, is paid as it is made ("An immediate invoice is still
286
+ // created, but the amount is 0", docs.stripe.com/billing/subscriptions/trials/free-trials)
287
+ { operation: 'PostSubscriptions', from: ['draft'], to: 'paid', source: 'https://docs.stripe.com/billing/subscriptions/trials/free-trials' },
288
+ { operation: 'PostSubscriptionsSubscriptionExposedId', from: ['draft'], to: 'open', source: 'https://docs.stripe.com/billing/subscriptions/upgrade-downgrade#immediate-payment' },
289
+ // the customer pays an open invoice in the billing portal
290
+ by('external', ['open'], 'paid', 'https://docs.stripe.com/customer-management'),
291
+ // (Stripe also finalizes any other auto-advancing draft after an hour, retries an open invoice on its schedule
292
+ // and, retries exhausted, may write it off, and takes payment on the hosted invoice page; the twin's other
293
+ // invoices move only by the calls above)
294
+ ],
295
+ };
296
+
297
+ /** A subscription's `status` as the twin's own operations move it; canceling ends any subscription. */
298
+ const subscriptionStatus: StateField = {
299
+ initial: 'active',
300
+ transitions: [
301
+ { operation: 'DeleteSubscriptionsSubscriptionExposedId', from: '*', to: 'canceled', source: 'https://docs.stripe.com/api/subscriptions/cancel' },
302
+ // (a test clock's advance moves no subscription itself: when the clock reaches its target, a trial that ended there
303
+ // ends by time's move below, on the next request; ../engine/test-clocks.ts finishClockAdvances)
304
+ // "Deleting the simulation also deletes the test customers associated with the clock and cancels their
305
+ // subscriptions" (docs.stripe.com/billing/testing/test-clocks/api-advanced-usage)
306
+ { operation: 'DeleteTestHelpersTestClocksTestClock', from: '*', to: 'canceled', source: 'https://docs.stripe.com/billing/testing/test-clocks/api-advanced-usage' },
307
+ // "Cancels a subscription schedule and its associated subscription immediately" (docs.stripe.com/api/subscription_schedules/cancel)
308
+ { operation: 'PostSubscriptionSchedulesScheduleCancel', from: ['active', 'trialing', 'past_due', 'incomplete'], to: 'canceled', source: 'https://docs.stripe.com/api/subscription_schedules/cancel' },
309
+ // confirming or capturing the first invoice's PaymentIntent, or paying the invoice itself, pays it and
310
+ // activates the subscription
311
+ ...['PostPaymentIntentsIntentConfirm', 'PostPaymentIntentsIntentCapture'].map((operation) => ({
312
+ operation, from: ['incomplete'], to: 'active', source: 'https://docs.stripe.com/billing/subscriptions/build-subscriptions',
313
+ })),
314
+ // or when its bank debit succeeds once submitted (../engine/payment-intents.ts settleBankDebits)
315
+ by('vendor', ['incomplete'], 'active', 'https://docs.stripe.com/billing/subscriptions/build-subscriptions'),
316
+ // paying the invoice a subscription waits on (its first, or a renewal that failed) makes it active
317
+ { operation: 'PostInvoicesInvoicePay', from: ['incomplete', 'past_due'], to: 'active', source: 'https://docs.stripe.com/billing/subscriptions/overview#payment-status' },
318
+ // an update's `trial_end`: `now` ends a trial at once and charges the new period, active when paid and past_due when
319
+ // not; a future timestamp starts a trial on a subscription out of one (semantics/subscriptions.ts applyTrialEnd)
320
+ { operation: 'PostSubscriptionsSubscriptionExposedId', from: ['trialing'], to: 'active', source: 'https://docs.stripe.com/api/subscriptions/update#update_subscription-trial_end' },
321
+ { operation: 'PostSubscriptionsSubscriptionExposedId', from: ['trialing'], to: 'past_due', source: 'https://docs.stripe.com/billing/subscriptions/upgrade-downgrade#immediate-payment' },
322
+ {
323
+ operation: 'PostSubscriptionsSubscriptionExposedId', from: ['active', 'past_due'], to: 'trialing',
324
+ // (Where the documentation stops and the twin decides: the wording of the refusal for a subscription neither
325
+ // active nor past_due; a canceled one answers what Stripe answers any update of a canceled subscription.)
326
+ refusal: { status: 400, message: 'A trial can only be added to an active or past_due subscription; this one is {from}.' },
327
+ refusals: { canceled: { status: 400, message: 'A canceled subscription can only update its cancellation_details and metadata.' } },
328
+ source: 'https://docs.stripe.com/billing/subscriptions/trials/free-trials#adding-a-new-trial-to-a-subscription-previously-in-a-trial',
329
+ },
330
+ // a trial ends on its own clock (Stripe pauses one that ends with no payment method to bill; the twin's
331
+ // trials end active), and a renewal whose charge is declined leaves the subscription past_due
332
+ // (../engine/renewals.ts)
333
+ by('time', ['trialing'], 'active', 'https://docs.stripe.com/billing/subscriptions/trials'),
334
+ by('time', ['active'], 'past_due', 'https://docs.stripe.com/billing/subscriptions/overview#payment-status'),
335
+ // one set to cancel at its period's end is canceled when the period ends
336
+ by('time', ['active', 'trialing', 'past_due'], 'canceled', 'https://docs.stripe.com/billing/subscriptions/cancel#cancel-at-end-of-cycle'),
337
+ // the customer pays the invoice it waits on in the billing portal
338
+ by('external', ['past_due'], 'active', 'https://docs.stripe.com/customer-management'),
339
+ // (Stripe also expires an incomplete subscription after 23 hours, and retries a failed renewal on its schedule,
340
+ // the settings ending the retries unpaid or canceled; the twin makes no retry)
341
+ // the customer cancels in the billing portal
342
+ by('external', ['active', 'trialing', 'past_due', 'unpaid', 'paused'], 'canceled', 'spec:/components/schemas/portal_subscription_cancel "Whether to cancel subscriptions immediately or at the end of the billing period."'),
343
+ ],
344
+ };
345
+
346
+ const notOpen = (verb: string) => ({ status: 400, code: 'checkout_session_not_open', message: `You may only ${verb} a Checkout Session that is currently in the \`open\` state.` });
347
+
348
+ /** A Checkout Session's `status`: an open session expires (asked to, or 24 hours on), or completes
349
+ * when the customer pays on the hosted page. Completion is the external actor's move, the one the
350
+ * hosted Checkout page (src/screens/checkout.tsx) performs. */
351
+ const checkoutStatus: StateField = {
352
+ initial: 'open',
353
+ transitions: [
354
+ { operation: 'PostCheckoutSessionsSessionExpire', from: ['open'], to: 'expired', refusal: notOpen('expire'), source: 'https://docs.stripe.com/api/checkout/sessions/expire' },
355
+ { actor: 'external', from: ['open'], to: 'complete', refusal: notOpen('complete'), source: 'https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-status' },
356
+ // (Stripe expires an open session at expires_at; the twin keeps it open until asked)
357
+ ],
358
+ };
359
+
360
+ /** A Checkout Session's `payment_status`: the customer completing a payment or subscription session
361
+ * pays it; a delayed payment method settles later. */
362
+ const checkoutPaymentStatus: StateField = {
363
+ initial: 'unpaid',
364
+ transitions: [
365
+ { actor: 'external', from: '*', to: 'paid', source: 'https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-payment_status' },
366
+ // (a delayed method settles a session later at Stripe; the twin's settle on the page)
367
+ ],
368
+ };
369
+
370
+ /** A dispute's `status`: closing concedes it; the bank decides the rest, and an unanswered one is
371
+ * lost when its evidence is due. */
372
+ const disputeStatus: StateField = {
373
+ initial: 'warning_needs_response',
374
+ transitions: [
375
+ { operation: 'PostDisputesDisputeClose', from: '*', to: 'lost', source: 'https://docs.stripe.com/api/disputes/close' },
376
+ // submitting evidence puts a dispute (or an inquiry) under review; in test mode the evidence decides it
377
+ { operation: 'PostDisputesDispute', from: ['needs_response'], to: 'under_review', source: 'https://docs.stripe.com/api/disputes/update#update_dispute-submit' },
378
+ { operation: 'PostDisputesDispute', from: ['warning_needs_response'], to: 'warning_under_review', source: 'https://docs.stripe.com/api/disputes/update#update_dispute-submit' },
379
+ by('vendor', ['under_review'], 'won', 'https://docs.stripe.com/testing#evidence'),
380
+ by('vendor', ['under_review'], 'lost', 'https://docs.stripe.com/testing#evidence'),
381
+ // (the bank decides a dispute under review, escalates an inquiry and loses one left unanswered; the twin
382
+ // decides none)
383
+ // Stripe also closes an inquiry the bank drops (warning_closed); no inquiry the twin holds is dropped
384
+ ],
385
+ };
386
+
387
+ /** A payout's `status`: cancel ends it; reversing cancels it and pays a reversal, never twice. */
388
+ const payoutStatus: StateField = {
389
+ initial: 'pending',
390
+ transitions: [
391
+ // only a pending payout can be canceled (docs.stripe.com/api/payouts/cancel); reversing a paid one makes a new
392
+ // payout and leaves the original paid (semantics/balance.ts)
393
+ { operation: 'PostPayoutsPayoutCancel', from: ['pending'], to: 'canceled', source: 'https://docs.stripe.com/api/payouts/cancel' },
394
+ // it arrives in the bank on its arrival date
395
+ by('time', ['pending'], 'paid', 'https://docs.stripe.com/payouts#payout-statuses'),
396
+ // (a bank may fail a payout at Stripe; the twin's arrive)
397
+ ],
398
+ };
399
+
400
+ /** A credit note's `status`: issued, then voided once. */
401
+ const creditNoteStatus: StateField = {
402
+ initial: 'issued',
403
+ transitions: [
404
+ {
405
+ operation: 'PostCreditNotesIdVoid',
406
+ from: ['issued'],
407
+ to: 'void',
408
+ refusal: { status: 400, code: 'credit_note_already_voided', message: 'This credit note has already been voided.' },
409
+ source: 'https://docs.stripe.com/api/credit_notes/void',
410
+ },
411
+ ],
412
+ };
413
+
414
+ const scheduleEnded = (verb: string) => ({ status: 400, code: 'subscription_schedule_status_invalid', message: `This subscription schedule has status {from} and cannot be ${verb}.` });
415
+
416
+ /** A subscription schedule's `status`: canceling or releasing ends it; an ended one refuses both. */
417
+ const scheduleStatus: StateField = {
418
+ initial: 'active',
419
+ transitions: [
420
+ // "A subscription schedule can only be canceled if its status is not_started or active"; "A schedule can only be
421
+ // released if its status is not_started or active" (the cancel and release pages)
422
+ { operation: 'PostSubscriptionSchedulesScheduleCancel', from: ['active', 'not_started'], to: 'canceled', refusal: scheduleEnded('canceled'), source: 'https://docs.stripe.com/api/subscription_schedules/cancel' },
423
+ { operation: 'PostSubscriptionSchedulesScheduleRelease', from: ['active', 'not_started'], to: 'released', refusal: scheduleEnded('released'), source: 'https://docs.stripe.com/api/subscription_schedules/release' },
424
+ // its phases run on the clock: it starts at its start date and ends with its last phase
425
+ // (a schedule whose end_behavior is cancel completes at its end at Stripe; the twin's release)
426
+ // (Stripe starts a schedule at its start date and ends it with its last phase; the twin's start at once
427
+ // and end when canceled or released)
428
+ ],
429
+ };
430
+
431
+ const quoteRefusal = (verb: string) => ({ status: 400, code: 'quote_invalid_status', message: `This quote cannot be ${verb} because it has status {from}.` });
432
+
433
+ /** A quote's `status`: a draft is finalized into open, an open one accepted, and either canceled. */
434
+ const quoteStatus: StateField = {
435
+ initial: 'draft',
436
+ transitions: [
437
+ { operation: 'PostQuotesQuoteFinalize', from: ['draft'], to: 'open', refusal: quoteRefusal('finalized'), source: 'https://docs.stripe.com/api/quotes/finalize' },
438
+ { operation: 'PostQuotesQuoteAccept', from: ['open'], to: 'accepted', refusal: quoteRefusal('accepted'), source: 'https://docs.stripe.com/api/quotes/accept' },
439
+ { operation: 'PostQuotesQuoteCancel', from: ['draft', 'open'], to: 'canceled', refusal: quoteRefusal('canceled'), source: 'https://docs.stripe.com/api/quotes/cancel' },
440
+ // an open quote not accepted by its expires_at is canceled
441
+ // (Stripe cancels an open quote at its expires_at; the twin keeps it open)
442
+ ],
443
+ };
444
+
445
+ const setBy = (operation: string, values: string[], source: string): Transition[] => values.map((to) => ({ operation, from: '*' as const, to, source }));
446
+
447
+ /** An Issuing authorization's `status`: approve and decline close a pending one, once; a capture
448
+ * closes it, or leaves it pending when told not to close. */
449
+ const issuingAuthorizationStatus: StateField = {
450
+ initial: 'pending',
451
+ transitions: [
452
+ // approving keeps it pending (approved) until the merchant captures; declining closes it
453
+ { operation: 'PostIssuingAuthorizationsAuthorizationApprove', from: ['pending'], refusal: { status: 400, code: 'authorization_already_finalized', message: 'This authorization has already been finalized (status {from}).' }, source: 'https://docs.stripe.com/issuing/purchases/authorizations' },
454
+ { operation: 'PostIssuingAuthorizationsAuthorizationDecline', from: ['pending'], to: 'closed', refusal: { status: 400, code: 'authorization_already_finalized', message: 'This authorization has already been finalized (status {from}).' }, source: 'https://docs.stripe.com/api/issuing/authorizations/decline' },
455
+ { operation: 'PostTestHelpersIssuingAuthorizationsAuthorizationCapture', from: ['pending'], to: 'closed', source: 'https://docs.stripe.com/api/issuing/authorizations/test_mode_capture' },
456
+ { operation: 'PostTestHelpersIssuingAuthorizationsAuthorizationCapture', from: ['pending'], source: 'https://docs.stripe.com/api/issuing/authorizations/test_mode_capture' },
457
+ // a real-time request no one answered is decided when its window ends: "If Stripe doesn't receive your approve or
458
+ // decline response within 2 seconds, the Authorization is automatically approved or declined based on your timeout
459
+ // settings" (semantics/issuing.ts lapseRealtimeRequests)
460
+ by('time', ['pending'], 'closed', 'https://docs.stripe.com/issuing/controls/real-time-authorizations'),
461
+ // (Stripe also closes, reverses and expires one as the merchant and the clock act; in test mode the
462
+ // capture helper above closes it, and the twin serves no other)
463
+ ],
464
+ };
465
+
466
+ /** A Treasury flow's `status` as the twin's own operations move it: only a processing flow cancels. */
467
+ const flowCancel = (operation: string, code: string, name: string, network: Transition[]): StateField => ({
468
+ initial: 'processing',
469
+ transitions: [
470
+ { operation, from: ['processing'], to: 'canceled', refusal: { status: 400, code, message: `This ${name} cannot be canceled because it is no longer processing.` }, source: 'https://docs.stripe.com/api/treasury' },
471
+ ...network,
472
+ ],
473
+ });
474
+ /** An outbound flow on the network: Stripe posts or fails it and a posted one may come back returned (in
475
+ * test mode by test helpers the twin does not serve), so none of those moves is the twin's. */
476
+ const outbound = (_doc: string): Transition[] => [];
477
+
478
+ export const states = {
479
+ 'billing.meter': {
480
+ notState: ['event_time_window'],
481
+ state: { status: { initial: 'active', transitions: [
482
+ { operation: 'PostBillingMetersIdDeactivate', from: '*', to: 'inactive', source: 'https://docs.stripe.com/api/billing/meter/deactivate' },
483
+ { operation: 'PostBillingMetersIdReactivate', from: '*', to: 'active', source: 'https://docs.stripe.com/api/billing/meter/reactivate' },
484
+ ] } },
485
+ },
486
+ 'billing.credit_grant': {
487
+ notState: ['category'],
488
+ },
489
+ 'billing.alert': {
490
+ state: { status: { initial: 'active', transitions: [
491
+ { operation: 'PostBillingAlertsIdActivate', from: '*', to: 'active', source: 'https://docs.stripe.com/api/billing/alert/activate' },
492
+ { operation: 'PostBillingAlertsIdDeactivate', from: '*', to: 'inactive', source: 'https://docs.stripe.com/api/billing/alert/deactivate' },
493
+ { operation: 'PostBillingAlertsIdArchive', from: '*', to: 'archived', source: 'https://docs.stripe.com/api/billing/alert/archive' },
494
+ ] } },
495
+ },
496
+ payment_intent: {
497
+ state: { status: paymentIntentStatus },
498
+ notState: ['cancellation_reason', 'capture_method', 'confirmation_method', 'setup_future_usage'],
499
+ },
500
+ customer: {
501
+ notState: ['tax_exempt'],
502
+ },
503
+ tax_id: {
504
+ notState: ['type'],
505
+ },
506
+ customer_balance_transaction: {
507
+ notState: ['type'],
508
+ },
509
+ customer_cash_balance_transaction: {
510
+ notState: ['type'],
511
+ },
512
+ payment_source: {
513
+ state: { status: bankAccountStatus('https://docs.stripe.com/api/customer_bank_accounts/object#customer_bank_account_object-status') },
514
+ notState: ['allow_redisplay', 'business_type', 'regulated_status', 'type'],
515
+ },
516
+ source: {
517
+ state: {
518
+ status: {
519
+ initial: 'chargeable',
520
+ transitions: [
521
+ // (Stripe makes a redirect source chargeable when the customer authorizes it on the bank's page;
522
+ // the twin has no such page, so a non-card source stays pending)
523
+ // Stripe also fails a source the customer abandons, consumes a single-use one once charged and
524
+ // cancels one left unused; the twin's sources stay chargeable
525
+ ],
526
+ },
527
+ },
528
+ notState: ['allow_redisplay', 'type'],
529
+ },
530
+ charge: {
531
+ state: { status: chargeStatus, captured: chargeCaptured, paid: chargePaid, refunded: chargeRefunded },
532
+ },
533
+ refund: {
534
+ state: { status: refundStatus },
535
+ notState: ['pending_reason', 'reason'],
536
+ },
537
+ setup_intent: {
538
+ state: { status: setupIntentStatus },
539
+ notState: ['cancellation_reason'],
540
+ },
541
+ payment_method: {
542
+ notState: ['allow_redisplay', 'type'],
543
+ },
544
+ subscription: {
545
+ state: { status: subscriptionStatus },
546
+ notState: ['collection_method'],
547
+ },
548
+ invoice: {
549
+ state: { status: invoiceStatus },
550
+ notState: ['billing_reason', 'collection_method', 'customer_tax_exempt'],
551
+ },
552
+ 'checkout.session': {
553
+ state: { status: checkoutStatus, payment_status: checkoutPaymentStatus },
554
+ notState: ['billing_address_collection', 'customer_creation', 'locale', 'mode', 'origin_context', 'payment_method_collection', 'redirect_on_completion', 'submit_type', 'ui_mode'],
555
+ },
556
+ mandate: {
557
+ state: {
558
+ status: {
559
+ initial: 'active',
560
+ transitions: [
561
+ // a single-use mandate is spent by its payment: inactive "The mandate was rejected, revoked, or previously
562
+ // used, and may not be used to initiate future payments" (../engine/payment-intents.ts settleBankDebits)
563
+ by('vendor', ['active'], 'inactive', 'https://docs.stripe.com/api/mandates/object'),
564
+ // (Stripe also activates a pending mandate and deactivates one revoked; the twin's are active when made)
565
+ ],
566
+ },
567
+ },
568
+ notState: ['type'],
569
+ },
570
+ dispute: {
571
+ state: { status: disputeStatus },
572
+ notState: ['is_charge_refundable'],
573
+ },
574
+ payout: {
575
+ state: { status: payoutStatus },
576
+ notState: ['reconciliation_status', 'type'],
577
+ },
578
+ balance_transaction: {
579
+ state: { status: { initial: 'available', vendorInitial: 'pending', transitions: [by('time', ['pending'], 'available', 'https://docs.stripe.com/api/balance_transactions/object#balance_transaction_object-status')] } },
580
+ notState: ['balance_type', 'type'],
581
+ },
582
+ coupon: {
583
+ notState: ['duration'],
584
+ state: { valid: { initial: true, transitions: [by('time', ['true'], 'false', 'spec:/components/schemas/coupon/properties/redeem_by "Date after which the coupon can no longer be redeemed."')] } },
585
+ },
586
+ promotion_code: {
587
+ state: {
588
+ active: {
589
+ initial: true,
590
+ transitions: [
591
+ ...flag('PostPromotionCodesPromotionCode', 'https://docs.stripe.com/api/promotion_codes/update'),
592
+ ],
593
+ },
594
+ },
595
+ },
596
+ credit_note: {
597
+ state: { status: creditNoteStatus },
598
+ notState: ['reason', 'type'],
599
+ },
600
+ subscription_schedule: {
601
+ state: { status: scheduleStatus },
602
+ notState: ['end_behavior'],
603
+ },
604
+ 'entitlements.feature': {
605
+ state: { active: { initial: true, transitions: flag('PostEntitlementsFeaturesId', 'spec:PostEntitlementsFeaturesId "Update a feature’s metadata or permanently deactivate it."') } },
606
+ },
607
+ 'test_helpers.test_clock': {
608
+ state: {
609
+ status: {
610
+ initial: 'ready',
611
+ transitions: [
612
+ // "advancing: The clock has started to advance but hasn't reached the specified time"; "ready: The clock has
613
+ // completed advancing to the specified time" (docs.stripe.com/billing/testing/test-clocks/api-advanced-usage)
614
+ { operation: 'PostTestHelpersTestClocksTestClockAdvance', from: ['ready'], to: 'advancing', refusal: { status: 400, code: 'test_clock_not_ready', message: 'This test clock is still advancing.' }, source: 'https://docs.stripe.com/api/test_clocks/advance' },
615
+ by('vendor', ['advancing'], 'ready', 'https://docs.stripe.com/billing/testing/test-clocks/api-advanced-usage'),
616
+ // (Stripe may also end an advance in internal_failure; the twin's advances complete)
617
+ ],
618
+ },
619
+ },
620
+ },
621
+ webhook_endpoint: {
622
+ state: {
623
+ status: {
624
+ initial: 'enabled',
625
+ transitions: [
626
+ ...['enabled', 'disabled'].map((to) => ({ operation: 'PostWebhookEndpointsWebhookEndpoint', from: '*' as const, to, source: 'https://docs.stripe.com/api/webhook_endpoints/update#update_webhook_endpoint-disabled' })),
627
+ ],
628
+ },
629
+ },
630
+ },
631
+ account: {
632
+ notState: ['business_type', 'type'],
633
+ },
634
+ person: {
635
+ notState: ['political_exposure'],
636
+ },
637
+ capability: {
638
+ state: {
639
+ status: {
640
+ initial: 'unrequested',
641
+ transitions: [
642
+ ...['pending', 'inactive'].map((to) => ({ operation: 'PostAccountsAccountCapabilitiesCapability', from: '*' as const, to, source: 'https://docs.stripe.com/api/capabilities/update' })),
643
+ // Stripe reviews the account's requirements
644
+ by('vendor', ['pending', 'inactive'], 'active', 'https://docs.stripe.com/connect/account-capabilities#capability-status'),
645
+ by('vendor', ['active', 'pending'], 'inactive', 'https://docs.stripe.com/connect/account-capabilities#capability-status'),
646
+ ],
647
+ },
648
+ },
649
+ },
650
+ external_account: {
651
+ state: { status: bankAccountStatus('https://docs.stripe.com/api/external_account_bank_accounts/object#account_bank_account_object-status') },
652
+ notState: ['allow_redisplay', 'regulated_status'],
653
+ },
654
+ application_fee: {
655
+ state: { refunded: { initial: false, transitions: [
656
+ { operation: 'PostApplicationFeesIdRefunds', from: ['false'], to: 'true', source: 'https://docs.stripe.com/api/fee_refunds/create' },
657
+ // a refund of its charge with refund_application_fee refunds it in proportion
658
+ ...['PostRefunds', 'PostChargesChargeRefunds'].map((operation) => ({ operation, from: ['false'], to: 'true', source: 'https://docs.stripe.com/api/refunds/create#create_refund-refund_application_fee' })),
659
+ ] } },
660
+ },
661
+ file: {
662
+ notState: ['purpose'],
663
+ },
664
+ 'identity.verification_session': {
665
+ state: {
666
+ status: {
667
+ initial: 'requires_input',
668
+ transitions: [
669
+ by('external', ['requires_input'], 'processing', 'https://docs.stripe.com/identity/how-sessions-work'),
670
+ by('vendor', ['processing'], 'verified', 'https://docs.stripe.com/identity/how-sessions-work'),
671
+ by('vendor', ['processing'], 'requires_input', 'https://docs.stripe.com/identity/how-sessions-work'),
672
+ ],
673
+ },
674
+ },
675
+ notState: ['type'],
676
+ },
677
+ 'identity.verification_report': {
678
+ notState: ['type'],
679
+ },
680
+ 'billing_portal.session': {
681
+ notState: ['locale'],
682
+ },
683
+ 'billing_portal.configuration': {
684
+ state: { active: { initial: true, transitions: flag('PostBillingPortalConfigurationsConfiguration', 'https://docs.stripe.com/api/customer_portal/configurations/update') } },
685
+ notState: ['is_default'],
686
+ },
687
+ tax_rate: {
688
+ state: { active: { initial: true, transitions: flag('PostTaxRatesTaxRate', 'https://docs.stripe.com/api/tax_rates/update') } },
689
+ notState: ['jurisdiction_level', 'rate_type', 'state', 'tax_type'],
690
+ },
691
+ 'tax.settings': {
692
+ notState: ['status'],
693
+ },
694
+ 'tax.registration': {
695
+ state: {
696
+ // Stripe schedules a registration with a future active_from and expires one at expires_at; the twin's
697
+ // are active from the start and never expire
698
+ status: { initial: 'active', transitions: [] },
699
+ },
700
+ },
701
+ 'tax.transaction': {
702
+ notState: ['type'],
703
+ },
704
+ payment_link: {
705
+ state: { active: { initial: true, transitions: flag('PostPaymentLinksPaymentLink', 'https://docs.stripe.com/api/payment_links/payment_links/update') } },
706
+ notState: ['billing_address_collection', 'customer_creation', 'payment_method_collection', 'submit_type'],
707
+ },
708
+ quote: {
709
+ state: { status: quoteStatus },
710
+ notState: ['collection_method'],
711
+ },
712
+ review: {
713
+ state: {
714
+ open: {
715
+ initial: true,
716
+ transitions: [
717
+ // (Stripe also closes one when the payment is refunded or disputed; the twin's close only on approval)
718
+ { operation: 'PostReviewsReviewApprove', from: ['true'], to: 'false', refusal: { status: 400, code: 'review_already_closed', message: 'This review has already been closed.' }, source: 'https://docs.stripe.com/api/radar/reviews/approve' },
719
+ ],
720
+ },
721
+ },
722
+ notState: ['closed_reason', 'opened_reason'],
723
+ },
724
+ 'radar.value_list': {
725
+ notState: ['item_type'],
726
+ },
727
+ 'issuing.cardholder': {
728
+ state: { status: { initial: 'active', transitions: setBy('PostIssuingCardholdersCardholder', ['active', 'inactive', 'blocked'], 'https://docs.stripe.com/api/issuing/cardholders/update') } },
729
+ notState: ['type'],
730
+ },
731
+ 'issuing.card': {
732
+ state: { status: { initial: 'active', transitions: setBy('PostIssuingCardsCard', ['active', 'inactive', 'canceled'], 'https://docs.stripe.com/api/issuing/cards/update') } },
733
+ notState: ['cancellation_reason', 'replacement_reason', 'type'],
734
+ },
735
+ 'issuing.authorization': {
736
+ state: { status: issuingAuthorizationStatus },
737
+ notState: ['authorization_method', 'card_presence'],
738
+ },
739
+ 'issuing.transaction': {
740
+ notState: ['type', 'wallet'],
741
+ },
742
+ 'issuing.dispute': {
743
+ state: {
744
+ status: {
745
+ initial: 'unsubmitted',
746
+ transitions: [
747
+ { operation: 'PostIssuingDisputesDisputeSubmit', from: ['unsubmitted'], to: 'submitted', refusal: { status: 400, code: 'dispute_unsubmitted_required', message: 'This dispute has already been submitted (status {from}).' }, source: 'spec:PostIssuingDisputesDisputeSubmit "Submits an Issuing <code>Dispute</code> to the card network."' },
748
+ // (Stripe decides a submitted dispute won or lost and expires one never submitted; the twin decides none)
749
+ ],
750
+ },
751
+ },
752
+ notState: ['loss_reason'],
753
+ },
754
+ 'issuing.token': {
755
+ state: { status: { initial: 'active', transitions: [...setBy('PostIssuingTokensToken', ['active', 'deleted', 'suspended'], 'https://docs.stripe.com/api/issuing/tokens/update')] } },
756
+ notState: ['network', 'wallet_provider'],
757
+ },
758
+ 'issuing.personalization_design': {
759
+ state: {
760
+ status: {
761
+ // a new design waits on Stripe's review (docs.stripe.com/issuing/cards/physical/personalization-design)
762
+ initial: 'review',
763
+ transitions: [
764
+ ...setBy('PostTestHelpersIssuingPersonalizationDesignsPersonalizationDesignActivate', ['active'], 'spec:PostTestHelpersIssuingPersonalizationDesignsPersonalizationDesignActivate "to <code>active</code>"'),
765
+ ...setBy('PostTestHelpersIssuingPersonalizationDesignsPersonalizationDesignDeactivate', ['inactive'], 'spec:PostTestHelpersIssuingPersonalizationDesignsPersonalizationDesignDeactivate "to <code>inactive</code>"'),
766
+ ...setBy('PostTestHelpersIssuingPersonalizationDesignsPersonalizationDesignReject', ['rejected'], 'spec:PostTestHelpersIssuingPersonalizationDesignsPersonalizationDesignReject "to <code>rejected</code>"'),
767
+ // (outside test mode Stripe's review decides it; the twin is test mode, where these helpers do)
768
+ ],
769
+ },
770
+ },
771
+ },
772
+ 'terminal.reader': {
773
+ notState: ['device_type'],
774
+ // (a real reader goes offline and back; the twin's simulated readers stay online)
775
+ state: { status: { initial: 'online', transitions: [] } },
776
+ },
777
+ 'terminal.configuration': {
778
+ notState: ['is_account_default'],
779
+ },
780
+ topup: {
781
+ state: {
782
+ status: {
783
+ // a top-up starts pending (the create page's example answers "status": "pending") and its funds arrive days
784
+ // later: "USA (USD) ACH Debit Transfer 5 days" (docs.stripe.com/connect/top-ups; semantics/terminal.ts)
785
+ initial: 'pending',
786
+ transitions: [
787
+ { operation: 'PostTopupsTopupCancel', from: ['pending'], to: 'canceled', refusal: { status: 400, code: 'topup_unexpected_state', message: 'This top-up cannot be canceled because it has a status of {from}.' }, source: 'https://docs.stripe.com/api/topups/cancel' },
788
+ // to the Issuing balance alike: "Your top-ups can take up to 5 business days to become available"
789
+ // (docs.stripe.com/issuing/funding/balance)
790
+ by('vendor', ['pending'], 'succeeded', 'https://docs.stripe.com/connect/top-ups'),
791
+ // (Stripe also fails a top-up or reverses a settled one; the twin's top-ups do neither)
792
+ ],
793
+ },
794
+ },
795
+ notState: ['initiated_by'],
796
+ },
797
+ 'treasury.financial_account': {
798
+ state: { status: { initial: 'open', transitions: [] } },
799
+ notState: ['is_default'],
800
+ },
801
+ 'treasury.outbound_payment': {
802
+ state: { status: flowCancel('PostTreasuryOutboundPaymentsIdCancel', 'outbound_payment_not_cancelable', 'OutboundPayment', outbound('https://docs.stripe.com/treasury/moving-money/financial-accounts/out-of/outbound-payments')) },
803
+ },
804
+ 'treasury.outbound_transfer': {
805
+ state: { status: flowCancel('PostTreasuryOutboundTransfersOutboundTransferCancel', 'outbound_transfer_not_cancelable', 'OutboundTransfer', outbound('https://docs.stripe.com/treasury/moving-money/financial-accounts/out-of/outbound-transfers')) },
806
+ },
807
+ 'treasury.inbound_transfer': {
808
+ // "An InboundTransfer is processing if it is created and pending. The status changes to succeeded once the funds have
809
+ // been "confirmed""; in test mode the succeed helper confirms them (docs.stripe.com/api/treasury/inbound_transfers)
810
+ state: { status: flowCancel('PostTreasuryInboundTransfersInboundTransferCancel', 'inbound_transfer_not_cancelable', 'InboundTransfer', [
811
+ { operation: 'PostTestHelpersTreasuryInboundTransfersIdSucceed', from: ['processing'], to: 'succeeded', refusal: { status: 400, code: 'inbound_transfer_not_processing', message: 'This InboundTransfer cannot succeed because it is no longer processing.' }, source: 'https://docs.stripe.com/api/treasury/inbound_transfers' },
812
+ ]) },
813
+ },
814
+ 'treasury.received_credit': {
815
+ state: { status: { initial: 'succeeded', transitions: [] } },
816
+ notState: ['failure_code', 'network'],
817
+ },
818
+ 'treasury.received_debit': {
819
+ state: { status: { initial: 'succeeded', transitions: [] } },
820
+ notState: ['failure_code', 'network'],
821
+ },
822
+ 'treasury.transaction': {
823
+ notState: ['flow_type'],
824
+ // void: "The Transaction never impacted the balance. For example, a Transaction would enter this state if an
825
+ // OutboundPayment was initiated but then canceled" (docs.stripe.com/api/treasury/transactions/object); canceling an
826
+ // outbound flow voids its open transaction (semantics/treasury.ts). (Stripe also posts an open transaction as its
827
+ // flow settles; the twin's outbound flows stay processing)
828
+ state: { status: { initial: 'open', transitions: [
829
+ ...['PostTreasuryOutboundPaymentsIdCancel', 'PostTreasuryOutboundTransfersOutboundTransferCancel', 'PostTreasuryInboundTransfersInboundTransferCancel'].map((operation) => ({ operation, from: ['open'], to: 'void', source: 'https://docs.stripe.com/api/treasury/transactions/object' })),
830
+ // an inbound transfer's transaction posts when it succeeds ("a transaction is created and posted")
831
+ { operation: 'PostTestHelpersTreasuryInboundTransfersIdSucceed', from: ['open'], to: 'posted', source: 'https://docs.stripe.com/api/treasury/inbound_transfers' },
832
+ ] } },
833
+ },
834
+ 'treasury.transaction_entry': {
835
+ notState: ['flow_type', 'type'],
836
+ },
837
+ 'climate.order': {
838
+ state: {
839
+ status: {
840
+ // an order is created confirmed: the create page's example answers "status": "confirmed" with confirmed_at set
841
+ // (docs.stripe.com/api/climate/order/create)
842
+ initial: 'confirmed',
843
+ transitions: [
844
+ { operation: 'PostClimateOrdersOrderCancel', from: ['awaiting_funds', 'confirmed', 'open'], to: 'canceled', refusal: { status: 400, code: 'climate_order_not_cancelable', message: 'This order can no longer be canceled because it is {from}.' }, source: 'https://docs.stripe.com/api/climate/order/cancel' },
845
+ // funded, confirmed by the supplier, then delivered
846
+ // (Stripe funds, confirms and delivers an order over months; the twin's orders stay where they are made)
847
+ ],
848
+ },
849
+ },
850
+ notState: ['cancellation_reason'],
851
+ },
852
+ 'financial_connections.account': {
853
+ state: {
854
+ status: {
855
+ initial: 'active',
856
+ transitions: [
857
+ { operation: 'PostFinancialConnectionsAccountsAccountDisconnect', from: '*', to: 'disconnected', source: 'https://docs.stripe.com/api/financial_connections/accounts/disconnect' },
858
+ // (Stripe marks an account inactive when the bank link breaks, and active again; the twin's links hold)
859
+ ],
860
+ },
861
+ },
862
+ notState: ['category', 'subcategory'],
863
+ },
864
+ 'financial_connections.transaction': {
865
+ // (a bank's pending transaction posts or is voided at Stripe; the twin's arrive posted)
866
+ state: { status: { initial: 'posted', transitions: [] } },
867
+ },
868
+ 'reporting.report_run': {
869
+ // "When first created, the object appears with status="pending""; "When the run completes, Stripe updates the
870
+ // object, and it has a status of succeeded" (docs.stripe.com/reports/api; ../engine/platform.ts finishReportRuns).
871
+ // (Stripe may also fail a run; the twin's runs succeed)
872
+ state: { status: { initial: 'pending', transitions: [by('vendor', ['pending'], 'succeeded', 'https://docs.stripe.com/reports/api')] } },
873
+ },
874
+ product: {
875
+ state: { active: { initial: true, transitions: flag('PostProductsId', 'https://docs.stripe.com/api/products/update#update_product-active') } },
876
+ },
877
+ price: {
878
+ notState: ['billing_scheme', 'tax_behavior', 'tiers_mode', 'type'],
879
+ // deleting a plan leaves its price for its subscribers, inactive: "Deleting plans means new subscribers can’t be added.
880
+ // Existing subscribers aren’t affected." (docs.stripe.com/api/plans/delete; semantics/plans.ts)
881
+ state: { active: { initial: true, transitions: [...flag('PostPricesPrice', 'https://docs.stripe.com/api/prices/update#update_price-active'), { operation: 'DeletePlansPlan', from: ['true'], to: 'false', source: 'https://docs.stripe.com/api/plans/delete' }] } },
882
+ },
883
+ } satisfies Record<string, { state?: Record<string, StateField>; notState?: string[] }>;