@fantastic.dev/better-stripe 0.6.1 → 0.8.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 (359) hide show
  1. package/CHANGELOG.md +28 -16
  2. package/README.md +130 -90
  3. package/dist/client/billing/checkout.d.ts +1 -1
  4. package/dist/client/billing/checkout.d.ts.map +1 -1
  5. package/dist/client/billing/checkout.js +7 -2
  6. package/dist/client/billing/checkout.js.map +1 -1
  7. package/dist/client/connect/paymentMethods.d.ts.map +1 -1
  8. package/dist/client/connect/paymentMethods.js.map +1 -1
  9. package/dist/client/connect/refundActor.d.ts.map +1 -1
  10. package/dist/client/connect/refundActor.js.map +1 -1
  11. package/dist/client/connect/refunds.d.ts.map +1 -1
  12. package/dist/client/connect/refunds.js.map +1 -1
  13. package/dist/client/connect/transfers.d.ts.map +1 -1
  14. package/dist/client/connect/transfers.js +15 -4
  15. package/dist/client/connect/transfers.js.map +1 -1
  16. package/dist/client/core/accountDefaults.d.ts +6 -0
  17. package/dist/client/core/accountDefaults.d.ts.map +1 -0
  18. package/dist/client/core/accountDefaults.js +15 -0
  19. package/dist/client/core/accountDefaults.js.map +1 -0
  20. package/dist/client/core/accounts.d.ts +1 -5
  21. package/dist/client/core/accounts.d.ts.map +1 -1
  22. package/dist/client/core/accounts.js +2 -14
  23. package/dist/client/core/accounts.js.map +1 -1
  24. package/dist/client/core/fees.d.ts.map +1 -1
  25. package/dist/client/core/fees.js +7 -2
  26. package/dist/client/core/fees.js.map +1 -1
  27. package/dist/client/index.d.ts +1 -1
  28. package/dist/client/index.d.ts.map +1 -1
  29. package/dist/client/products/prices.d.ts.map +1 -1
  30. package/dist/client/products/prices.js.map +1 -1
  31. package/dist/client/products/products.d.ts.map +1 -1
  32. package/dist/client/products/products.js +3 -1
  33. package/dist/client/products/products.js.map +1 -1
  34. package/dist/client/utils/owner.d.ts.map +1 -1
  35. package/dist/client/utils/owner.js +3 -1
  36. package/dist/client/utils/owner.js.map +1 -1
  37. package/dist/client/utils/stripeDashboardUrl.d.ts.map +1 -1
  38. package/dist/client/utils/stripeDashboardUrl.js.map +1 -1
  39. package/dist/client/webhooks/helpers.d.ts +10 -0
  40. package/dist/client/webhooks/helpers.d.ts.map +1 -1
  41. package/dist/client/webhooks/helpers.js +18 -0
  42. package/dist/client/webhooks/helpers.js.map +1 -1
  43. package/dist/client/webhooks/processors.d.ts.map +1 -1
  44. package/dist/client/webhooks/processors.js +10 -24
  45. package/dist/client/webhooks/processors.js.map +1 -1
  46. package/dist/component/_generated/component.d.ts +34 -0
  47. package/dist/component/_generated/component.d.ts.map +1 -1
  48. package/dist/component/billing/queries.d.ts +36 -0
  49. package/dist/component/billing/queries.d.ts.map +1 -1
  50. package/dist/component/billing/queries.js +10 -0
  51. package/dist/component/billing/queries.js.map +1 -1
  52. package/dist/component/billing/schema.d.ts +1 -0
  53. package/dist/component/billing/schema.d.ts.map +1 -1
  54. package/dist/component/billing/schema.js +1 -0
  55. package/dist/component/billing/schema.js.map +1 -1
  56. package/dist/component/connect/mutations.d.ts.map +1 -1
  57. package/dist/component/connect/mutations.js +28 -28
  58. package/dist/component/connect/mutations.js.map +1 -1
  59. package/dist/component/connect/schema.d.ts.map +1 -1
  60. package/dist/component/connect/schema.js.map +1 -1
  61. package/dist/component/lib/paymentSeller.d.ts +3 -0
  62. package/dist/component/lib/paymentSeller.d.ts.map +1 -0
  63. package/dist/component/lib/paymentSeller.js +10 -0
  64. package/dist/component/lib/paymentSeller.js.map +1 -0
  65. package/dist/component/lib/reversals.d.ts +10 -0
  66. package/dist/component/lib/reversals.d.ts.map +1 -1
  67. package/dist/component/lib/reversals.js +17 -0
  68. package/dist/component/lib/reversals.js.map +1 -1
  69. package/dist/component/schema.d.ts +1 -0
  70. package/dist/react/components/ConnectProvider.d.ts +1 -1
  71. package/dist/react/components/ConnectProvider.d.ts.map +1 -1
  72. package/dist/react/components/ConnectProvider.js +18 -4
  73. package/dist/react/components/ConnectProvider.js.map +1 -1
  74. package/dist/react/components/ConnectStatusBadge.d.ts.map +1 -1
  75. package/dist/react/components/ConnectStatusBadge.js.map +1 -1
  76. package/dist/react/components/EmbeddedDisputes.d.ts +1 -1
  77. package/dist/react/components/EmbeddedDisputes.d.ts.map +1 -1
  78. package/dist/react/components/EmbeddedDisputes.js +1 -1
  79. package/dist/react/components/EmbeddedDisputes.js.map +1 -1
  80. package/dist/react/components/SplitBreakdown.d.ts.map +1 -1
  81. package/dist/react/components/SplitBreakdown.js +12 -2
  82. package/dist/react/components/SplitBreakdown.js.map +1 -1
  83. package/dist/react/hooks/useCheckoutSession.d.ts.map +1 -1
  84. package/dist/react/hooks/useCheckoutSession.js.map +1 -1
  85. package/dist/react/hooks/useConfirmPayment.d.ts.map +1 -1
  86. package/dist/react/hooks/useConfirmPayment.js.map +1 -1
  87. package/dist/react/index.d.ts +1 -0
  88. package/dist/react/index.d.ts.map +1 -1
  89. package/dist/react/index.js +2 -0
  90. package/dist/react/index.js.map +1 -1
  91. package/dist/react/workflows/Account.d.ts +67 -0
  92. package/dist/react/workflows/Account.d.ts.map +1 -0
  93. package/dist/react/workflows/Account.js +74 -0
  94. package/dist/react/workflows/Account.js.map +1 -0
  95. package/dist/react/workflows/Billing.d.ts +60 -0
  96. package/dist/react/workflows/Billing.d.ts.map +1 -0
  97. package/dist/react/workflows/Billing.js +84 -0
  98. package/dist/react/workflows/Billing.js.map +1 -0
  99. package/dist/react/workflows/BillingPlans.d.ts +45 -0
  100. package/dist/react/workflows/BillingPlans.d.ts.map +1 -0
  101. package/dist/react/workflows/BillingPlans.js +51 -0
  102. package/dist/react/workflows/BillingPlans.js.map +1 -0
  103. package/dist/react/workflows/Checkout.d.ts +46 -0
  104. package/dist/react/workflows/Checkout.d.ts.map +1 -0
  105. package/dist/react/workflows/Checkout.js +61 -0
  106. package/dist/react/workflows/Checkout.js.map +1 -0
  107. package/dist/react/workflows/CheckoutChooser.d.ts +20 -0
  108. package/dist/react/workflows/CheckoutChooser.d.ts.map +1 -0
  109. package/dist/react/workflows/CheckoutChooser.js +24 -0
  110. package/dist/react/workflows/CheckoutChooser.js.map +1 -0
  111. package/dist/react/workflows/CheckoutForms.d.ts +26 -0
  112. package/dist/react/workflows/CheckoutForms.d.ts.map +1 -0
  113. package/dist/react/workflows/CheckoutForms.js +126 -0
  114. package/dist/react/workflows/CheckoutForms.js.map +1 -0
  115. package/dist/react/workflows/ClipboardButton.d.ts +17 -0
  116. package/dist/react/workflows/ClipboardButton.d.ts.map +1 -0
  117. package/dist/react/workflows/ClipboardButton.js +35 -0
  118. package/dist/react/workflows/ClipboardButton.js.map +1 -0
  119. package/dist/react/workflows/Collection.d.ts +30 -0
  120. package/dist/react/workflows/Collection.d.ts.map +1 -0
  121. package/dist/react/workflows/Collection.js +25 -0
  122. package/dist/react/workflows/Collection.js.map +1 -0
  123. package/dist/react/workflows/Collections.d.ts +56 -0
  124. package/dist/react/workflows/Collections.d.ts.map +1 -0
  125. package/dist/react/workflows/Collections.js +111 -0
  126. package/dist/react/workflows/Collections.js.map +1 -0
  127. package/dist/react/workflows/Connect.d.ts +19 -0
  128. package/dist/react/workflows/Connect.d.ts.map +1 -0
  129. package/dist/react/workflows/Connect.js +43 -0
  130. package/dist/react/workflows/Connect.js.map +1 -0
  131. package/dist/react/workflows/Costs.d.ts +48 -0
  132. package/dist/react/workflows/Costs.d.ts.map +1 -0
  133. package/dist/react/workflows/Costs.js +66 -0
  134. package/dist/react/workflows/Costs.js.map +1 -0
  135. package/dist/react/workflows/Disputes.d.ts +36 -0
  136. package/dist/react/workflows/Disputes.d.ts.map +1 -0
  137. package/dist/react/workflows/Disputes.js +74 -0
  138. package/dist/react/workflows/Disputes.js.map +1 -0
  139. package/dist/react/workflows/Earnings.d.ts +42 -0
  140. package/dist/react/workflows/Earnings.d.ts.map +1 -0
  141. package/dist/react/workflows/Earnings.js +38 -0
  142. package/dist/react/workflows/Earnings.js.map +1 -0
  143. package/dist/react/workflows/Financials.d.ts +43 -0
  144. package/dist/react/workflows/Financials.d.ts.map +1 -0
  145. package/dist/react/workflows/Financials.js +57 -0
  146. package/dist/react/workflows/Financials.js.map +1 -0
  147. package/dist/react/workflows/IntegrationSwitch.d.ts +23 -0
  148. package/dist/react/workflows/IntegrationSwitch.d.ts.map +1 -0
  149. package/dist/react/workflows/IntegrationSwitch.js +31 -0
  150. package/dist/react/workflows/IntegrationSwitch.js.map +1 -0
  151. package/dist/react/workflows/Onboarding.d.ts +56 -0
  152. package/dist/react/workflows/Onboarding.d.ts.map +1 -0
  153. package/dist/react/workflows/Onboarding.js +86 -0
  154. package/dist/react/workflows/Onboarding.js.map +1 -0
  155. package/dist/react/workflows/Overview.d.ts +51 -0
  156. package/dist/react/workflows/Overview.d.ts.map +1 -0
  157. package/dist/react/workflows/Overview.js +63 -0
  158. package/dist/react/workflows/Overview.js.map +1 -0
  159. package/dist/react/workflows/PaymentMethods.d.ts +35 -0
  160. package/dist/react/workflows/PaymentMethods.d.ts.map +1 -0
  161. package/dist/react/workflows/PaymentMethods.js +63 -0
  162. package/dist/react/workflows/PaymentMethods.js.map +1 -0
  163. package/dist/react/workflows/PaymentReceipt.d.ts +20 -0
  164. package/dist/react/workflows/PaymentReceipt.d.ts.map +1 -0
  165. package/dist/react/workflows/PaymentReceipt.js +24 -0
  166. package/dist/react/workflows/PaymentReceipt.js.map +1 -0
  167. package/dist/react/workflows/Payouts.d.ts +47 -0
  168. package/dist/react/workflows/Payouts.d.ts.map +1 -0
  169. package/dist/react/workflows/Payouts.js +87 -0
  170. package/dist/react/workflows/Payouts.js.map +1 -0
  171. package/dist/react/workflows/Products.d.ts +92 -0
  172. package/dist/react/workflows/Products.d.ts.map +1 -0
  173. package/dist/react/workflows/Products.js +179 -0
  174. package/dist/react/workflows/Products.js.map +1 -0
  175. package/dist/react/workflows/ReferralLinks.d.ts +26 -0
  176. package/dist/react/workflows/ReferralLinks.d.ts.map +1 -0
  177. package/dist/react/workflows/ReferralLinks.js +30 -0
  178. package/dist/react/workflows/ReferralLinks.js.map +1 -0
  179. package/dist/react/workflows/Refunds.d.ts +72 -0
  180. package/dist/react/workflows/Refunds.d.ts.map +1 -0
  181. package/dist/react/workflows/Refunds.js +95 -0
  182. package/dist/react/workflows/Refunds.js.map +1 -0
  183. package/dist/react/workflows/Setup.d.ts +50 -0
  184. package/dist/react/workflows/Setup.d.ts.map +1 -0
  185. package/dist/react/workflows/Setup.js +59 -0
  186. package/dist/react/workflows/Setup.js.map +1 -0
  187. package/dist/react/workflows/Storefront.d.ts +53 -0
  188. package/dist/react/workflows/Storefront.d.ts.map +1 -0
  189. package/dist/react/workflows/Storefront.js +44 -0
  190. package/dist/react/workflows/Storefront.js.map +1 -0
  191. package/dist/react/workflows/SubscriptionOverview.d.ts +13 -0
  192. package/dist/react/workflows/SubscriptionOverview.d.ts.map +1 -0
  193. package/dist/react/workflows/SubscriptionOverview.js +26 -0
  194. package/dist/react/workflows/SubscriptionOverview.js.map +1 -0
  195. package/dist/react/workflows/Subscriptions.d.ts +92 -0
  196. package/dist/react/workflows/Subscriptions.d.ts.map +1 -0
  197. package/dist/react/workflows/Subscriptions.js +149 -0
  198. package/dist/react/workflows/Subscriptions.js.map +1 -0
  199. package/dist/react/workflows/Tasks.d.ts +40 -0
  200. package/dist/react/workflows/Tasks.d.ts.map +1 -0
  201. package/dist/react/workflows/Tasks.js +113 -0
  202. package/dist/react/workflows/Tasks.js.map +1 -0
  203. package/dist/react/workflows/checkout-options.d.ts +37 -0
  204. package/dist/react/workflows/checkout-options.d.ts.map +1 -0
  205. package/dist/react/workflows/checkout-options.js +43 -0
  206. package/dist/react/workflows/checkout-options.js.map +1 -0
  207. package/dist/react/workflows/current-subscription.d.ts +11 -0
  208. package/dist/react/workflows/current-subscription.d.ts.map +1 -0
  209. package/dist/react/workflows/current-subscription.js +14 -0
  210. package/dist/react/workflows/current-subscription.js.map +1 -0
  211. package/dist/react/workflows/filters.d.ts +17 -0
  212. package/dist/react/workflows/filters.d.ts.map +1 -0
  213. package/dist/react/workflows/filters.js +23 -0
  214. package/dist/react/workflows/filters.js.map +1 -0
  215. package/dist/react/workflows/index.d.ts +70 -0
  216. package/dist/react/workflows/index.d.ts.map +1 -0
  217. package/dist/react/workflows/index.js +38 -0
  218. package/dist/react/workflows/index.js.map +1 -0
  219. package/dist/react/workflows/useWorkflowAction.d.ts +11 -0
  220. package/dist/react/workflows/useWorkflowAction.d.ts.map +1 -0
  221. package/dist/react/workflows/useWorkflowAction.js +68 -0
  222. package/dist/react/workflows/useWorkflowAction.js.map +1 -0
  223. package/dist/react/workflows/useWorkflowResource.d.ts +9 -0
  224. package/dist/react/workflows/useWorkflowResource.d.ts.map +1 -0
  225. package/dist/react/workflows/useWorkflowResource.js +67 -0
  226. package/dist/react/workflows/useWorkflowResource.js.map +1 -0
  227. package/docs/react-workflows-audit.md +66 -0
  228. package/docs/react-workflows.md +231 -0
  229. package/package.json +19 -3
  230. package/src/client/billing/checkout-ui-modes.test.ts +49 -0
  231. package/src/client/billing/checkout.ts +8 -3
  232. package/src/client/billing/invoices.test.ts +12 -6
  233. package/src/client/connect/paymentMethods.test.ts +3 -1
  234. package/src/client/connect/paymentMethods.ts +4 -1
  235. package/src/client/connect/refundActor.ts +1 -2
  236. package/src/client/connect/refunds.test.ts +35 -10
  237. package/src/client/connect/refunds.ts +4 -1
  238. package/src/client/connect/transfers.test.ts +66 -12
  239. package/src/client/connect/transfers.ts +32 -8
  240. package/src/client/core/accountDefaults.ts +15 -0
  241. package/src/client/core/accounts.ts +14 -17
  242. package/src/client/core/config.test.ts +2 -1
  243. package/src/client/core/descriptors.test.ts +6 -4
  244. package/src/client/core/fees.test.ts +20 -28
  245. package/src/client/core/fees.ts +9 -2
  246. package/src/client/index.test.ts +22 -22
  247. package/src/client/index.ts +1 -1
  248. package/src/client/products/prices.test.ts +8 -2
  249. package/src/client/products/prices.ts +4 -1
  250. package/src/client/products/products.test.ts +61 -20
  251. package/src/client/products/products.ts +3 -1
  252. package/src/client/utils/data.test.ts +3 -1
  253. package/src/client/utils/owner.test.ts +4 -1
  254. package/src/client/utils/owner.ts +5 -1
  255. package/src/client/utils/stripeDashboardUrl.ts +1 -4
  256. package/src/client/webhooks/handler.test.ts +16 -19
  257. package/src/client/webhooks/helpers.test.ts +26 -13
  258. package/src/client/webhooks/helpers.ts +23 -0
  259. package/src/client/webhooks/hooks.test.ts +1 -2
  260. package/src/client/webhooks/processors.test.ts +34 -34
  261. package/src/client/webhooks/processors.ts +9 -26
  262. package/src/client/webhooks.test.ts +1 -2
  263. package/src/component/_generated/api.ts +2 -0
  264. package/src/component/_generated/component.ts +46 -0
  265. package/src/component/billing/queries.ts +12 -0
  266. package/src/component/billing/schema.ts +1 -0
  267. package/src/component/connect/mutations.ts +34 -35
  268. package/src/component/connect/schema.ts +4 -3
  269. package/src/component/connect.test.ts +1 -5
  270. package/src/component/lib/paymentSeller.ts +15 -0
  271. package/src/component/lib/reversals.ts +30 -2
  272. package/src/component/seller-case-ownership.test.ts +61 -0
  273. package/src/component/store-subscriptions.test.ts +32 -0
  274. package/src/component/subscription-scoping.test.ts +5 -1
  275. package/src/component/triggers.test.ts +7 -4
  276. package/src/react/components/BuyerBillingView.render.test.tsx +7 -2
  277. package/src/react/components/ConnectProvider.live.test.tsx +61 -0
  278. package/src/react/components/ConnectProvider.tsx +18 -4
  279. package/src/react/components/ConnectStatusBadge.tsx +1 -4
  280. package/src/react/components/DisputeDetail.render.test.tsx +5 -1
  281. package/src/react/components/EarningsSummary.render.test.tsx +2 -6
  282. package/src/react/components/EmbeddedDisputes.render.test.tsx +7 -5
  283. package/src/react/components/EmbeddedDisputes.tsx +4 -1
  284. package/src/react/components/EvidenceForm.render.test.tsx +2 -8
  285. package/src/react/components/SplitBreakdown.render.test.tsx +28 -5
  286. package/src/react/components/SplitBreakdown.tsx +12 -2
  287. package/src/react/hooks/useCheckoutSession.ts +1 -2
  288. package/src/react/hooks/useConfirmPayment.ts +1 -2
  289. package/src/react/hooks/useEarnings.test.ts +43 -8
  290. package/src/react/hooks/useStripeMode.test.ts +5 -8
  291. package/src/react/index.ts +3 -0
  292. package/src/react/workflows/Account.test.tsx +31 -0
  293. package/src/react/workflows/Account.tsx +183 -0
  294. package/src/react/workflows/Billing.test.tsx +45 -0
  295. package/src/react/workflows/Billing.tsx +213 -0
  296. package/src/react/workflows/BillingPlans.test.tsx +31 -0
  297. package/src/react/workflows/BillingPlans.tsx +130 -0
  298. package/src/react/workflows/Checkout.test.tsx +118 -0
  299. package/src/react/workflows/Checkout.tsx +135 -0
  300. package/src/react/workflows/CheckoutChooser.test.tsx +44 -0
  301. package/src/react/workflows/CheckoutChooser.tsx +77 -0
  302. package/src/react/workflows/CheckoutForm.test.tsx +66 -0
  303. package/src/react/workflows/CheckoutForms.test.tsx +123 -0
  304. package/src/react/workflows/CheckoutForms.tsx +247 -0
  305. package/src/react/workflows/ClipboardButton.test.tsx +34 -0
  306. package/src/react/workflows/ClipboardButton.tsx +67 -0
  307. package/src/react/workflows/Collection.tsx +76 -0
  308. package/src/react/workflows/Collections.test.tsx +86 -0
  309. package/src/react/workflows/Collections.tsx +213 -0
  310. package/src/react/workflows/Connect.test.tsx +50 -0
  311. package/src/react/workflows/Connect.tsx +107 -0
  312. package/src/react/workflows/Costs.test.tsx +41 -0
  313. package/src/react/workflows/Costs.tsx +133 -0
  314. package/src/react/workflows/Disputes.test.tsx +25 -0
  315. package/src/react/workflows/Disputes.tsx +164 -0
  316. package/src/react/workflows/Earnings.test.ts +19 -0
  317. package/src/react/workflows/Earnings.tsx +84 -0
  318. package/src/react/workflows/Financials.test.tsx +35 -0
  319. package/src/react/workflows/Financials.tsx +117 -0
  320. package/src/react/workflows/IntegrationSwitch.test.tsx +36 -0
  321. package/src/react/workflows/IntegrationSwitch.tsx +63 -0
  322. package/src/react/workflows/Onboarding.test.tsx +75 -0
  323. package/src/react/workflows/Onboarding.tsx +171 -0
  324. package/src/react/workflows/Overview.test.tsx +57 -0
  325. package/src/react/workflows/Overview.tsx +123 -0
  326. package/src/react/workflows/PaymentMethods.test.tsx +60 -0
  327. package/src/react/workflows/PaymentMethods.tsx +117 -0
  328. package/src/react/workflows/PaymentReceipt.test.tsx +24 -0
  329. package/src/react/workflows/PaymentReceipt.tsx +46 -0
  330. package/src/react/workflows/Payouts.test.tsx +82 -0
  331. package/src/react/workflows/Payouts.tsx +212 -0
  332. package/src/react/workflows/Products.test.tsx +90 -0
  333. package/src/react/workflows/Products.tsx +377 -0
  334. package/src/react/workflows/ReferralLinks.test.tsx +39 -0
  335. package/src/react/workflows/ReferralLinks.tsx +75 -0
  336. package/src/react/workflows/Refunds.test.tsx +75 -0
  337. package/src/react/workflows/Refunds.tsx +223 -0
  338. package/src/react/workflows/Setup.test.tsx +25 -0
  339. package/src/react/workflows/Setup.tsx +166 -0
  340. package/src/react/workflows/Storefront.test.tsx +82 -0
  341. package/src/react/workflows/Storefront.tsx +138 -0
  342. package/src/react/workflows/SubscriptionOverview.test.tsx +27 -0
  343. package/src/react/workflows/SubscriptionOverview.tsx +48 -0
  344. package/src/react/workflows/Subscriptions.test.tsx +61 -0
  345. package/src/react/workflows/Subscriptions.tsx +282 -0
  346. package/src/react/workflows/Tasks.test.tsx +23 -0
  347. package/src/react/workflows/Tasks.tsx +199 -0
  348. package/src/react/workflows/checkout-options.ts +42 -0
  349. package/src/react/workflows/current-subscription.test.ts +29 -0
  350. package/src/react/workflows/current-subscription.ts +25 -0
  351. package/src/react/workflows/filters.test.ts +12 -0
  352. package/src/react/workflows/filters.ts +22 -0
  353. package/src/react/workflows/index.ts +238 -0
  354. package/src/react/workflows/native-interactions.test.tsx +73 -0
  355. package/src/react/workflows/public-workflows.test.tsx +216 -0
  356. package/src/react/workflows/useWorkflowAction.test.tsx +54 -0
  357. package/src/react/workflows/useWorkflowAction.ts +75 -0
  358. package/src/react/workflows/useWorkflowResource.test.tsx +41 -0
  359. package/src/react/workflows/useWorkflowResource.ts +78 -0
@@ -19,10 +19,7 @@ import { renderToStaticMarkup } from "react-dom/server";
19
19
  import { describe, expect, it, vi } from "vitest";
20
20
 
21
21
  import { EvidenceForm as BarrelExport } from "../index.js";
22
- import {
23
- EvidenceForm,
24
- type EvidenceFormRenderProps,
25
- } from "./EvidenceForm.js";
22
+ import { EvidenceForm, type EvidenceFormRenderProps } from "./EvidenceForm.js";
26
23
 
27
24
  const allFields = {
28
25
  productDescription: "Ceramics Masterclass, lifetime access",
@@ -33,10 +30,7 @@ const allFields = {
33
30
 
34
31
  /** Render via the children prop and hand back the captured render props. */
35
32
  function capture(
36
- props: Omit<
37
- Parameters<typeof EvidenceForm>[0],
38
- "children"
39
- >,
33
+ props: Omit<Parameters<typeof EvidenceForm>[0], "children">,
40
34
  ): EvidenceFormRenderProps {
41
35
  let received: EvidenceFormRenderProps | undefined;
42
36
  renderToStaticMarkup(
@@ -34,8 +34,18 @@ const leg = (over: Record<string, unknown>) => ({
34
34
 
35
35
  const totals = {
36
36
  legs: [
37
- leg({ stripeTransferId: "tr_store", role: "store", amount: 8000, net: 8000 }),
38
- leg({ stripeTransferId: "tr_aff", role: "affiliate", amount: 1000, net: 1000 }),
37
+ leg({
38
+ stripeTransferId: "tr_store",
39
+ role: "store",
40
+ amount: 8000,
41
+ net: 8000,
42
+ }),
43
+ leg({
44
+ stripeTransferId: "tr_aff",
45
+ role: "affiliate",
46
+ amount: 1000,
47
+ net: 1000,
48
+ }),
39
49
  ],
40
50
  store: 8000,
41
51
  affiliate: 1000,
@@ -79,7 +89,10 @@ describe("SplitBreakdown", () => {
79
89
  createElement(SplitBreakdown, {
80
90
  breakdown: {
81
91
  ...totals,
82
- legs: [...totals.legs, leg({ stripeTransferId: "tr_misc", amount: 500, net: 500 })],
92
+ legs: [
93
+ ...totals.legs,
94
+ leg({ stripeTransferId: "tr_misc", amount: 500, net: 500 }),
95
+ ],
83
96
  other: 500,
84
97
  recipientsTotal: 9500,
85
98
  platform: 500,
@@ -136,8 +149,18 @@ describe("SplitBreakdown", () => {
136
149
  expect(received!.breakdown).toBe(totals);
137
150
  expect(received!.lines).toEqual([
138
151
  { key: "store", label: "Store", amount: 8000, amountLabel: "$80.00" },
139
- { key: "affiliate", label: "Affiliate", amount: 1000, amountLabel: "$10.00" },
140
- { key: "platform", label: "Platform", amount: 1000, amountLabel: "$10.00" },
152
+ {
153
+ key: "affiliate",
154
+ label: "Affiliate",
155
+ amount: 1000,
156
+ amountLabel: "$10.00",
157
+ },
158
+ {
159
+ key: "platform",
160
+ label: "Platform",
161
+ amount: 1000,
162
+ amountLabel: "$10.00",
163
+ },
141
164
  ]);
142
165
  expect(html).toBe("<p>3</p>");
143
166
  });
@@ -75,7 +75,11 @@ export function SplitBreakdown({
75
75
  const money = (amount: number) => formatPrice(amount, currency, locale);
76
76
 
77
77
  const lines: SplitBreakdownLine[] = [
78
- { key: "store" as const, label: labels?.store ?? "Store", amount: breakdown.store },
78
+ {
79
+ key: "store" as const,
80
+ label: labels?.store ?? "Store",
81
+ amount: breakdown.store,
82
+ },
79
83
  {
80
84
  key: "affiliate" as const,
81
85
  label: labels?.affiliate ?? "Affiliate",
@@ -83,7 +87,13 @@ export function SplitBreakdown({
83
87
  },
84
88
  // The catch-all bucket only earns a line when it carries money.
85
89
  ...(breakdown.other > 0
86
- ? [{ key: "other" as const, label: labels?.other ?? "Other", amount: breakdown.other }]
90
+ ? [
91
+ {
92
+ key: "other" as const,
93
+ label: labels?.other ?? "Other",
94
+ amount: breakdown.other,
95
+ },
96
+ ]
87
97
  : []),
88
98
  {
89
99
  key: "platform" as const,
@@ -14,8 +14,7 @@ function extractErrorMessage(error: unknown, fallback: string): string {
14
14
  * Result of a checkout confirmation attempt.
15
15
  */
16
16
  export type CheckoutConfirmResult =
17
- | { type: "success" }
18
- | { type: "error"; message: string };
17
+ { type: "success" } | { type: "error"; message: string };
19
18
 
20
19
  /**
21
20
  * Checkout session state and actions.
@@ -8,8 +8,7 @@ import { useElements, useStripe } from "@stripe/react-stripe-js";
8
8
  * Normalized result from a Stripe confirmation operation.
9
9
  */
10
10
  export type StripeConfirmResult =
11
- | { success: true }
12
- | { success: false; error: string };
11
+ { success: true } | { success: false; error: string };
13
12
 
14
13
  /**
15
14
  * Hook for confirming a PaymentIntent (immediate charge) or SetupIntent (future charge / trial).
@@ -48,8 +48,20 @@ const earningsResult = {
48
48
  };
49
49
 
50
50
  const previewPayouts = [
51
- { stripePayoutId: "po_1", accountId: "acct_store", amount: 4000, currency: "usd", status: "paid" },
52
- { stripePayoutId: "po_2", accountId: "acct_store", amount: 1500, currency: "usd", status: "pending" },
51
+ {
52
+ stripePayoutId: "po_1",
53
+ accountId: "acct_store",
54
+ amount: 4000,
55
+ currency: "usd",
56
+ status: "paid",
57
+ },
58
+ {
59
+ stripePayoutId: "po_2",
60
+ accountId: "acct_store",
61
+ amount: 1500,
62
+ currency: "usd",
63
+ status: "pending",
64
+ },
53
65
  ];
54
66
 
55
67
  const payoutsResult = {
@@ -70,7 +82,11 @@ describe("createUseEarnings", () => {
70
82
  [payoutsRef, payoutsResult],
71
83
  ]),
72
84
  );
73
- const useEarnings = createUseEarnings(mockUseQuery, earningsRef, payoutsRef);
85
+ const useEarnings = createUseEarnings(
86
+ mockUseQuery,
87
+ earningsRef,
88
+ payoutsRef,
89
+ );
74
90
 
75
91
  const result = useEarnings("acct_store");
76
92
 
@@ -92,7 +108,11 @@ describe("createUseEarnings", () => {
92
108
  [payoutsRef, payoutsResult],
93
109
  ]),
94
110
  );
95
- const useEarnings = createUseEarnings(mockUseQuery, earningsRef, payoutsRef);
111
+ const useEarnings = createUseEarnings(
112
+ mockUseQuery,
113
+ earningsRef,
114
+ payoutsRef,
115
+ );
96
116
 
97
117
  const result = useEarnings("acct_store");
98
118
 
@@ -111,7 +131,11 @@ describe("createUseEarnings", () => {
111
131
  [payoutsRef, undefined],
112
132
  ]),
113
133
  );
114
- const useEarnings = createUseEarnings(mockUseQuery, earningsRef, payoutsRef);
134
+ const useEarnings = createUseEarnings(
135
+ mockUseQuery,
136
+ earningsRef,
137
+ payoutsRef,
138
+ );
115
139
 
116
140
  const result = useEarnings("acct_store");
117
141
 
@@ -125,7 +149,11 @@ describe("createUseEarnings", () => {
125
149
 
126
150
  it("skips both queries when the account id is undefined", () => {
127
151
  const mockUseQuery = useQueryFor(new Map());
128
- const useEarnings = createUseEarnings(mockUseQuery, earningsRef, payoutsRef);
152
+ const useEarnings = createUseEarnings(
153
+ mockUseQuery,
154
+ earningsRef,
155
+ payoutsRef,
156
+ );
129
157
 
130
158
  const result = useEarnings(undefined);
131
159
 
@@ -143,11 +171,18 @@ describe("createUseEarnings", () => {
143
171
  it("treats empty ledgers as loaded with zero totals", () => {
144
172
  const mockUseQuery = useQueryFor(
145
173
  new Map<unknown, unknown>([
146
- [earningsRef, { gross: 0, reversed: 0, transferCount: 0, transfers: [] }],
174
+ [
175
+ earningsRef,
176
+ { gross: 0, reversed: 0, transferCount: 0, transfers: [] },
177
+ ],
147
178
  [payoutsRef, { paidOut: 0, payoutCount: 0, payouts: [] }],
148
179
  ]),
149
180
  );
150
- const useEarnings = createUseEarnings(mockUseQuery, earningsRef, payoutsRef);
181
+ const useEarnings = createUseEarnings(
182
+ mockUseQuery,
183
+ earningsRef,
184
+ payoutsRef,
185
+ );
151
186
 
152
187
  const result = useEarnings("acct_new");
153
188
 
@@ -28,16 +28,13 @@ describe("useStripeMode", () => {
28
28
  expect(useQueryMock).toHaveBeenCalledWith(mockQueryRef, {});
29
29
  });
30
30
 
31
- it.each(["test", "live"] as const)(
32
- "returns the resolved %s mode",
33
- (mode) => {
34
- useQueryMock.mockReturnValue(mode);
31
+ it.each(["test", "live"] as const)("returns the resolved %s mode", (mode) => {
32
+ useQueryMock.mockReturnValue(mode);
35
33
 
36
- const result = useStripeMode(mockQueryRef);
34
+ const result = useStripeMode(mockQueryRef);
37
35
 
38
- expect(result).toBe(mode);
39
- },
40
- );
36
+ expect(result).toBe(mode);
37
+ });
41
38
 
42
39
  it("returns undefined while the query is still loading", () => {
43
40
  useQueryMock.mockReturnValue(undefined);
@@ -277,3 +277,6 @@ export {
277
277
  getRequirementKey,
278
278
  getRequirementLabel,
279
279
  } from "./lib/connect-requirement-keys.js";
280
+
281
+ // Complete unstyled workflows
282
+ export * from "./workflows/index.js";
@@ -0,0 +1,31 @@
1
+ // @vitest-environment jsdom
2
+ import { act, cleanup, renderHook } from "@testing-library/react";
3
+ import { afterEach, expect, it, vi } from "vitest";
4
+ import { useAccountManager } from "./Account.js";
5
+ afterEach(cleanup);
6
+ it("opens an authorized dashboard link and exposes configuration failures", async () => {
7
+ const navigate = vi.fn();
8
+ const configure = vi
9
+ .fn()
10
+ .mockRejectedValue(new Error("Capability unavailable"));
11
+ const { result } = renderHook(() =>
12
+ useAccountManager({
13
+ scopeKey: "acct_one",
14
+ createDashboardLink: async () => ({
15
+ url: "https://connect.stripe.com/dashboard",
16
+ }),
17
+ configure,
18
+ onNavigate: navigate,
19
+ }),
20
+ );
21
+ await act(async () => {
22
+ await result.current.openDashboard();
23
+ });
24
+ expect(navigate).toHaveBeenCalledWith("https://connect.stripe.com/dashboard");
25
+ await act(async () => {
26
+ await result.current.configure("merchant");
27
+ });
28
+ expect(configure).toHaveBeenCalledWith("merchant");
29
+ expect(result.current.error).toBe("Capability unavailable");
30
+ expect(result.current.lastConfiguration).toBe("merchant");
31
+ });
@@ -0,0 +1,183 @@
1
+ "use client";
2
+ import { useState, type ReactNode } from "react";
3
+ import { useWorkflowAction } from "./useWorkflowAction.js";
4
+ import { Connect, type ConnectProps } from "./Connect.js";
5
+ export type AccountConfiguration = "customer" | "recipient" | "merchant";
6
+ export type AccountManagerOptions = {
7
+ scopeKey: string;
8
+ createDashboardLink?: () => Promise<{ url: string }>;
9
+ configure?: (configuration: AccountConfiguration) => Promise<unknown>;
10
+ onNavigate?: (url: string) => void;
11
+ };
12
+ export function useAccountManager(props: AccountManagerOptions) {
13
+ const [configuration, setConfiguration] =
14
+ useState<AccountConfiguration | null>(null);
15
+ const action = useWorkflowAction(
16
+ async (
17
+ command:
18
+ | { type: "login" }
19
+ | { type: "configure"; configuration: AccountConfiguration },
20
+ ) => {
21
+ if (command.type === "login") {
22
+ if (!props.createDashboardLink)
23
+ throw new Error("Dashboard access is not configured.");
24
+ const result = await props.createDashboardLink();
25
+ if (!result.url)
26
+ throw new Error("Stripe did not return a dashboard URL.");
27
+ return { type: "login" as const, url: result.url };
28
+ }
29
+ setConfiguration(command.configuration);
30
+ if (!props.configure)
31
+ throw new Error("Account configuration is not supported.");
32
+ await props.configure(command.configuration);
33
+ return {
34
+ type: "configure" as const,
35
+ configuration: command.configuration,
36
+ };
37
+ },
38
+ props.scopeKey,
39
+ );
40
+ return {
41
+ pendingConfiguration: action.isPending ? configuration : null,
42
+ lastConfiguration: configuration,
43
+ isPending: action.isPending,
44
+ error: action.error,
45
+ result: action.result,
46
+ openDashboard: async () => {
47
+ const result = await action.run({ type: "login" });
48
+ if (result?.type === "login")
49
+ (props.onNavigate ?? ((url) => window.location.assign(url)))(
50
+ result.url,
51
+ );
52
+ },
53
+ configure: (configuration: AccountConfiguration) =>
54
+ action.run({ type: "configure", configuration }),
55
+ };
56
+ }
57
+ export type AccountSummary = {
58
+ stripeAccountId: string;
59
+ email?: string;
60
+ country?: string;
61
+ onboardingStatus?: string;
62
+ configurations?: string[];
63
+ missingRequirements?: string[];
64
+ };
65
+ export type HeadlessAccountProps = AccountManagerOptions & {
66
+ presentation?: "headless";
67
+ account: AccountSummary | null | undefined;
68
+ children?: (
69
+ state: ReturnType<typeof useAccountManager> & {
70
+ account: AccountSummary | null | undefined;
71
+ },
72
+ ) => ReactNode;
73
+ };
74
+ export type AccountProps =
75
+ | HeadlessAccountProps
76
+ | (Omit<ConnectProps, "component"> & { presentation: "embedded" });
77
+ export function Account(props: AccountProps) {
78
+ return props.presentation === "embedded" ? (
79
+ <Connect {...props} component="account" />
80
+ ) : (
81
+ <AccountBody key={props.scopeKey} {...props} />
82
+ );
83
+ }
84
+ function AccountBody(props: HeadlessAccountProps) {
85
+ const state = useAccountManager(props);
86
+ if (props.children)
87
+ return <>{props.children({ ...state, account: props.account })}</>;
88
+ if (props.account === undefined) return <p role="status">Loading account…</p>;
89
+ if (!props.account) return <p>No Stripe account has been set up.</p>;
90
+ return (
91
+ <section data-better-stripe="account" aria-busy={state.isPending}>
92
+ <h2>Account</h2>
93
+ <dl>
94
+ <dt>Account ID</dt>
95
+ <dd>{props.account.stripeAccountId}</dd>
96
+ <dt>Email</dt>
97
+ <dd>{props.account.email ?? "Not supplied"}</dd>
98
+ <dt>Country</dt>
99
+ <dd>{props.account.country ?? "Not supplied"}</dd>
100
+ <dt>Status</dt>
101
+ <dd>{props.account.onboardingStatus ?? "pending"}</dd>
102
+ </dl>
103
+ {state.error && <p role="alert">{state.error}</p>}
104
+ {props.createDashboardLink && (
105
+ <button
106
+ type="button"
107
+ disabled={state.isPending}
108
+ onClick={() => {
109
+ void state.openDashboard();
110
+ }}
111
+ >
112
+ {state.isPending ? "Opening…" : "Open Stripe dashboard"}
113
+ </button>
114
+ )}
115
+ <h3>Configurations</h3>
116
+ {props.account.configurations?.length ? (
117
+ <ul>
118
+ {props.account.configurations.map((value) => (
119
+ <li key={value}>{value}</li>
120
+ ))}
121
+ </ul>
122
+ ) : (
123
+ <p>No configurations yet.</p>
124
+ )}
125
+ {props.configure &&
126
+ (["customer", "recipient", "merchant"] as const)
127
+ .filter((value) => !props.account!.configurations?.includes(value))
128
+ .map((value) => (
129
+ <button
130
+ key={value}
131
+ type="button"
132
+ disabled={state.isPending}
133
+ onClick={() => {
134
+ void state.configure(value);
135
+ }}
136
+ >
137
+ Add {value} configuration
138
+ </button>
139
+ ))}
140
+ {!!props.account.missingRequirements?.length && (
141
+ <>
142
+ <h3>Requirements</h3>
143
+ <ul>
144
+ {props.account.missingRequirements.map((value) => (
145
+ <li key={value}>{value}</li>
146
+ ))}
147
+ </ul>
148
+ </>
149
+ )}
150
+ </section>
151
+ );
152
+ }
153
+ export type AccountConfigurationsProps = {
154
+ configurations: string[];
155
+ children?: (state: {
156
+ items: { key: string; label: string }[];
157
+ isEmpty: boolean;
158
+ }) => ReactNode;
159
+ };
160
+ export function AccountConfigurations({
161
+ configurations,
162
+ children,
163
+ }: AccountConfigurationsProps) {
164
+ const labels: Record<string, string> = {
165
+ recipient: "Recipient (payouts)",
166
+ customer: "Customer (billable)",
167
+ merchant: "Merchant (card payments)",
168
+ };
169
+ const items = configurations.map((key) => ({
170
+ key,
171
+ label: labels[key] ?? key,
172
+ }));
173
+ if (children) return <>{children({ items, isEmpty: !items.length })}</>;
174
+ return items.length ? (
175
+ <ul data-better-stripe="account-configurations">
176
+ {items.map((item) => (
177
+ <li key={item.key}>{item.label}</li>
178
+ ))}
179
+ </ul>
180
+ ) : (
181
+ <p>No configurations yet.</p>
182
+ );
183
+ }
@@ -0,0 +1,45 @@
1
+ // @vitest-environment jsdom
2
+ import {
3
+ act,
4
+ cleanup,
5
+ renderHook,
6
+ render,
7
+ screen,
8
+ } from "@testing-library/react";
9
+ import userEvent from "@testing-library/user-event";
10
+ import { afterEach, expect, it, vi } from "vitest";
11
+ import { useBalanceFunding, InvoiceEstimate } from "./Billing.js";
12
+ afterEach(cleanup);
13
+ it("requires explicit consent before enabling balance payments", async () => {
14
+ const change = vi.fn().mockResolvedValue(null);
15
+ const { result } = renderHook(() =>
16
+ useBalanceFunding({ scopeKey: "seller", change }),
17
+ );
18
+ await act(async () => {
19
+ await result.current.confirm(true);
20
+ });
21
+ expect(change).not.toHaveBeenCalled();
22
+ expect(result.current.error).toContain("consent");
23
+ act(() => result.current.setConsent(true));
24
+ await act(async () => {
25
+ await result.current.confirm(true);
26
+ });
27
+ expect(change).toHaveBeenCalledWith({ enabled: true, consent: true });
28
+ expect(result.current.consent).toBe(false);
29
+ });
30
+ it("loads an itemized estimate only when requested and displays the server total", async () => {
31
+ const load = vi.fn().mockResolvedValue({
32
+ currency: "usd",
33
+ total: 3700,
34
+ nextBillingAt: 1800000000000,
35
+ lines: [
36
+ { id: "plan", description: "Store plan", amount: 2900 },
37
+ { id: "cost", description: "Refund costs", amount: 800 },
38
+ ],
39
+ });
40
+ render(<InvoiceEstimate scopeKey="seller" load={load} />);
41
+ expect(load).not.toHaveBeenCalled();
42
+ await userEvent.click(screen.getByRole("button", { name: "View estimate" }));
43
+ await screen.findByText("$37.00");
44
+ expect(screen.getByText("Refund costs")).toBeTruthy();
45
+ });