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