@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,122 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
|
|
3
|
+
declare class StripeServerAPI {
|
|
4
|
+
private stripe;
|
|
5
|
+
constructor(secretKey: string, options?: {
|
|
6
|
+
apiVersion?: string;
|
|
7
|
+
typescript?: boolean;
|
|
8
|
+
});
|
|
9
|
+
createCustomer(params: {
|
|
10
|
+
email: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
phone?: string;
|
|
13
|
+
metadata?: Record<string, string>;
|
|
14
|
+
}): Promise<Stripe.Response<Stripe.Customer>>;
|
|
15
|
+
getCustomer(customerId: string): Promise<Stripe.Response<Stripe.Customer | Stripe.DeletedCustomer>>;
|
|
16
|
+
updateCustomer(customerId: string, params: {
|
|
17
|
+
email?: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
phone?: string;
|
|
20
|
+
metadata?: Record<string, string>;
|
|
21
|
+
}): Promise<Stripe.Response<Stripe.Customer>>;
|
|
22
|
+
deleteCustomer(customerId: string): Promise<Stripe.Response<Stripe.DeletedCustomer>>;
|
|
23
|
+
createSubscription(params: {
|
|
24
|
+
customerId: string;
|
|
25
|
+
priceId: string;
|
|
26
|
+
quantity?: number;
|
|
27
|
+
trialPeriodDays?: number;
|
|
28
|
+
metadata?: Record<string, string>;
|
|
29
|
+
paymentBehavior?: 'default_incomplete' | 'error_if_incomplete' | 'allow_incomplete';
|
|
30
|
+
}): Promise<Stripe.Response<Stripe.Subscription>>;
|
|
31
|
+
getSubscription(subscriptionId: string): Promise<Stripe.Response<Stripe.Subscription>>;
|
|
32
|
+
updateSubscription(subscriptionId: string, params: {
|
|
33
|
+
priceId?: string;
|
|
34
|
+
quantity?: number;
|
|
35
|
+
metadata?: Record<string, string>;
|
|
36
|
+
cancelAtPeriodEnd?: boolean;
|
|
37
|
+
}): Promise<Stripe.Response<Stripe.Subscription>>;
|
|
38
|
+
cancelSubscription(subscriptionId: string, immediately?: boolean): Promise<Stripe.Response<Stripe.Subscription>>;
|
|
39
|
+
reactivateSubscription(subscriptionId: string): Promise<Stripe.Response<Stripe.Subscription>>;
|
|
40
|
+
getCustomerSubscriptions(customerId: string): Promise<Stripe.Response<Stripe.ApiList<Stripe.Subscription>>>;
|
|
41
|
+
createCheckoutSession(params: {
|
|
42
|
+
priceId: string;
|
|
43
|
+
customerId?: string;
|
|
44
|
+
customerEmail?: string;
|
|
45
|
+
successUrl: string;
|
|
46
|
+
cancelUrl: string;
|
|
47
|
+
mode?: 'payment' | 'subscription' | 'setup';
|
|
48
|
+
allowPromotionCodes?: boolean;
|
|
49
|
+
billingAddressCollection?: 'auto' | 'required';
|
|
50
|
+
metadata?: Record<string, string>;
|
|
51
|
+
trialPeriodDays?: number;
|
|
52
|
+
}): Promise<Stripe.Response<Stripe.Checkout.Session>>;
|
|
53
|
+
createPaymentIntent(params: {
|
|
54
|
+
amount: number;
|
|
55
|
+
currency: string;
|
|
56
|
+
customerId?: string;
|
|
57
|
+
paymentMethodTypes?: string[];
|
|
58
|
+
metadata?: Record<string, string>;
|
|
59
|
+
description?: string;
|
|
60
|
+
}): Promise<Stripe.Response<Stripe.PaymentIntent>>;
|
|
61
|
+
confirmPaymentIntent(paymentIntentId: string, params?: {
|
|
62
|
+
paymentMethod?: string;
|
|
63
|
+
}): Promise<Stripe.Response<Stripe.PaymentIntent>>;
|
|
64
|
+
createSetupIntent(params: {
|
|
65
|
+
customerId: string;
|
|
66
|
+
paymentMethodTypes?: string[];
|
|
67
|
+
metadata?: Record<string, string>;
|
|
68
|
+
}): Promise<Stripe.Response<Stripe.SetupIntent>>;
|
|
69
|
+
createPortalSession(params: {
|
|
70
|
+
customerId: string;
|
|
71
|
+
returnUrl: string;
|
|
72
|
+
}): Promise<Stripe.Response<Stripe.BillingPortal.Session>>;
|
|
73
|
+
getCustomerPaymentMethods(customerId: string, type?: string): Promise<Stripe.Response<Stripe.ApiList<Stripe.PaymentMethod>>>;
|
|
74
|
+
attachPaymentMethod(paymentMethodId: string, customerId: string): Promise<Stripe.Response<Stripe.PaymentMethod>>;
|
|
75
|
+
detachPaymentMethod(paymentMethodId: string): Promise<Stripe.Response<Stripe.PaymentMethod>>;
|
|
76
|
+
setDefaultPaymentMethod(customerId: string, paymentMethodId: string): Promise<Stripe.Response<Stripe.Customer>>;
|
|
77
|
+
getCustomerInvoices(customerId: string, limit?: number): Promise<Stripe.Response<Stripe.ApiList<Stripe.Invoice>>>;
|
|
78
|
+
getInvoice(invoiceId: string): Promise<Stripe.Response<Stripe.Invoice>>;
|
|
79
|
+
constructWebhookEvent(payload: string | Buffer, signature: string, webhookSecret: string): Stripe.Event;
|
|
80
|
+
getPrice(priceId: string): Promise<Stripe.Response<Stripe.Price>>;
|
|
81
|
+
getPrices(params?: {
|
|
82
|
+
active?: boolean;
|
|
83
|
+
limit?: number;
|
|
84
|
+
product?: string;
|
|
85
|
+
}): Promise<Stripe.Response<Stripe.ApiList<Stripe.Price>>>;
|
|
86
|
+
getProduct(productId: string): Promise<Stripe.Response<Stripe.Product>>;
|
|
87
|
+
createEphemeralKey(customerId: string, apiVersion: string): Promise<Stripe.Response<Stripe.EphemeralKey>>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface WebhookHandlers {
|
|
91
|
+
onCustomerSubscriptionCreated?: (subscription: Stripe.Subscription) => Promise<void>;
|
|
92
|
+
onCustomerSubscriptionUpdated?: (subscription: Stripe.Subscription) => Promise<void>;
|
|
93
|
+
onCustomerSubscriptionDeleted?: (subscription: Stripe.Subscription) => Promise<void>;
|
|
94
|
+
onInvoicePaymentSucceeded?: (invoice: Stripe.Invoice) => Promise<void>;
|
|
95
|
+
onInvoicePaymentFailed?: (invoice: Stripe.Invoice) => Promise<void>;
|
|
96
|
+
onCheckoutSessionCompleted?: (session: Stripe.Checkout.Session) => Promise<void>;
|
|
97
|
+
onPaymentIntentSucceeded?: (paymentIntent: Stripe.PaymentIntent) => Promise<void>;
|
|
98
|
+
onPaymentIntentPaymentFailed?: (paymentIntent: Stripe.PaymentIntent) => Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
declare class StripeWebhookHandler {
|
|
101
|
+
private stripeAPI;
|
|
102
|
+
private handlers;
|
|
103
|
+
constructor(secretKey: string, handlers?: WebhookHandlers);
|
|
104
|
+
handleWebhook(payload: string | Buffer, signature: string, webhookSecret: string): Promise<{
|
|
105
|
+
success: boolean;
|
|
106
|
+
error?: string;
|
|
107
|
+
}>;
|
|
108
|
+
private processEvent;
|
|
109
|
+
private handleSubscriptionCreated;
|
|
110
|
+
private handleSubscriptionUpdated;
|
|
111
|
+
private handleSubscriptionDeleted;
|
|
112
|
+
private handleInvoicePaymentSucceeded;
|
|
113
|
+
private handleInvoicePaymentFailed;
|
|
114
|
+
private handleCheckoutSessionCompleted;
|
|
115
|
+
private handlePaymentIntentSucceeded;
|
|
116
|
+
private handlePaymentIntentFailed;
|
|
117
|
+
}
|
|
118
|
+
declare const createStripeWebhookHandler: (secretKey: string, handlers?: WebhookHandlers) => StripeWebhookHandler;
|
|
119
|
+
declare const createStripeWebhookMiddleware: (secretKey: string, webhookSecret: string, handlers?: WebhookHandlers) => (req: any, res: any, next: any) => Promise<any>;
|
|
120
|
+
declare const createNextJSWebhookHandler: (secretKey: string, webhookSecret: string, handlers?: WebhookHandlers) => (req: any, res: any) => Promise<any>;
|
|
121
|
+
|
|
122
|
+
export { StripeServerAPI, StripeWebhookHandler, type WebhookHandlers, createNextJSWebhookHandler, createStripeWebhookHandler, createStripeWebhookMiddleware };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
|
|
3
|
+
declare class StripeServerAPI {
|
|
4
|
+
private stripe;
|
|
5
|
+
constructor(secretKey: string, options?: {
|
|
6
|
+
apiVersion?: string;
|
|
7
|
+
typescript?: boolean;
|
|
8
|
+
});
|
|
9
|
+
createCustomer(params: {
|
|
10
|
+
email: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
phone?: string;
|
|
13
|
+
metadata?: Record<string, string>;
|
|
14
|
+
}): Promise<Stripe.Response<Stripe.Customer>>;
|
|
15
|
+
getCustomer(customerId: string): Promise<Stripe.Response<Stripe.Customer | Stripe.DeletedCustomer>>;
|
|
16
|
+
updateCustomer(customerId: string, params: {
|
|
17
|
+
email?: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
phone?: string;
|
|
20
|
+
metadata?: Record<string, string>;
|
|
21
|
+
}): Promise<Stripe.Response<Stripe.Customer>>;
|
|
22
|
+
deleteCustomer(customerId: string): Promise<Stripe.Response<Stripe.DeletedCustomer>>;
|
|
23
|
+
createSubscription(params: {
|
|
24
|
+
customerId: string;
|
|
25
|
+
priceId: string;
|
|
26
|
+
quantity?: number;
|
|
27
|
+
trialPeriodDays?: number;
|
|
28
|
+
metadata?: Record<string, string>;
|
|
29
|
+
paymentBehavior?: 'default_incomplete' | 'error_if_incomplete' | 'allow_incomplete';
|
|
30
|
+
}): Promise<Stripe.Response<Stripe.Subscription>>;
|
|
31
|
+
getSubscription(subscriptionId: string): Promise<Stripe.Response<Stripe.Subscription>>;
|
|
32
|
+
updateSubscription(subscriptionId: string, params: {
|
|
33
|
+
priceId?: string;
|
|
34
|
+
quantity?: number;
|
|
35
|
+
metadata?: Record<string, string>;
|
|
36
|
+
cancelAtPeriodEnd?: boolean;
|
|
37
|
+
}): Promise<Stripe.Response<Stripe.Subscription>>;
|
|
38
|
+
cancelSubscription(subscriptionId: string, immediately?: boolean): Promise<Stripe.Response<Stripe.Subscription>>;
|
|
39
|
+
reactivateSubscription(subscriptionId: string): Promise<Stripe.Response<Stripe.Subscription>>;
|
|
40
|
+
getCustomerSubscriptions(customerId: string): Promise<Stripe.Response<Stripe.ApiList<Stripe.Subscription>>>;
|
|
41
|
+
createCheckoutSession(params: {
|
|
42
|
+
priceId: string;
|
|
43
|
+
customerId?: string;
|
|
44
|
+
customerEmail?: string;
|
|
45
|
+
successUrl: string;
|
|
46
|
+
cancelUrl: string;
|
|
47
|
+
mode?: 'payment' | 'subscription' | 'setup';
|
|
48
|
+
allowPromotionCodes?: boolean;
|
|
49
|
+
billingAddressCollection?: 'auto' | 'required';
|
|
50
|
+
metadata?: Record<string, string>;
|
|
51
|
+
trialPeriodDays?: number;
|
|
52
|
+
}): Promise<Stripe.Response<Stripe.Checkout.Session>>;
|
|
53
|
+
createPaymentIntent(params: {
|
|
54
|
+
amount: number;
|
|
55
|
+
currency: string;
|
|
56
|
+
customerId?: string;
|
|
57
|
+
paymentMethodTypes?: string[];
|
|
58
|
+
metadata?: Record<string, string>;
|
|
59
|
+
description?: string;
|
|
60
|
+
}): Promise<Stripe.Response<Stripe.PaymentIntent>>;
|
|
61
|
+
confirmPaymentIntent(paymentIntentId: string, params?: {
|
|
62
|
+
paymentMethod?: string;
|
|
63
|
+
}): Promise<Stripe.Response<Stripe.PaymentIntent>>;
|
|
64
|
+
createSetupIntent(params: {
|
|
65
|
+
customerId: string;
|
|
66
|
+
paymentMethodTypes?: string[];
|
|
67
|
+
metadata?: Record<string, string>;
|
|
68
|
+
}): Promise<Stripe.Response<Stripe.SetupIntent>>;
|
|
69
|
+
createPortalSession(params: {
|
|
70
|
+
customerId: string;
|
|
71
|
+
returnUrl: string;
|
|
72
|
+
}): Promise<Stripe.Response<Stripe.BillingPortal.Session>>;
|
|
73
|
+
getCustomerPaymentMethods(customerId: string, type?: string): Promise<Stripe.Response<Stripe.ApiList<Stripe.PaymentMethod>>>;
|
|
74
|
+
attachPaymentMethod(paymentMethodId: string, customerId: string): Promise<Stripe.Response<Stripe.PaymentMethod>>;
|
|
75
|
+
detachPaymentMethod(paymentMethodId: string): Promise<Stripe.Response<Stripe.PaymentMethod>>;
|
|
76
|
+
setDefaultPaymentMethod(customerId: string, paymentMethodId: string): Promise<Stripe.Response<Stripe.Customer>>;
|
|
77
|
+
getCustomerInvoices(customerId: string, limit?: number): Promise<Stripe.Response<Stripe.ApiList<Stripe.Invoice>>>;
|
|
78
|
+
getInvoice(invoiceId: string): Promise<Stripe.Response<Stripe.Invoice>>;
|
|
79
|
+
constructWebhookEvent(payload: string | Buffer, signature: string, webhookSecret: string): Stripe.Event;
|
|
80
|
+
getPrice(priceId: string): Promise<Stripe.Response<Stripe.Price>>;
|
|
81
|
+
getPrices(params?: {
|
|
82
|
+
active?: boolean;
|
|
83
|
+
limit?: number;
|
|
84
|
+
product?: string;
|
|
85
|
+
}): Promise<Stripe.Response<Stripe.ApiList<Stripe.Price>>>;
|
|
86
|
+
getProduct(productId: string): Promise<Stripe.Response<Stripe.Product>>;
|
|
87
|
+
createEphemeralKey(customerId: string, apiVersion: string): Promise<Stripe.Response<Stripe.EphemeralKey>>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface WebhookHandlers {
|
|
91
|
+
onCustomerSubscriptionCreated?: (subscription: Stripe.Subscription) => Promise<void>;
|
|
92
|
+
onCustomerSubscriptionUpdated?: (subscription: Stripe.Subscription) => Promise<void>;
|
|
93
|
+
onCustomerSubscriptionDeleted?: (subscription: Stripe.Subscription) => Promise<void>;
|
|
94
|
+
onInvoicePaymentSucceeded?: (invoice: Stripe.Invoice) => Promise<void>;
|
|
95
|
+
onInvoicePaymentFailed?: (invoice: Stripe.Invoice) => Promise<void>;
|
|
96
|
+
onCheckoutSessionCompleted?: (session: Stripe.Checkout.Session) => Promise<void>;
|
|
97
|
+
onPaymentIntentSucceeded?: (paymentIntent: Stripe.PaymentIntent) => Promise<void>;
|
|
98
|
+
onPaymentIntentPaymentFailed?: (paymentIntent: Stripe.PaymentIntent) => Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
declare class StripeWebhookHandler {
|
|
101
|
+
private stripeAPI;
|
|
102
|
+
private handlers;
|
|
103
|
+
constructor(secretKey: string, handlers?: WebhookHandlers);
|
|
104
|
+
handleWebhook(payload: string | Buffer, signature: string, webhookSecret: string): Promise<{
|
|
105
|
+
success: boolean;
|
|
106
|
+
error?: string;
|
|
107
|
+
}>;
|
|
108
|
+
private processEvent;
|
|
109
|
+
private handleSubscriptionCreated;
|
|
110
|
+
private handleSubscriptionUpdated;
|
|
111
|
+
private handleSubscriptionDeleted;
|
|
112
|
+
private handleInvoicePaymentSucceeded;
|
|
113
|
+
private handleInvoicePaymentFailed;
|
|
114
|
+
private handleCheckoutSessionCompleted;
|
|
115
|
+
private handlePaymentIntentSucceeded;
|
|
116
|
+
private handlePaymentIntentFailed;
|
|
117
|
+
}
|
|
118
|
+
declare const createStripeWebhookHandler: (secretKey: string, handlers?: WebhookHandlers) => StripeWebhookHandler;
|
|
119
|
+
declare const createStripeWebhookMiddleware: (secretKey: string, webhookSecret: string, handlers?: WebhookHandlers) => (req: any, res: any, next: any) => Promise<any>;
|
|
120
|
+
declare const createNextJSWebhookHandler: (secretKey: string, webhookSecret: string, handlers?: WebhookHandlers) => (req: any, res: any) => Promise<any>;
|
|
121
|
+
|
|
122
|
+
export { StripeServerAPI, StripeWebhookHandler, type WebhookHandlers, createNextJSWebhookHandler, createStripeWebhookHandler, createStripeWebhookMiddleware };
|