Skip to content

Commit 6705ef8

Browse files
chore: wip
1 parent b7ed22d commit 6705ef8

File tree

1 file changed

+119
-135
lines changed

1 file changed

+119
-135
lines changed
Lines changed: 119 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,121 @@
1-
// import type { ChargeOptions, CustomerOptions, DisputeOptions, EventOptions } from '@stacksjs/types'
2-
// import { isString } from '@stacksjs/utils'
3-
// import Stripe from 'stripe'
4-
// import { services } from '@stacksjs/config'
5-
6-
// const apiKey = services?.stripe?.apiKey
7-
8-
// if (!isString(apiKey)) {
9-
// console.error('Stripe API key is not defined')
10-
// process.exit(1)
11-
// }
12-
13-
// const stripe = new Stripe(apiKey, {
14-
// apiVersion: '2022-11-15',
15-
// })
16-
17-
// const balance = async () => {
18-
// return {
19-
// retrieve: async () => {
20-
// await stripe.balance.retrieve()
21-
// },
22-
// }
23-
// }
24-
25-
// const balanceTransactions = async (txn: string, limit: number) => {
26-
// return {
27-
// retrieve: async () => {
28-
// await stripe.balanceTransactions.retrieve(txn)
29-
// },
30-
// list: async () => {
31-
// await stripe.balanceTransactions.list({
32-
// limit,
33-
// })
34-
// },
35-
// }
36-
// }
37-
38-
// const dispute = async (options: DisputeOptions) => {
39-
// return {
40-
// retrieve: async () => {
41-
// await stripe.disputes.retrieve(options.dp_id)
42-
// },
43-
// update: async () => {
44-
// await stripe.disputes.update(
45-
// options.dp_id,
46-
// { ...options.metadata },
47-
// )
48-
// },
49-
// close: async () => {
50-
// await stripe.disputes.close(options.dp_id)
51-
// },
52-
// list: async () => {
53-
// await stripe.disputes.list(options.listOptions)
54-
// },
55-
// }
56-
// }
57-
58-
// const charge = async (amount: number, options?: ChargeOptions) => {
59-
// return {
60-
// create: async () => {
61-
// await stripe.charges.create({
62-
// amount,
63-
// ...options,
64-
// })
65-
// },
66-
// retrieve: async () => {
67-
// await stripe.charges.retrieve(options?.chargeId)
68-
// },
69-
// update: async () => {
70-
// await stripe.charges.update(
71-
// options?.chargeId,
72-
// { metadata: options?.metadata },
73-
// )
74-
// },
75-
// capture: async () => {
76-
// await stripe.charges.capture(options?.chargeId)
77-
// },
78-
// list: async () => {
79-
// await stripe.charges.list({
80-
// limit: options?.limit,
81-
// })
82-
// },
83-
// search: async () => {
84-
// await stripe.charges.search({
85-
// ...options?.searchOptions,
86-
// })
87-
// },
88-
// }
89-
// }
90-
91-
// const customer = async (options: CustomerOptions) => {
92-
// return {
93-
// create: async () => {
94-
// await stripe.customers.create(options)
95-
// },
96-
// retrieve: async () => {
97-
// await stripe.customers.retrieve(options.address)
98-
// },
99-
// update: async () => {
100-
// await stripe.customers.update(
101-
// options.address,
102-
// { ...options.metadata },
103-
// )
104-
// },
105-
// delete: async () => {
106-
// await stripe.customers.del(options.address)
107-
// },
108-
// list: async () => {
109-
// await stripe.customers.list(options.listOptions)
110-
// },
111-
// search: async () => {
112-
// await stripe.customers.search(options.searchOptions)
113-
// },
114-
// }
115-
// }
116-
117-
// const events = async (options: EventOptions) => {
118-
// return {
119-
// retrieve: async () => {
120-
// await stripe.events.retrieve(options.event_id)
121-
// },
122-
// list: async () => {
123-
// await stripe.events.list(options.listOptions)
124-
// },
125-
// }
126-
// }
127-
128-
// export {
129-
// balance,
130-
// balanceTransactions,
131-
// charge,
132-
// customer,
133-
// dispute,
134-
// events,
135-
// }
1+
import Stripe from 'stripe';
2+
3+
import { services } from '@stacksjs/config'
4+
5+
const apiKey = services?.stripe?.apiKey || ''
6+
7+
const stripe = new Stripe(apiKey, {
8+
apiVersion: '2022-11-15',
9+
});
10+
11+
12+
export const paymentIntent = function() {
13+
async function create(params: Stripe.PaymentIntentCreateParams) {
14+
return await stripe.paymentIntents.create(params);
15+
}
16+
17+
async function retrieve(stripeId: string) {
18+
return await stripe.paymentIntents.retrieve(stripeId);
19+
}
20+
21+
async function update(stripeId: string, params: Stripe.PaymentIntentCreateParams) {
22+
return await stripe.paymentIntents.update(stripeId, params);
23+
}
24+
25+
async function cancel(stripeId: string) {
26+
return await stripe.paymentIntents.cancel(stripeId);
27+
}
28+
29+
return { create, retrieve, update, cancel }
30+
}
31+
32+
export const balance = function(){
33+
async function retrieve () {
34+
return await stripe.balance.retrieve()
35+
}
36+
37+
return { retrieve }
38+
}()
39+
40+
export const customer = function() {
41+
async function create (params: Stripe.CustomerCreateParams) {
42+
return await stripe.customers.create(params);
43+
};
44+
45+
async function update(stripeId: string, params: Stripe.CustomerCreateParams) {
46+
return await stripe.customers.update(stripeId, params);
47+
};
48+
49+
async function retrieve (stripeId: string) {
50+
return await stripe.customers.retrieve(stripeId);
51+
};
52+
53+
return { create, update, retrieve }
54+
}()
55+
56+
export const charge = function () {
57+
async function create (params: Stripe.ChargeCreateParams) {
58+
return await stripe.charges.create(params);
59+
}
60+
61+
async function update (stripeId: string, params: Stripe.ChargeCreateParams) {
62+
return await stripe.charges.update(stripeId, params);
63+
}
64+
65+
async function capture (stripeId: string) {
66+
return await stripe.charges.capture(stripeId);
67+
}
68+
69+
async function retrieve (stripeId: string) {
70+
return await stripe.charges.retrieve(stripeId);
71+
}
72+
73+
return { create, update, retrieve, capture }
74+
}()
75+
76+
77+
export const balanceTransactions = function () {
78+
async function retrieve (stripeId: string) {
79+
await stripe.balanceTransactions.retrieve(stripeId)
80+
}
81+
82+
async function list (limit: number) {
83+
await stripe.balanceTransactions.list({ limit, })
84+
}
85+
86+
return { retrieve, list }
87+
}()
88+
89+
export const dispute = function () {
90+
async function retrieve (stripeId: string) {
91+
return await stripe.disputes.retrieve(stripeId)
92+
}
93+
94+
async function update (stripeId: string, params: Stripe.DisputeUpdateParams) {
95+
return await stripe.disputes.update(stripeId, params)
96+
}
97+
98+
async function close (stripeId: string) {
99+
return await stripe.disputes.close(stripeId)
100+
}
101+
102+
async function list (limit: number) {
103+
return await stripe.disputes.list({ limit })
104+
}
105+
106+
return { retrieve, update, close, list }
107+
}()
108+
109+
export const events = function () {
110+
async function retrieve (stripeId: string) {
111+
await stripe.events.retrieve(stripeId)
112+
}
113+
114+
async function list (limit: number) {
115+
await stripe.events.list({ limit })
116+
}
117+
118+
return { retrieve, list }
119+
}()
136120

137121
export const stripeWip = 1

0 commit comments

Comments
 (0)