@digilogiclabs/saas-factory-payments 0.1.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.
- package/LICENSE +22 -0
- package/README.md +679 -0
- package/dist/index.d.mts +365 -0
- package/dist/index.d.ts +365 -0
- package/dist/index.js +869 -0
- package/dist/index.mjs +806 -0
- package/dist/native/index.d.mts +266 -0
- package/dist/native/index.d.ts +266 -0
- package/dist/native/index.js +1833 -0
- package/dist/native/index.mjs +1815 -0
- package/dist/server/index.d.mts +122 -0
- package/dist/server/index.d.ts +122 -0
- package/dist/server/index.js +484 -0
- package/dist/server/index.mjs +443 -0
- package/dist/web/index.d.mts +281 -0
- package/dist/web/index.d.ts +281 -0
- package/dist/web/index.js +1651 -0
- package/dist/web/index.mjs +1604 -0
- package/package.json +153 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Stripe, StripeElements } from '@stripe/stripe-js';
|
|
3
|
+
|
|
4
|
+
interface CheckoutButtonProps {
|
|
5
|
+
priceId: string;
|
|
6
|
+
customerId?: string;
|
|
7
|
+
customerEmail?: string;
|
|
8
|
+
successUrl?: string;
|
|
9
|
+
cancelUrl?: string;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
allowPromotionCodes?: boolean;
|
|
14
|
+
billingAddressCollection?: 'auto' | 'required';
|
|
15
|
+
metadata?: Record<string, string>;
|
|
16
|
+
trialPeriodDays?: number;
|
|
17
|
+
onSuccess?: () => void;
|
|
18
|
+
onError?: (error: string) => void;
|
|
19
|
+
onLoading?: (loading: boolean) => void;
|
|
20
|
+
}
|
|
21
|
+
declare const CheckoutButton: React.FC<CheckoutButtonProps>;
|
|
22
|
+
|
|
23
|
+
interface Subscription {
|
|
24
|
+
id: string;
|
|
25
|
+
customerId: string;
|
|
26
|
+
priceId: string;
|
|
27
|
+
status: 'active' | 'canceled' | 'past_due' | 'unpaid' | 'incomplete' | 'incomplete_expired' | 'trialing';
|
|
28
|
+
currentPeriodStart: Date;
|
|
29
|
+
currentPeriodEnd: Date;
|
|
30
|
+
cancelAtPeriodEnd: boolean;
|
|
31
|
+
trialEnd?: Date;
|
|
32
|
+
trialStart?: Date;
|
|
33
|
+
canceledAt?: Date;
|
|
34
|
+
endedAt?: Date;
|
|
35
|
+
metadata?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Customer {
|
|
39
|
+
id: string;
|
|
40
|
+
email: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
phone?: string;
|
|
43
|
+
stripeCustomerId?: string;
|
|
44
|
+
subscriptions: Subscription[];
|
|
45
|
+
defaultPaymentMethodId?: string;
|
|
46
|
+
metadata?: Record<string, string>;
|
|
47
|
+
created: Date;
|
|
48
|
+
updated: Date;
|
|
49
|
+
}
|
|
50
|
+
interface PaymentMethod {
|
|
51
|
+
id: string;
|
|
52
|
+
type: 'card' | 'bank_account' | 'sepa_debit' | 'ideal' | 'sofort';
|
|
53
|
+
card?: {
|
|
54
|
+
brand: string;
|
|
55
|
+
last4: string;
|
|
56
|
+
expMonth: number;
|
|
57
|
+
expYear: number;
|
|
58
|
+
country?: string;
|
|
59
|
+
};
|
|
60
|
+
bankAccount?: {
|
|
61
|
+
last4: string;
|
|
62
|
+
bankName?: string;
|
|
63
|
+
accountType?: string;
|
|
64
|
+
};
|
|
65
|
+
isDefault: boolean;
|
|
66
|
+
created: Date;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface PaymentsConfig {
|
|
70
|
+
provider: 'stripe';
|
|
71
|
+
publishableKey: string;
|
|
72
|
+
secretKey?: string;
|
|
73
|
+
webhookSecret?: string;
|
|
74
|
+
environment: 'development' | 'production';
|
|
75
|
+
apiVersion?: string;
|
|
76
|
+
}
|
|
77
|
+
interface PricingPlan {
|
|
78
|
+
id: string;
|
|
79
|
+
name: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
price: number;
|
|
82
|
+
currency: string;
|
|
83
|
+
interval: 'day' | 'week' | 'month' | 'year';
|
|
84
|
+
intervalCount?: number;
|
|
85
|
+
stripePriceId: string;
|
|
86
|
+
stripeProductId?: string;
|
|
87
|
+
features: string[];
|
|
88
|
+
popular?: boolean;
|
|
89
|
+
trialPeriodDays?: number;
|
|
90
|
+
metadata?: Record<string, string>;
|
|
91
|
+
}
|
|
92
|
+
interface CheckoutSessionParams {
|
|
93
|
+
priceId: string;
|
|
94
|
+
customerId?: string;
|
|
95
|
+
customerEmail?: string;
|
|
96
|
+
successUrl: string;
|
|
97
|
+
cancelUrl: string;
|
|
98
|
+
mode?: 'payment' | 'subscription' | 'setup';
|
|
99
|
+
allowPromotionCodes?: boolean;
|
|
100
|
+
billingAddressCollection?: 'auto' | 'required';
|
|
101
|
+
metadata?: Record<string, string>;
|
|
102
|
+
trialPeriodDays?: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface PricingTableProps {
|
|
106
|
+
plans: PricingPlan[];
|
|
107
|
+
customerId?: string;
|
|
108
|
+
customerEmail?: string;
|
|
109
|
+
successUrl?: string;
|
|
110
|
+
cancelUrl?: string;
|
|
111
|
+
className?: string;
|
|
112
|
+
onPlanSelect?: (plan: PricingPlan) => void;
|
|
113
|
+
onCheckoutSuccess?: (plan: PricingPlan) => void;
|
|
114
|
+
onCheckoutError?: (plan: PricingPlan, error: string) => void;
|
|
115
|
+
showFeatures?: boolean;
|
|
116
|
+
showTrialInfo?: boolean;
|
|
117
|
+
layout?: 'grid' | 'list';
|
|
118
|
+
maxColumns?: number;
|
|
119
|
+
}
|
|
120
|
+
declare const PricingTable: React.FC<PricingTableProps>;
|
|
121
|
+
|
|
122
|
+
interface PaymentFormProps {
|
|
123
|
+
clientSecret?: string;
|
|
124
|
+
customerId?: string;
|
|
125
|
+
customerEmail?: string;
|
|
126
|
+
amount?: number;
|
|
127
|
+
currency?: string;
|
|
128
|
+
description?: string;
|
|
129
|
+
metadata?: Record<string, string>;
|
|
130
|
+
onSuccess?: (paymentIntent: any) => void;
|
|
131
|
+
onError?: (error: string) => void;
|
|
132
|
+
onLoading?: (loading: boolean) => void;
|
|
133
|
+
className?: string;
|
|
134
|
+
showBillingDetails?: boolean;
|
|
135
|
+
elementType?: 'card' | 'payment';
|
|
136
|
+
}
|
|
137
|
+
declare const PaymentForm: React.FC<PaymentFormProps>;
|
|
138
|
+
|
|
139
|
+
interface BillingPortalProps {
|
|
140
|
+
customerId: string;
|
|
141
|
+
returnUrl?: string;
|
|
142
|
+
children?: React.ReactNode;
|
|
143
|
+
className?: string;
|
|
144
|
+
onSuccess?: () => void;
|
|
145
|
+
onError?: (error: string) => void;
|
|
146
|
+
onLoading?: (loading: boolean) => void;
|
|
147
|
+
}
|
|
148
|
+
declare const BillingPortal: React.FC<BillingPortalProps>;
|
|
149
|
+
|
|
150
|
+
interface StripeProviderProps {
|
|
151
|
+
children: React.ReactNode;
|
|
152
|
+
options?: {
|
|
153
|
+
fonts?: Array<{
|
|
154
|
+
cssSrc: string;
|
|
155
|
+
}>;
|
|
156
|
+
locale?: string;
|
|
157
|
+
apiVersion?: string;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
declare const StripeProvider: React.FC<StripeProviderProps>;
|
|
161
|
+
|
|
162
|
+
interface UseSubscriptionOptions {
|
|
163
|
+
customerId?: string;
|
|
164
|
+
subscriptionId?: string;
|
|
165
|
+
autoFetch?: boolean;
|
|
166
|
+
onError?: (error: string) => void;
|
|
167
|
+
}
|
|
168
|
+
interface UseSubscriptionReturn {
|
|
169
|
+
subscription: Subscription | null;
|
|
170
|
+
subscriptions: Subscription[];
|
|
171
|
+
loading: boolean;
|
|
172
|
+
error: string | null;
|
|
173
|
+
refetch: () => Promise<void>;
|
|
174
|
+
cancel: (subscriptionId?: string) => Promise<boolean>;
|
|
175
|
+
reactivate: (subscriptionId?: string) => Promise<boolean>;
|
|
176
|
+
updatePaymentMethod: (subscriptionId: string, paymentMethodId: string) => Promise<boolean>;
|
|
177
|
+
}
|
|
178
|
+
declare const useSubscription: (options?: UseSubscriptionOptions) => UseSubscriptionReturn;
|
|
179
|
+
|
|
180
|
+
interface UseCheckoutOptions {
|
|
181
|
+
onSuccess?: (sessionId: string) => void;
|
|
182
|
+
onError?: (error: string) => void;
|
|
183
|
+
onLoading?: (loading: boolean) => void;
|
|
184
|
+
}
|
|
185
|
+
interface UseCheckoutReturn {
|
|
186
|
+
loading: boolean;
|
|
187
|
+
error: string | null;
|
|
188
|
+
createCheckoutSession: (params: CheckoutSessionParams) => Promise<string | null>;
|
|
189
|
+
redirectToCheckout: (params: CheckoutSessionParams) => Promise<boolean>;
|
|
190
|
+
createPaymentIntent: (params: {
|
|
191
|
+
amount: number;
|
|
192
|
+
currency: string;
|
|
193
|
+
customerId?: string;
|
|
194
|
+
description?: string;
|
|
195
|
+
metadata?: Record<string, string>;
|
|
196
|
+
}) => Promise<string | null>;
|
|
197
|
+
}
|
|
198
|
+
declare const useCheckout: (options?: UseCheckoutOptions) => UseCheckoutReturn;
|
|
199
|
+
|
|
200
|
+
interface UseCustomerOptions {
|
|
201
|
+
customerId?: string;
|
|
202
|
+
autoFetch?: boolean;
|
|
203
|
+
onError?: (error: string) => void;
|
|
204
|
+
}
|
|
205
|
+
interface UseCustomerReturn {
|
|
206
|
+
customer: Customer | null;
|
|
207
|
+
paymentMethods: PaymentMethod[];
|
|
208
|
+
loading: boolean;
|
|
209
|
+
error: string | null;
|
|
210
|
+
refetch: () => Promise<void>;
|
|
211
|
+
createCustomer: (params: {
|
|
212
|
+
email: string;
|
|
213
|
+
name?: string;
|
|
214
|
+
phone?: string;
|
|
215
|
+
metadata?: Record<string, string>;
|
|
216
|
+
}) => Promise<Customer | null>;
|
|
217
|
+
updateCustomer: (params: {
|
|
218
|
+
email?: string;
|
|
219
|
+
name?: string;
|
|
220
|
+
phone?: string;
|
|
221
|
+
metadata?: Record<string, string>;
|
|
222
|
+
}) => Promise<boolean>;
|
|
223
|
+
deleteCustomer: () => Promise<boolean>;
|
|
224
|
+
fetchPaymentMethods: () => Promise<PaymentMethod[]>;
|
|
225
|
+
addPaymentMethod: (paymentMethodId: string) => Promise<boolean>;
|
|
226
|
+
removePaymentMethod: (paymentMethodId: string) => Promise<boolean>;
|
|
227
|
+
setDefaultPaymentMethod: (paymentMethodId: string) => Promise<boolean>;
|
|
228
|
+
}
|
|
229
|
+
declare const useCustomer: (options?: UseCustomerOptions) => UseCustomerReturn;
|
|
230
|
+
|
|
231
|
+
declare const getStripe: (publishableKey: string) => Promise<Stripe | null>;
|
|
232
|
+
declare const initializeStripe: (config: PaymentsConfig) => Promise<Stripe | null>;
|
|
233
|
+
declare const createCheckoutSession: (params: {
|
|
234
|
+
priceId: string;
|
|
235
|
+
customerId?: string;
|
|
236
|
+
customerEmail?: string;
|
|
237
|
+
successUrl: string;
|
|
238
|
+
cancelUrl: string;
|
|
239
|
+
allowPromotionCodes?: boolean;
|
|
240
|
+
billingAddressCollection?: "auto" | "required";
|
|
241
|
+
metadata?: Record<string, string>;
|
|
242
|
+
trialPeriodDays?: number;
|
|
243
|
+
}) => Promise<{
|
|
244
|
+
sessionId: string;
|
|
245
|
+
} | {
|
|
246
|
+
error: string;
|
|
247
|
+
}>;
|
|
248
|
+
declare const createPaymentIntent: (params: {
|
|
249
|
+
amount: number;
|
|
250
|
+
currency: string;
|
|
251
|
+
customerId?: string;
|
|
252
|
+
description?: string;
|
|
253
|
+
metadata?: Record<string, string>;
|
|
254
|
+
}) => Promise<{
|
|
255
|
+
clientSecret: string;
|
|
256
|
+
} | {
|
|
257
|
+
error: string;
|
|
258
|
+
}>;
|
|
259
|
+
declare const createPortalSession: (params: {
|
|
260
|
+
customerId: string;
|
|
261
|
+
returnUrl: string;
|
|
262
|
+
}) => Promise<{
|
|
263
|
+
url: string;
|
|
264
|
+
} | {
|
|
265
|
+
error: string;
|
|
266
|
+
}>;
|
|
267
|
+
declare const confirmPayment: (stripe: Stripe, elements: StripeElements, clientSecret: string, options?: {
|
|
268
|
+
returnUrl?: string;
|
|
269
|
+
receiptEmail?: string;
|
|
270
|
+
}) => Promise<{
|
|
271
|
+
success: boolean;
|
|
272
|
+
error?: string;
|
|
273
|
+
paymentIntent?: any;
|
|
274
|
+
}>;
|
|
275
|
+
declare const redirectToCheckout: (stripe: Stripe, sessionId: string) => Promise<{
|
|
276
|
+
success: boolean;
|
|
277
|
+
error?: string;
|
|
278
|
+
}>;
|
|
279
|
+
declare const formatStripeError: (error: any) => string;
|
|
280
|
+
|
|
281
|
+
export { BillingPortal, CheckoutButton, PaymentForm, PricingTable, StripeProvider, confirmPayment, createCheckoutSession, createPaymentIntent, createPortalSession, formatStripeError, getStripe, initializeStripe, redirectToCheckout, useCheckout, useCustomer, useSubscription };
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Stripe, StripeElements } from '@stripe/stripe-js';
|
|
3
|
+
|
|
4
|
+
interface CheckoutButtonProps {
|
|
5
|
+
priceId: string;
|
|
6
|
+
customerId?: string;
|
|
7
|
+
customerEmail?: string;
|
|
8
|
+
successUrl?: string;
|
|
9
|
+
cancelUrl?: string;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
allowPromotionCodes?: boolean;
|
|
14
|
+
billingAddressCollection?: 'auto' | 'required';
|
|
15
|
+
metadata?: Record<string, string>;
|
|
16
|
+
trialPeriodDays?: number;
|
|
17
|
+
onSuccess?: () => void;
|
|
18
|
+
onError?: (error: string) => void;
|
|
19
|
+
onLoading?: (loading: boolean) => void;
|
|
20
|
+
}
|
|
21
|
+
declare const CheckoutButton: React.FC<CheckoutButtonProps>;
|
|
22
|
+
|
|
23
|
+
interface Subscription {
|
|
24
|
+
id: string;
|
|
25
|
+
customerId: string;
|
|
26
|
+
priceId: string;
|
|
27
|
+
status: 'active' | 'canceled' | 'past_due' | 'unpaid' | 'incomplete' | 'incomplete_expired' | 'trialing';
|
|
28
|
+
currentPeriodStart: Date;
|
|
29
|
+
currentPeriodEnd: Date;
|
|
30
|
+
cancelAtPeriodEnd: boolean;
|
|
31
|
+
trialEnd?: Date;
|
|
32
|
+
trialStart?: Date;
|
|
33
|
+
canceledAt?: Date;
|
|
34
|
+
endedAt?: Date;
|
|
35
|
+
metadata?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Customer {
|
|
39
|
+
id: string;
|
|
40
|
+
email: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
phone?: string;
|
|
43
|
+
stripeCustomerId?: string;
|
|
44
|
+
subscriptions: Subscription[];
|
|
45
|
+
defaultPaymentMethodId?: string;
|
|
46
|
+
metadata?: Record<string, string>;
|
|
47
|
+
created: Date;
|
|
48
|
+
updated: Date;
|
|
49
|
+
}
|
|
50
|
+
interface PaymentMethod {
|
|
51
|
+
id: string;
|
|
52
|
+
type: 'card' | 'bank_account' | 'sepa_debit' | 'ideal' | 'sofort';
|
|
53
|
+
card?: {
|
|
54
|
+
brand: string;
|
|
55
|
+
last4: string;
|
|
56
|
+
expMonth: number;
|
|
57
|
+
expYear: number;
|
|
58
|
+
country?: string;
|
|
59
|
+
};
|
|
60
|
+
bankAccount?: {
|
|
61
|
+
last4: string;
|
|
62
|
+
bankName?: string;
|
|
63
|
+
accountType?: string;
|
|
64
|
+
};
|
|
65
|
+
isDefault: boolean;
|
|
66
|
+
created: Date;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface PaymentsConfig {
|
|
70
|
+
provider: 'stripe';
|
|
71
|
+
publishableKey: string;
|
|
72
|
+
secretKey?: string;
|
|
73
|
+
webhookSecret?: string;
|
|
74
|
+
environment: 'development' | 'production';
|
|
75
|
+
apiVersion?: string;
|
|
76
|
+
}
|
|
77
|
+
interface PricingPlan {
|
|
78
|
+
id: string;
|
|
79
|
+
name: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
price: number;
|
|
82
|
+
currency: string;
|
|
83
|
+
interval: 'day' | 'week' | 'month' | 'year';
|
|
84
|
+
intervalCount?: number;
|
|
85
|
+
stripePriceId: string;
|
|
86
|
+
stripeProductId?: string;
|
|
87
|
+
features: string[];
|
|
88
|
+
popular?: boolean;
|
|
89
|
+
trialPeriodDays?: number;
|
|
90
|
+
metadata?: Record<string, string>;
|
|
91
|
+
}
|
|
92
|
+
interface CheckoutSessionParams {
|
|
93
|
+
priceId: string;
|
|
94
|
+
customerId?: string;
|
|
95
|
+
customerEmail?: string;
|
|
96
|
+
successUrl: string;
|
|
97
|
+
cancelUrl: string;
|
|
98
|
+
mode?: 'payment' | 'subscription' | 'setup';
|
|
99
|
+
allowPromotionCodes?: boolean;
|
|
100
|
+
billingAddressCollection?: 'auto' | 'required';
|
|
101
|
+
metadata?: Record<string, string>;
|
|
102
|
+
trialPeriodDays?: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface PricingTableProps {
|
|
106
|
+
plans: PricingPlan[];
|
|
107
|
+
customerId?: string;
|
|
108
|
+
customerEmail?: string;
|
|
109
|
+
successUrl?: string;
|
|
110
|
+
cancelUrl?: string;
|
|
111
|
+
className?: string;
|
|
112
|
+
onPlanSelect?: (plan: PricingPlan) => void;
|
|
113
|
+
onCheckoutSuccess?: (plan: PricingPlan) => void;
|
|
114
|
+
onCheckoutError?: (plan: PricingPlan, error: string) => void;
|
|
115
|
+
showFeatures?: boolean;
|
|
116
|
+
showTrialInfo?: boolean;
|
|
117
|
+
layout?: 'grid' | 'list';
|
|
118
|
+
maxColumns?: number;
|
|
119
|
+
}
|
|
120
|
+
declare const PricingTable: React.FC<PricingTableProps>;
|
|
121
|
+
|
|
122
|
+
interface PaymentFormProps {
|
|
123
|
+
clientSecret?: string;
|
|
124
|
+
customerId?: string;
|
|
125
|
+
customerEmail?: string;
|
|
126
|
+
amount?: number;
|
|
127
|
+
currency?: string;
|
|
128
|
+
description?: string;
|
|
129
|
+
metadata?: Record<string, string>;
|
|
130
|
+
onSuccess?: (paymentIntent: any) => void;
|
|
131
|
+
onError?: (error: string) => void;
|
|
132
|
+
onLoading?: (loading: boolean) => void;
|
|
133
|
+
className?: string;
|
|
134
|
+
showBillingDetails?: boolean;
|
|
135
|
+
elementType?: 'card' | 'payment';
|
|
136
|
+
}
|
|
137
|
+
declare const PaymentForm: React.FC<PaymentFormProps>;
|
|
138
|
+
|
|
139
|
+
interface BillingPortalProps {
|
|
140
|
+
customerId: string;
|
|
141
|
+
returnUrl?: string;
|
|
142
|
+
children?: React.ReactNode;
|
|
143
|
+
className?: string;
|
|
144
|
+
onSuccess?: () => void;
|
|
145
|
+
onError?: (error: string) => void;
|
|
146
|
+
onLoading?: (loading: boolean) => void;
|
|
147
|
+
}
|
|
148
|
+
declare const BillingPortal: React.FC<BillingPortalProps>;
|
|
149
|
+
|
|
150
|
+
interface StripeProviderProps {
|
|
151
|
+
children: React.ReactNode;
|
|
152
|
+
options?: {
|
|
153
|
+
fonts?: Array<{
|
|
154
|
+
cssSrc: string;
|
|
155
|
+
}>;
|
|
156
|
+
locale?: string;
|
|
157
|
+
apiVersion?: string;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
declare const StripeProvider: React.FC<StripeProviderProps>;
|
|
161
|
+
|
|
162
|
+
interface UseSubscriptionOptions {
|
|
163
|
+
customerId?: string;
|
|
164
|
+
subscriptionId?: string;
|
|
165
|
+
autoFetch?: boolean;
|
|
166
|
+
onError?: (error: string) => void;
|
|
167
|
+
}
|
|
168
|
+
interface UseSubscriptionReturn {
|
|
169
|
+
subscription: Subscription | null;
|
|
170
|
+
subscriptions: Subscription[];
|
|
171
|
+
loading: boolean;
|
|
172
|
+
error: string | null;
|
|
173
|
+
refetch: () => Promise<void>;
|
|
174
|
+
cancel: (subscriptionId?: string) => Promise<boolean>;
|
|
175
|
+
reactivate: (subscriptionId?: string) => Promise<boolean>;
|
|
176
|
+
updatePaymentMethod: (subscriptionId: string, paymentMethodId: string) => Promise<boolean>;
|
|
177
|
+
}
|
|
178
|
+
declare const useSubscription: (options?: UseSubscriptionOptions) => UseSubscriptionReturn;
|
|
179
|
+
|
|
180
|
+
interface UseCheckoutOptions {
|
|
181
|
+
onSuccess?: (sessionId: string) => void;
|
|
182
|
+
onError?: (error: string) => void;
|
|
183
|
+
onLoading?: (loading: boolean) => void;
|
|
184
|
+
}
|
|
185
|
+
interface UseCheckoutReturn {
|
|
186
|
+
loading: boolean;
|
|
187
|
+
error: string | null;
|
|
188
|
+
createCheckoutSession: (params: CheckoutSessionParams) => Promise<string | null>;
|
|
189
|
+
redirectToCheckout: (params: CheckoutSessionParams) => Promise<boolean>;
|
|
190
|
+
createPaymentIntent: (params: {
|
|
191
|
+
amount: number;
|
|
192
|
+
currency: string;
|
|
193
|
+
customerId?: string;
|
|
194
|
+
description?: string;
|
|
195
|
+
metadata?: Record<string, string>;
|
|
196
|
+
}) => Promise<string | null>;
|
|
197
|
+
}
|
|
198
|
+
declare const useCheckout: (options?: UseCheckoutOptions) => UseCheckoutReturn;
|
|
199
|
+
|
|
200
|
+
interface UseCustomerOptions {
|
|
201
|
+
customerId?: string;
|
|
202
|
+
autoFetch?: boolean;
|
|
203
|
+
onError?: (error: string) => void;
|
|
204
|
+
}
|
|
205
|
+
interface UseCustomerReturn {
|
|
206
|
+
customer: Customer | null;
|
|
207
|
+
paymentMethods: PaymentMethod[];
|
|
208
|
+
loading: boolean;
|
|
209
|
+
error: string | null;
|
|
210
|
+
refetch: () => Promise<void>;
|
|
211
|
+
createCustomer: (params: {
|
|
212
|
+
email: string;
|
|
213
|
+
name?: string;
|
|
214
|
+
phone?: string;
|
|
215
|
+
metadata?: Record<string, string>;
|
|
216
|
+
}) => Promise<Customer | null>;
|
|
217
|
+
updateCustomer: (params: {
|
|
218
|
+
email?: string;
|
|
219
|
+
name?: string;
|
|
220
|
+
phone?: string;
|
|
221
|
+
metadata?: Record<string, string>;
|
|
222
|
+
}) => Promise<boolean>;
|
|
223
|
+
deleteCustomer: () => Promise<boolean>;
|
|
224
|
+
fetchPaymentMethods: () => Promise<PaymentMethod[]>;
|
|
225
|
+
addPaymentMethod: (paymentMethodId: string) => Promise<boolean>;
|
|
226
|
+
removePaymentMethod: (paymentMethodId: string) => Promise<boolean>;
|
|
227
|
+
setDefaultPaymentMethod: (paymentMethodId: string) => Promise<boolean>;
|
|
228
|
+
}
|
|
229
|
+
declare const useCustomer: (options?: UseCustomerOptions) => UseCustomerReturn;
|
|
230
|
+
|
|
231
|
+
declare const getStripe: (publishableKey: string) => Promise<Stripe | null>;
|
|
232
|
+
declare const initializeStripe: (config: PaymentsConfig) => Promise<Stripe | null>;
|
|
233
|
+
declare const createCheckoutSession: (params: {
|
|
234
|
+
priceId: string;
|
|
235
|
+
customerId?: string;
|
|
236
|
+
customerEmail?: string;
|
|
237
|
+
successUrl: string;
|
|
238
|
+
cancelUrl: string;
|
|
239
|
+
allowPromotionCodes?: boolean;
|
|
240
|
+
billingAddressCollection?: "auto" | "required";
|
|
241
|
+
metadata?: Record<string, string>;
|
|
242
|
+
trialPeriodDays?: number;
|
|
243
|
+
}) => Promise<{
|
|
244
|
+
sessionId: string;
|
|
245
|
+
} | {
|
|
246
|
+
error: string;
|
|
247
|
+
}>;
|
|
248
|
+
declare const createPaymentIntent: (params: {
|
|
249
|
+
amount: number;
|
|
250
|
+
currency: string;
|
|
251
|
+
customerId?: string;
|
|
252
|
+
description?: string;
|
|
253
|
+
metadata?: Record<string, string>;
|
|
254
|
+
}) => Promise<{
|
|
255
|
+
clientSecret: string;
|
|
256
|
+
} | {
|
|
257
|
+
error: string;
|
|
258
|
+
}>;
|
|
259
|
+
declare const createPortalSession: (params: {
|
|
260
|
+
customerId: string;
|
|
261
|
+
returnUrl: string;
|
|
262
|
+
}) => Promise<{
|
|
263
|
+
url: string;
|
|
264
|
+
} | {
|
|
265
|
+
error: string;
|
|
266
|
+
}>;
|
|
267
|
+
declare const confirmPayment: (stripe: Stripe, elements: StripeElements, clientSecret: string, options?: {
|
|
268
|
+
returnUrl?: string;
|
|
269
|
+
receiptEmail?: string;
|
|
270
|
+
}) => Promise<{
|
|
271
|
+
success: boolean;
|
|
272
|
+
error?: string;
|
|
273
|
+
paymentIntent?: any;
|
|
274
|
+
}>;
|
|
275
|
+
declare const redirectToCheckout: (stripe: Stripe, sessionId: string) => Promise<{
|
|
276
|
+
success: boolean;
|
|
277
|
+
error?: string;
|
|
278
|
+
}>;
|
|
279
|
+
declare const formatStripeError: (error: any) => string;
|
|
280
|
+
|
|
281
|
+
export { BillingPortal, CheckoutButton, PaymentForm, PricingTable, StripeProvider, confirmPayment, createCheckoutSession, createPaymentIntent, createPortalSession, formatStripeError, getStripe, initializeStripe, redirectToCheckout, useCheckout, useCustomer, useSubscription };
|