@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,92 @@
1
+ import { type ReactNode } from "react";
2
+ import { type PriceCardPrice } from "../components/PriceCard.js";
3
+ export type ProductInput = {
4
+ name: string;
5
+ description?: string;
6
+ };
7
+ export type PriceInput = {
8
+ stripeProductId: string;
9
+ unitAmount: number;
10
+ currency: string;
11
+ type: "one_time" | "recurring";
12
+ interval?: "month" | "year" | "week" | "day";
13
+ };
14
+ export type ProductActions = {
15
+ scopeKey: string;
16
+ createProduct: (args: ProductInput) => Promise<unknown>;
17
+ createPrice: (args: PriceInput) => Promise<unknown>;
18
+ updateProduct?: (args: ProductInput & {
19
+ stripeProductId: string;
20
+ }) => Promise<unknown>;
21
+ deactivateProduct?: (args: {
22
+ stripeProductId: string;
23
+ }) => Promise<unknown>;
24
+ deactivatePrice?: (args: {
25
+ stripePriceId: string;
26
+ }) => Promise<unknown>;
27
+ };
28
+ export type ProductEdit = {
29
+ stripeProductId: string;
30
+ name: string;
31
+ description: string;
32
+ };
33
+ export declare function useProductManager(props: ProductActions): {
34
+ scope: string;
35
+ expandedProduct: string | null;
36
+ showCreateDialog: boolean;
37
+ showAddPriceFor: string | null;
38
+ newProduct: {
39
+ name: string;
40
+ description: string;
41
+ };
42
+ newPrice: {
43
+ amount: string;
44
+ currency: string;
45
+ interval: string;
46
+ };
47
+ editingProduct: ProductEdit | null;
48
+ error: string | null;
49
+ clearError: () => void;
50
+ isPending: boolean;
51
+ isCreatingProduct: boolean;
52
+ isCreatingPrice: boolean;
53
+ isSavingEdit: boolean;
54
+ deactivatingId: string | null | undefined;
55
+ deactivatingPriceId: string | null | undefined;
56
+ setExpandedProduct: (value: string | null) => void;
57
+ setShowCreateDialog: (value: boolean) => void;
58
+ setShowAddPriceFor: (value: string | null) => void;
59
+ setNewProduct: (value: {
60
+ name: string;
61
+ description: string;
62
+ }) => void;
63
+ setNewPrice: (value: {
64
+ amount: string;
65
+ currency: string;
66
+ interval: string;
67
+ }) => void;
68
+ setEditingProduct: (value: ProductEdit | null) => void;
69
+ handleCreateProduct: () => Promise<void>;
70
+ handleAddPrice: (id: string) => Promise<void>;
71
+ handleSaveEdit: () => Promise<void>;
72
+ handleDeactivate: (id: string) => Promise<boolean | undefined>;
73
+ handleDeactivatePrice: (id: string) => Promise<boolean | undefined>;
74
+ };
75
+ export type CatalogProduct = {
76
+ stripeProductId: string;
77
+ name: string;
78
+ description?: string;
79
+ active: boolean;
80
+ prices: PriceCardPrice[];
81
+ };
82
+ export type ProductsRenderProps = ReturnType<typeof useProductManager> & {
83
+ products: CatalogProduct[];
84
+ isLoading: boolean;
85
+ };
86
+ export type ProductsProps = ProductActions & {
87
+ products: CatalogProduct[] | undefined;
88
+ children?: (state: ProductsRenderProps) => ReactNode;
89
+ };
90
+ /** Complete catalog creation/editing/archiving controller, with optional custom rendering. Amount inputs use minor units. */
91
+ export declare function Products(props: ProductsProps): import("react").JSX.Element;
92
+ //# sourceMappingURL=Products.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Products.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Products.tsx"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5E,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,UAAU,GAAG;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;IAC/B,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;CAC9C,CAAC;AACF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,CAAC,IAAI,EAAE,YAAY,KAA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AG;IACvE,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG;IAC3C,QAAQ,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,SAAS,CAAC;CACtD,CAAC;AACF,6HAA6H;AAC7H,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,+BAE5C"}
@@ -0,0 +1,179 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId, useState } from "react";
4
+ import { useWorkflowAction } from "./useWorkflowAction.js";
5
+ import { PriceCard } from "../components/PriceCard.js";
6
+ export function useProductManager(props) {
7
+ const initial = {
8
+ scope: props.scopeKey,
9
+ expandedProduct: null,
10
+ showCreateDialog: false,
11
+ showAddPriceFor: null,
12
+ newProduct: { name: "", description: "" },
13
+ newPrice: { amount: "", currency: "usd", interval: "month" },
14
+ editingProduct: null,
15
+ };
16
+ const [fields, setFields] = useState(initial);
17
+ if (fields.scope !== props.scopeKey)
18
+ setFields(initial);
19
+ const [command, setCommand] = useState(null);
20
+ const action = useWorkflowAction(async (command) => {
21
+ setCommand(command);
22
+ switch (command.type) {
23
+ case "create": {
24
+ if (!fields.newProduct.name.trim())
25
+ throw new Error("Enter a product name.");
26
+ await props.createProduct({
27
+ name: fields.newProduct.name.trim(),
28
+ description: fields.newProduct.description.trim() || undefined,
29
+ });
30
+ break;
31
+ }
32
+ case "price": {
33
+ const unitAmount = Number(fields.newPrice.amount);
34
+ if (!/^\d+$/.test(fields.newPrice.amount) ||
35
+ !Number.isSafeInteger(unitAmount) ||
36
+ unitAmount <= 0)
37
+ throw new Error("Enter a positive integer price in minor units.");
38
+ if (!/^[a-zA-Z]{3}$/.test(fields.newPrice.currency))
39
+ throw new Error("Enter a three-letter currency code.");
40
+ const interval = fields.newPrice.interval;
41
+ if (!["one_time", "month", "year", "week", "day"].includes(interval))
42
+ throw new Error("Choose a supported price interval.");
43
+ await props.createPrice({
44
+ stripeProductId: command.id,
45
+ unitAmount,
46
+ currency: fields.newPrice.currency.toLowerCase(),
47
+ type: interval === "one_time" ? "one_time" : "recurring",
48
+ interval: interval === "one_time"
49
+ ? undefined
50
+ : interval,
51
+ });
52
+ break;
53
+ }
54
+ case "edit": {
55
+ if (!props.updateProduct || !fields.editingProduct)
56
+ throw new Error("Product editing is not configured.");
57
+ if (!fields.editingProduct.name.trim())
58
+ throw new Error("Enter a product name.");
59
+ await props.updateProduct({
60
+ stripeProductId: fields.editingProduct.stripeProductId,
61
+ name: fields.editingProduct.name.trim(),
62
+ description: fields.editingProduct.description.trim() || undefined,
63
+ });
64
+ break;
65
+ }
66
+ case "archiveProduct":
67
+ if (!props.deactivateProduct)
68
+ throw new Error("Product archiving is not configured.");
69
+ else
70
+ await props.deactivateProduct({ stripeProductId: command.id });
71
+ break;
72
+ case "archivePrice":
73
+ if (!props.deactivatePrice)
74
+ throw new Error("Price archiving is not configured.");
75
+ else
76
+ await props.deactivatePrice({ stripePriceId: command.id });
77
+ break;
78
+ }
79
+ return true;
80
+ }, props.scopeKey);
81
+ const run = action.run;
82
+ const set = (key, value) => setFields((previous) => ({ ...previous, [key]: value }));
83
+ return {
84
+ ...fields,
85
+ error: action.error,
86
+ clearError: action.reset,
87
+ isPending: action.isPending,
88
+ isCreatingProduct: action.isPending && command?.type === "create",
89
+ isCreatingPrice: action.isPending && command?.type === "price",
90
+ isSavingEdit: action.isPending && command?.type === "edit",
91
+ deactivatingId: action.isPending && command?.type === "archiveProduct"
92
+ ? command.id
93
+ : null,
94
+ deactivatingPriceId: action.isPending && command?.type === "archivePrice" ? command.id : null,
95
+ setExpandedProduct: (value) => set("expandedProduct", value),
96
+ setShowCreateDialog: (value) => set("showCreateDialog", value),
97
+ setShowAddPriceFor: (value) => set("showAddPriceFor", value),
98
+ setNewProduct: (value) => set("newProduct", value),
99
+ setNewPrice: (value) => set("newPrice", value),
100
+ setEditingProduct: (value) => set("editingProduct", value),
101
+ handleCreateProduct: async () => {
102
+ if (await run({ type: "create" }))
103
+ setFields((previous) => ({
104
+ ...previous,
105
+ newProduct: initial.newProduct,
106
+ showCreateDialog: false,
107
+ }));
108
+ },
109
+ handleAddPrice: async (id) => {
110
+ if (await run({ type: "price", id }))
111
+ setFields((previous) => ({
112
+ ...previous,
113
+ newPrice: initial.newPrice,
114
+ showAddPriceFor: null,
115
+ }));
116
+ },
117
+ handleSaveEdit: async () => {
118
+ if (await run({ type: "edit" }))
119
+ set("editingProduct", null);
120
+ },
121
+ handleDeactivate: (id) => run({ type: "archiveProduct", id }),
122
+ handleDeactivatePrice: (id) => run({ type: "archivePrice", id }),
123
+ };
124
+ }
125
+ /** Complete catalog creation/editing/archiving controller, with optional custom rendering. Amount inputs use minor units. */
126
+ export function Products(props) {
127
+ return _jsx(ProductsBody, { ...props }, props.scopeKey);
128
+ }
129
+ function ProductsBody(props) {
130
+ const state = useProductManager(props);
131
+ const id = useId();
132
+ const result = {
133
+ ...state,
134
+ products: props.products ?? [],
135
+ isLoading: props.products === undefined,
136
+ };
137
+ if (props.children)
138
+ return _jsx(_Fragment, { children: props.children(result) });
139
+ return (_jsxs("section", { "data-better-stripe": "products", "aria-busy": state.isPending, children: [_jsx("h2", { children: "Products" }), state.error && _jsx("p", { role: "alert", children: state.error }), _jsxs("form", { onSubmit: (event) => {
140
+ event.preventDefault();
141
+ void state.handleCreateProduct();
142
+ }, children: [_jsx("label", { htmlFor: `${id}-name`, children: "Product name" }), _jsx("input", { id: `${id}-name`, required: true, value: state.newProduct.name, onChange: (event) => state.setNewProduct({
143
+ ...state.newProduct,
144
+ name: event.target.value,
145
+ }) }), _jsx("label", { htmlFor: `${id}-description`, children: "Description" }), _jsx("input", { id: `${id}-description`, value: state.newProduct.description, onChange: (event) => state.setNewProduct({
146
+ ...state.newProduct,
147
+ description: event.target.value,
148
+ }) }), _jsx("button", { type: "submit", disabled: state.isPending, children: state.isCreatingProduct ? "Creating…" : "Create product" })] }), result.isLoading ? (_jsx("p", { role: "status", children: "Loading products\u2026" })) : !result.products.length ? (_jsx("p", { children: "No products yet." })) : (result.products.map((product) => (_jsxs("article", { children: [_jsx("h3", { children: product.name }), _jsx("p", { children: product.description }), product.prices.map((price) => (_jsxs("div", { children: [_jsx(PriceCard, { price: price, children: ({ formattedPrice }) => _jsx("p", { children: formattedPrice }) }), props.deactivatePrice && price.active && (_jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
149
+ void state.handleDeactivatePrice(price.stripePriceId);
150
+ }, children: "Archive price" }))] }, price.stripePriceId))), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => state.setShowAddPriceFor(product.stripeProductId), children: "Add price" }), props.updateProduct && (_jsx("button", { type: "button", onClick: () => state.setEditingProduct({
151
+ stripeProductId: product.stripeProductId,
152
+ name: product.name,
153
+ description: product.description ?? "",
154
+ }), children: "Edit product" })), props.deactivateProduct && (_jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
155
+ void state.handleDeactivate(product.stripeProductId);
156
+ }, children: "Archive product" }))] }, product.stripeProductId)))), state.showAddPriceFor && (_jsxs("form", { onSubmit: (event) => {
157
+ event.preventDefault();
158
+ void state.handleAddPrice(state.showAddPriceFor);
159
+ }, children: [_jsx("label", { htmlFor: `${id}-amount`, children: "Price in minor units" }), _jsx("input", { id: `${id}-amount`, type: "number", required: true, min: "1", step: "1", value: state.newPrice.amount, onChange: (event) => state.setNewPrice({
160
+ ...state.newPrice,
161
+ amount: event.target.value,
162
+ }) }), _jsx("label", { htmlFor: `${id}-currency`, children: "Currency" }), _jsx("input", { id: `${id}-currency`, required: true, minLength: 3, maxLength: 3, value: state.newPrice.currency, onChange: (event) => state.setNewPrice({
163
+ ...state.newPrice,
164
+ currency: event.target.value,
165
+ }) }), _jsx("label", { htmlFor: `${id}-interval`, children: "Interval" }), _jsx("select", { id: `${id}-interval`, value: state.newPrice.interval, onChange: (event) => state.setNewPrice({
166
+ ...state.newPrice,
167
+ interval: event.target.value,
168
+ }), children: ["one_time", "month", "year", "week", "day"].map((value) => (_jsx("option", { children: value }, value))) }), _jsx("button", { type: "submit", disabled: state.isPending, children: state.isCreatingPrice ? "Creating…" : "Create price" })] })), state.editingProduct && (_jsxs("form", { onSubmit: (event) => {
169
+ event.preventDefault();
170
+ void state.handleSaveEdit();
171
+ }, children: [_jsx("label", { htmlFor: `${id}-edit-name`, children: "Product name" }), _jsx("input", { id: `${id}-edit-name`, required: true, value: state.editingProduct.name, onChange: (event) => state.setEditingProduct({
172
+ ...state.editingProduct,
173
+ name: event.target.value,
174
+ }) }), _jsx("label", { htmlFor: `${id}-edit-description`, children: "Description" }), _jsx("input", { id: `${id}-edit-description`, value: state.editingProduct.description, onChange: (event) => state.setEditingProduct({
175
+ ...state.editingProduct,
176
+ description: event.target.value,
177
+ }) }), _jsx("button", { type: "submit", disabled: state.isPending, children: state.isSavingEdit ? "Saving…" : "Save product" })] }))] }));
178
+ }
179
+ //# sourceMappingURL=Products.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Products.js","sourceRoot":"","sources":["../../../src/react/workflows/Products.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAuB,MAAM,4BAA4B,CAAC;AAwB5E,MAAM,UAAU,iBAAiB,CAAC,KAAqB;IACrD,MAAM,OAAO,GAAG;QACd,KAAK,EAAE,KAAK,CAAC,QAAQ;QACrB,eAAe,EAAE,IAAqB;QACtC,gBAAgB,EAAE,KAAK;QACvB,eAAe,EAAE,IAAqB;QACtC,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;QACzC,QAAQ,EAA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AI,EAAC,QAAQ,EAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,YAC5C,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,GACzC,IACJ,CACR,IACO,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { ReactNode } from "react";
2
+ export type ReferralLink = {
3
+ id: string;
4
+ label: string;
5
+ url: string;
6
+ };
7
+ export declare function useReferralLinks({ scopeKey, writeText, }?: {
8
+ scopeKey?: string;
9
+ writeText?: (text: string) => Promise<void>;
10
+ }): {
11
+ copy: (url: string) => Promise<string | undefined>;
12
+ copiedUrl: string | undefined;
13
+ error: string | null;
14
+ isPending: boolean;
15
+ };
16
+ export type ReferralLinksProps = {
17
+ links: ReferralLink[] | undefined;
18
+ scopeKey?: string;
19
+ writeText?: (text: string) => Promise<void>;
20
+ children?: (state: ReturnType<typeof useReferralLinks> & {
21
+ links: ReferralLink[];
22
+ isLoading: boolean;
23
+ }) => ReactNode;
24
+ };
25
+ export declare function ReferralLinks(props: ReferralLinksProps): import("react").JSX.Element;
26
+ //# sourceMappingURL=ReferralLinks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferralLinks.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/ReferralLinks.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,YAAY,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AACtE,wBAAgB,gBAAgB,CAAC,EAC/B,QAA2B,EAC3B,SAAiE,GAClE,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAO;IAOtE,IAAI;IACJ,SAAS;IACT,KAAK;IACL,SAAS;EAEZ;AACD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GAAG;QAC3C,KAAK,EAAE,YAAY,EAAE,CAAC;QACtB,SAAS,EAAE,OAAO,CAAC;KACpB,KACE,SAAS,CAAC;CAChB,CAAC;AACF,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,+BA2CtD"}
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useWorkflowAction } from "./useWorkflowAction.js";
4
+ export function useReferralLinks({ scopeKey = "referral-links", writeText = (text) => navigator.clipboard.writeText(text), } = {}) {
5
+ const action = useWorkflowAction(async (url) => {
6
+ if (!url.trim())
7
+ throw new Error("A referral URL is required.");
8
+ await writeText(url);
9
+ return url;
10
+ }, scopeKey);
11
+ return {
12
+ copy: action.run,
13
+ copiedUrl: action.result,
14
+ error: action.error,
15
+ isPending: action.isPending,
16
+ };
17
+ }
18
+ export function ReferralLinks(props) {
19
+ const state = useReferralLinks(props);
20
+ if (props.children)
21
+ return (_jsx(_Fragment, { children: props.children({
22
+ ...state,
23
+ links: props.links ?? [],
24
+ isLoading: props.links === undefined,
25
+ }) }));
26
+ return (_jsxs("section", { "data-better-stripe": "referral-links", children: [_jsx("h2", { children: "Referral links" }), state.error && _jsx("p", { role: "alert", children: state.error }), state.copiedUrl && _jsx("p", { role: "status", children: "Referral link copied" }), props.links === undefined ? (_jsx("p", { role: "status", children: "Loading referral links\u2026" })) : !props.links.length ? (_jsx("p", { children: "No referral links yet." })) : (_jsx("ul", { children: props.links.map((link) => (_jsxs("li", { children: [_jsx("a", { href: link.url, children: link.label }), _jsx("p", { children: link.url }), _jsx("button", { type: "button", disabled: state.isPending, "aria-label": `Copy referral link for ${link.label}`, onClick: () => {
27
+ void state.copy(link.url);
28
+ }, children: state.isPending ? "Copying…" : "Copy link" })] }, link.id))) }))] }));
29
+ }
30
+ //# sourceMappingURL=ReferralLinks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferralLinks.js","sourceRoot":"","sources":["../../../src/react/workflows/ReferralLinks.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,UAAU,gBAAgB,CAAC,EAC/B,QAAQ,GAAG,gBAAgB,EAC3B,SAAS,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,GAClE,GAAuE,EAAE;IACxE,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,GAAW,EAAE,EAAE;QACrD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAChE,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,QAAQ,CAAC,CAAC;IACb,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,GAAG;QAChB,SAAS,EAAE,MAAM,CAAC,MAAM;QACxB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAC;AACJ,CAAC;AAYD,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,QAAQ;QAChB,OAAO,CACL,4BACG,KAAK,CAAC,QAAQ,CAAC;gBACd,GAAG,KAAK;gBACR,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE;gBACxB,SAAS,EAAE,KAAK,CAAC,KAAK,KAAK,SAAS;aACrC,CAAC,GACD,CACJ,CAAC;IACJ,OAAO,CACL,yCAA4B,gBAAgB,aAC1C,0CAAuB,EACtB,KAAK,CAAC,KAAK,IAAI,YAAG,IAAI,EAAC,OAAO,YAAE,KAAK,CAAC,KAAK,GAAK,EAChD,KAAK,CAAC,SAAS,IAAI,YAAG,IAAI,EAAC,QAAQ,qCAAyB,EAC5D,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAC3B,YAAG,IAAI,EAAC,QAAQ,6CAA4B,CAC7C,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CACxB,iDAA6B,CAC9B,CAAC,CAAC,CAAC,CACF,uBACG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACzB,yBACE,YAAG,IAAI,EAAE,IAAI,CAAC,GAAG,YAAG,IAAI,CAAC,KAAK,GAAK,EACnC,sBAAI,IAAI,CAAC,GAAG,GAAK,EACjB,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,KAAK,CAAC,SAAS,gBACb,0BAA0B,IAAI,CAAC,KAAK,EAAE,EAClD,OAAO,EAAE,GAAG,EAAE;gCACZ,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;4BAC5B,CAAC,YAEA,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,GACpC,KAZF,IAAI,CAAC,EAAE,CAaX,CACN,CAAC,GACC,CACN,IACO,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,72 @@
1
+ import { type ReactNode } from "react";
2
+ import { type ConnectProps } from "./Connect.js";
3
+ export type RefundRequest = {
4
+ stripePaymentIntentId: string;
5
+ amountCents?: number;
6
+ reason: "requested_by_customer";
7
+ };
8
+ export type ReversalRequest = {
9
+ sourceChargeId: string;
10
+ amountCents?: number;
11
+ };
12
+ export type RefundResult = {
13
+ stripeRefundId: string;
14
+ };
15
+ export type ReversalResult = {
16
+ reversals: {
17
+ stripeTransferId: string;
18
+ amount: number;
19
+ }[];
20
+ summary: {
21
+ reversalCount: number;
22
+ totalReversed: number;
23
+ };
24
+ };
25
+ export type RefundActionsProps = {
26
+ scopeKey: string;
27
+ paymentIntentId?: string;
28
+ sourceChargeId?: string;
29
+ issueRefund: (args: RefundRequest) => Promise<RefundResult>;
30
+ reverseTransfers?: (args: ReversalRequest) => Promise<ReversalResult>;
31
+ };
32
+ /** Currency input expressed in two decimal minor units. Rejects rounding and scientific notation. */
33
+ export declare function parseAmountCents(value: string): number | null;
34
+ export declare function useRefunds(props: RefundActionsProps): {
35
+ scope: string;
36
+ paymentIntentId: string;
37
+ sourceChargeId: string;
38
+ refundAmount: string;
39
+ reversalAmount: string;
40
+ setPaymentIntentId: (value: string) => void;
41
+ setSourceChargeId: (value: string) => void;
42
+ setRefundAmount: (value: string) => void;
43
+ setReversalAmount: (value: string) => void;
44
+ error: string | null;
45
+ isPending: boolean;
46
+ busy: "refund" | "reversal" | null;
47
+ refundResult: RefundResult | null;
48
+ reversalResult: ReversalResult | null;
49
+ submitRefund: (kind: "full" | "partial") => Promise<{
50
+ type: "refund";
51
+ value: RefundResult;
52
+ } | {
53
+ type: "reversal";
54
+ value: ReversalResult;
55
+ } | undefined>;
56
+ submitReversal: (kind: "full" | "partial") => Promise<{
57
+ type: "refund";
58
+ value: RefundResult;
59
+ } | {
60
+ type: "reversal";
61
+ value: ReversalResult;
62
+ } | undefined>;
63
+ };
64
+ export type RefundsRenderProps = ReturnType<typeof useRefunds>;
65
+ export type RefundsProps = (RefundActionsProps & {
66
+ presentation?: "headless";
67
+ children?: (state: RefundsRenderProps) => ReactNode;
68
+ }) | (Omit<ConnectProps, "component"> & {
69
+ presentation: "embedded";
70
+ });
71
+ export declare function Refunds(props: RefundsProps): import("react").JSX.Element;
72
+ //# sourceMappingURL=Refunds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Refunds.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Refunds.tsx"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,MAAM,MAAM,aAAa,GAAG;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,uBAAuB,CAAC;CACjC,CAAC;AACF,MAAM,MAAM,eAAe,GAAG;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC/E,MAAM,MAAM,YAAY,GAAG;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,CAAC;AACtD,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1D,OAAO,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3D,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5D,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CACvE,CAAC;AACF,qGAAqG;AACrG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK7D;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,kBAAkB;;;;;;gCAsEpB,MAAM;+BACP,MAAM;6BACR,MAAM;+BACJ,MAAM;;;;;;yBAOZ,MAAM,GAAG,SAAS;cApC3B,QAAQ;;;cAUV,UAAU;;;2BA4BG,MAAM,GAAG,SAAS;;;;;;;EAG5C;AACD,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAC/D,MAAM,MAAM,YAAY,GACpB,CAAC,kBAAkB,GAAG;IACpB,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,SAAS,CAAC;CACrD,CAAC,GACF,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GAAG;IAAE,YAAY,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AACrE,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,+BAM1C"}
@@ -0,0 +1,95 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState, useId } from "react";
4
+ import { useWorkflowAction } from "./useWorkflowAction.js";
5
+ import { Connect } from "./Connect.js";
6
+ /** Currency input expressed in two decimal minor units. Rejects rounding and scientific notation. */
7
+ export function parseAmountCents(value) {
8
+ if (!/^\d+(?:\.\d{1,2})?$/.test(value.trim()))
9
+ return null;
10
+ const [whole, fraction = ""] = value.trim().split(".");
11
+ const amount = Number(whole) * 100 + Number(fraction.padEnd(2, "0"));
12
+ return Number.isSafeInteger(amount) && amount > 0 ? amount : null;
13
+ }
14
+ export function useRefunds(props) {
15
+ const initial = {
16
+ scope: props.scopeKey,
17
+ paymentIntentId: props.paymentIntentId ?? "",
18
+ sourceChargeId: props.sourceChargeId ?? "",
19
+ refundAmount: "",
20
+ reversalAmount: "",
21
+ };
22
+ const [fields, setFields] = useState(initial);
23
+ if (fields.scope !== props.scopeKey)
24
+ setFields(initial);
25
+ const [operationType, setOperationType] = useState("refund");
26
+ const action = useWorkflowAction(async (operation) => {
27
+ setOperationType(operation.type);
28
+ const id = (operation.type === "refund"
29
+ ? fields.paymentIntentId
30
+ : fields.sourceChargeId).trim();
31
+ if (!id)
32
+ throw new Error(operation.type === "refund"
33
+ ? "Enter a PaymentIntent id before issuing a refund."
34
+ : "Enter a source charge id before reversing transfers.");
35
+ const amount = operation.kind === "partial"
36
+ ? parseAmountCents(operation.type === "refund"
37
+ ? fields.refundAmount
38
+ : fields.reversalAmount)
39
+ : undefined;
40
+ if (amount === null)
41
+ throw new Error(`Enter a positive partial ${operation.type === "refund" ? "refund" : "reversal"} amount with at most two decimal places.`);
42
+ if (operation.type === "refund")
43
+ return {
44
+ type: "refund",
45
+ value: await props.issueRefund({
46
+ stripePaymentIntentId: id,
47
+ amountCents: amount,
48
+ reason: "requested_by_customer",
49
+ }),
50
+ };
51
+ if (!props.reverseTransfers)
52
+ throw new Error("Transfer reversals are not configured.");
53
+ return {
54
+ type: "reversal",
55
+ value: await props.reverseTransfers({
56
+ sourceChargeId: id,
57
+ amountCents: amount,
58
+ }),
59
+ };
60
+ }, props.scopeKey);
61
+ const set = (name, value) => setFields((previous) => ({ ...previous, [name]: value }));
62
+ return {
63
+ ...fields,
64
+ setPaymentIntentId: (value) => set("paymentIntentId", value),
65
+ setSourceChargeId: (value) => set("sourceChargeId", value),
66
+ setRefundAmount: (value) => set("refundAmount", value),
67
+ setReversalAmount: (value) => set("reversalAmount", value),
68
+ error: action.error,
69
+ isPending: action.isPending,
70
+ busy: action.isPending ? operationType : null,
71
+ refundResult: action.result?.type === "refund" ? action.result.value : null,
72
+ reversalResult: action.result?.type === "reversal" ? action.result.value : null,
73
+ submitRefund: (kind) => action.run({ type: "refund", kind }),
74
+ submitReversal: (kind) => action.run({ type: "reversal", kind }),
75
+ };
76
+ }
77
+ export function Refunds(props) {
78
+ return props.presentation === "embedded" ? (_jsx(Connect, { ...props, component: "refunds" })) : (_jsx(RefundsBody, { ...props }, props.scopeKey));
79
+ }
80
+ function RefundsBody(props) {
81
+ const state = useRefunds(props);
82
+ const id = useId();
83
+ if (props.children)
84
+ return _jsx(_Fragment, { children: props.children(state) });
85
+ return (_jsxs("section", { "data-better-stripe": "refunds", "aria-busy": state.isPending, children: [_jsx("h2", { children: "Refunds" }), state.error && _jsx("p", { role: "alert", children: state.error }), _jsx("label", { htmlFor: `${id}-payment`, children: "PaymentIntent ID" }), _jsx("input", { id: `${id}-payment`, value: state.paymentIntentId, onChange: (event) => state.setPaymentIntentId(event.target.value) }), _jsx("label", { htmlFor: `${id}-amount`, children: "Partial refund amount" }), _jsx("input", { id: `${id}-amount`, type: "number", min: "0.01", step: "0.01", value: state.refundAmount, onChange: (event) => state.setRefundAmount(event.target.value) }), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
86
+ void state.submitRefund("full");
87
+ }, children: state.isPending ? "Processing…" : "Full refund" }), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
88
+ void state.submitRefund("partial");
89
+ }, children: "Partial refund" }), state.refundResult && (_jsxs("p", { role: "status", children: ["Refund created: ", state.refundResult.stripeRefundId] })), props.reverseTransfers && (_jsxs(_Fragment, { children: [_jsx("h3", { children: "Transfer reversals" }), _jsx("label", { htmlFor: `${id}-charge`, children: "Source charge ID" }), _jsx("input", { id: `${id}-charge`, value: state.sourceChargeId, onChange: (event) => state.setSourceChargeId(event.target.value) }), _jsx("label", { htmlFor: `${id}-reversal`, children: "Partial reversal amount" }), _jsx("input", { id: `${id}-reversal`, type: "number", min: "0.01", step: "0.01", value: state.reversalAmount, onChange: (event) => state.setReversalAmount(event.target.value) }), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
90
+ void state.submitReversal("full");
91
+ }, children: "Reverse all transfers" }), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
92
+ void state.submitReversal("partial");
93
+ }, children: "Partial reversal" }), state.reversalResult && (_jsxs("p", { role: "status", children: ["Reversed ", state.reversalResult.summary.reversalCount, " transfers."] }))] }))] }));
94
+ }
95
+ //# sourceMappingURL=Refunds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Refunds.js","sourceRoot":"","sources":["../../../src/react/workflows/Refunds.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAkB,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAqB,MAAM,cAAc,CAAC;AAmB1D,qGAAqG;AACrG,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3D,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACrE,OAAO,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACpE,CAAC;AACD,MAAM,UAAU,UAAU,CAAC,KAAyB;IAClD,MAAM,OAAO,GAAG;QACd,KAAK,EAAE,KAAK,CAAC,QAAQ;QACrB,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,EAAE;QAC5C,cAAc,EAAE,KAAK,CAAC,cAAc,IAAI,EAAE;QAC1C,YAAY,EAAE,EAAE;QAChB,cAAc,EAAE,EAAE;KACnB,CAAC;IACF,MAAM,CAAC,MAAM,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GAAG,EAAE,WAAW,wCAAiC,EACjE,gBACE,EAAE,EAAE,GAAG,EAAE,WAAW,EACpB,IAAI,EAAC,QAAQ,EACb,GAAG,EAAC,MAAM,EACV,IAAI,EAAC,MAAM,EACX,KAAK,EAAE,KAAK,CAAC,cAAc,EAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAChE,EACF,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,OAAO,EAAE,GAAG,EAAE;4BACZ,KAAK,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;wBACpC,CAAC,sCAGM,EACT,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,OAAO,EAAE,GAAG,EAAE;4BACZ,KAAK,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;wBACvC,CAAC,iCAGM,EACR,KAAK,CAAC,cAAc,IAAI,CACvB,aAAG,IAAI,EAAC,QAAQ,0BACJ,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,aAAa,mBAClD,CACL,IACA,CACJ,IACO,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { ReactNode } from "react";
2
+ export type WebhookSetupOptions<Status, Result> = {
3
+ scopeKey: string;
4
+ load: () => Promise<Status>;
5
+ setup: () => Promise<Result>;
6
+ };
7
+ export declare function useWebhookSetup<Status, Result>(props: WebhookSetupOptions<Status, Result>): {
8
+ status: Status | undefined;
9
+ isChecking: boolean;
10
+ statusError: string | null;
11
+ checkStatus: () => void;
12
+ result: Awaited<Result> | undefined;
13
+ isPending: boolean;
14
+ error: string | null;
15
+ configure: () => Promise<void>;
16
+ };
17
+ export declare function WebhookSetup<Status, Result>(props: WebhookSetupOptions<Status, Result> & {
18
+ renderStatus?: (status: Status) => ReactNode;
19
+ children?: (state: ReturnType<typeof useWebhookSetup<Status, Result>>) => ReactNode;
20
+ }): import("react").JSX.Element;
21
+ export type EnvironmentCheck = {
22
+ id: string;
23
+ label: string;
24
+ configured: boolean;
25
+ };
26
+ export declare function EnvironmentStatus({ checks, isLoading, error, children, }: {
27
+ checks: EnvironmentCheck[] | undefined;
28
+ isLoading?: boolean;
29
+ error?: string | null;
30
+ children?: (state: {
31
+ checks: EnvironmentCheck[];
32
+ allConfigured: boolean;
33
+ isLoading: boolean;
34
+ error: string | null;
35
+ }) => ReactNode;
36
+ }): import("react").JSX.Element;
37
+ export type FixtureProgressState = {
38
+ cursor: number;
39
+ total: number;
40
+ status: string;
41
+ error?: string;
42
+ };
43
+ export declare function FixtureProgress({ state, children, }: {
44
+ state: FixtureProgressState | null | undefined;
45
+ children?: (state: FixtureProgressState & {
46
+ progress: number;
47
+ message: string;
48
+ }) => ReactNode;
49
+ }): import("react").JSX.Element;
50
+ //# sourceMappingURL=Setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Setup.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Setup.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,MAAM,MAAM,mBAAmB,CAAC,MAAM,EAAE,MAAM,IAAI;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5B,KAAK,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9B,CAAC;AACF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAC5C,KAAK,EAAE,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC;IAQxC,MAAM;IACN,UAAU;IACV,WAAW;IACX,WAAW;IACX,MAAM;IACN,SAAS;IACT,KAAK;IACL,SAAS;EAIZ;AACD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EACzC,KAAK,EAAE,mB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