@fantastic.dev/better-stripe 0.7.0 → 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 (343) hide show
  1. package/CHANGELOG.md +23 -18
  2. package/README.md +122 -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 +1 -19
  45. package/dist/client/webhooks/processors.js.map +1 -1
  46. package/dist/component/connect/mutations.d.ts.map +1 -1
  47. package/dist/component/connect/mutations.js +4 -33
  48. package/dist/component/connect/mutations.js.map +1 -1
  49. package/dist/component/connect/schema.d.ts.map +1 -1
  50. package/dist/component/connect/schema.js.map +1 -1
  51. package/dist/component/lib/paymentSeller.d.ts +3 -0
  52. package/dist/component/lib/paymentSeller.d.ts.map +1 -0
  53. package/dist/component/lib/paymentSeller.js +10 -0
  54. package/dist/component/lib/paymentSeller.js.map +1 -0
  55. package/dist/component/lib/reversals.d.ts +10 -0
  56. package/dist/component/lib/reversals.d.ts.map +1 -1
  57. package/dist/component/lib/reversals.js +17 -0
  58. package/dist/component/lib/reversals.js.map +1 -1
  59. package/dist/react/components/ConnectProvider.d.ts +1 -1
  60. package/dist/react/components/ConnectProvider.d.ts.map +1 -1
  61. package/dist/react/components/ConnectProvider.js +18 -4
  62. package/dist/react/components/ConnectProvider.js.map +1 -1
  63. package/dist/react/components/ConnectStatusBadge.d.ts.map +1 -1
  64. package/dist/react/components/ConnectStatusBadge.js.map +1 -1
  65. package/dist/react/components/EmbeddedDisputes.d.ts +1 -1
  66. package/dist/react/components/EmbeddedDisputes.d.ts.map +1 -1
  67. package/dist/react/components/EmbeddedDisputes.js +1 -1
  68. package/dist/react/components/EmbeddedDisputes.js.map +1 -1
  69. package/dist/react/components/SplitBreakdown.d.ts.map +1 -1
  70. package/dist/react/components/SplitBreakdown.js +12 -2
  71. package/dist/react/components/SplitBreakdown.js.map +1 -1
  72. package/dist/react/hooks/useCheckoutSession.d.ts.map +1 -1
  73. package/dist/react/hooks/useCheckoutSession.js.map +1 -1
  74. package/dist/react/hooks/useConfirmPayment.d.ts.map +1 -1
  75. package/dist/react/hooks/useConfirmPayment.js.map +1 -1
  76. package/dist/react/index.d.ts +1 -0
  77. package/dist/react/index.d.ts.map +1 -1
  78. package/dist/react/index.js +2 -0
  79. package/dist/react/index.js.map +1 -1
  80. package/dist/react/workflows/Account.d.ts +67 -0
  81. package/dist/react/workflows/Account.d.ts.map +1 -0
  82. package/dist/react/workflows/Account.js +74 -0
  83. package/dist/react/workflows/Account.js.map +1 -0
  84. package/dist/react/workflows/Billing.d.ts +60 -0
  85. package/dist/react/workflows/Billing.d.ts.map +1 -0
  86. package/dist/react/workflows/Billing.js +84 -0
  87. package/dist/react/workflows/Billing.js.map +1 -0
  88. package/dist/react/workflows/BillingPlans.d.ts +45 -0
  89. package/dist/react/workflows/BillingPlans.d.ts.map +1 -0
  90. package/dist/react/workflows/BillingPlans.js +51 -0
  91. package/dist/react/workflows/BillingPlans.js.map +1 -0
  92. package/dist/react/workflows/Checkout.d.ts +46 -0
  93. package/dist/react/workflows/Checkout.d.ts.map +1 -0
  94. package/dist/react/workflows/Checkout.js +61 -0
  95. package/dist/react/workflows/Checkout.js.map +1 -0
  96. package/dist/react/workflows/CheckoutChooser.d.ts +20 -0
  97. package/dist/react/workflows/CheckoutChooser.d.ts.map +1 -0
  98. package/dist/react/workflows/CheckoutChooser.js +24 -0
  99. package/dist/react/workflows/CheckoutChooser.js.map +1 -0
  100. package/dist/react/workflows/CheckoutForms.d.ts +26 -0
  101. package/dist/react/workflows/CheckoutForms.d.ts.map +1 -0
  102. package/dist/react/workflows/CheckoutForms.js +126 -0
  103. package/dist/react/workflows/CheckoutForms.js.map +1 -0
  104. package/dist/react/workflows/ClipboardButton.d.ts +17 -0
  105. package/dist/react/workflows/ClipboardButton.d.ts.map +1 -0
  106. package/dist/react/workflows/ClipboardButton.js +35 -0
  107. package/dist/react/workflows/ClipboardButton.js.map +1 -0
  108. package/dist/react/workflows/Collection.d.ts +30 -0
  109. package/dist/react/workflows/Collection.d.ts.map +1 -0
  110. package/dist/react/workflows/Collection.js +25 -0
  111. package/dist/react/workflows/Collection.js.map +1 -0
  112. package/dist/react/workflows/Collections.d.ts +56 -0
  113. package/dist/react/workflows/Collections.d.ts.map +1 -0
  114. package/dist/react/workflows/Collections.js +111 -0
  115. package/dist/react/workflows/Collections.js.map +1 -0
  116. package/dist/react/workflows/Connect.d.ts +19 -0
  117. package/dist/react/workflows/Connect.d.ts.map +1 -0
  118. package/dist/react/workflows/Connect.js +43 -0
  119. package/dist/react/workflows/Connect.js.map +1 -0
  120. package/dist/react/workflows/Costs.d.ts +48 -0
  121. package/dist/react/workflows/Costs.d.ts.map +1 -0
  122. package/dist/react/workflows/Costs.js +66 -0
  123. package/dist/react/workflows/Costs.js.map +1 -0
  124. package/dist/react/workflows/Disputes.d.ts +36 -0
  125. package/dist/react/workflows/Disputes.d.ts.map +1 -0
  126. package/dist/react/workflows/Disputes.js +74 -0
  127. package/dist/react/workflows/Disputes.js.map +1 -0
  128. package/dist/react/workflows/Earnings.d.ts +42 -0
  129. package/dist/react/workflows/Earnings.d.ts.map +1 -0
  130. package/dist/react/workflows/Earnings.js +38 -0
  131. package/dist/react/workflows/Earnings.js.map +1 -0
  132. package/dist/react/workflows/Financials.d.ts +43 -0
  133. package/dist/react/workflows/Financials.d.ts.map +1 -0
  134. package/dist/react/workflows/Financials.js +57 -0
  135. package/dist/react/workflows/Financials.js.map +1 -0
  136. package/dist/react/workflows/IntegrationSwitch.d.ts +23 -0
  137. package/dist/react/workflows/IntegrationSwitch.d.ts.map +1 -0
  138. package/dist/react/workflows/IntegrationSwitch.js +31 -0
  139. package/dist/react/workflows/IntegrationSwitch.js.map +1 -0
  140. package/dist/react/workflows/Onboarding.d.ts +56 -0
  141. package/dist/react/workflows/Onboarding.d.ts.map +1 -0
  142. package/dist/react/workflows/Onboarding.js +86 -0
  143. package/dist/react/workflows/Onboarding.js.map +1 -0
  144. package/dist/react/workflows/Overview.d.ts +51 -0
  145. package/dist/react/workflows/Overview.d.ts.map +1 -0
  146. package/dist/react/workflows/Overview.js +63 -0
  147. package/dist/react/workflows/Overview.js.map +1 -0
  148. package/dist/react/workflows/PaymentMethods.d.ts +35 -0
  149. package/dist/react/workflows/PaymentMethods.d.ts.map +1 -0
  150. package/dist/react/workflows/PaymentMethods.js +63 -0
  151. package/dist/react/workflows/PaymentMethods.js.map +1 -0
  152. package/dist/react/workflows/PaymentReceipt.d.ts +20 -0
  153. package/dist/react/workflows/PaymentReceipt.d.ts.map +1 -0
  154. package/dist/react/workflows/PaymentReceipt.js +24 -0
  155. package/dist/react/workflows/PaymentReceipt.js.map +1 -0
  156. package/dist/react/workflows/Payouts.d.ts +47 -0
  157. package/dist/react/workflows/Payouts.d.ts.map +1 -0
  158. package/dist/react/workflows/Payouts.js +87 -0
  159. package/dist/react/workflows/Payouts.js.map +1 -0
  160. package/dist/react/workflows/Products.d.ts +92 -0
  161. package/dist/react/workflows/Products.d.ts.map +1 -0
  162. package/dist/react/workflows/Products.js +179 -0
  163. package/dist/react/workflows/Products.js.map +1 -0
  164. package/dist/react/workflows/ReferralLinks.d.ts +26 -0
  165. package/dist/react/workflows/ReferralLinks.d.ts.map +1 -0
  166. package/dist/react/workflows/ReferralLinks.js +30 -0
  167. package/dist/react/workflows/ReferralLinks.js.map +1 -0
  168. package/dist/react/workflows/Refunds.d.ts +72 -0
  169. package/dist/react/workflows/Refunds.d.ts.map +1 -0
  170. package/dist/react/workflows/Refunds.js +95 -0
  171. package/dist/react/workflows/Refunds.js.map +1 -0
  172. package/dist/react/workflows/Setup.d.ts +50 -0
  173. package/dist/react/workflows/Setup.d.ts.map +1 -0
  174. package/dist/react/workflows/Setup.js +59 -0
  175. package/dist/react/workflows/Setup.js.map +1 -0
  176. package/dist/react/workflows/Storefront.d.ts +53 -0
  177. package/dist/react/workflows/Storefront.d.ts.map +1 -0
  178. package/dist/react/workflows/Storefront.js +44 -0
  179. package/dist/react/workflows/Storefront.js.map +1 -0
  180. package/dist/react/workflows/SubscriptionOverview.d.ts +13 -0
  181. package/dist/react/workflows/SubscriptionOverview.d.ts.map +1 -0
  182. package/dist/react/workflows/SubscriptionOverview.js +26 -0
  183. package/dist/react/workflows/SubscriptionOverview.js.map +1 -0
  184. package/dist/react/workflows/Subscriptions.d.ts +92 -0
  185. package/dist/react/workflows/Subscriptions.d.ts.map +1 -0
  186. package/dist/react/workflows/Subscriptions.js +149 -0
  187. package/dist/react/workflows/Subscriptions.js.map +1 -0
  188. package/dist/react/workflows/Tasks.d.ts +40 -0
  189. package/dist/react/workflows/Tasks.d.ts.map +1 -0
  190. package/dist/react/workflows/Tasks.js +113 -0
  191. package/dist/react/workflows/Tasks.js.map +1 -0
  192. package/dist/react/workflows/checkout-options.d.ts +37 -0
  193. package/dist/react/workflows/checkout-options.d.ts.map +1 -0
  194. package/dist/react/workflows/checkout-options.js +43 -0
  195. package/dist/react/workflows/checkout-options.js.map +1 -0
  196. package/dist/react/workflows/current-subscription.d.ts +11 -0
  197. package/dist/react/workflows/current-subscription.d.ts.map +1 -0
  198. package/dist/react/workflows/current-subscription.js +14 -0
  199. package/dist/react/workflows/current-subscription.js.map +1 -0
  200. package/dist/react/workflows/filters.d.ts +17 -0
  201. package/dist/react/workflows/filters.d.ts.map +1 -0
  202. package/dist/react/workflows/filters.js +23 -0
  203. package/dist/react/workflows/filters.js.map +1 -0
  204. package/dist/react/workflows/index.d.ts +70 -0
  205. package/dist/react/workflows/index.d.ts.map +1 -0
  206. package/dist/react/workflows/index.js +38 -0
  207. package/dist/react/workflows/index.js.map +1 -0
  208. package/dist/react/workflows/useWorkflowAction.d.ts +11 -0
  209. package/dist/react/workflows/useWorkflowAction.d.ts.map +1 -0
  210. package/dist/react/workflows/useWorkflowAction.js +68 -0
  211. package/dist/react/workflows/useWorkflowAction.js.map +1 -0
  212. package/dist/react/workflows/useWorkflowResource.d.ts +9 -0
  213. package/dist/react/workflows/useWorkflowResource.d.ts.map +1 -0
  214. package/dist/react/workflows/useWorkflowResource.js +67 -0
  215. package/dist/react/workflows/useWorkflowResource.js.map +1 -0
  216. package/docs/react-workflows-audit.md +66 -0
  217. package/docs/react-workflows.md +231 -0
  218. package/package.json +19 -3
  219. package/src/client/billing/checkout-ui-modes.test.ts +49 -0
  220. package/src/client/billing/checkout.ts +8 -3
  221. package/src/client/billing/invoices.test.ts +12 -6
  222. package/src/client/connect/paymentMethods.test.ts +3 -1
  223. package/src/client/connect/paymentMethods.ts +4 -1
  224. package/src/client/connect/refundActor.ts +1 -2
  225. package/src/client/connect/refunds.test.ts +35 -10
  226. package/src/client/connect/refunds.ts +4 -1
  227. package/src/client/connect/transfers.test.ts +66 -12
  228. package/src/client/connect/transfers.ts +32 -8
  229. package/src/client/core/accountDefaults.ts +15 -0
  230. package/src/client/core/accounts.ts +14 -17
  231. package/src/client/core/config.test.ts +2 -1
  232. package/src/client/core/descriptors.test.ts +6 -4
  233. package/src/client/core/fees.test.ts +20 -28
  234. package/src/client/core/fees.ts +9 -2
  235. package/src/client/index.test.ts +22 -22
  236. package/src/client/index.ts +1 -1
  237. package/src/client/products/prices.test.ts +8 -2
  238. package/src/client/products/prices.ts +4 -1
  239. package/src/client/products/products.test.ts +61 -20
  240. package/src/client/products/products.ts +3 -1
  241. package/src/client/utils/data.test.ts +3 -1
  242. package/src/client/utils/owner.test.ts +4 -1
  243. package/src/client/utils/owner.ts +5 -1
  244. package/src/client/utils/stripeDashboardUrl.ts +1 -4
  245. package/src/client/webhooks/handler.test.ts +16 -19
  246. package/src/client/webhooks/helpers.test.ts +26 -13
  247. package/src/client/webhooks/helpers.ts +23 -0
  248. package/src/client/webhooks/hooks.test.ts +1 -2
  249. package/src/client/webhooks/processors.test.ts +18 -34
  250. package/src/client/webhooks/processors.ts +1 -23
  251. package/src/client/webhooks.test.ts +1 -2
  252. package/src/component/_generated/api.ts +2 -0
  253. package/src/component/connect/mutations.ts +5 -46
  254. package/src/component/connect/schema.ts +4 -3
  255. package/src/component/connect.test.ts +1 -5
  256. package/src/component/lib/paymentSeller.ts +15 -0
  257. package/src/component/lib/reversals.ts +30 -2
  258. package/src/component/subscription-scoping.test.ts +5 -1
  259. package/src/component/triggers.test.ts +7 -4
  260. package/src/react/components/BuyerBillingView.render.test.tsx +7 -2
  261. package/src/react/components/ConnectProvider.live.test.tsx +61 -0
  262. package/src/react/components/ConnectProvider.tsx +18 -4
  263. package/src/react/components/ConnectStatusBadge.tsx +1 -4
  264. package/src/react/components/DisputeDetail.render.test.tsx +5 -1
  265. package/src/react/components/EarningsSummary.render.test.tsx +2 -6
  266. package/src/react/components/EmbeddedDisputes.render.test.tsx +7 -5
  267. package/src/react/components/EmbeddedDisputes.tsx +4 -1
  268. package/src/react/components/EvidenceForm.render.test.tsx +2 -8
  269. package/src/react/components/SplitBreakdown.render.test.tsx +28 -5
  270. package/src/react/components/SplitBreakdown.tsx +12 -2
  271. package/src/react/hooks/useCheckoutSession.ts +1 -2
  272. package/src/react/hooks/useConfirmPayment.ts +1 -2
  273. package/src/react/hooks/useEarnings.test.ts +43 -8
  274. package/src/react/hooks/useStripeMode.test.ts +5 -8
  275. package/src/react/index.ts +3 -0
  276. package/src/react/workflows/Account.test.tsx +31 -0
  277. package/src/react/workflows/Account.tsx +183 -0
  278. package/src/react/workflows/Billing.test.tsx +45 -0
  279. package/src/react/workflows/Billing.tsx +213 -0
  280. package/src/react/workflows/BillingPlans.test.tsx +31 -0
  281. package/src/react/workflows/BillingPlans.tsx +130 -0
  282. package/src/react/workflows/Checkout.test.tsx +118 -0
  283. package/src/react/workflows/Checkout.tsx +135 -0
  284. package/src/react/workflows/CheckoutChooser.test.tsx +44 -0
  285. package/src/react/workflows/CheckoutChooser.tsx +77 -0
  286. package/src/react/workflows/CheckoutForm.test.tsx +66 -0
  287. package/src/react/workflows/CheckoutForms.test.tsx +123 -0
  288. package/src/react/workflows/CheckoutForms.tsx +247 -0
  289. package/src/react/workflows/ClipboardButton.test.tsx +34 -0
  290. package/src/react/workflows/ClipboardButton.tsx +67 -0
  291. package/src/react/workflows/Collection.tsx +76 -0
  292. package/src/react/workflows/Collections.test.tsx +86 -0
  293. package/src/react/workflows/Collections.tsx +213 -0
  294. package/src/react/workflows/Connect.test.tsx +50 -0
  295. package/src/react/workflows/Connect.tsx +107 -0
  296. package/src/react/workflows/Costs.test.tsx +41 -0
  297. package/src/react/workflows/Costs.tsx +133 -0
  298. package/src/react/workflows/Disputes.test.tsx +25 -0
  299. package/src/react/workflows/Disputes.tsx +164 -0
  300. package/src/react/workflows/Earnings.test.ts +19 -0
  301. package/src/react/workflows/Earnings.tsx +84 -0
  302. package/src/react/workflows/Financials.test.tsx +35 -0
  303. package/src/react/workflows/Financials.tsx +117 -0
  304. package/src/react/workflows/IntegrationSwitch.test.tsx +36 -0
  305. package/src/react/workflows/IntegrationSwitch.tsx +63 -0
  306. package/src/react/workflows/Onboarding.test.tsx +75 -0
  307. package/src/react/workflows/Onboarding.tsx +171 -0
  308. package/src/react/workflows/Overview.test.tsx +57 -0
  309. package/src/react/workflows/Overview.tsx +123 -0
  310. package/src/react/workflows/PaymentMethods.test.tsx +60 -0
  311. package/src/react/workflows/PaymentMethods.tsx +117 -0
  312. package/src/react/workflows/PaymentReceipt.test.tsx +24 -0
  313. package/src/react/workflows/PaymentReceipt.tsx +46 -0
  314. package/src/react/workflows/Payouts.test.tsx +82 -0
  315. package/src/react/workflows/Payouts.tsx +212 -0
  316. package/src/react/workflows/Products.test.tsx +90 -0
  317. package/src/react/workflows/Products.tsx +377 -0
  318. package/src/react/workflows/ReferralLinks.test.tsx +39 -0
  319. package/src/react/workflows/ReferralLinks.tsx +75 -0
  320. package/src/react/workflows/Refunds.test.tsx +75 -0
  321. package/src/react/workflows/Refunds.tsx +223 -0
  322. package/src/react/workflows/Setup.test.tsx +25 -0
  323. package/src/react/workflows/Setup.tsx +166 -0
  324. package/src/react/workflows/Storefront.test.tsx +82 -0
  325. package/src/react/workflows/Storefront.tsx +138 -0
  326. package/src/react/workflows/SubscriptionOverview.test.tsx +27 -0
  327. package/src/react/workflows/SubscriptionOverview.tsx +48 -0
  328. package/src/react/workflows/Subscriptions.test.tsx +61 -0
  329. package/src/react/workflows/Subscriptions.tsx +282 -0
  330. package/src/react/workflows/Tasks.test.tsx +23 -0
  331. package/src/react/workflows/Tasks.tsx +199 -0
  332. package/src/react/workflows/checkout-options.ts +42 -0
  333. package/src/react/workflows/current-subscription.test.ts +29 -0
  334. package/src/react/workflows/current-subscription.ts +25 -0
  335. package/src/react/workflows/filters.test.ts +12 -0
  336. package/src/react/workflows/filters.ts +22 -0
  337. package/src/react/workflows/index.ts +238 -0
  338. package/src/react/workflows/native-interactions.test.tsx +73 -0
  339. package/src/react/workflows/public-workflows.test.tsx +216 -0
  340. package/src/react/workflows/useWorkflowAction.test.tsx +54 -0
  341. package/src/react/workflows/useWorkflowAction.ts +75 -0
  342. package/src/react/workflows/useWorkflowResource.test.tsx +41 -0
  343. package/src/react/workflows/useWorkflowResource.ts +78 -0
@@ -0,0 +1,247 @@
1
+ "use client";
2
+ import {
3
+ useId,
4
+ useMemo,
5
+ useState,
6
+ type FormEvent,
7
+ type ReactNode,
8
+ } from "react";
9
+ import { loadStripe, type Appearance } from "@stripe/stripe-js";
10
+ import {
11
+ PaymentElement as IntentElement,
12
+ useElements,
13
+ useStripe,
14
+ } from "@stripe/react-stripe-js";
15
+ import {
16
+ PaymentElement,
17
+ useCheckout,
18
+ CheckoutFormProvider,
19
+ CheckoutForm as StripeCheckoutForm,
20
+ useCheckoutForm,
21
+ } from "@stripe/react-stripe-js/checkout";
22
+ import { CheckoutSessionProvider } from "../components/CheckoutSessionProvider.js";
23
+ import { StripeProvider } from "../components/StripeProvider.js";
24
+ import { useWorkflowAction } from "./useWorkflowAction.js";
25
+ export type CheckoutFormState = {
26
+ email: string;
27
+ setEmail: (email: string) => void;
28
+ emailInputId: string;
29
+ isPending: boolean;
30
+ error: string | null;
31
+ paymentElement: ReactNode;
32
+ submit: (event: FormEvent<HTMLFormElement>) => void;
33
+ };
34
+ export type CheckoutFormOptions = {
35
+ email?: string;
36
+ appearance?: Appearance;
37
+ renderForm?: (state: CheckoutFormState) => ReactNode;
38
+ };
39
+ export type CheckoutFormProps = CheckoutFormOptions & {
40
+ publishableKey: string;
41
+ clientSecret: string;
42
+ returnUrl: string;
43
+ onNavigate: (url: string) => void;
44
+ };
45
+ function NativeForm({
46
+ email,
47
+ setEmail,
48
+ emailInputId,
49
+ paymentElement,
50
+ submit,
51
+ isPending,
52
+ error,
53
+ }: CheckoutFormState) {
54
+ return (
55
+ <form
56
+ onSubmit={submit}
57
+ data-better-stripe="checkout-form"
58
+ aria-busy={isPending}
59
+ >
60
+ <label htmlFor={emailInputId}>Email for your receipt</label>
61
+ <input
62
+ id={emailInputId}
63
+ type="email"
64
+ name="email"
65
+ required
66
+ autoComplete="email"
67
+ value={email}
68
+ onChange={(event) => setEmail(event.target.value)}
69
+ />
70
+ {paymentElement}
71
+ {error && <p role="alert">{error}</p>}
72
+ <button type="submit" disabled={isPending}>
73
+ {isPending ? "Processing…" : "Pay"}
74
+ </button>
75
+ </form>
76
+ );
77
+ }
78
+ export function CheckoutElementsForm(props: CheckoutFormProps) {
79
+ return (
80
+ <CheckoutSessionProvider
81
+ publishableKey={props.publishableKey}
82
+ clientSecret={props.clientSecret}
83
+ appearance={props.appearance}
84
+ >
85
+ <SessionForm {...props} />
86
+ </CheckoutSessionProvider>
87
+ );
88
+ }
89
+ function SessionForm({
90
+ email: initialEmail = "",
91
+ returnUrl,
92
+ onNavigate,
93
+ renderForm,
94
+ }: CheckoutFormProps) {
95
+ const checkout = useCheckout();
96
+ const [email, setEmail] = useState(initialEmail);
97
+ const emailInputId = useId();
98
+ const action = useWorkflowAction(async () => {
99
+ if (checkout.type !== "success") throw new Error("Checkout is not ready.");
100
+ const updated = await checkout.checkout.updateEmail(email);
101
+ if (updated.type === "error") throw new Error(updated.error.message);
102
+ const confirmed = await checkout.checkout.confirm();
103
+ if (confirmed.type === "error") throw new Error(confirmed.error.message);
104
+ onNavigate(
105
+ returnUrl.replace("{CHECKOUT_SESSION_ID}", checkout.checkout.id),
106
+ );
107
+ });
108
+ if (checkout.type === "loading")
109
+ return <p role="status">Loading checkout…</p>;
110
+ if (checkout.type === "error")
111
+ return <p role="alert">{checkout.error.message}</p>;
112
+ const state: CheckoutFormState = {
113
+ email,
114
+ setEmail,
115
+ emailInputId,
116
+ paymentElement: <PaymentElement />,
117
+ error: action.error,
118
+ isPending: action.isPending,
119
+ submit: (event) => {
120
+ event.preventDefault();
121
+ void action.run();
122
+ },
123
+ };
124
+ return <>{renderForm ? renderForm(state) : <NativeForm {...state} />}</>;
125
+ }
126
+ export function PaymentIntentForm(props: CheckoutFormProps) {
127
+ return (
128
+ <StripeProvider
129
+ publishableKey={props.publishableKey}
130
+ elementsOptions={{
131
+ clientSecret: props.clientSecret,
132
+ ...(props.appearance ? { appearance: props.appearance } : {}),
133
+ }}
134
+ >
135
+ <IntentForm {...props} />
136
+ </StripeProvider>
137
+ );
138
+ }
139
+ function IntentForm({
140
+ email: initialEmail = "",
141
+ returnUrl,
142
+ onNavigate,
143
+ renderForm,
144
+ }: CheckoutFormProps) {
145
+ const stripe = useStripe();
146
+ const elements = useElements();
147
+ const emailInputId = useId();
148
+ const [email, setEmail] = useState(initialEmail);
149
+ const action = useWorkflowAction(async () => {
150
+ if (!stripe || !elements)
151
+ throw new Error("Payment details are still loading.");
152
+ const validation = await elements.submit();
153
+ if (validation.error)
154
+ throw new Error(
155
+ validation.error.message ?? "Check your payment details.",
156
+ );
157
+ const result = await stripe.confirmPayment({
158
+ elements,
159
+ confirmParams: {
160
+ return_url: returnUrl,
161
+ payment_method_data: { billing_details: { email } },
162
+ },
163
+ redirect: "if_required",
164
+ });
165
+ if (result.error)
166
+ throw new Error(result.error.message ?? "Payment failed.");
167
+ if (result.paymentIntent) {
168
+ const url = new URL(returnUrl, window.location.origin);
169
+ url.searchParams.set("payment_intent", result.paymentIntent.id);
170
+ onNavigate(url.toString());
171
+ }
172
+ });
173
+ const state: CheckoutFormState = {
174
+ email,
175
+ setEmail,
176
+ emailInputId,
177
+ paymentElement: <IntentElement />,
178
+ error: action.error,
179
+ isPending: action.isPending || !stripe || !elements,
180
+ submit: (event) => {
181
+ event.preventDefault();
182
+ void action.run();
183
+ },
184
+ };
185
+ return <>{renderForm ? renderForm(state) : <NativeForm {...state} />}</>;
186
+ }
187
+ export function CheckoutForm(props: CheckoutFormProps) {
188
+ const stripe = useMemo(
189
+ () => loadStripe(props.publishableKey),
190
+ [props.publishableKey],
191
+ );
192
+ return (
193
+ <CheckoutFormProvider
194
+ stripe={stripe}
195
+ options={{
196
+ clientSecret: props.clientSecret,
197
+ ...(props.appearance
198
+ ? { elementsOptions: { appearance: props.appearance } }
199
+ : {}),
200
+ }}
201
+ >
202
+ <CompactForm {...props} />
203
+ </CheckoutFormProvider>
204
+ );
205
+ }
206
+ function CompactForm({ returnUrl, onNavigate }: CheckoutFormProps) {
207
+ const checkout = useCheckoutForm();
208
+ const [loadError, setLoadError] = useState<string | null>(null);
209
+ const action = useWorkflowAction(
210
+ async (
211
+ event: Parameters<
212
+ NonNullable<
213
+ React.ComponentProps<typeof StripeCheckoutForm>["onConfirm"]
214
+ >
215
+ >[0],
216
+ ) => {
217
+ if (checkout.type !== "success")
218
+ throw new Error("Checkout is not ready.");
219
+ const result = await checkout.checkout.confirm({
220
+ formConfirmEvent: event,
221
+ });
222
+ if (result.type === "error") throw new Error(result.error.message);
223
+ onNavigate(
224
+ returnUrl.replace("{CHECKOUT_SESSION_ID}", checkout.checkout.id),
225
+ );
226
+ },
227
+ );
228
+ if (checkout.type === "loading")
229
+ return <p role="status">Loading embedded form…</p>;
230
+ if (checkout.type === "error")
231
+ return <p role="alert">{checkout.error.message}</p>;
232
+ return (
233
+ <div data-better-stripe="checkout-form" aria-busy={action.isPending}>
234
+ <StripeCheckoutForm
235
+ onLoadError={({ error }) =>
236
+ setLoadError(error.message ?? "Could not load checkout.")
237
+ }
238
+ onConfirm={async (event) => {
239
+ await action.run(event);
240
+ }}
241
+ />
242
+ {(loadError || action.error) && (
243
+ <p role="alert">{loadError || action.error}</p>
244
+ )}
245
+ </div>
246
+ );
247
+ }
@@ -0,0 +1,34 @@
1
+ // @vitest-environment jsdom
2
+ import {
3
+ act,
4
+ cleanup,
5
+ fireEvent,
6
+ render,
7
+ screen,
8
+ } from "@testing-library/react";
9
+ import { afterEach, expect, it, vi } from "vitest";
10
+ import { ClipboardButton } from "./ClipboardButton.js";
11
+ afterEach(() => {
12
+ cleanup();
13
+ vi.useRealTimers();
14
+ });
15
+ it("copies on demand, restores its label, and catches denied clipboard access", async () => {
16
+ vi.useFakeTimers();
17
+ const writeText = vi
18
+ .fn()
19
+ .mockResolvedValueOnce(undefined)
20
+ .mockRejectedValueOnce(new Error("Clipboard denied"));
21
+ render(<ClipboardButton text="pnpm check:all" writeText={writeText} />);
22
+ await act(async () => {
23
+ fireEvent.click(screen.getByRole("button", { name: "Copy" }));
24
+ });
25
+ expect(writeText).toHaveBeenCalledWith("pnpm check:all");
26
+ expect(screen.getByText("Copied!")).toBeTruthy();
27
+ act(() => {
28
+ vi.advanceTimersByTime(2000);
29
+ });
30
+ await act(async () => {
31
+ fireEvent.click(screen.getByRole("button", { name: "Copy" }));
32
+ });
33
+ expect(screen.getByRole("alert").textContent).toContain("Clipboard denied");
34
+ });
@@ -0,0 +1,67 @@
1
+ "use client";
2
+ import { useEffect, useRef, type ReactNode } from "react";
3
+ import { useWorkflowAction } from "./useWorkflowAction.js";
4
+ export type ClipboardButtonProps = {
5
+ text: string;
6
+ label?: string;
7
+ copiedLabel?: string;
8
+ resetAfterMs?: number;
9
+ writeText?: (text: string) => Promise<void>;
10
+ children?: (state: {
11
+ copy: () => Promise<void>;
12
+ copied: boolean;
13
+ isPending: boolean;
14
+ error: string | null;
15
+ label: string;
16
+ }) => ReactNode;
17
+ };
18
+ export function ClipboardButton({
19
+ text,
20
+ label = "Copy",
21
+ copiedLabel = "Copied!",
22
+ resetAfterMs = 2000,
23
+ writeText = (text) => navigator.clipboard.writeText(text),
24
+ children,
25
+ }: ClipboardButtonProps) {
26
+ const action = useWorkflowAction(async () => {
27
+ await writeText(text);
28
+ return text;
29
+ });
30
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
31
+ useEffect(
32
+ () => () => {
33
+ clearTimeout(timer.current);
34
+ },
35
+ [],
36
+ );
37
+ const copied = action.result === text;
38
+ const copy = async () => {
39
+ const result = await action.run();
40
+ if (result !== undefined) {
41
+ clearTimeout(timer.current);
42
+ timer.current = setTimeout(action.reset, resetAfterMs);
43
+ }
44
+ };
45
+ const state = {
46
+ copy,
47
+ copied,
48
+ isPending: action.isPending,
49
+ error: action.error,
50
+ label: copied ? copiedLabel : label,
51
+ };
52
+ if (children) return <>{children(state)}</>;
53
+ return (
54
+ <span data-better-stripe="clipboard">
55
+ <button
56
+ type="button"
57
+ disabled={state.isPending}
58
+ onClick={() => {
59
+ void copy();
60
+ }}
61
+ >
62
+ {state.label}
63
+ </button>
64
+ {state.error && <span role="alert">{state.error}</span>}
65
+ </span>
66
+ );
67
+ }
@@ -0,0 +1,76 @@
1
+ "use client";
2
+ import type { Key, ReactNode } from "react";
3
+ export type WorkflowColumn<Row> = {
4
+ id: string;
5
+ label: string;
6
+ align?: "start" | "end";
7
+ cell: (row: Row) => ReactNode;
8
+ };
9
+ export type CollectionRenderProps<Row> = {
10
+ rows: Row[];
11
+ columns: WorkflowColumn<Row>[];
12
+ getKey: (row: Row) => Key;
13
+ isLoading: boolean;
14
+ isEmpty: boolean;
15
+ error: string | null;
16
+ emptyLabel: string;
17
+ loadingLabel: string;
18
+ };
19
+ export type CollectionProps<Row> = {
20
+ rows: Row[] | null | undefined;
21
+ columns: WorkflowColumn<Row>[];
22
+ getKey: (row: Row) => Key;
23
+ isLoading?: boolean;
24
+ error?: string | null;
25
+ emptyLabel?: string;
26
+ loadingLabel?: string;
27
+ children?: (state: CollectionRenderProps<Row>) => ReactNode;
28
+ };
29
+ /** Accessible native table by default. Render props let the application supply its design-system elements. */
30
+ export function Collection<Row>({
31
+ rows,
32
+ columns,
33
+ getKey,
34
+ isLoading = rows === undefined,
35
+ error = null,
36
+ emptyLabel = "No records yet.",
37
+ loadingLabel = "Loading…",
38
+ children,
39
+ }: CollectionProps<Row>) {
40
+ const state: CollectionRenderProps<Row> = {
41
+ rows: rows ?? [],
42
+ columns,
43
+ getKey,
44
+ isLoading,
45
+ isEmpty: !isLoading && !rows?.length,
46
+ error,
47
+ emptyLabel,
48
+ loadingLabel,
49
+ };
50
+ if (children) return <>{children(state)}</>;
51
+ if (error) return <p role="alert">{error}</p>;
52
+ if (isLoading) return <p role="status">{loadingLabel}</p>;
53
+ if (state.isEmpty) return <p>{emptyLabel}</p>;
54
+ return (
55
+ <table data-better-stripe="collection">
56
+ <thead>
57
+ <tr>
58
+ {columns.map((column) => (
59
+ <th key={column.id} scope="col">
60
+ {column.label}
61
+ </th>
62
+ ))}
63
+ </tr>
64
+ </thead>
65
+ <tbody>
66
+ {state.rows.map((row) => (
67
+ <tr key={getKey(row)}>
68
+ {columns.map((column) => (
69
+ <td key={column.id}>{column.cell(row)}</td>
70
+ ))}
71
+ </tr>
72
+ ))}
73
+ </tbody>
74
+ </table>
75
+ );
76
+ }
@@ -0,0 +1,86 @@
1
+ // @vitest-environment jsdom
2
+ import { cleanup, render, screen } from "@testing-library/react";
3
+ import { afterEach, expect, it } from "vitest";
4
+ import {
5
+ Sales,
6
+ Invoices,
7
+ RefundHistory,
8
+ ReferredSales,
9
+ } from "./Collections.js";
10
+ afterEach(cleanup);
11
+ it("renders sale economics in minor units without recomputing the platform's fee policy", () => {
12
+ render(
13
+ <Sales
14
+ rows={[
15
+ {
16
+ paymentIntentId: "pi_sale",
17
+ planId: "custom",
18
+ gross: 10000,
19
+ processingFee: 320,
20
+ platformNet: 580,
21
+ affiliateNet: 1820,
22
+ costRecoveryAmount: 100,
23
+ sellerNet: 7180,
24
+ currency: "usd",
25
+ status: "settled",
26
+ },
27
+ ]}
28
+ />,
29
+ );
30
+ expect(screen.getByText("$100.00")).toBeTruthy();
31
+ expect(screen.getByText("$71.80")).toBeTruthy();
32
+ expect(screen.getByText("pi_sale")).toBeTruthy();
33
+ });
34
+ it("renders invoice links and explicit loading/empty states", () => {
35
+ const { rerender } = render(<Invoices rows={undefined} />);
36
+ expect(screen.getByRole("status").textContent).toContain("Loading");
37
+ rerender(<Invoices rows={[]} />);
38
+ expect(screen.getByText("No invoices yet.")).toBeTruthy();
39
+ rerender(
40
+ <Invoices
41
+ rows={[
42
+ {
43
+ stripeInvoiceId: "in_test",
44
+ status: "paid",
45
+ amountPaid: 1200,
46
+ currency: "usd",
47
+ hostedInvoiceUrl: "https://invoice.stripe.com/test",
48
+ },
49
+ ]}
50
+ />,
51
+ );
52
+ expect(
53
+ screen.getByRole("link", { name: "View invoice" }).getAttribute("href"),
54
+ ).toBe("https://invoice.stripe.com/test");
55
+ });
56
+ it("preserves store attribution in referred sales and refund statuses in history", () => {
57
+ const { unmount } = render(
58
+ <ReferredSales
59
+ rows={[
60
+ {
61
+ stripeTransferId: "tr_test",
62
+ storeName: "Independent Store",
63
+ amount: 900,
64
+ currency: "usd",
65
+ },
66
+ ]}
67
+ />,
68
+ );
69
+ expect(screen.getByText("Independent Store")).toBeTruthy();
70
+ unmount();
71
+ render(
72
+ <RefundHistory
73
+ rows={[
74
+ {
75
+ stripeRefundId: "re_test",
76
+ amount: 1000,
77
+ currency: "usd",
78
+ status: "failed",
79
+ _creationTime: Date.UTC(2026, 9, 13),
80
+ },
81
+ ]}
82
+ />,
83
+ );
84
+ expect(screen.getByText("failed")).toBeTruthy();
85
+ expect(screen.getByRole("columnheader", { name: "Created" })).toBeTruthy();
86
+ });