@fantastic.dev/better-stripe 0.12.0 → 0.13.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 (67) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +64 -8
  3. package/dist/client/costRecovery-invoices.d.ts +38 -0
  4. package/dist/client/costRecovery-invoices.d.ts.map +1 -0
  5. package/dist/client/costRecovery-invoices.js +105 -0
  6. package/dist/client/costRecovery-invoices.js.map +1 -0
  7. package/dist/client/costRecovery.d.ts +43 -2
  8. package/dist/client/costRecovery.d.ts.map +1 -1
  9. package/dist/client/costRecovery.js +69 -2
  10. package/dist/client/costRecovery.js.map +1 -1
  11. package/dist/client/index.js +1 -1
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/component/_generated/component.d.ts +78 -0
  14. package/dist/component/_generated/component.d.ts.map +1 -1
  15. package/dist/component/costRecovery/claims.d.ts.map +1 -1
  16. package/dist/component/costRecovery/claims.js +15 -8
  17. package/dist/component/costRecovery/claims.js.map +1 -1
  18. package/dist/component/costRecovery/completion.d.ts +6 -0
  19. package/dist/component/costRecovery/completion.d.ts.map +1 -1
  20. package/dist/component/costRecovery/helpers.d.ts +6 -0
  21. package/dist/component/costRecovery/helpers.d.ts.map +1 -1
  22. package/dist/component/costRecovery/mutations.d.ts +72 -0
  23. package/dist/component/costRecovery/mutations.d.ts.map +1 -1
  24. package/dist/component/costRecovery/mutations.js +57 -0
  25. package/dist/component/costRecovery/mutations.js.map +1 -1
  26. package/dist/component/costRecovery/queries.d.ts +6 -0
  27. package/dist/component/costRecovery/queries.d.ts.map +1 -1
  28. package/dist/component/costRecovery/reservations.d.ts +12 -0
  29. package/dist/component/costRecovery/reservations.d.ts.map +1 -1
  30. package/dist/component/costRecovery/schema.d.ts +44 -2
  31. package/dist/component/costRecovery/schema.d.ts.map +1 -1
  32. package/dist/component/costRecovery/schema.js +6 -0
  33. package/dist/component/costRecovery/schema.js.map +1 -1
  34. package/dist/component/schema.d.ts +17 -1
  35. package/dist/react/workflows/Collections.d.ts.map +1 -1
  36. package/dist/react/workflows/Collections.js +2 -1
  37. package/dist/react/workflows/Collections.js.map +1 -1
  38. package/dist/react/workflows/Refunds.d.ts +14 -3
  39. package/dist/react/workflows/Refunds.d.ts.map +1 -1
  40. package/dist/react/workflows/Refunds.js +58 -16
  41. package/dist/react/workflows/Refunds.js.map +1 -1
  42. package/dist/react/workflows/index.d.ts +3 -1
  43. package/dist/react/workflows/index.d.ts.map +1 -1
  44. package/dist/react/workflows/index.js +2 -1
  45. package/dist/react/workflows/index.js.map +1 -1
  46. package/dist/react/workflows/refund-preview.d.ts +16 -0
  47. package/dist/react/workflows/refund-preview.d.ts.map +1 -0
  48. package/dist/react/workflows/refund-preview.js +38 -0
  49. package/dist/react/workflows/refund-preview.js.map +1 -0
  50. package/docs/react-workflows.md +79 -4
  51. package/package.json +1 -1
  52. package/src/client/costRecovery-invoices.test.ts +401 -0
  53. package/src/client/costRecovery-invoices.transport.test.ts +107 -0
  54. package/src/client/costRecovery-invoices.ts +144 -0
  55. package/src/client/costRecovery.ts +107 -2
  56. package/src/client/index.ts +1 -1
  57. package/src/component/_generated/component.ts +99 -0
  58. package/src/component/costRecovery/claims.ts +18 -8
  59. package/src/component/costRecovery/mutations.ts +72 -0
  60. package/src/component/costRecovery/schema.ts +8 -0
  61. package/src/react/workflows/Collections.test.tsx +36 -0
  62. package/src/react/workflows/Collections.tsx +3 -1
  63. package/src/react/workflows/Refunds.currency.test.tsx +290 -0
  64. package/src/react/workflows/Refunds.tsx +115 -25
  65. package/src/react/workflows/index.ts +8 -1
  66. package/src/react/workflows/refund-preview.test.ts +65 -0
  67. package/src/react/workflows/refund-preview.ts +56 -0
@@ -0,0 +1,56 @@
1
+ import { getChargeCurrencyMetadata } from "../../client/charge-currency.js";
2
+ import { formatPrice } from "../lib/price-helpers.js";
3
+
4
+ export type RefundPreviewGroup = {
5
+ currency: string;
6
+ status: string;
7
+ /** Loaded rows only. Null means unknown/invalid units or an unsafe sum. */
8
+ amount: number | null;
9
+ count: number;
10
+ };
11
+
12
+ function isRefundAmount(amount: number, currency: string): boolean {
13
+ return (
14
+ Number.isSafeInteger(amount) &&
15
+ amount >= 0 &&
16
+ getChargeCurrencyMetadata(currency) !== null
17
+ );
18
+ }
19
+
20
+ /** Observed refund units, including fractional ISK/UGX amounts; not input eligibility. */
21
+ export function formatRefundAmount(
22
+ amount: number,
23
+ currency: string,
24
+ locale = "en-US",
25
+ ): string | null {
26
+ return isRefundAmount(amount, currency)
27
+ ? formatPrice(amount, currency, locale)
28
+ : null;
29
+ }
30
+
31
+ /** Group only the supplied preview, preserving provider status and currency. */
32
+ export function groupRefundPreview(
33
+ rows: readonly { amount: number; currency: string; status: string }[],
34
+ ): RefundPreviewGroup[] {
35
+ const groups = new Map<string, RefundPreviewGroup>();
36
+ for (const row of rows) {
37
+ const currency = row.currency.toLowerCase();
38
+ const key = JSON.stringify([currency, row.status]);
39
+ const group = groups.get(key) ?? {
40
+ currency,
41
+ status: row.status,
42
+ amount: 0,
43
+ count: 0,
44
+ };
45
+ group.count++;
46
+ if (group.amount === null || !isRefundAmount(row.amount, currency))
47
+ group.amount = null;
48
+ else {
49
+ const sum = BigInt(group.amount) + BigInt(row.amount);
50
+ group.amount =
51
+ sum <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(sum) : null;
52
+ }
53
+ groups.set(key, group);
54
+ }
55
+ return [...groups.values()];
56
+ }