@stacksjs/payments 0.64.6 → 0.65.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/dist/drivers/stripe.d.ts +42 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +28 -16
- package/package.json +10 -16
- package/src/drivers/stripe.ts +70 -29
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/payments",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.65.0",
|
|
5
5
|
"description": "The Stacks payments package. Currently supporting Stripe.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
|
+
"contributors": ["Chris Breuer <chris@stacksjs.org>"],
|
|
7
8
|
"license": "MIT",
|
|
8
9
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
|
9
10
|
"homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/payments#readme",
|
|
@@ -36,26 +37,19 @@
|
|
|
36
37
|
},
|
|
37
38
|
"module": "dist/index.js",
|
|
38
39
|
"types": "dist/index.d.ts",
|
|
39
|
-
"
|
|
40
|
-
"Chris Breuer <chris@stacksjs.org>"
|
|
41
|
-
],
|
|
42
|
-
"files": [
|
|
43
|
-
"README.md",
|
|
44
|
-
"dist",
|
|
45
|
-
"src"
|
|
46
|
-
],
|
|
40
|
+
"files": ["README.md", "dist", "src"],
|
|
47
41
|
"scripts": {
|
|
48
|
-
"build": "bun
|
|
49
|
-
"typecheck": "bun
|
|
42
|
+
"build": "bun build.ts",
|
|
43
|
+
"typecheck": "bun tsc --noEmit",
|
|
50
44
|
"prepublishOnly": "bun run build"
|
|
51
45
|
},
|
|
52
46
|
"dependencies": {
|
|
53
|
-
"@stacksjs/utils": "
|
|
54
|
-
"@stripe/stripe-js": "^4.
|
|
55
|
-
"stripe": "^
|
|
47
|
+
"@stacksjs/utils": "0.64.6",
|
|
48
|
+
"@stripe/stripe-js": "^4.8.0",
|
|
49
|
+
"stripe": "^17.2.0"
|
|
56
50
|
},
|
|
57
51
|
"devDependencies": {
|
|
58
|
-
"@stacksjs/config": "
|
|
59
|
-
"@stacksjs/development": "
|
|
52
|
+
"@stacksjs/config": "0.64.6",
|
|
53
|
+
"@stacksjs/development": "0.64.6"
|
|
60
54
|
}
|
|
61
55
|
}
|
package/src/drivers/stripe.ts
CHANGED
|
@@ -2,114 +2,155 @@ import Stripe from 'stripe'
|
|
|
2
2
|
|
|
3
3
|
const apiKey = ''
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
apiVersion: '
|
|
5
|
+
const client = new Stripe(apiKey, {
|
|
6
|
+
apiVersion: '2024-06-20',
|
|
7
7
|
})
|
|
8
8
|
|
|
9
9
|
// TODO: learn about subscriptions
|
|
10
|
-
export
|
|
10
|
+
export interface PaymentIntent {
|
|
11
|
+
create: (params: Stripe.PaymentIntentCreateParams) => Promise<Stripe.Response<Stripe.PaymentIntent>>
|
|
12
|
+
retrieve: (stripeId: string) => Promise<Stripe.Response<Stripe.PaymentIntent>>
|
|
13
|
+
update: (stripeId: string, params: Stripe.PaymentIntentCreateParams) => Promise<Stripe.Response<Stripe.PaymentIntent>>
|
|
14
|
+
cancel: (stripeId: string) => Promise<Stripe.Response<Stripe.PaymentIntent>>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const paymentIntent: PaymentIntent = (() => {
|
|
11
18
|
async function create(params: Stripe.PaymentIntentCreateParams) {
|
|
12
|
-
return await
|
|
19
|
+
return await client.paymentIntents.create(params)
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
async function retrieve(stripeId: string) {
|
|
16
|
-
return await
|
|
23
|
+
return await client.paymentIntents.retrieve(stripeId)
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
async function update(stripeId: string, params: Stripe.PaymentIntentCreateParams) {
|
|
20
|
-
return await
|
|
27
|
+
return await client.paymentIntents.update(stripeId, params)
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
async function cancel(stripeId: string) {
|
|
24
|
-
return await
|
|
31
|
+
return await client.paymentIntents.cancel(stripeId)
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
return { create, retrieve, update, cancel }
|
|
28
35
|
})()
|
|
29
36
|
|
|
30
|
-
export
|
|
37
|
+
export interface Balance {
|
|
38
|
+
retrieve: () => Promise<Stripe.Response<Stripe.Balance>>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const balance: Balance = (() => {
|
|
31
42
|
async function retrieve() {
|
|
32
|
-
return await
|
|
43
|
+
return await client.balance.retrieve()
|
|
33
44
|
}
|
|
34
45
|
|
|
35
46
|
return { retrieve }
|
|
36
47
|
})()
|
|
37
48
|
|
|
38
|
-
export
|
|
49
|
+
export interface Customer {
|
|
50
|
+
create: (params: Stripe.CustomerCreateParams) => Promise<Stripe.Response<Stripe.Customer>>
|
|
51
|
+
update: (stripeId: string, params: Stripe.CustomerCreateParams) => Promise<Stripe.Response<Stripe.Customer>>
|
|
52
|
+
retrieve: (stripeId: string) => Promise<Stripe.Response<Stripe.Customer | Stripe.DeletedCustomer>>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const customer: Customer = (() => {
|
|
39
56
|
async function create(params: Stripe.CustomerCreateParams) {
|
|
40
|
-
return await
|
|
57
|
+
return await client.customers.create(params)
|
|
41
58
|
}
|
|
42
59
|
|
|
43
60
|
async function update(stripeId: string, params: Stripe.CustomerCreateParams) {
|
|
44
|
-
return await
|
|
61
|
+
return await client.customers.update(stripeId, params)
|
|
45
62
|
}
|
|
46
63
|
|
|
47
64
|
async function retrieve(stripeId: string) {
|
|
48
|
-
return await
|
|
65
|
+
return await client.customers.retrieve(stripeId)
|
|
49
66
|
}
|
|
50
67
|
|
|
51
68
|
return { create, update, retrieve }
|
|
52
69
|
})()
|
|
53
70
|
|
|
54
|
-
export
|
|
71
|
+
export interface Charge {
|
|
72
|
+
create: (params: Stripe.ChargeCreateParams) => Promise<Stripe.Response<Stripe.Charge>>
|
|
73
|
+
update: (stripeId: string, params: Stripe.ChargeCreateParams) => Promise<Stripe.Response<Stripe.Charge>>
|
|
74
|
+
capture: (stripeId: string) => Promise<Stripe.Response<Stripe.Charge>>
|
|
75
|
+
retrieve: (stripeId: string) => Promise<Stripe.Response<Stripe.Charge>>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const charge: Charge = (() => {
|
|
55
79
|
async function create(params: Stripe.ChargeCreateParams) {
|
|
56
|
-
return await
|
|
80
|
+
return await client.charges.create(params)
|
|
57
81
|
}
|
|
58
82
|
|
|
59
83
|
async function update(stripeId: string, params: Stripe.ChargeCreateParams) {
|
|
60
|
-
return await
|
|
84
|
+
return await client.charges.update(stripeId, params)
|
|
61
85
|
}
|
|
62
86
|
|
|
63
87
|
async function capture(stripeId: string) {
|
|
64
|
-
return await
|
|
88
|
+
return await client.charges.capture(stripeId)
|
|
65
89
|
}
|
|
66
90
|
|
|
67
91
|
async function retrieve(stripeId: string) {
|
|
68
|
-
return await
|
|
92
|
+
return await client.charges.retrieve(stripeId)
|
|
69
93
|
}
|
|
70
94
|
|
|
71
95
|
return { create, update, retrieve, capture }
|
|
72
96
|
})()
|
|
73
97
|
|
|
74
|
-
export
|
|
98
|
+
export interface BalanceTransactions {
|
|
99
|
+
retrieve: (stripeId: string) => Promise<Stripe.Response<Stripe.BalanceTransaction>>
|
|
100
|
+
list: (limit: number) => Promise<Stripe.Response<Stripe.ApiList<Stripe.BalanceTransaction>>>
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const balanceTransactions: BalanceTransactions = (() => {
|
|
75
104
|
async function retrieve(stripeId: string) {
|
|
76
|
-
await
|
|
105
|
+
return await client.balanceTransactions.retrieve(stripeId)
|
|
77
106
|
}
|
|
78
107
|
|
|
79
108
|
async function list(limit: number) {
|
|
80
|
-
await
|
|
109
|
+
return await client.balanceTransactions.list({ limit })
|
|
81
110
|
}
|
|
82
111
|
|
|
83
112
|
return { retrieve, list }
|
|
84
113
|
})()
|
|
85
114
|
|
|
86
|
-
export
|
|
115
|
+
export interface Dispute {
|
|
116
|
+
retrieve: (stripeId: string) => Promise<Stripe.Response<Stripe.Dispute>>
|
|
117
|
+
update: (stripeId: string, params: Stripe.DisputeUpdateParams) => Promise<Stripe.Response<Stripe.Dispute>>
|
|
118
|
+
close: (stripeId: string) => Promise<Stripe.Response<Stripe.Dispute>>
|
|
119
|
+
list: (limit: number) => Promise<Stripe.Response<Stripe.ApiList<Stripe.Dispute>>>
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export const dispute: Dispute = (() => {
|
|
87
123
|
async function retrieve(stripeId: string) {
|
|
88
|
-
return await
|
|
124
|
+
return await client.disputes.retrieve(stripeId)
|
|
89
125
|
}
|
|
90
126
|
|
|
91
127
|
async function update(stripeId: string, params: Stripe.DisputeUpdateParams) {
|
|
92
|
-
return await
|
|
128
|
+
return await client.disputes.update(stripeId, params)
|
|
93
129
|
}
|
|
94
130
|
|
|
95
131
|
async function close(stripeId: string) {
|
|
96
|
-
return await
|
|
132
|
+
return await client.disputes.close(stripeId)
|
|
97
133
|
}
|
|
98
134
|
|
|
99
135
|
async function list(limit: number) {
|
|
100
|
-
return await
|
|
136
|
+
return await client.disputes.list({ limit })
|
|
101
137
|
}
|
|
102
138
|
|
|
103
139
|
return { retrieve, update, close, list }
|
|
104
140
|
})()
|
|
105
141
|
|
|
106
|
-
export
|
|
142
|
+
export interface PaymentEvents {
|
|
143
|
+
retrieve: (stripeId: string) => Promise<Stripe.Response<Stripe.Event>>
|
|
144
|
+
list: (limit: number) => Promise<Stripe.Response<Stripe.ApiList<Stripe.Event>>>
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const events: PaymentEvents = (() => {
|
|
107
148
|
async function retrieve(stripeId: string) {
|
|
108
|
-
await
|
|
149
|
+
return await client.events.retrieve(stripeId)
|
|
109
150
|
}
|
|
110
151
|
|
|
111
152
|
async function list(limit: number) {
|
|
112
|
-
await
|
|
153
|
+
return await client.events.list({ limit })
|
|
113
154
|
}
|
|
114
155
|
|
|
115
156
|
return { retrieve, list }
|