@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
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface Subscription {
|
|
4
|
+
id: string;
|
|
5
|
+
customerId: string;
|
|
6
|
+
priceId: string;
|
|
7
|
+
status: 'active' | 'canceled' | 'past_due' | 'unpaid' | 'incomplete' | 'incomplete_expired' | 'trialing';
|
|
8
|
+
currentPeriodStart: Date;
|
|
9
|
+
currentPeriodEnd: Date;
|
|
10
|
+
cancelAtPeriodEnd: boolean;
|
|
11
|
+
trialEnd?: Date;
|
|
12
|
+
trialStart?: Date;
|
|
13
|
+
canceledAt?: Date;
|
|
14
|
+
endedAt?: Date;
|
|
15
|
+
metadata?: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
interface SubscriptionItem {
|
|
18
|
+
id: string;
|
|
19
|
+
subscriptionId: string;
|
|
20
|
+
priceId: string;
|
|
21
|
+
quantity: number;
|
|
22
|
+
metadata?: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
interface SubscriptionCreateParams {
|
|
25
|
+
customerId: string;
|
|
26
|
+
priceId: string;
|
|
27
|
+
quantity?: number;
|
|
28
|
+
trialPeriodDays?: number;
|
|
29
|
+
metadata?: Record<string, string>;
|
|
30
|
+
paymentBehavior?: 'default_incomplete' | 'error_if_incomplete' | 'allow_incomplete';
|
|
31
|
+
}
|
|
32
|
+
interface SubscriptionUpdateParams {
|
|
33
|
+
priceId?: string;
|
|
34
|
+
quantity?: number;
|
|
35
|
+
cancelAtPeriodEnd?: boolean;
|
|
36
|
+
metadata?: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
type SubscriptionStatus = Subscription['status'];
|
|
39
|
+
|
|
40
|
+
interface Customer {
|
|
41
|
+
id: string;
|
|
42
|
+
email: string;
|
|
43
|
+
name?: string;
|
|
44
|
+
phone?: string;
|
|
45
|
+
stripeCustomerId?: string;
|
|
46
|
+
subscriptions: Subscription[];
|
|
47
|
+
defaultPaymentMethodId?: string;
|
|
48
|
+
metadata?: Record<string, string>;
|
|
49
|
+
created: Date;
|
|
50
|
+
updated: Date;
|
|
51
|
+
}
|
|
52
|
+
interface CustomerCreateParams {
|
|
53
|
+
email: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
phone?: string;
|
|
56
|
+
metadata?: Record<string, string>;
|
|
57
|
+
paymentMethod?: string;
|
|
58
|
+
}
|
|
59
|
+
interface CustomerUpdateParams {
|
|
60
|
+
email?: string;
|
|
61
|
+
name?: string;
|
|
62
|
+
phone?: string;
|
|
63
|
+
metadata?: Record<string, string>;
|
|
64
|
+
defaultPaymentMethod?: string;
|
|
65
|
+
}
|
|
66
|
+
interface PaymentMethod {
|
|
67
|
+
id: string;
|
|
68
|
+
type: 'card' | 'bank_account' | 'sepa_debit' | 'ideal' | 'sofort';
|
|
69
|
+
card?: {
|
|
70
|
+
brand: string;
|
|
71
|
+
last4: string;
|
|
72
|
+
expMonth: number;
|
|
73
|
+
expYear: number;
|
|
74
|
+
country?: string;
|
|
75
|
+
};
|
|
76
|
+
bankAccount?: {
|
|
77
|
+
last4: string;
|
|
78
|
+
bankName?: string;
|
|
79
|
+
accountType?: string;
|
|
80
|
+
};
|
|
81
|
+
isDefault: boolean;
|
|
82
|
+
created: Date;
|
|
83
|
+
}
|
|
84
|
+
interface BillingAddress {
|
|
85
|
+
line1?: string;
|
|
86
|
+
line2?: string;
|
|
87
|
+
city?: string;
|
|
88
|
+
state?: string;
|
|
89
|
+
postalCode?: string;
|
|
90
|
+
country?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface PaymentsConfig {
|
|
94
|
+
provider: 'stripe';
|
|
95
|
+
publishableKey: string;
|
|
96
|
+
secretKey?: string;
|
|
97
|
+
webhookSecret?: string;
|
|
98
|
+
environment: 'development' | 'production';
|
|
99
|
+
apiVersion?: string;
|
|
100
|
+
}
|
|
101
|
+
interface PricingPlan {
|
|
102
|
+
id: string;
|
|
103
|
+
name: string;
|
|
104
|
+
description?: string;
|
|
105
|
+
price: number;
|
|
106
|
+
currency: string;
|
|
107
|
+
interval: 'day' | 'week' | 'month' | 'year';
|
|
108
|
+
intervalCount?: number;
|
|
109
|
+
stripePriceId: string;
|
|
110
|
+
stripeProductId?: string;
|
|
111
|
+
features: string[];
|
|
112
|
+
popular?: boolean;
|
|
113
|
+
trialPeriodDays?: number;
|
|
114
|
+
metadata?: Record<string, string>;
|
|
115
|
+
}
|
|
116
|
+
interface CheckoutSessionParams {
|
|
117
|
+
priceId: string;
|
|
118
|
+
customerId?: string;
|
|
119
|
+
customerEmail?: string;
|
|
120
|
+
successUrl: string;
|
|
121
|
+
cancelUrl: string;
|
|
122
|
+
mode?: 'payment' | 'subscription' | 'setup';
|
|
123
|
+
allowPromotionCodes?: boolean;
|
|
124
|
+
billingAddressCollection?: 'auto' | 'required';
|
|
125
|
+
metadata?: Record<string, string>;
|
|
126
|
+
trialPeriodDays?: number;
|
|
127
|
+
}
|
|
128
|
+
interface PaymentIntentParams {
|
|
129
|
+
amount: number;
|
|
130
|
+
currency: string;
|
|
131
|
+
customerId?: string;
|
|
132
|
+
paymentMethodTypes?: string[];
|
|
133
|
+
metadata?: Record<string, string>;
|
|
134
|
+
description?: string;
|
|
135
|
+
}
|
|
136
|
+
interface WebhookEvent {
|
|
137
|
+
id: string;
|
|
138
|
+
type: string;
|
|
139
|
+
data: {
|
|
140
|
+
object: any;
|
|
141
|
+
previous_attributes?: any;
|
|
142
|
+
};
|
|
143
|
+
created: number;
|
|
144
|
+
livemode: boolean;
|
|
145
|
+
pending_webhooks: number;
|
|
146
|
+
request?: {
|
|
147
|
+
id: string;
|
|
148
|
+
idempotency_key?: string;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
interface StripeError {
|
|
152
|
+
type: 'card_error' | 'invalid_request_error' | 'api_error' | 'authentication_error' | 'rate_limit_error';
|
|
153
|
+
code?: string;
|
|
154
|
+
message: string;
|
|
155
|
+
param?: string;
|
|
156
|
+
decline_code?: string;
|
|
157
|
+
}
|
|
158
|
+
interface Invoice {
|
|
159
|
+
id: string;
|
|
160
|
+
customerId: string;
|
|
161
|
+
subscriptionId?: string;
|
|
162
|
+
status: 'draft' | 'open' | 'paid' | 'uncollectible' | 'void';
|
|
163
|
+
amountDue: number;
|
|
164
|
+
amountPaid: number;
|
|
165
|
+
currency: string;
|
|
166
|
+
dueDate?: Date;
|
|
167
|
+
paidAt?: Date;
|
|
168
|
+
hostedInvoiceUrl?: string;
|
|
169
|
+
invoicePdf?: string;
|
|
170
|
+
metadata?: Record<string, string>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare const STRIPE_API_VERSION = "2023-10-16";
|
|
174
|
+
declare const PAYMENT_METHODS: {
|
|
175
|
+
readonly CARD: "card";
|
|
176
|
+
readonly BANK_ACCOUNT: "bank_account";
|
|
177
|
+
readonly SEPA_DEBIT: "sepa_debit";
|
|
178
|
+
readonly IDEAL: "ideal";
|
|
179
|
+
readonly SOFORT: "sofort";
|
|
180
|
+
};
|
|
181
|
+
declare const SUBSCRIPTION_STATUS: {
|
|
182
|
+
readonly ACTIVE: "active";
|
|
183
|
+
readonly CANCELED: "canceled";
|
|
184
|
+
readonly PAST_DUE: "past_due";
|
|
185
|
+
readonly UNPAID: "unpaid";
|
|
186
|
+
readonly INCOMPLETE: "incomplete";
|
|
187
|
+
readonly INCOMPLETE_EXPIRED: "incomplete_expired";
|
|
188
|
+
readonly TRIALING: "trialing";
|
|
189
|
+
};
|
|
190
|
+
declare const INVOICE_STATUS: {
|
|
191
|
+
readonly DRAFT: "draft";
|
|
192
|
+
readonly OPEN: "open";
|
|
193
|
+
readonly PAID: "paid";
|
|
194
|
+
readonly UNCOLLECTIBLE: "uncollectible";
|
|
195
|
+
readonly VOID: "void";
|
|
196
|
+
};
|
|
197
|
+
declare const CHECKOUT_MODE: {
|
|
198
|
+
readonly PAYMENT: "payment";
|
|
199
|
+
readonly SUBSCRIPTION: "subscription";
|
|
200
|
+
readonly SETUP: "setup";
|
|
201
|
+
};
|
|
202
|
+
declare const BILLING_INTERVALS: {
|
|
203
|
+
readonly DAY: "day";
|
|
204
|
+
readonly WEEK: "week";
|
|
205
|
+
readonly MONTH: "month";
|
|
206
|
+
readonly YEAR: "year";
|
|
207
|
+
};
|
|
208
|
+
declare const CURRENCY_SYMBOLS: {
|
|
209
|
+
readonly USD: "$";
|
|
210
|
+
readonly EUR: "€";
|
|
211
|
+
readonly GBP: "£";
|
|
212
|
+
readonly JPY: "¥";
|
|
213
|
+
readonly CAD: "C$";
|
|
214
|
+
readonly AUD: "A$";
|
|
215
|
+
readonly CHF: "CHF";
|
|
216
|
+
readonly CNY: "¥";
|
|
217
|
+
readonly SEK: "kr";
|
|
218
|
+
readonly NZD: "NZ$";
|
|
219
|
+
};
|
|
220
|
+
declare const DEFAULT_CURRENCY = "USD";
|
|
221
|
+
declare const WEBHOOK_EVENTS: {
|
|
222
|
+
readonly CUSTOMER_SUBSCRIPTION_CREATED: "customer.subscription.created";
|
|
223
|
+
readonly CUSTOMER_SUBSCRIPTION_UPDATED: "customer.subscription.updated";
|
|
224
|
+
readonly CUSTOMER_SUBSCRIPTION_DELETED: "customer.subscription.deleted";
|
|
225
|
+
readonly INVOICE_PAYMENT_SUCCEEDED: "invoice.payment_succeeded";
|
|
226
|
+
readonly INVOICE_PAYMENT_FAILED: "invoice.payment_failed";
|
|
227
|
+
readonly CHECKOUT_SESSION_COMPLETED: "checkout.session.completed";
|
|
228
|
+
readonly PAYMENT_INTENT_SUCCEEDED: "payment_intent.succeeded";
|
|
229
|
+
readonly PAYMENT_INTENT_PAYMENT_FAILED: "payment_intent.payment_failed";
|
|
230
|
+
};
|
|
231
|
+
declare const ERROR_MESSAGES: {
|
|
232
|
+
readonly PROVIDER_NOT_CONFIGURED: "Payments provider is not properly configured";
|
|
233
|
+
readonly STRIPE_NOT_LOADED: "Stripe has not been loaded yet";
|
|
234
|
+
readonly INVALID_PRICE_ID: "Invalid price ID provided";
|
|
235
|
+
readonly INVALID_CUSTOMER_ID: "Invalid customer ID provided";
|
|
236
|
+
readonly CHECKOUT_FAILED: "Checkout session creation failed";
|
|
237
|
+
readonly PAYMENT_FAILED: "Payment processing failed";
|
|
238
|
+
readonly SUBSCRIPTION_NOT_FOUND: "Subscription not found";
|
|
239
|
+
readonly CUSTOMER_NOT_FOUND: "Customer not found";
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
declare const validateEmail: (email: string) => boolean;
|
|
243
|
+
declare const validatePhoneNumber: (phone: string) => boolean;
|
|
244
|
+
declare const validatePaymentsConfig: (config: PaymentsConfig) => {
|
|
245
|
+
isValid: boolean;
|
|
246
|
+
errors: string[];
|
|
247
|
+
};
|
|
248
|
+
declare const validatePricingPlan: (plan: PricingPlan) => {
|
|
249
|
+
isValid: boolean;
|
|
250
|
+
errors: string[];
|
|
251
|
+
};
|
|
252
|
+
declare const validateStripeId: (id: string, type: "customer" | "subscription" | "price" | "product" | "payment_intent") => boolean;
|
|
253
|
+
declare const validateAmount: (amount: number, currency: string) => {
|
|
254
|
+
isValid: boolean;
|
|
255
|
+
error?: string;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
declare const formatCurrency: (amount: number, currency?: string, options?: {
|
|
259
|
+
showSymbol?: boolean;
|
|
260
|
+
showCents?: boolean;
|
|
261
|
+
locale?: string;
|
|
262
|
+
}) => string;
|
|
263
|
+
declare const formatPricingPlan: (plan: PricingPlan) => string;
|
|
264
|
+
declare const formatSubscriptionStatus: (status: SubscriptionStatus) => string;
|
|
265
|
+
declare const formatDate: (date: Date | string | number, options?: {
|
|
266
|
+
format?: "short" | "medium" | "long" | "full";
|
|
267
|
+
locale?: string;
|
|
268
|
+
timeZone?: string;
|
|
269
|
+
}) => string;
|
|
270
|
+
declare const formatRelativeTime: (date: Date | string | number, options?: {
|
|
271
|
+
locale?: string;
|
|
272
|
+
numeric?: "always" | "auto";
|
|
273
|
+
}) => string;
|
|
274
|
+
declare const formatBillingInterval: (interval: string, count?: number) => string;
|
|
275
|
+
declare const formatTrialPeriod: (days: number) => string;
|
|
276
|
+
declare const truncateText: (text: string, maxLength: number) => string;
|
|
277
|
+
declare const formatCardBrand: (brand: string) => string;
|
|
278
|
+
declare const formatPaymentMethodDisplay: (paymentMethod: {
|
|
279
|
+
type: string;
|
|
280
|
+
card?: {
|
|
281
|
+
brand: string;
|
|
282
|
+
last4: string;
|
|
283
|
+
};
|
|
284
|
+
bankAccount?: {
|
|
285
|
+
last4: string;
|
|
286
|
+
bankName?: string;
|
|
287
|
+
};
|
|
288
|
+
}) => string;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Environment validation utilities for SaaS Factory Payments
|
|
292
|
+
*/
|
|
293
|
+
interface EnvironmentConfig {
|
|
294
|
+
stripePublishableKey: string;
|
|
295
|
+
stripeSecretKey?: string;
|
|
296
|
+
stripeWebhookSecret?: string;
|
|
297
|
+
environment: 'development' | 'production';
|
|
298
|
+
appUrl?: string;
|
|
299
|
+
}
|
|
300
|
+
declare const validateEnvironment: (config: Partial<EnvironmentConfig>) => {
|
|
301
|
+
isValid: boolean;
|
|
302
|
+
errors: string[];
|
|
303
|
+
warnings: string[];
|
|
304
|
+
};
|
|
305
|
+
declare const getEnvironmentConfig: () => EnvironmentConfig;
|
|
306
|
+
declare const validateCurrentEnvironment: () => {
|
|
307
|
+
isValid: boolean;
|
|
308
|
+
errors: string[];
|
|
309
|
+
warnings: string[];
|
|
310
|
+
};
|
|
311
|
+
declare const isDevelopment: () => boolean;
|
|
312
|
+
declare const isProduction: () => boolean;
|
|
313
|
+
declare const isServer: () => boolean;
|
|
314
|
+
declare const isClient: () => boolean;
|
|
315
|
+
|
|
316
|
+
interface PaymentsContextType {
|
|
317
|
+
config: PaymentsConfig;
|
|
318
|
+
isConfigured: boolean;
|
|
319
|
+
isProduction: boolean;
|
|
320
|
+
}
|
|
321
|
+
interface PaymentsProviderProps {
|
|
322
|
+
children: ReactNode;
|
|
323
|
+
config: PaymentsConfig;
|
|
324
|
+
}
|
|
325
|
+
declare const PaymentsProvider: React.FC<PaymentsProviderProps>;
|
|
326
|
+
declare const usePaymentsConfig: () => PaymentsContextType;
|
|
327
|
+
declare const usePaymentsConfigSafe: () => PaymentsContextType | null;
|
|
328
|
+
|
|
329
|
+
interface UsePaymentsOptions {
|
|
330
|
+
customerId?: string;
|
|
331
|
+
autoFetch?: boolean;
|
|
332
|
+
onError?: (error: string) => void;
|
|
333
|
+
}
|
|
334
|
+
interface UsePaymentsReturn {
|
|
335
|
+
customer: Customer | null;
|
|
336
|
+
subscriptions: Subscription[];
|
|
337
|
+
activeSubscription: Subscription | null;
|
|
338
|
+
loading: boolean;
|
|
339
|
+
error: string | null;
|
|
340
|
+
createCustomer: (params: {
|
|
341
|
+
email: string;
|
|
342
|
+
name?: string;
|
|
343
|
+
phone?: string;
|
|
344
|
+
metadata?: Record<string, string>;
|
|
345
|
+
}) => Promise<Customer | null>;
|
|
346
|
+
updateCustomer: (params: {
|
|
347
|
+
email?: string;
|
|
348
|
+
name?: string;
|
|
349
|
+
phone?: string;
|
|
350
|
+
metadata?: Record<string, string>;
|
|
351
|
+
}) => Promise<boolean>;
|
|
352
|
+
subscribe: (priceId: string, options?: {
|
|
353
|
+
trialPeriodDays?: number;
|
|
354
|
+
metadata?: Record<string, string>;
|
|
355
|
+
}) => Promise<boolean>;
|
|
356
|
+
cancelSubscription: (subscriptionId?: string) => Promise<boolean>;
|
|
357
|
+
reactivateSubscription: (subscriptionId?: string) => Promise<boolean>;
|
|
358
|
+
refetch: () => Promise<void>;
|
|
359
|
+
hasActiveSubscription: () => boolean;
|
|
360
|
+
isSubscribedToPlan: (priceId: string) => boolean;
|
|
361
|
+
getSubscriptionStatus: (subscriptionId?: string) => string | null;
|
|
362
|
+
}
|
|
363
|
+
declare const usePayments: (options?: UsePaymentsOptions) => UsePaymentsReturn;
|
|
364
|
+
|
|
365
|
+
export { BILLING_INTERVALS, type BillingAddress, CHECKOUT_MODE, CURRENCY_SYMBOLS, type CheckoutSessionParams, type Customer, type CustomerCreateParams, type CustomerUpdateParams, DEFAULT_CURRENCY, ERROR_MESSAGES, type EnvironmentConfig, INVOICE_STATUS, type Invoice, PAYMENT_METHODS, type PaymentIntentParams, type PaymentMethod, type PaymentsConfig, PaymentsProvider, type PricingPlan, STRIPE_API_VERSION, SUBSCRIPTION_STATUS, type StripeError, type Subscription, type SubscriptionCreateParams, type SubscriptionItem, type SubscriptionStatus, type SubscriptionUpdateParams, WEBHOOK_EVENTS, type WebhookEvent, formatBillingInterval, formatCardBrand, formatCurrency, formatDate, formatPaymentMethodDisplay, formatPricingPlan, formatRelativeTime, formatSubscriptionStatus, formatTrialPeriod, getEnvironmentConfig, isClient, isDevelopment, isProduction, isServer, truncateText, usePayments, usePaymentsConfig, usePaymentsConfigSafe, validateAmount, validateCurrentEnvironment, validateEmail, validateEnvironment, validatePaymentsConfig, validatePhoneNumber, validatePricingPlan, validateStripeId };
|