@umituz/web-payment 0.0.0-stage → 1.0.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 (150) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +349 -2
  3. package/dist/billing-adapter.interface-CDkeeowZ.d.mts +94 -0
  4. package/dist/billing-adapter.interface-m7yE50I0.d.ts +94 -0
  5. package/dist/billing-cycle.enum--hJRYlgP.d.mts +10 -0
  6. package/dist/billing-cycle.enum--hJRYlgP.d.ts +10 -0
  7. package/dist/billing-env-D4YjvA3M.d.mts +8 -0
  8. package/dist/billing-env-D4YjvA3M.d.ts +8 -0
  9. package/dist/checkout-metadata-D7Wp_DAD.d.mts +27 -0
  10. package/dist/checkout-metadata-D7Wp_DAD.d.ts +27 -0
  11. package/dist/chunk-2KV7JFYF.mjs +61 -0
  12. package/dist/chunk-2NH5DOLT.mjs +101 -0
  13. package/dist/chunk-3AXPZOCV.mjs +106 -0
  14. package/dist/chunk-4N3BASZ6.mjs +51 -0
  15. package/dist/chunk-NHKK3ENU.mjs +1128 -0
  16. package/dist/chunk-PIWNUAKW.mjs +30 -0
  17. package/dist/chunk-QFB7AOSQ.mjs +33 -0
  18. package/dist/chunk-RQTMBR74.mjs +30 -0
  19. package/dist/chunk-U45FS4FF.mjs +110 -0
  20. package/dist/chunk-X6R76FZT.mjs +0 -0
  21. package/dist/chunk-XQ2HJTTA.mjs +252 -0
  22. package/dist/core.d.mts +17 -0
  23. package/dist/core.d.ts +17 -0
  24. package/dist/core.js +425 -0
  25. package/dist/core.mjs +66 -0
  26. package/dist/http.d.mts +12 -0
  27. package/dist/http.d.ts +12 -0
  28. package/dist/http.js +115 -0
  29. package/dist/http.mjs +88 -0
  30. package/dist/index.d.mts +17 -0
  31. package/dist/index.d.ts +17 -0
  32. package/dist/index.js +1929 -0
  33. package/dist/index.mjs +153 -0
  34. package/dist/memory.d.mts +14 -0
  35. package/dist/memory.d.ts +14 -0
  36. package/dist/memory.js +130 -0
  37. package/dist/memory.mjs +6 -0
  38. package/dist/portal.d.mts +445 -0
  39. package/dist/portal.d.ts +445 -0
  40. package/dist/portal.js +2927 -0
  41. package/dist/portal.mjs +2737 -0
  42. package/dist/product.mapper-CnY1ISOp.d.ts +97 -0
  43. package/dist/product.mapper-noVl-sel.d.mts +97 -0
  44. package/dist/products.d.mts +64 -0
  45. package/dist/products.d.ts +64 -0
  46. package/dist/products.js +370 -0
  47. package/dist/products.mjs +21 -0
  48. package/dist/react.d.mts +182 -0
  49. package/dist/react.d.ts +182 -0
  50. package/dist/react.js +1874 -0
  51. package/dist/react.mjs +105 -0
  52. package/dist/server.d.mts +177 -0
  53. package/dist/server.d.ts +177 -0
  54. package/dist/server.js +622 -0
  55. package/dist/server.mjs +417 -0
  56. package/dist/visual-tokens-BCLVR85G.d.mts +94 -0
  57. package/dist/visual-tokens-BCLVR85G.d.ts +94 -0
  58. package/package.json +122 -4
  59. package/src/core.ts +81 -0
  60. package/src/domain/entities/cancellation.entity.ts +28 -0
  61. package/src/domain/entities/checkout.entity.ts +21 -0
  62. package/src/domain/entities/index.ts +10 -0
  63. package/src/domain/entities/order.entity.ts +15 -0
  64. package/src/domain/entities/product.entity.ts +16 -0
  65. package/src/domain/entities/subscription.entity.ts +24 -0
  66. package/src/domain/entities/sync.entity.ts +4 -0
  67. package/src/domain/enums/amount-type.enum.ts +10 -0
  68. package/src/domain/enums/billing-cycle.enum.ts +30 -0
  69. package/src/domain/enums/index.ts +5 -0
  70. package/src/domain/enums/payment-provider.enum.ts +14 -0
  71. package/src/domain/enums/subscription-status.enum.ts +32 -0
  72. package/src/domain/index.ts +5 -0
  73. package/src/domain/interfaces/billing-adapter.interface.ts +18 -0
  74. package/src/domain/interfaces/index.ts +1 -0
  75. package/src/domain/mappers/product.mapper.ts +176 -0
  76. package/src/domain/utils/minor-units.ts +20 -0
  77. package/src/domain/utils/percent-discount.ts +17 -0
  78. package/src/http.ts +3 -0
  79. package/src/index.ts +12 -0
  80. package/src/infrastructure/browser/hosted-checkout.ts +26 -0
  81. package/src/infrastructure/config/billing-env.ts +31 -0
  82. package/src/infrastructure/constants/billing.constants.ts +10 -0
  83. package/src/infrastructure/http/http-client.ts +83 -0
  84. package/src/infrastructure/pagination/page-iterator.ts +43 -0
  85. package/src/infrastructure/query/query-builder.ts +26 -0
  86. package/src/infrastructure/services/billing.client.ts +300 -0
  87. package/src/infrastructure/services/create-billing-client.ts +23 -0
  88. package/src/infrastructure/services/http/create-http-adapter.ts +123 -0
  89. package/src/infrastructure/services/memory/create-memory-adapter.ts +126 -0
  90. package/src/infrastructure/services/product.repository.ts +198 -0
  91. package/src/infrastructure/utils/checkout-metadata.ts +55 -0
  92. package/src/infrastructure/utils/date-renderer.ts +53 -0
  93. package/src/infrastructure/utils/money-formatter.ts +39 -0
  94. package/src/infrastructure/utils/normalization.util.ts +22 -0
  95. package/src/infrastructure/utils/pagination-clamp.ts +11 -0
  96. package/src/infrastructure/utils/receipt.util.ts +6 -0
  97. package/src/infrastructure/utils/security.util.ts +23 -0
  98. package/src/infrastructure/utils/type-guards.util.ts +23 -0
  99. package/src/infrastructure/utils/validation.util.ts +10 -0
  100. package/src/infrastructure/webhook/parse-event.ts +135 -0
  101. package/src/infrastructure/webhook/verify-webhook.ts +124 -0
  102. package/src/memory.ts +3 -0
  103. package/src/portal.ts +2 -0
  104. package/src/presentation/components/BillingHistoryList.tsx +172 -0
  105. package/src/presentation/components/BillingProvider.tsx +179 -0
  106. package/src/presentation/components/CancelSubscriptionButton.tsx +155 -0
  107. package/src/presentation/components/CheckoutButton.tsx +76 -0
  108. package/src/presentation/components/CustomerPortalLink.tsx +71 -0
  109. package/src/presentation/components/PricingTable.tsx +225 -0
  110. package/src/presentation/components/SubscriptionStatusBadge.tsx +102 -0
  111. package/src/presentation/context/billing-context.ts +30 -0
  112. package/src/presentation/hooks/useBilling.ts +3 -0
  113. package/src/presentation/hooks/useCancelSubscription.ts +47 -0
  114. package/src/presentation/hooks/useCheckoutButton.ts +49 -0
  115. package/src/presentation/hooks/useProducts.ts +76 -0
  116. package/src/presentation/navigation/navigation.strategy.ts +16 -0
  117. package/src/presentation/portal/TurnkeyBillingPage.tsx +144 -0
  118. package/src/presentation/portal/components/BillingLayout.tsx +163 -0
  119. package/src/presentation/portal/components/BillingPage.tsx +22 -0
  120. package/src/presentation/portal/components/BillingPortal.tsx +248 -0
  121. package/src/presentation/portal/components/InvoiceCard.tsx +275 -0
  122. package/src/presentation/portal/components/OverviewTab.tsx +137 -0
  123. package/src/presentation/portal/components/PaymentMethodsList.tsx +268 -0
  124. package/src/presentation/portal/components/PlanComparison.tsx +405 -0
  125. package/src/presentation/portal/components/PlanTab.tsx +197 -0
  126. package/src/presentation/portal/components/PortalButton.tsx +89 -0
  127. package/src/presentation/portal/components/PortalSpinner.tsx +30 -0
  128. package/src/presentation/portal/components/UsageCard.tsx +158 -0
  129. package/src/presentation/portal/components/index.ts +11 -0
  130. package/src/presentation/portal/constants.ts +44 -0
  131. package/src/presentation/portal/create-portal-client.ts +202 -0
  132. package/src/presentation/portal/hooks/index.ts +3 -0
  133. package/src/presentation/portal/hooks/useBilling.ts +240 -0
  134. package/src/presentation/portal/index.ts +97 -0
  135. package/src/presentation/portal/labels.tsx +218 -0
  136. package/src/presentation/portal/styles.ts +70 -0
  137. package/src/presentation/portal/types.ts +213 -0
  138. package/src/presentation/portal/utils/billing.ts +193 -0
  139. package/src/presentation/portal/utils/index.ts +27 -0
  140. package/src/presentation/portal/utils/plans.ts +71 -0
  141. package/src/presentation/theme/visual-tokens.ts +103 -0
  142. package/src/presentation/utils/cancellation-reason-catalog.ts +18 -0
  143. package/src/presentation/utils/checkout-button-visual.ts +50 -0
  144. package/src/presentation/utils/inline-error-visual.ts +21 -0
  145. package/src/presentation/utils/product-pricing.ts +33 -0
  146. package/src/presentation/utils/status-label.ts +23 -0
  147. package/src/presentation/utils/status-tone.ts +25 -0
  148. package/src/products.ts +20 -0
  149. package/src/react.tsx +63 -0
  150. package/src/server.ts +79 -0
@@ -0,0 +1,445 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ButtonHTMLAttributes } from 'react';
3
+ import { b as BillingCycle } from './billing-cycle.enum--hJRYlgP.mjs';
4
+ export { B as BILLING_CYCLE } from './billing-cycle.enum--hJRYlgP.mjs';
5
+ import { b as VisualTone, N as NavigationStrategy } from './visual-tokens-BCLVR85G.mjs';
6
+ import { a as Product, h as ProductPrice } from './product.mapper-noVl-sel.mjs';
7
+ import { B as BillingAdapter } from './billing-adapter.interface-CDkeeowZ.mjs';
8
+
9
+ declare const SUBSCRIPTION_STATUS: {
10
+ readonly ACTIVE: "active";
11
+ readonly TRIALING: "trialing";
12
+ readonly PAST_DUE: "past_due";
13
+ readonly CANCELED: "canceled";
14
+ readonly UNPAID: "unpaid";
15
+ readonly INCOMPLETE: "incomplete";
16
+ readonly REVOKED: "revoked";
17
+ };
18
+ declare const INVOICE_STATUS: {
19
+ readonly DRAFT: "draft";
20
+ readonly OPEN: "open";
21
+ readonly PAID: "paid";
22
+ readonly VOID: "void";
23
+ readonly UNCOLLECTIBLE: "uncollectible";
24
+ readonly REFUNDED: "refunded";
25
+ };
26
+ declare const CURRENCY: {
27
+ readonly USD: "USD";
28
+ readonly EUR: "EUR";
29
+ readonly GBP: "GBP";
30
+ readonly TRY: "TRY";
31
+ readonly JPY: "JPY";
32
+ };
33
+ type Currency$1 = typeof CURRENCY[keyof typeof CURRENCY];
34
+ declare const PLAN_TYPE: {
35
+ readonly STANDARD: "standard";
36
+ readonly PRO: "pro";
37
+ readonly BUSINESS: "business";
38
+ readonly ENTERPRISE: "enterprise";
39
+ };
40
+ declare const DEFAULT_BILLING_CONFIG: {
41
+ readonly enableYearlyDiscount: true;
42
+ readonly yearlyDiscount: 20;
43
+ readonly currencies: Currency$1[];
44
+ readonly defaultCurrency: "USD";
45
+ readonly taxRate: 0;
46
+ };
47
+
48
+ declare function formatLabel(template: string, params: Record<string, string | number>): string;
49
+ interface BillingLabels {
50
+ common: {
51
+ loading: string;
52
+ usage: string;
53
+ };
54
+ page: {
55
+ backToDashboard: string;
56
+ title: string;
57
+ description: string;
58
+ needHelp: string;
59
+ contactAria: string;
60
+ };
61
+ tabs: {
62
+ overview: string;
63
+ paymentMethods: string;
64
+ invoices: string;
65
+ plan: string;
66
+ };
67
+ overview: {
68
+ currentSubscription: string;
69
+ trialDaysLeft: string;
70
+ nextBilling: string;
71
+ upcomingInvoice: string;
72
+ };
73
+ invoices: {
74
+ empty: string;
75
+ moreItems: string;
76
+ due: string;
77
+ viewInvoice: string;
78
+ downloadPdf: string;
79
+ };
80
+ plan: {
81
+ title: string;
82
+ actionsTitle: string;
83
+ changePlan: string;
84
+ cancelSubscription: string;
85
+ confirmCancel: string;
86
+ cancelling: string;
87
+ cancelConfirmMessage: string;
88
+ cancelFailed: string;
89
+ };
90
+ planComparison: {
91
+ monthly: string;
92
+ yearly: string;
93
+ monthlyShort: string;
94
+ yearlyShort: string;
95
+ save: string;
96
+ saveWithYearly: string;
97
+ mostPopular: string;
98
+ currentPlan: string;
99
+ selectPlan: string;
100
+ processing: string;
101
+ billingCycleLabel: string;
102
+ radiogroupLabel: string;
103
+ };
104
+ paymentMethods: {
105
+ none: string;
106
+ add: string;
107
+ bankAccount: string;
108
+ expires: string;
109
+ default: string;
110
+ setDefault: string;
111
+ remove: string;
112
+ removeConfirm: string;
113
+ confirmRemove: string;
114
+ cancelRemove: string;
115
+ };
116
+ usage: {
117
+ limit: string;
118
+ resets: string;
119
+ };
120
+ status: Record<SubscriptionStatus, string>;
121
+ invoiceStatus: Record<InvoiceStatus, string>;
122
+ }
123
+ type BillingLabelsOverrides = {
124
+ [K in keyof BillingLabels]?: BillingLabels[K] extends string ? string : {
125
+ [K2 in keyof BillingLabels[K]]?: BillingLabels[K][K2];
126
+ };
127
+ };
128
+ declare const DEFAULT_BILLING_LABELS: Readonly<BillingLabels>;
129
+ declare function mergeLabels(overrides?: BillingLabelsOverrides): BillingLabels;
130
+ declare function BillingLabelsProvider({ labels, children, }: {
131
+ labels?: BillingLabelsOverrides;
132
+ children: ReactNode;
133
+ }): react.JSX.Element;
134
+ declare function useBillingLabels(): BillingLabels;
135
+
136
+ type SubscriptionStatus = typeof SUBSCRIPTION_STATUS[keyof typeof SUBSCRIPTION_STATUS];
137
+ type InvoiceStatus = typeof INVOICE_STATUS[keyof typeof INVOICE_STATUS];
138
+ type PlanType = string;
139
+ type Currency = typeof CURRENCY[keyof typeof CURRENCY];
140
+ type PlanFeature = string | {
141
+ text: string;
142
+ bold?: boolean;
143
+ included?: boolean;
144
+ };
145
+ interface PlanTier {
146
+ id: string;
147
+ type?: PlanType;
148
+ name: string;
149
+ description: string;
150
+ badge?: string;
151
+ badgeColor?: string;
152
+ monthlyPrice: number;
153
+ yearlyPrice: number;
154
+ currency: Currency;
155
+ features: PlanFeature[];
156
+ highlight?: boolean;
157
+ maxUsers?: number;
158
+ storageLimit?: number;
159
+ apiLimit?: number;
160
+ }
161
+ interface Subscription {
162
+ id: string;
163
+ planId: string;
164
+ plan: PlanTier;
165
+ status: SubscriptionStatus;
166
+ cycle: BillingCycle;
167
+ currentPeriodStart: string;
168
+ currentPeriodEnd: string;
169
+ cancelAtPeriodEnd?: boolean;
170
+ trialEnd?: string;
171
+ seats?: number;
172
+ }
173
+ type PaymentMethodType = 'card' | 'bank_account' | 'wallet';
174
+ interface PaymentMethod {
175
+ id: string;
176
+ type: PaymentMethodType;
177
+ isDefault: boolean;
178
+ card?: {
179
+ last4: string;
180
+ brand: string;
181
+ expiryMonth: number;
182
+ expiryYear: number;
183
+ name?: string;
184
+ };
185
+ bankAccount?: {
186
+ last4: string;
187
+ bankName: string;
188
+ accountType?: 'checking' | 'savings';
189
+ };
190
+ createdAt: string;
191
+ }
192
+ interface InvoiceItem {
193
+ description: string;
194
+ quantity: number;
195
+ unitPrice: number;
196
+ amount: number;
197
+ }
198
+ interface Invoice {
199
+ id: string;
200
+ number: string;
201
+ amount: number;
202
+ currency: string;
203
+ status: InvoiceStatus;
204
+ date: string;
205
+ dueDate: string;
206
+ paidAt?: string;
207
+ invoiceUrl?: string;
208
+ pdfUrl?: string;
209
+ items?: InvoiceItem[];
210
+ subtotal?: number;
211
+ tax?: number;
212
+ total?: number;
213
+ }
214
+ interface UsageMetric {
215
+ id: string;
216
+ name: string;
217
+ current: number;
218
+ limit: number;
219
+ unit: string;
220
+ resetPeriod: 'daily' | 'monthly' | 'yearly';
221
+ resetAt?: string;
222
+ }
223
+ interface BillingSummary {
224
+ subscription: Subscription;
225
+ paymentMethods: PaymentMethod[];
226
+ defaultPaymentMethod?: PaymentMethod;
227
+ upcomingInvoice?: {
228
+ amount: number;
229
+ currency: Currency;
230
+ date: string;
231
+ };
232
+ usage: UsageMetric[];
233
+ recentInvoices: Invoice[];
234
+ }
235
+ type PaymentMethodInput = {
236
+ type: 'card';
237
+ last4: string;
238
+ brand: string;
239
+ expiryMonth: number;
240
+ expiryYear: number;
241
+ name?: string;
242
+ } | {
243
+ type: 'bank_account';
244
+ last4: string;
245
+ bankName: string;
246
+ accountType?: 'checking' | 'savings';
247
+ };
248
+ interface PlanComparisonProps {
249
+ plans: PlanTier[];
250
+ selectedPlan?: string;
251
+ cycle: BillingCycle;
252
+ showCycleToggle?: boolean;
253
+ showFeatures?: boolean;
254
+ onPlanSelect?: (planId: string) => void;
255
+ onCycleChange?: (cycle: BillingCycle) => void;
256
+ loading?: boolean;
257
+ labels?: BillingLabelsOverrides;
258
+ }
259
+ interface PaymentMethodsListProps {
260
+ paymentMethods: PaymentMethod[];
261
+ loading?: boolean;
262
+ busyId?: string | null;
263
+ onSetDefault?: (methodId: string) => void;
264
+ onRemove?: (methodId: string) => void;
265
+ onAddNew?: () => void;
266
+ }
267
+ interface InvoiceCardProps {
268
+ invoice: Invoice;
269
+ compact?: boolean;
270
+ onClick?: (invoice: Invoice) => void;
271
+ onDownload?: (invoice: Invoice) => void;
272
+ locale?: string;
273
+ }
274
+ interface UsageCardProps {
275
+ metric: UsageMetric;
276
+ locale?: string;
277
+ showProgress?: boolean;
278
+ showLimit?: boolean;
279
+ }
280
+ type BillingTabId = 'overview' | 'payment-methods' | 'invoices' | 'plan';
281
+ interface BillingPortalProps {
282
+ billing: BillingSummary;
283
+ loading?: boolean;
284
+ error?: string;
285
+ showTabs?: boolean;
286
+ activeTab?: BillingTabId;
287
+ locale?: string;
288
+ onTabChange?: (tab: BillingTabId) => void;
289
+ onAddPaymentMethod?: () => void;
290
+ onSetDefaultPaymentMethod?: (methodId: string) => void;
291
+ onRemovePaymentMethod?: (methodId: string) => void;
292
+ onViewInvoice?: (invoice: Invoice) => void;
293
+ onChangePlan?: () => void;
294
+ onCancelSubscription?: () => void | Promise<void>;
295
+ labels?: BillingLabelsOverrides;
296
+ }
297
+ interface BillingLayoutProps {
298
+ config: BillingConfig;
299
+ children?: ReactNode;
300
+ onBack?: () => void;
301
+ }
302
+ interface BillingConfig {
303
+ brandName: string;
304
+ logo?: ReactNode;
305
+ plans: PlanTier[];
306
+ currencies?: Currency[];
307
+ defaultCurrency?: Currency;
308
+ enableYearlyDiscount?: boolean;
309
+ yearlyDiscount?: number;
310
+ taxRate?: number;
311
+ supportEmail?: string;
312
+ cancelRoute?: string;
313
+ updatePaymentRoute?: string;
314
+ invoiceHistoryRoute?: string;
315
+ }
316
+ interface BillingPageProps extends Omit<BillingPortalProps, 'showTabs'> {
317
+ config: BillingConfig;
318
+ }
319
+
320
+ declare const BillingPortal: ({ billing, loading, error, showTabs, activeTab, locale, onTabChange, onAddPaymentMethod, onSetDefaultPaymentMethod, onRemovePaymentMethod, onViewInvoice, onChangePlan, onCancelSubscription, labels, }: BillingPortalProps) => react.JSX.Element;
321
+
322
+ declare const BillingLayout: ({ config, children, onBack }: BillingLayoutProps) => react.JSX.Element;
323
+
324
+ declare const BillingPage: ({ config, labels, ...portalProps }: BillingPageProps) => react.JSX.Element;
325
+
326
+ declare const RADIO_GROUP_NAME = "plan-comparison";
327
+ declare const PlanComparison: ({ plans, selectedPlan, cycle, showCycleToggle, showFeatures, onPlanSelect, onCycleChange, loading, labels: labelsOverride, }: PlanComparisonProps) => react.JSX.Element;
328
+
329
+ declare const PaymentMethodsList: ({ paymentMethods, loading, busyId, onSetDefault, onRemove, onAddNew, }: PaymentMethodsListProps) => react.JSX.Element;
330
+
331
+ declare const InvoiceCard: ({ invoice, compact, locale, onClick, onDownload, }: InvoiceCardProps) => react.JSX.Element;
332
+
333
+ declare const UsageCard: ({ metric, locale, showProgress, showLimit, }: UsageCardProps) => react.JSX.Element;
334
+
335
+ type PortalButtonVariant = 'default' | 'outline' | 'destructive' | 'ghost';
336
+ type PortalButtonSize = 'sm' | 'md';
337
+ interface PortalButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
338
+ variant?: PortalButtonVariant;
339
+ size?: PortalButtonSize;
340
+ fullWidth?: boolean;
341
+ pill?: boolean;
342
+ icon?: ReactNode;
343
+ children?: ReactNode;
344
+ }
345
+ declare const PortalButton: ({ variant, size, fullWidth, pill, icon, children, disabled, style, type, ...rest }: PortalButtonProps) => react.JSX.Element;
346
+
347
+ declare const PortalSpinner: ({ size }: {
348
+ size?: number;
349
+ }) => react.JSX.Element;
350
+
351
+ interface BillingApiClient {
352
+ loadBilling: () => Promise<BillingSummary>;
353
+ updatePlan: (planId: string) => Promise<void>;
354
+ cancelSubscription: () => Promise<void>;
355
+ updateCycle: (cycle: BillingCycle) => Promise<void>;
356
+ addPaymentMethod: (input: PaymentMethodInput) => Promise<PaymentMethod>;
357
+ removePaymentMethod: (methodId: string) => Promise<void>;
358
+ setDefaultPaymentMethod: (methodId: string) => Promise<void>;
359
+ getInvoiceUrl: (invoiceId: string) => Promise<string>;
360
+ }
361
+ interface UseBillingOptions {
362
+ initialData?: BillingSummary;
363
+ apiClient: BillingApiClient;
364
+ }
365
+ interface UseBillingReturn {
366
+ billing: BillingSummary | null;
367
+ isLoading: boolean;
368
+ error: string | null;
369
+ loadBilling: () => Promise<void>;
370
+ updatePlan: (planId: string) => Promise<void>;
371
+ cancelSubscription: () => Promise<void>;
372
+ updateCycle: (cycle: BillingCycle) => Promise<void>;
373
+ addPaymentMethod: (input: PaymentMethodInput) => Promise<PaymentMethod | null>;
374
+ removePaymentMethod: (methodId: string) => Promise<void>;
375
+ setDefaultPaymentMethod: (methodId: string) => Promise<void>;
376
+ getInvoiceUrl: (invoiceId: string) => Promise<string | null>;
377
+ }
378
+ declare function useBilling(options: UseBillingOptions): UseBillingReturn;
379
+ declare const createStubBillingApiClient: (overrides?: Partial<BillingApiClient>) => BillingApiClient;
380
+
381
+ declare function formatNumber(num: number, locale?: string): string;
382
+ declare function formatPrice(amount: number, currency?: string): string;
383
+ declare function calculateDiscount(monthlyPrice: number, yearlyPrice: number): number;
384
+ declare function calculateProratedAmount(amount: number, daysUsed: number, totalDays: number): number;
385
+ declare function getPlanPrice(plan: PlanTier, cycle: BillingCycle): number;
386
+ declare function calculateUsagePercentage(metric: UsageMetric): number;
387
+ declare function isNearLimit(metric: UsageMetric, threshold?: number): boolean;
388
+ declare function getStatusTone(status: SubscriptionStatus): VisualTone;
389
+ declare function getStatusLabel(status: SubscriptionStatus): string;
390
+ declare function getInvoiceStatusTone(status: InvoiceStatus): VisualTone;
391
+ declare function getInvoiceStatusLabel(status: InvoiceStatus): string;
392
+ declare function formatCardNumber(last4: string, brand: string): string;
393
+ declare function formatExpiry(month: number, year: number): string;
394
+ declare function getDaysRemaining(endDate: string): number;
395
+ declare function isTrialExpiringSoon(trialEnd: string, daysThreshold?: number): boolean;
396
+ declare function getNextBillingDate(currentPeriodEnd: string, cycle: BillingCycle): Date;
397
+ declare function groupInvoicesByStatus(invoices: Invoice[]): Record<InvoiceStatus, Invoice[]>;
398
+ declare function calculateInvoiceTotal(invoices: Invoice[], status?: InvoiceStatus): number;
399
+ declare function sortInvoicesByDate(invoices: Invoice[], order?: 'asc' | 'desc'): Invoice[];
400
+ declare function formatFeature(feature: string | {
401
+ text: string;
402
+ bold?: boolean;
403
+ included?: boolean;
404
+ }): {
405
+ text: string;
406
+ bold?: boolean;
407
+ included?: boolean;
408
+ };
409
+ declare function isPopularPlan(plan: PlanTier, plans: PlanTier[]): boolean;
410
+ declare function getTrialDaysText(trialEnd: string): string;
411
+
412
+ declare function transformProductToPlan(product: Product, price: ProductPrice): PlanTier;
413
+ declare function transformProducts(products: Product[]): PlanTier[];
414
+
415
+ interface PortalClientOptions {
416
+ adapter: BillingAdapter;
417
+ products: Product[];
418
+ userId?: string;
419
+ defaultCycle?: BillingCycle;
420
+ successUrl?: string;
421
+ navigation?: NavigationStrategy;
422
+ }
423
+ interface PortalClient extends BillingApiClient {
424
+ selectPlan: (productId: string, cycle?: BillingCycle) => Promise<void>;
425
+ openPortal: () => Promise<string>;
426
+ }
427
+ declare function createPortalClient(options: PortalClientOptions): PortalClient;
428
+
429
+ interface TurnkeyBillingPageProps {
430
+ adapter: BillingAdapter;
431
+ products: Product[];
432
+ config: Omit<BillingConfig, 'plans'> & {
433
+ plans?: PlanTier[];
434
+ };
435
+ userId?: string;
436
+ defaultCycle?: BillingCycle;
437
+ successUrl?: string;
438
+ navigation?: NavigationStrategy;
439
+ locale?: string;
440
+ labels?: BillingLabelsOverrides;
441
+ onError?: (error: Error) => void;
442
+ }
443
+ declare function TurnkeyBillingPage({ adapter, products, config, userId, defaultCycle, successUrl, navigation, locale, labels, onError, }: TurnkeyBillingPageProps): react.JSX.Element;
444
+
445
+ export { type BillingApiClient, type BillingConfig, BillingCycle, type BillingLabels, type BillingLabelsOverrides, BillingLabelsProvider, BillingLayout, type BillingLayoutProps, BillingPage, type BillingPageProps, BillingPortal, type BillingPortalProps, type BillingSummary, type BillingTabId, CURRENCY, type Currency, DEFAULT_BILLING_CONFIG, DEFAULT_BILLING_LABELS, INVOICE_STATUS, type Invoice, InvoiceCard, type InvoiceCardProps, type InvoiceItem, type InvoiceStatus, PLAN_TYPE, type PaymentMethod, type PaymentMethodInput, type PaymentMethodType, PaymentMethodsList, type PaymentMethodsListProps, PlanComparison, type PlanComparisonProps, type PlanTier, type PlanType, PortalButton, type PortalButtonProps, type PortalButtonSize, type PortalButtonVariant, type PortalClient, type PortalClientOptions, PortalSpinner, RADIO_GROUP_NAME, SUBSCRIPTION_STATUS, type Subscription, type SubscriptionStatus, TurnkeyBillingPage, type TurnkeyBillingPageProps, UsageCard, type UsageCardProps, type UsageMetric, type UseBillingOptions, type UseBillingReturn, calculateDiscount, calculateInvoiceTotal, calculateProratedAmount, calculateUsagePercentage, createPortalClient, createStubBillingApiClient, formatCardNumber, formatExpiry, formatFeature, formatLabel, formatNumber, formatPrice, getDaysRemaining, getInvoiceStatusLabel, getInvoiceStatusTone, getNextBillingDate, getPlanPrice, getStatusLabel, getStatusTone, getTrialDaysText, groupInvoicesByStatus, isNearLimit, isPopularPlan, isTrialExpiringSoon, mergeLabels, sortInvoicesByDate, transformProductToPlan, transformProducts, useBilling, useBillingLabels };