@fantastic.dev/better-stripe 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (359) hide show
  1. package/CHANGELOG.md +29 -18
  2. package/README.md +123 -91
  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/disputes.d.ts +1 -1
  8. package/dist/client/connect/disputes.d.ts.map +1 -1
  9. package/dist/client/connect/disputes.js +12 -6
  10. package/dist/client/connect/disputes.js.map +1 -1
  11. package/dist/client/connect/paymentMethods.d.ts.map +1 -1
  12. package/dist/client/connect/paymentMethods.js.map +1 -1
  13. package/dist/client/connect/refundActor.d.ts.map +1 -1
  14. package/dist/client/connect/refundActor.js.map +1 -1
  15. package/dist/client/connect/refunds.d.ts.map +1 -1
  16. package/dist/client/connect/refunds.js.map +1 -1
  17. package/dist/client/connect/transfers.d.ts.map +1 -1
  18. package/dist/client/connect/transfers.js +15 -4
  19. package/dist/client/connect/transfers.js.map +1 -1
  20. package/dist/client/core/accountDefaults.d.ts +6 -0
  21. package/dist/client/core/accountDefaults.d.ts.map +1 -0
  22. package/dist/client/core/accountDefaults.js +15 -0
  23. package/dist/client/core/accountDefaults.js.map +1 -0
  24. package/dist/client/core/accounts.d.ts +1 -5
  25. package/dist/client/core/accounts.d.ts.map +1 -1
  26. package/dist/client/core/accounts.js +2 -14
  27. package/dist/client/core/accounts.js.map +1 -1
  28. package/dist/client/core/fees.d.ts.map +1 -1
  29. package/dist/client/core/fees.js +7 -2
  30. package/dist/client/core/fees.js.map +1 -1
  31. package/dist/client/index.d.ts +1 -1
  32. package/dist/client/index.d.ts.map +1 -1
  33. package/dist/client/products/prices.d.ts.map +1 -1
  34. package/dist/client/products/prices.js.map +1 -1
  35. package/dist/client/products/products.d.ts.map +1 -1
  36. package/dist/client/products/products.js +3 -1
  37. package/dist/client/products/products.js.map +1 -1
  38. package/dist/client/utils/owner.d.ts.map +1 -1
  39. package/dist/client/utils/owner.js +3 -1
  40. package/dist/client/utils/owner.js.map +1 -1
  41. package/dist/client/utils/stripeDashboardUrl.d.ts.map +1 -1
  42. package/dist/client/utils/stripeDashboardUrl.js.map +1 -1
  43. package/dist/client/webhooks/helpers.d.ts +10 -0
  44. package/dist/client/webhooks/helpers.d.ts.map +1 -1
  45. package/dist/client/webhooks/helpers.js +18 -0
  46. package/dist/client/webhooks/helpers.js.map +1 -1
  47. package/dist/client/webhooks/processors.d.ts.map +1 -1
  48. package/dist/client/webhooks/processors.js +1 -19
  49. package/dist/client/webhooks/processors.js.map +1 -1
  50. package/dist/component/connect/mutations.d.ts.map +1 -1
  51. package/dist/component/connect/mutations.js +4 -33
  52. package/dist/component/connect/mutations.js.map +1 -1
  53. package/dist/component/connect/schema.d.ts.map +1 -1
  54. package/dist/component/connect/schema.js.map +1 -1
  55. package/dist/component/lib/paymentSeller.d.ts +3 -0
  56. package/dist/component/lib/paymentSeller.d.ts.map +1 -0
  57. package/dist/component/lib/paymentSeller.js +10 -0
  58. package/dist/component/lib/paymentSeller.js.map +1 -0
  59. package/dist/component/lib/reversals.d.ts +10 -0
  60. package/dist/component/lib/reversals.d.ts.map +1 -1
  61. package/dist/component/lib/reversals.js +17 -0
  62. package/dist/component/lib/reversals.js.map +1 -1
  63. package/dist/react/components/ConnectProvider.d.ts +1 -1
  64. package/dist/react/components/ConnectProvider.d.ts.map +1 -1
  65. package/dist/react/components/ConnectProvider.js +18 -4
  66. package/dist/react/components/ConnectProvider.js.map +1 -1
  67. package/dist/react/components/ConnectStatusBadge.d.ts.map +1 -1
  68. package/dist/react/components/ConnectStatusBadge.js.map +1 -1
  69. package/dist/react/components/DisputeDetail.d.ts +4 -1
  70. package/dist/react/components/DisputeDetail.d.ts.map +1 -1
  71. package/dist/react/components/DisputeDetail.js +12 -6
  72. package/dist/react/components/DisputeDetail.js.map +1 -1
  73. package/dist/react/components/DisputesList.d.ts.map +1 -1
  74. package/dist/react/components/DisputesList.js +2 -1
  75. package/dist/react/components/DisputesList.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 +2 -1
  88. package/dist/react/index.d.ts.map +1 -1
  89. package/dist/react/index.js +3 -1
  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 +48 -0
  168. package/dist/react/workflows/Payouts.d.ts.map +1 -0
  169. package/dist/react/workflows/Payouts.js +88 -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 +88 -0
  228. package/docs/react-workflows.md +234 -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/disputes.test.ts +15 -0
  234. package/src/client/connect/disputes.ts +13 -7
  235. package/src/client/connect/paymentMethods.test.ts +3 -1
  236. package/src/client/connect/paymentMethods.ts +4 -1
  237. package/src/client/connect/refundActor.ts +1 -2
  238. package/src/client/connect/refunds.test.ts +35 -10
  239. package/src/client/connect/refunds.ts +4 -1
  240. package/src/client/connect/transfers.test.ts +66 -12
  241. package/src/client/connect/transfers.ts +32 -8
  242. package/src/client/core/accountDefaults.ts +15 -0
  243. package/src/client/core/accounts.ts +14 -17
  244. package/src/client/core/config.test.ts +2 -1
  245. package/src/client/core/descriptors.test.ts +6 -4
  246. package/src/client/core/fees.test.ts +20 -28
  247. package/src/client/core/fees.ts +9 -2
  248. package/src/client/index.test.ts +22 -22
  249. package/src/client/index.ts +1 -1
  250. package/src/client/products/prices.test.ts +8 -2
  251. package/src/client/products/prices.ts +4 -1
  252. package/src/client/products/products.test.ts +61 -20
  253. package/src/client/products/products.ts +3 -1
  254. package/src/client/utils/data.test.ts +3 -1
  255. package/src/client/utils/owner.test.ts +4 -1
  256. package/src/client/utils/owner.ts +5 -1
  257. package/src/client/utils/stripeDashboardUrl.ts +1 -4
  258. package/src/client/webhooks/handler.test.ts +16 -19
  259. package/src/client/webhooks/helpers.test.ts +26 -13
  260. package/src/client/webhooks/helpers.ts +23 -0
  261. package/src/client/webhooks/hooks.test.ts +1 -2
  262. package/src/client/webhooks/processors.test.ts +18 -34
  263. package/src/client/webhooks/processors.ts +1 -23
  264. package/src/client/webhooks.test.ts +1 -2
  265. package/src/component/_generated/api.ts +2 -0
  266. package/src/component/connect/mutations.ts +5 -46
  267. package/src/component/connect/schema.ts +4 -3
  268. package/src/component/connect.test.ts +1 -5
  269. package/src/component/lib/paymentSeller.ts +15 -0
  270. package/src/component/lib/reversals.ts +30 -2
  271. package/src/component/subscription-scoping.test.ts +5 -1
  272. package/src/component/triggers.test.ts +7 -4
  273. package/src/react/components/BuyerBillingView.render.test.tsx +7 -2
  274. package/src/react/components/ConnectProvider.live.test.tsx +61 -0
  275. package/src/react/components/ConnectProvider.tsx +18 -4
  276. package/src/react/components/ConnectStatusBadge.tsx +1 -4
  277. package/src/react/components/DisputeDetail.render.test.tsx +5 -1
  278. package/src/react/components/DisputeDetail.tsx +14 -5
  279. package/src/react/components/DisputesList.render.test.tsx +21 -0
  280. package/src/react/components/DisputesList.tsx +2 -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 +3 -10
  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 +7 -1
  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 +64 -0
  315. package/src/react/workflows/Disputes.tsx +173 -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 +112 -0
  331. package/src/react/workflows/Payouts.tsx +215 -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
@@ -0,0 +1,112 @@
1
+ // @vitest-environment jsdom
2
+ import { cleanup, render, screen } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { afterEach, expect, it, vi } from "vitest";
5
+ import { Payouts } from "./Payouts.js";
6
+ afterEach(cleanup);
7
+ const row = (id: string, status = "paid") => ({
8
+ id,
9
+ status,
10
+ amount: 5000,
11
+ currency: "usd",
12
+ arrivalDate: 1800000000000,
13
+ created: 1799990000000,
14
+ });
15
+ it("shows balances, the actual next payout/date, and merges paginated history without duplicates", async () => {
16
+ const first = row("po_first");
17
+ const next = row("po_next", "pending");
18
+ const load = vi
19
+ .fn()
20
+ .mockResolvedValueOnce({
21
+ balances: [{ currency: "usd", available: 12000, pending: 2000 }],
22
+ upcoming: [next],
23
+ payouts: [next, first],
24
+ nextCursor: "po_first",
25
+ })
26
+ .mockResolvedValueOnce({
27
+ balances: [],
28
+ upcoming: [next],
29
+ payouts: [first, row("po_older")],
30
+ nextCursor: null,
31
+ });
32
+ render(<Payouts scopeKey="acct_one" load={load} />);
33
+ await screen.findByText("$120.00");
34
+ expect(screen.getByText("$20.00")).toBeTruthy();
35
+ expect(screen.getByText("po_next")).toBeTruthy();
36
+ await userEvent.click(
37
+ screen.getByRole("button", { name: "Load more payouts" }),
38
+ );
39
+ await screen.findByText("po_older");
40
+ expect(screen.getAllByText("po_first")).toHaveLength(1);
41
+ expect(screen.getByText("$120.00")).toBeTruthy();
42
+ expect(load).toHaveBeenLastCalledWith("po_first");
43
+ });
44
+ it("shows a load error with a working retry", async () => {
45
+ const load = vi
46
+ .fn()
47
+ .mockRejectedValueOnce(new Error("No balance access"))
48
+ .mockResolvedValueOnce({
49
+ balances: [],
50
+ upcoming: [],
51
+ payouts: [],
52
+ nextCursor: null,
53
+ });
54
+ render(<Payouts scopeKey="acct_one" load={load} />);
55
+ expect((await screen.findByRole("alert")).textContent).toContain(
56
+ "No balance access",
57
+ );
58
+ await userEvent.click(screen.getByRole("button", { name: "Refresh" }));
59
+ await screen.findByText("No previous payouts yet.");
60
+ });
61
+ it("exports payout history with explicit empty/loading states and date formatting", async () => {
62
+ const { PayoutHistory } = await import("./Payouts.js");
63
+ const { rerender } = render(<PayoutHistory rows={undefined} />);
64
+ expect(screen.getByRole("status")).toBeTruthy();
65
+ rerender(<PayoutHistory rows={[]} />);
66
+ expect(screen.getByText("No payouts yet.")).toBeTruthy();
67
+ rerender(
68
+ <PayoutHistory
69
+ rows={[
70
+ {
71
+ id: "po_history",
72
+ amount: 900,
73
+ currency: "usd",
74
+ status: "paid",
75
+ arrivalDate: null,
76
+ },
77
+ ]}
78
+ />,
79
+ );
80
+ expect(screen.getByText("po_history")).toBeTruthy();
81
+ expect(screen.getByText("Not supplied by Stripe")).toBeTruthy();
82
+ });
83
+ it("keeps completed payouts out of upcoming and sorts the remaining arrivals", async () => {
84
+ const pending = {
85
+ ...row("po_pending", "pending"),
86
+ arrivalDate: 1900000000000,
87
+ };
88
+ const transit = {
89
+ ...row("po_transit", "in_transit"),
90
+ arrivalDate: 1800000000000,
91
+ };
92
+ const paid = row("po_paid");
93
+ const failed = row("po_failed", "failed");
94
+ const load = async () => ({
95
+ balances: [],
96
+ upcoming: [paid, pending, failed, transit],
97
+ payouts: [paid, pending, failed, transit],
98
+ nextCursor: null,
99
+ });
100
+ const { container } = render(<Payouts scopeKey="seller" load={load} />);
101
+ await screen.findByText("po_pending");
102
+ const headings = Array.from(container.querySelectorAll("h3"));
103
+ const upcomingTable = headings.find(
104
+ (node) => node.textContent === "Upcoming payouts",
105
+ )!.nextElementSibling!;
106
+ expect(upcomingTable.textContent).not.toContain("po_paid");
107
+ expect(upcomingTable.textContent).not.toContain("po_failed");
108
+ expect(upcomingTable.textContent!.indexOf("po_transit")).toBeLessThan(
109
+ upcomingTable.textContent!.indexOf("po_pending"),
110
+ );
111
+ expect(screen.getAllByText("po_paid")).toHaveLength(1);
112
+ });
@@ -0,0 +1,215 @@
1
+ "use client";
2
+ import { useState, type ReactNode } from "react";
3
+ import { Connect, type ConnectProps } from "./Connect.js";
4
+ import { useWorkflowAction } from "./useWorkflowAction.js";
5
+ import { useWorkflowResource } from "./useWorkflowResource.js";
6
+ import {
7
+ Collection,
8
+ type CollectionProps,
9
+ type WorkflowColumn,
10
+ } from "./Collection.js";
11
+ import { formatPrice } from "../lib/price-helpers.js";
12
+ export type PayoutRow = {
13
+ id: string;
14
+ amount: number;
15
+ currency: string;
16
+ status: string;
17
+ /** Unix milliseconds. */ arrivalDate: number | null;
18
+ created: number;
19
+ };
20
+ export type PayoutSnapshot = {
21
+ balances: { currency: string; available: number; pending: number }[];
22
+ payouts: PayoutRow[];
23
+ upcoming: PayoutRow[];
24
+ nextCursor: string | null;
25
+ };
26
+ export type PayoutsRenderProps = {
27
+ data: PayoutSnapshot | undefined;
28
+ error: string | null;
29
+ isLoading: boolean;
30
+ isPending: boolean;
31
+ nextPayout: PayoutRow | undefined;
32
+ previousPayouts: PayoutRow[];
33
+ upcomingPayouts: PayoutRow[];
34
+ refresh: () => void;
35
+ loadMore: () => Promise<void>;
36
+ };
37
+ export type HeadlessPayoutsProps = {
38
+ presentation?: "headless";
39
+ scopeKey: string;
40
+ load: (cursor?: string) => Promise<PayoutSnapshot>;
41
+ children?: (state: PayoutsRenderProps) => ReactNode;
42
+ };
43
+ export type PayoutsProps =
44
+ | HeadlessPayoutsProps
45
+ | (Omit<ConnectProps, "component"> & { presentation: "embedded" });
46
+ const upcoming = (row: PayoutRow) =>
47
+ row.status === "pending" || row.status === "in_transit";
48
+ export function Payouts(props: PayoutsProps) {
49
+ return props.presentation === "embedded" ? (
50
+ <Connect {...props} component="payouts" />
51
+ ) : (
52
+ <PayoutsBody key={props.scopeKey} {...props} />
53
+ );
54
+ }
55
+ function PayoutsBody({ load, scopeKey, children }: HeadlessPayoutsProps) {
56
+ const resource = useWorkflowResource(() => load(), scopeKey);
57
+ const more = useWorkflowAction(
58
+ (cursor: string) => load(cursor),
59
+ `${scopeKey}:${resource.revision}`,
60
+ );
61
+ const [pages, setPages] = useState<{
62
+ base: PayoutSnapshot | undefined;
63
+ rows: PayoutRow[];
64
+ cursor: string | null | undefined;
65
+ }>({ base: undefined, rows: [], cursor: undefined });
66
+ if (pages.base !== resource.data)
67
+ setPages({ base: resource.data, rows: [], cursor: undefined });
68
+ const base = resource.data;
69
+ const nextCursor =
70
+ pages.cursor === undefined ? (base?.nextCursor ?? null) : pages.cursor;
71
+ const data = base
72
+ ? {
73
+ ...base,
74
+ nextCursor,
75
+ payouts: [
76
+ ...new Map(
77
+ [...base.payouts, ...pages.rows].map((row) => [row.id, row]),
78
+ ).values(),
79
+ ],
80
+ }
81
+ : undefined;
82
+ const loadMore = async () => {
83
+ if (!nextCursor || resource.isLoading) return;
84
+ const next = await more.run(nextCursor);
85
+ if (next)
86
+ setPages((previous) => ({
87
+ ...previous,
88
+ rows: [...previous.rows, ...next.payouts],
89
+ cursor: next.nextCursor,
90
+ }));
91
+ };
92
+ const sortedUpcoming =
93
+ data?.upcoming
94
+ .filter(upcoming)
95
+ .slice()
96
+ .sort(
97
+ (a, b) => (a.arrivalDate ?? Infinity) - (b.arrivalDate ?? Infinity),
98
+ ) ?? [];
99
+ const state: PayoutsRenderProps = {
100
+ data,
101
+ isLoading: resource.isLoading,
102
+ isPending: resource.isLoading || more.isPending,
103
+ error: resource.error ?? more.error,
104
+ nextPayout: sortedUpcoming[0],
105
+ upcomingPayouts: sortedUpcoming,
106
+ previousPayouts: data?.payouts.filter((row) => !upcoming(row)) ?? [],
107
+ refresh: resource.refresh,
108
+ loadMore,
109
+ };
110
+ return <>{children ? children(state) : <NativePayouts {...state} />}</>;
111
+ }
112
+ function date(value: number | null) {
113
+ return value === null
114
+ ? "Not supplied by Stripe"
115
+ : new Date(value).toLocaleDateString(undefined, { timeZone: "UTC" });
116
+ }
117
+ export type PayoutHistoryRow = Pick<
118
+ PayoutRow,
119
+ "id" | "amount" | "currency" | "status" | "arrivalDate"
120
+ >;
121
+ export type PayoutHistoryProps<
122
+ Row extends PayoutHistoryRow = PayoutHistoryRow,
123
+ > = Omit<CollectionProps<Row>, "columns" | "getKey"> & {
124
+ columns?: WorkflowColumn<Row>[];
125
+ };
126
+ export function PayoutHistory<Row extends PayoutHistoryRow>(
127
+ props: PayoutHistoryProps<Row>,
128
+ ) {
129
+ const columns: WorkflowColumn<Row>[] = [
130
+ { id: "id", label: "Payout ID", cell: (row) => row.id },
131
+ {
132
+ id: "amount",
133
+ label: "Amount",
134
+ align: "end",
135
+ cell: (row) => formatPrice(row.amount, row.currency),
136
+ },
137
+ { id: "status", label: "Status", cell: (row) => row.status },
138
+ {
139
+ id: "arrival",
140
+ label: "Arrival date",
141
+ cell: (row) => date(row.arrivalDate),
142
+ },
143
+ ];
144
+ return (
145
+ <Collection
146
+ emptyLabel="No payouts yet."
147
+ {...props}
148
+ getKey={(row) => row.id}
149
+ columns={props.columns ?? columns}
150
+ />
151
+ );
152
+ }
153
+ function NativePayouts({
154
+ data,
155
+ isLoading,
156
+ isPending,
157
+ error,
158
+ nextPayout,
159
+ previousPayouts,
160
+ upcomingPayouts,
161
+ refresh,
162
+ loadMore,
163
+ }: PayoutsRenderProps) {
164
+ return (
165
+ <section data-better-stripe="payouts" aria-busy={isPending}>
166
+ <h2>Payouts</h2>
167
+ <button type="button" disabled={isPending} onClick={refresh}>
168
+ {isPending ? "Refreshing…" : "Refresh"}
169
+ </button>
170
+ {error && <p role="alert">{error}</p>}
171
+ {isLoading && !data && <p role="status">Loading payouts…</p>}
172
+ {data && (
173
+ <>
174
+ <dl>
175
+ {data.balances.map((balance) => (
176
+ <div key={balance.currency}>
177
+ <dt>Available</dt>
178
+ <dd>{formatPrice(balance.available, balance.currency)}</dd>
179
+ <dt>Pending</dt>
180
+ <dd>{formatPrice(balance.pending, balance.currency)}</dd>
181
+ </div>
182
+ ))}
183
+ <dt>Next payout</dt>
184
+ <dd>
185
+ {nextPayout
186
+ ? `${formatPrice(nextPayout.amount, nextPayout.currency)} · ${date(nextPayout.arrivalDate)}`
187
+ : "Not scheduled"}
188
+ </dd>
189
+ </dl>
190
+ <h3>Upcoming payouts</h3>
191
+ <PayoutHistory
192
+ rows={upcomingPayouts}
193
+ emptyLabel="No upcoming payouts scheduled."
194
+ />
195
+ <h3>Previous payouts</h3>
196
+ <PayoutHistory
197
+ rows={previousPayouts}
198
+ emptyLabel="No previous payouts yet."
199
+ />
200
+ {data.nextCursor && (
201
+ <button
202
+ type="button"
203
+ disabled={isPending}
204
+ onClick={() => {
205
+ void loadMore();
206
+ }}
207
+ >
208
+ {isPending ? "Loading…" : "Load more payouts"}
209
+ </button>
210
+ )}
211
+ </>
212
+ )}
213
+ </section>
214
+ );
215
+ }
@@ -0,0 +1,90 @@
1
+ // @vitest-environment jsdom
2
+ import { act, cleanup, renderHook } from "@testing-library/react";
3
+ import { afterEach, expect, it, vi } from "vitest";
4
+ import { useProductManager } from "./Products.js";
5
+ afterEach(cleanup);
6
+ it("validates product names and price minor units before mutation", async () => {
7
+ const createProduct = vi.fn().mockResolvedValue("prod_test");
8
+ const createPrice = vi.fn().mockResolvedValue("price_test");
9
+ const { result } = renderHook(() =>
10
+ useProductManager({ scopeKey: "seller", createProduct, createPrice }),
11
+ );
12
+ await act(async () => {
13
+ await result.current.handleCreateProduct();
14
+ });
15
+ expect(createProduct).not.toHaveBeenCalled();
16
+ act(() =>
17
+ result.current.setNewProduct({
18
+ name: " Classic Tee ",
19
+ description: "Cotton",
20
+ }),
21
+ );
22
+ await act(async () => {
23
+ await result.current.handleCreateProduct();
24
+ });
25
+ expect(createProduct).toHaveBeenCalledWith({
26
+ name: "Classic Tee",
27
+ description: "Cotton",
28
+ });
29
+ act(() =>
30
+ result.current.setNewPrice({
31
+ amount: "12.50",
32
+ currency: "usd",
33
+ interval: "one_time",
34
+ }),
35
+ );
36
+ await act(async () => {
37
+ await result.current.handleAddPrice("prod_test");
38
+ });
39
+ expect(createPrice).not.toHaveBeenCalled();
40
+ act(() =>
41
+ result.current.setNewPrice({
42
+ amount: "2900",
43
+ currency: "usd",
44
+ interval: "one_time",
45
+ }),
46
+ );
47
+ await act(async () => {
48
+ await result.current.handleAddPrice("prod_test");
49
+ });
50
+ expect(createPrice).toHaveBeenCalledWith({
51
+ stripeProductId: "prod_test",
52
+ unitAmount: 2900,
53
+ currency: "usd",
54
+ type: "one_time",
55
+ interval: undefined,
56
+ });
57
+ });
58
+
59
+ it("keeps the active product operation when a second operation is attempted", async () => {
60
+ let finish!: () => void;
61
+ const deactivateProduct = vi.fn(
62
+ () =>
63
+ new Promise<void>((resolve) => {
64
+ finish = resolve;
65
+ }),
66
+ );
67
+ const deactivatePrice = vi.fn();
68
+ const { result } = renderHook(() =>
69
+ useProductManager({
70
+ scopeKey: "seller",
71
+ createProduct: async () => null,
72
+ createPrice: async () => null,
73
+ deactivateProduct,
74
+ deactivatePrice,
75
+ }),
76
+ );
77
+ let pending!: Promise<unknown>;
78
+ act(() => {
79
+ pending = result.current.handleDeactivate("prod_one");
80
+ });
81
+ await act(async () => {
82
+ await result.current.handleDeactivatePrice("price_one");
83
+ });
84
+ expect(result.current.deactivatingId).toBe("prod_one");
85
+ expect(deactivatePrice).not.toHaveBeenCalled();
86
+ await act(async () => {
87
+ finish();
88
+ await pending;
89
+ });
90
+ });