Skip to content

Commit 66dbfb9

Browse files
yashranawayaagarwal1012
authored andcommitted
refactor: remove unused Stripe functions and streamline code across templates
1 parent e601b23 commit 66dbfb9

File tree

4 files changed

+0
-451
lines changed

4 files changed

+0
-451
lines changed

packages/templates/express/src/lib/stripe.ts

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -13,110 +13,7 @@ export const getStripe = (): Stripe => {
1313
}
1414
return _stripe;
1515
};
16-
17-
18-
19-
let stripe = getStripe();
20-
21-
2216
export type Product = Stripe.Product;
2317
export type Customer = Stripe.Customer;
2418
export type Subscription = Stripe.Subscription;
2519
export type PaymentIntent = Stripe.PaymentIntent;
26-
27-
28-
export async function getProducts(): Promise<Product[]> {
29-
try {
30-
const { data } = await stripe.products.list({ limit: 100 });
31-
return data;
32-
} catch (error) {
33-
console.error('Error fetching products', error);
34-
throw new Error('Failed to fetch products');
35-
}
36-
}
37-
38-
export async function getProduct(product_id: string): Promise<Product> {
39-
try {
40-
return await stripe.products.retrieve(product_id);
41-
} catch (error) {
42-
console.error('Error fetching product', error);
43-
throw new Error('Failed to fetch product');
44-
}
45-
}
46-
47-
48-
export async function getCustomer(customer_id: string): Promise<Customer | Stripe.DeletedCustomer> {
49-
try {
50-
const customer = await stripe.customers.retrieve(customer_id);
51-
52-
if ((customer as Stripe.DeletedCustomer).deleted) {
53-
return customer as Stripe.DeletedCustomer;
54-
}
55-
return customer as Customer;
56-
} catch (error) {
57-
console.error('Error fetching customer', error);
58-
throw new Error('Failed to fetch customer');
59-
}
60-
}
61-
62-
export async function createCustomer(params: Stripe.CustomerCreateParams): Promise<Customer> {
63-
try {
64-
return await stripe.customers.create(params);
65-
} catch (error) {
66-
console.error('Error creating customer', error);
67-
throw new Error('Failed to create customer');
68-
}
69-
}
70-
71-
export async function updateCustomer(customer_id: string, params: Stripe.CustomerUpdateParams): Promise<Customer> {
72-
try {
73-
return await stripe.customers.update(customer_id, params);
74-
} catch (error) {
75-
console.error('Error updating customer', error);
76-
throw new Error('Failed to update customer');
77-
}
78-
}
79-
80-
81-
export async function getCustomerSubscriptions(customer_id: string): Promise<Subscription[]> {
82-
try {
83-
const { data } = await stripe.subscriptions.list({ customer: customer_id });
84-
return data;
85-
} catch (error) {
86-
console.error('Error fetching subscriptions', error);
87-
throw new Error('Failed to fetch subscriptions');
88-
}
89-
}
90-
91-
92-
export async function getCustomerPayments(customer_id: string): Promise<PaymentIntent[]> {
93-
try {
94-
const { data } = await stripe.paymentIntents.list({ customer: customer_id, limit: 100 });
95-
return data;
96-
} catch (error) {
97-
console.error('Error fetching payments', error);
98-
throw new Error('Failed to fetch payments');
99-
}
100-
}
101-
102-
103-
export async function checkout(opts: {
104-
price_id: string;
105-
customer_id?: string;
106-
success_url: string;
107-
cancel_url: string;
108-
}): Promise<{ checkout_url: string }> {
109-
try {
110-
const session = await stripe.checkout.sessions.create({
111-
mode: 'subscription',
112-
line_items: [{ price: opts.price_id, quantity: 1 }],
113-
customer: opts.customer_id ?? '',
114-
success_url: opts.success_url,
115-
cancel_url: opts.cancel_url,
116-
});
117-
return { checkout_url: session.url! };
118-
} catch (error) {
119-
console.error('Error creating checkout session', error);
120-
throw new Error('Failed to create checkout session');
121-
}
122-
}

packages/templates/fastify/src/lib/stripe.ts

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -26,108 +26,3 @@ export type Product = Stripe.Product;
2626
export type Customer = Stripe.Customer;
2727
export type Subscription = Stripe.Subscription;
2828
export type PaymentIntent = Stripe.PaymentIntent;
29-
30-
export async function getProducts(): Promise<Product[]> {
31-
try {
32-
const stripe = getStripe();
33-
const { data } = await stripe.products.list({ limit: 100 });
34-
return data;
35-
} catch (error) {
36-
console.error('Error fetching products', error);
37-
throw new Error('Failed to fetch products');
38-
}
39-
}
40-
41-
export async function getProduct(product_id: string): Promise<Product> {
42-
try {
43-
const stripe = getStripe();
44-
return await stripe.products.retrieve(product_id);
45-
} catch (error) {
46-
console.error('Error fetching product', error);
47-
throw new Error('Failed to fetch product');
48-
}
49-
}
50-
51-
export async function getCustomer(customer_id: string): Promise<Customer | Stripe.DeletedCustomer> {
52-
try {
53-
const stripe = getStripe();
54-
const customer = await stripe.customers.retrieve(customer_id);
55-
56-
if ((customer as Stripe.DeletedCustomer).deleted) {
57-
return customer as Stripe.DeletedCustomer;
58-
}
59-
return customer as Customer;
60-
} catch (error) {
61-
console.error('Error fetching customer', error);
62-
throw new Error('Failed to fetch customer');
63-
}
64-
}
65-
66-
export async function createCustomer(params: Stripe.CustomerCreateParams): Promise<Customer> {
67-
try {
68-
const stripe = getStripe();
69-
return await stripe.customers.create(params);
70-
} catch (error) {
71-
console.error('Error creating customer', error);
72-
throw new Error('Failed to create customer');
73-
}
74-
}
75-
76-
export async function updateCustomer(customer_id: string, params: Stripe.CustomerUpdateParams): Promise<Customer> {
77-
try {
78-
const stripe = getStripe();
79-
return await stripe.customers.update(customer_id, params);
80-
} catch (error) {
81-
console.error('Error updating customer', error);
82-
throw new Error('Failed to update customer');
83-
}
84-
}
85-
86-
export async function getCustomerSubscriptions(customer_id: string): Promise<Subscription[]> {
87-
try {
88-
const stripe = getStripe();
89-
const { data } = await stripe.subscriptions.list({ customer: customer_id });
90-
return data;
91-
} catch (error) {
92-
console.error('Error fetching subscriptions', error);
93-
throw new Error('Failed to fetch subscriptions');
94-
}
95-
}
96-
97-
export async function getCustomerPayments(customer_id: string): Promise<PaymentIntent[]> {
98-
try {
99-
const stripe = getStripe();
100-
const { data } = await stripe.paymentIntents.list({ customer: customer_id, limit: 100 });
101-
return data;
102-
} catch (error) {
103-
console.error('Error fetching payments', error);
104-
throw new Error('Failed to fetch payments');
105-
}
106-
}
107-
108-
export async function checkout(opts: {
109-
price_id: string;
110-
customer_id?: string;
111-
success_url: string;
112-
cancel_url: string;
113-
}): Promise<{ checkout_url: string }> {
114-
try {
115-
const stripe = getStripe();
116-
const sessionParams: Stripe.Checkout.SessionCreateParams = {
117-
mode: 'subscription',
118-
line_items: [{ price: opts.price_id, quantity: 1 }],
119-
success_url: opts.success_url,
120-
cancel_url: opts.cancel_url,
121-
};
122-
123-
if (opts.customer_id) {
124-
sessionParams.customer = opts.customer_id;
125-
}
126-
127-
const session = await stripe.checkout.sessions.create(sessionParams);
128-
return { checkout_url: session.url! };
129-
} catch (error) {
130-
console.error('Error creating checkout session', error);
131-
throw new Error('Failed to create checkout session');
132-
}
133-
}

packages/templates/hono/src/lib/stripe.ts

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -19,108 +19,3 @@ export type Customer = Stripe.Customer;
1919
export type Subscription = Stripe.Subscription;
2020
export type PaymentIntent = Stripe.PaymentIntent;
2121

22-
23-
export async function getProducts(): Promise<Product[]> {
24-
try {
25-
const stripe = getStripe();
26-
const { data } = await stripe.products.list({ limit: 100 });
27-
return data;
28-
} catch (error) {
29-
console.error('Error fetching products', error);
30-
throw new Error('Failed to fetch products');
31-
}
32-
}
33-
34-
export async function getProduct(product_id: string): Promise<Product> {
35-
try {
36-
const stripe = getStripe();
37-
return await stripe.products.retrieve(product_id);
38-
} catch (error) {
39-
console.error('Error fetching product', error);
40-
throw new Error('Failed to fetch product');
41-
}
42-
}
43-
44-
45-
export async function getCustomer(customer_id: string): Promise<Customer | Stripe.DeletedCustomer> {
46-
try {
47-
const stripe = getStripe();
48-
const customer = await stripe.customers.retrieve(customer_id);
49-
50-
if ((customer as Stripe.DeletedCustomer).deleted) {
51-
return customer as Stripe.DeletedCustomer;
52-
}
53-
return customer as Customer;
54-
} catch (error) {
55-
console.error('Error fetching customer', error);
56-
throw new Error('Failed to fetch customer');
57-
}
58-
}
59-
60-
export async function createCustomer(params: Stripe.CustomerCreateParams): Promise<Customer> {
61-
try {
62-
const stripe = getStripe();
63-
return await stripe.customers.create(params);
64-
} catch (error) {
65-
console.error('Error creating customer', error);
66-
throw new Error('Failed to create customer');
67-
}
68-
}
69-
70-
export async function updateCustomer(customer_id: string, params: Stripe.CustomerUpdateParams): Promise<Customer> {
71-
try {
72-
const stripe = getStripe();
73-
return await stripe.customers.update(customer_id, params);
74-
} catch (error) {
75-
console.error('Error updating customer', error);
76-
throw new Error('Failed to update customer');
77-
}
78-
}
79-
80-
81-
export async function getCustomerSubscriptions(customer_id: string): Promise<Subscription[]> {
82-
try {
83-
const stripe = getStripe();
84-
const { data } = await stripe.subscriptions.list({ customer: customer_id });
85-
return data;
86-
} catch (error) {
87-
console.error('Error fetching subscriptions', error);
88-
throw new Error('Failed to fetch subscriptions');
89-
}
90-
}
91-
92-
93-
export async function getCustomerPayments(customer_id: string): Promise<PaymentIntent[]> {
94-
try {
95-
const stripe = getStripe();
96-
const { data } = await stripe.paymentIntents.list({ customer: customer_id, limit: 100 });
97-
return data;
98-
} catch (error) {
99-
console.error('Error fetching payments', error);
100-
throw new Error('Failed to fetch payments');
101-
}
102-
}
103-
104-
105-
export async function checkout(opts: {
106-
price_id: string;
107-
customer_id?: string;
108-
success_url: string;
109-
cancel_url: string;
110-
}): Promise<{ checkout_url: string }> {
111-
try {
112-
const stripe = getStripe();
113-
const session = await stripe.checkout.sessions.create({
114-
mode: 'subscription',
115-
line_items: [{ price: opts.price_id, quantity: 1 }],
116-
customer: opts.customer_id ?? '',
117-
success_url: opts.success_url,
118-
cancel_url: opts.cancel_url,
119-
});
120-
return { checkout_url: session.url! };
121-
} catch (error) {
122-
console.error('Error creating checkout session', error);
123-
throw new Error('Failed to create checkout session');
124-
}
125-
}
126-

0 commit comments

Comments
 (0)