@frogbotai/piece-stripe 0.29.0 → 0.31.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/actions.d.ts.map +1 -1
- package/dist/actions.js +239 -149
- package/dist/actions.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +29 -21
- package/dist/client.js.map +1 -1
- package/dist/config.js +5 -1
- package/dist/config.js.map +1 -1
- package/dist/define.js +1 -0
- package/dist/define.js.map +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/triggers.d.ts.map +1 -1
- package/dist/triggers.js +59 -57
- package/dist/triggers.js.map +1 -1
- package/package.json +4 -4
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAgB,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAgB,cAAc,EAAE,MAAM,aAAa,CAAC;AA4EhE,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;CAezB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;CAgBxB,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;CAQ1B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2C9B,CAAC;AAiDH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;CAQtB,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiBzB,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;CAwC9B,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAYxB,CAAC;AAEH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqBtB,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuC7B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;CAQ7B,CAAC;AAIH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;CAQrB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;CAQpB,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;CAiBvB,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuC5B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;CAOhC,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;CAQ3B,CAAC;AAEH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;CAOtB,CAAC;AAeH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAYtB,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoB1B,CAAC;AAEX,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/actions.js
CHANGED
|
@@ -7,9 +7,9 @@ const optionalAddress = {
|
|
|
7
7
|
postalCode: z.string().optional(),
|
|
8
8
|
city: z.string().optional(),
|
|
9
9
|
state: z.string().optional(),
|
|
10
|
-
country: z.string().optional()
|
|
10
|
+
country: z.string().optional()
|
|
11
11
|
};
|
|
12
|
-
function action({ slug, description, input, path, method = 'POST', idempotent = false, map = (value)
|
|
12
|
+
function action({ slug, description, input, path, method = 'POST', idempotent = false, map = (value)=>value, options }) {
|
|
13
13
|
return defineAction({
|
|
14
14
|
slug,
|
|
15
15
|
description,
|
|
@@ -17,20 +17,20 @@ function action({ slug, description, input, path, method = 'POST', idempotent =
|
|
|
17
17
|
output,
|
|
18
18
|
idempotent,
|
|
19
19
|
options,
|
|
20
|
-
async run({ client, input }) {
|
|
20
|
+
async run ({ client, input }) {
|
|
21
21
|
const requestPath = typeof path === 'function' ? path(input) : path;
|
|
22
22
|
const requestMethod = typeof method === 'function' ? method(input) : method;
|
|
23
23
|
return client.request(requestPath, requestMethod, map(input));
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
const customerOptions = async ({ client })
|
|
28
|
-
const productOptions = async ({ client })
|
|
29
|
-
const subscriptionOptions = async ({ client })
|
|
30
|
-
const invoiceOptions = async ({ client })
|
|
31
|
-
const payoutOptions = async ({ client })
|
|
32
|
-
const paymentIntentOptions = async ({ client })
|
|
33
|
-
const paymentLinkOptions = async ({ client })
|
|
27
|
+
const customerOptions = async ({ client })=>client.options('customers', (item)=>String(item.name || item.email || item.id));
|
|
28
|
+
const productOptions = async ({ client })=>client.options('products', (item)=>String(item.name || item.id));
|
|
29
|
+
const subscriptionOptions = async ({ client })=>client.options('subscriptions', (item)=>String(item.id));
|
|
30
|
+
const invoiceOptions = async ({ client })=>client.options('invoices', (item)=>String(item.number || item.id));
|
|
31
|
+
const payoutOptions = async ({ client })=>client.options('payouts', (item)=>String(item.id));
|
|
32
|
+
const paymentIntentOptions = async ({ client })=>client.options('payment_intents', (item)=>String(item.description || item.id));
|
|
33
|
+
const paymentLinkOptions = async ({ client })=>client.options('payment_links', (item)=>String(item.url || item.id));
|
|
34
34
|
export const createCustomer = action({
|
|
35
35
|
slug: 'createCustomer',
|
|
36
36
|
description: 'Create a Stripe customer.',
|
|
@@ -39,13 +39,19 @@ export const createCustomer = action({
|
|
|
39
39
|
name: z.string(),
|
|
40
40
|
description: z.string().optional(),
|
|
41
41
|
phone: z.string().optional(),
|
|
42
|
-
...optionalAddress
|
|
42
|
+
...optionalAddress
|
|
43
43
|
}),
|
|
44
44
|
path: 'customers',
|
|
45
|
-
map: ({ line1, postalCode, city, state, country, ...customer })
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
map: ({ line1, postalCode, city, state, country, ...customer })=>({
|
|
46
|
+
...customer,
|
|
47
|
+
address: {
|
|
48
|
+
line1,
|
|
49
|
+
postal_code: postalCode,
|
|
50
|
+
city,
|
|
51
|
+
state,
|
|
52
|
+
country
|
|
53
|
+
}
|
|
54
|
+
})
|
|
49
55
|
});
|
|
50
56
|
export const createInvoice = action({
|
|
51
57
|
slug: 'createInvoice',
|
|
@@ -53,33 +59,38 @@ export const createInvoice = action({
|
|
|
53
59
|
input: z.object({
|
|
54
60
|
customerId: z.string(),
|
|
55
61
|
description: z.string().optional(),
|
|
56
|
-
daysUntilDue: z.number().int().positive().optional()
|
|
62
|
+
daysUntilDue: z.number().int().positive().optional()
|
|
57
63
|
}),
|
|
58
64
|
path: 'invoices',
|
|
59
|
-
map: ({ customerId, description, daysUntilDue })
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
options: {
|
|
65
|
+
map: ({ customerId, description, daysUntilDue })=>({
|
|
66
|
+
customer: customerId,
|
|
67
|
+
description,
|
|
68
|
+
collection_method: daysUntilDue ? 'send_invoice' : undefined,
|
|
69
|
+
days_until_due: daysUntilDue
|
|
70
|
+
}),
|
|
71
|
+
options: {
|
|
72
|
+
customerId: customerOptions
|
|
73
|
+
}
|
|
66
74
|
});
|
|
67
75
|
export const searchCustomers = action({
|
|
68
76
|
slug: 'searchCustomers',
|
|
69
77
|
description: 'Search Stripe customers by email.',
|
|
70
|
-
input: z.object({
|
|
78
|
+
input: z.object({
|
|
79
|
+
email: z.string().email()
|
|
80
|
+
}),
|
|
71
81
|
path: 'customers/search',
|
|
72
82
|
method: 'GET',
|
|
73
83
|
idempotent: true,
|
|
74
|
-
map: ({ email })
|
|
84
|
+
map: ({ email })=>({
|
|
85
|
+
query: `email:'${email.replaceAll("'", "\\'")}'`
|
|
86
|
+
})
|
|
75
87
|
});
|
|
76
88
|
export const searchSubscriptions = action({
|
|
77
89
|
slug: 'searchSubscriptions',
|
|
78
90
|
description: 'List and filter Stripe subscriptions.',
|
|
79
91
|
input: z.object({
|
|
80
92
|
priceIds: z.array(z.string()).optional(),
|
|
81
|
-
status: z
|
|
82
|
-
.enum([
|
|
93
|
+
status: z.enum([
|
|
83
94
|
'active',
|
|
84
95
|
'past_due',
|
|
85
96
|
'unpaid',
|
|
@@ -87,69 +98,70 @@ export const searchSubscriptions = action({
|
|
|
87
98
|
'incomplete',
|
|
88
99
|
'incomplete_expired',
|
|
89
100
|
'trialing',
|
|
90
|
-
'paused'
|
|
91
|
-
])
|
|
92
|
-
.optional(),
|
|
101
|
+
'paused'
|
|
102
|
+
]).optional(),
|
|
93
103
|
customerId: z.string().optional(),
|
|
94
104
|
createdAfter: z.string().datetime().optional(),
|
|
95
105
|
createdBefore: z.string().datetime().optional(),
|
|
96
106
|
limit: z.number().int().min(0).default(100),
|
|
97
|
-
includeCustomerDetails: z.boolean().default(false)
|
|
107
|
+
includeCustomerDetails: z.boolean().default(false)
|
|
98
108
|
}),
|
|
99
109
|
path: 'subscriptions',
|
|
100
110
|
method: 'GET',
|
|
101
111
|
idempotent: true,
|
|
102
|
-
map: ({ priceIds, status, customerId, createdAfter, createdBefore, limit, includeCustomerDetails
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
map: ({ priceIds, status, customerId, createdAfter, createdBefore, limit, includeCustomerDetails })=>({
|
|
113
|
+
price: priceIds?.[0],
|
|
114
|
+
status,
|
|
115
|
+
customer: customerId,
|
|
116
|
+
'created[gte]': createdAfter ? Math.floor(Date.parse(createdAfter) / 1000) : undefined,
|
|
117
|
+
'created[lte]': createdBefore ? Math.floor(Date.parse(createdBefore) / 1000) : undefined,
|
|
118
|
+
limit: limit === 0 ? 100 : limit,
|
|
119
|
+
expand: includeCustomerDetails ? [
|
|
120
|
+
'data.customer'
|
|
121
|
+
] : undefined
|
|
122
|
+
})
|
|
111
123
|
});
|
|
112
|
-
searchSubscriptions.run = async ({ client, input })
|
|
124
|
+
searchSubscriptions.run = async ({ client, input })=>{
|
|
113
125
|
const subscriptions = [];
|
|
114
126
|
let startingAfter;
|
|
115
127
|
do {
|
|
116
128
|
const page = await client.request('subscriptions', 'GET', {
|
|
117
129
|
status: input.status,
|
|
118
130
|
customer: input.customerId,
|
|
119
|
-
'created[gte]': input.createdAfter
|
|
120
|
-
|
|
121
|
-
: undefined,
|
|
122
|
-
'created[lte]': input.createdBefore
|
|
123
|
-
? Math.floor(Date.parse(input.createdBefore) / 1000)
|
|
124
|
-
: undefined,
|
|
131
|
+
'created[gte]': input.createdAfter ? Math.floor(Date.parse(input.createdAfter) / 1000) : undefined,
|
|
132
|
+
'created[lte]': input.createdBefore ? Math.floor(Date.parse(input.createdBefore) / 1000) : undefined,
|
|
125
133
|
limit: 100,
|
|
126
134
|
starting_after: startingAfter,
|
|
127
|
-
expand: input.includeCustomerDetails ? [
|
|
135
|
+
expand: input.includeCustomerDetails ? [
|
|
136
|
+
'data.customer'
|
|
137
|
+
] : undefined
|
|
128
138
|
});
|
|
129
139
|
const pageItems = Array.isArray(page.data) ? page.data : [];
|
|
130
140
|
subscriptions.push(...pageItems);
|
|
131
|
-
startingAfter =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
? subscriptions.filter((subscription) => {
|
|
138
|
-
const items = subscription.items;
|
|
139
|
-
return (items?.data?.some(({ price }) => typeof price?.id === 'string' && input.priceIds?.includes(price.id)) ?? false);
|
|
140
|
-
})
|
|
141
|
-
: subscriptions;
|
|
141
|
+
startingAfter = page.has_more === true && typeof pageItems.at(-1)?.id === 'string' ? pageItems.at(-1)?.id : undefined;
|
|
142
|
+
}while (startingAfter && (input.limit === 0 || subscriptions.length < input.limit))
|
|
143
|
+
const filtered = input.priceIds?.length ? subscriptions.filter((subscription)=>{
|
|
144
|
+
const items = subscription.items;
|
|
145
|
+
return items?.data?.some(({ price })=>typeof price?.id === 'string' && input.priceIds?.includes(price.id)) ?? false;
|
|
146
|
+
}) : subscriptions;
|
|
142
147
|
const data = input.limit === 0 ? filtered : filtered.slice(0, input.limit);
|
|
143
|
-
return {
|
|
148
|
+
return {
|
|
149
|
+
data,
|
|
150
|
+
has_more: startingAfter !== undefined
|
|
151
|
+
};
|
|
144
152
|
};
|
|
145
153
|
export const getCustomer = action({
|
|
146
154
|
slug: 'getCustomer',
|
|
147
155
|
description: 'Get a Stripe customer by ID.',
|
|
148
|
-
input: z.object({
|
|
149
|
-
|
|
156
|
+
input: z.object({
|
|
157
|
+
customerId: z.string()
|
|
158
|
+
}),
|
|
159
|
+
path: ({ customerId })=>`customers/${encodeURIComponent(customerId)}`,
|
|
150
160
|
method: 'GET',
|
|
151
161
|
idempotent: true,
|
|
152
|
-
options: {
|
|
162
|
+
options: {
|
|
163
|
+
customerId: customerOptions
|
|
164
|
+
}
|
|
153
165
|
});
|
|
154
166
|
export const updateCustomer = action({
|
|
155
167
|
slug: 'updateCustomer',
|
|
@@ -160,14 +172,22 @@ export const updateCustomer = action({
|
|
|
160
172
|
name: z.string().optional(),
|
|
161
173
|
description: z.string().optional(),
|
|
162
174
|
phone: z.string().optional(),
|
|
163
|
-
...optionalAddress
|
|
175
|
+
...optionalAddress
|
|
164
176
|
}),
|
|
165
|
-
path: ({ customerId })
|
|
166
|
-
map: ({ customerId: _customerId, line1, postalCode, city, state, country, ...customer })
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
path: ({ customerId })=>`customers/${encodeURIComponent(customerId)}`,
|
|
178
|
+
map: ({ customerId: _customerId, line1, postalCode, city, state, country, ...customer })=>({
|
|
179
|
+
...customer,
|
|
180
|
+
address: {
|
|
181
|
+
line1,
|
|
182
|
+
postal_code: postalCode,
|
|
183
|
+
city,
|
|
184
|
+
state,
|
|
185
|
+
country
|
|
186
|
+
}
|
|
187
|
+
}),
|
|
188
|
+
options: {
|
|
189
|
+
customerId: customerOptions
|
|
190
|
+
}
|
|
171
191
|
});
|
|
172
192
|
export const createPaymentIntent = action({
|
|
173
193
|
slug: 'createPaymentIntent',
|
|
@@ -180,10 +200,10 @@ export const createPaymentIntent = action({
|
|
|
180
200
|
confirm: z.boolean().default(false),
|
|
181
201
|
returnUrl: z.string().url().optional(),
|
|
182
202
|
description: z.string().optional(),
|
|
183
|
-
receiptEmail: z.string().email().optional()
|
|
203
|
+
receiptEmail: z.string().email().optional()
|
|
184
204
|
}),
|
|
185
205
|
path: 'payment_intents',
|
|
186
|
-
map: ({ amount, currency, customerId, paymentMethodId, confirm, returnUrl, description, receiptEmail
|
|
206
|
+
map: ({ amount, currency, customerId, paymentMethodId, confirm, returnUrl, description, receiptEmail })=>{
|
|
187
207
|
if (confirm && !paymentMethodId) {
|
|
188
208
|
throw new Error('Payment Method ID is required when confirming a payment.');
|
|
189
209
|
}
|
|
@@ -195,10 +215,12 @@ export const createPaymentIntent = action({
|
|
|
195
215
|
confirm,
|
|
196
216
|
return_url: returnUrl,
|
|
197
217
|
description,
|
|
198
|
-
receipt_email: receiptEmail
|
|
218
|
+
receipt_email: receiptEmail
|
|
199
219
|
};
|
|
200
220
|
},
|
|
201
|
-
options: {
|
|
221
|
+
options: {
|
|
222
|
+
customerId: customerOptions
|
|
223
|
+
}
|
|
202
224
|
});
|
|
203
225
|
export const createProduct = action({
|
|
204
226
|
slug: 'createProduct',
|
|
@@ -209,9 +231,9 @@ export const createProduct = action({
|
|
|
209
231
|
active: z.boolean().optional(),
|
|
210
232
|
images: z.array(z.string().url()).max(8).optional(),
|
|
211
233
|
url: z.string().url().optional(),
|
|
212
|
-
metadata
|
|
234
|
+
metadata
|
|
213
235
|
}),
|
|
214
|
-
path: 'products'
|
|
236
|
+
path: 'products'
|
|
215
237
|
});
|
|
216
238
|
export const createPrice = action({
|
|
217
239
|
slug: 'createPrice',
|
|
@@ -220,78 +242,111 @@ export const createPrice = action({
|
|
|
220
242
|
productId: z.string(),
|
|
221
243
|
unitAmount: z.number().positive(),
|
|
222
244
|
currency: z.string().length(3),
|
|
223
|
-
recurringInterval: z.enum([
|
|
224
|
-
|
|
245
|
+
recurringInterval: z.enum([
|
|
246
|
+
'one_time',
|
|
247
|
+
'day',
|
|
248
|
+
'week',
|
|
249
|
+
'month',
|
|
250
|
+
'year'
|
|
251
|
+
]).default('one_time'),
|
|
252
|
+
recurringIntervalCount: z.number().int().positive().optional()
|
|
225
253
|
}),
|
|
226
254
|
path: 'prices',
|
|
227
|
-
map: ({ productId, unitAmount, currency, recurringInterval, recurringIntervalCount })
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
255
|
+
map: ({ productId, unitAmount, currency, recurringInterval, recurringIntervalCount })=>({
|
|
256
|
+
product: productId,
|
|
257
|
+
unit_amount: Math.round(unitAmount * 100),
|
|
258
|
+
currency,
|
|
259
|
+
recurring: recurringInterval === 'one_time' ? undefined : {
|
|
260
|
+
interval: recurringInterval,
|
|
261
|
+
interval_count: recurringIntervalCount
|
|
262
|
+
}
|
|
263
|
+
}),
|
|
264
|
+
options: {
|
|
265
|
+
productId: productOptions
|
|
266
|
+
}
|
|
236
267
|
});
|
|
237
268
|
export const createSubscription = action({
|
|
238
269
|
slug: 'createSubscription',
|
|
239
270
|
description: 'Create a Stripe subscription.',
|
|
240
271
|
input: z.object({
|
|
241
272
|
customerId: z.string(),
|
|
242
|
-
items: z
|
|
243
|
-
|
|
244
|
-
.
|
|
245
|
-
|
|
273
|
+
items: z.array(z.object({
|
|
274
|
+
priceId: z.string(),
|
|
275
|
+
quantity: z.number().int().positive().optional()
|
|
276
|
+
})).min(1),
|
|
277
|
+
collectionMethod: z.enum([
|
|
278
|
+
'charge_automatically',
|
|
279
|
+
'send_invoice'
|
|
280
|
+
]).optional(),
|
|
246
281
|
daysUntilDue: z.number().int().positive().optional(),
|
|
247
282
|
trialPeriodDays: z.number().int().positive().optional(),
|
|
248
283
|
defaultPaymentMethodId: z.string().optional(),
|
|
249
|
-
metadata
|
|
284
|
+
metadata
|
|
250
285
|
}),
|
|
251
286
|
path: 'subscriptions',
|
|
252
|
-
map: ({ customerId, items, collectionMethod, daysUntilDue, trialPeriodDays, defaultPaymentMethodId, metadata
|
|
287
|
+
map: ({ customerId, items, collectionMethod, daysUntilDue, trialPeriodDays, defaultPaymentMethodId, metadata })=>{
|
|
253
288
|
if (daysUntilDue && collectionMethod !== 'send_invoice') {
|
|
254
289
|
throw new Error('Days until due requires the send_invoice collection method.');
|
|
255
290
|
}
|
|
256
291
|
return {
|
|
257
292
|
customer: customerId,
|
|
258
|
-
items: items.map(({ priceId, quantity })
|
|
293
|
+
items: items.map(({ priceId, quantity })=>({
|
|
294
|
+
price: priceId,
|
|
295
|
+
quantity
|
|
296
|
+
})),
|
|
259
297
|
collection_method: collectionMethod,
|
|
260
298
|
days_until_due: daysUntilDue,
|
|
261
299
|
trial_period_days: trialPeriodDays,
|
|
262
300
|
default_payment_method: defaultPaymentMethodId,
|
|
263
|
-
metadata
|
|
301
|
+
metadata
|
|
264
302
|
};
|
|
265
303
|
},
|
|
266
|
-
options: {
|
|
304
|
+
options: {
|
|
305
|
+
customerId: customerOptions
|
|
306
|
+
}
|
|
267
307
|
});
|
|
268
308
|
export const cancelSubscription = action({
|
|
269
309
|
slug: 'cancelSubscription',
|
|
270
310
|
description: 'Cancel a Stripe subscription now or at period end.',
|
|
271
|
-
input: z.object({
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
311
|
+
input: z.object({
|
|
312
|
+
subscriptionId: z.string(),
|
|
313
|
+
cancelAtPeriodEnd: z.boolean().default(false)
|
|
314
|
+
}),
|
|
315
|
+
path: ({ subscriptionId })=>`subscriptions/${encodeURIComponent(subscriptionId)}`,
|
|
316
|
+
method: ({ cancelAtPeriodEnd })=>cancelAtPeriodEnd ? 'POST' : 'DELETE',
|
|
317
|
+
map: ({ cancelAtPeriodEnd })=>({
|
|
318
|
+
cancel_at_period_end: cancelAtPeriodEnd
|
|
319
|
+
}),
|
|
320
|
+
options: {
|
|
321
|
+
subscriptionId: subscriptionOptions
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
const getInvoiceInput = z.object({
|
|
325
|
+
invoiceId: z.string()
|
|
276
326
|
});
|
|
277
|
-
const getInvoiceInput = z.object({ invoiceId: z.string() });
|
|
278
327
|
export const getInvoice = action({
|
|
279
328
|
slug: 'getInvoice',
|
|
280
329
|
description: 'Get a Stripe invoice selected from available invoices.',
|
|
281
330
|
input: getInvoiceInput,
|
|
282
|
-
path: ({ invoiceId })
|
|
331
|
+
path: ({ invoiceId })=>`invoices/${encodeURIComponent(invoiceId)}`,
|
|
283
332
|
method: 'GET',
|
|
284
333
|
idempotent: true,
|
|
285
|
-
options: {
|
|
334
|
+
options: {
|
|
335
|
+
invoiceId: invoiceOptions
|
|
336
|
+
}
|
|
286
337
|
});
|
|
287
338
|
export const getPayout = action({
|
|
288
339
|
slug: 'getPayout',
|
|
289
340
|
description: 'Get a Stripe payout by ID.',
|
|
290
|
-
input: z.object({
|
|
291
|
-
|
|
341
|
+
input: z.object({
|
|
342
|
+
payoutId: z.string()
|
|
343
|
+
}),
|
|
344
|
+
path: ({ payoutId })=>`payouts/${encodeURIComponent(payoutId)}`,
|
|
292
345
|
method: 'GET',
|
|
293
346
|
idempotent: true,
|
|
294
|
-
options: {
|
|
347
|
+
options: {
|
|
348
|
+
payoutId: payoutOptions
|
|
349
|
+
}
|
|
295
350
|
});
|
|
296
351
|
export const createRefund = action({
|
|
297
352
|
slug: 'createRefund',
|
|
@@ -299,94 +354,128 @@ export const createRefund = action({
|
|
|
299
354
|
input: z.object({
|
|
300
355
|
paymentIntentId: z.string(),
|
|
301
356
|
amount: z.number().positive().optional(),
|
|
302
|
-
reason: z.enum([
|
|
303
|
-
|
|
357
|
+
reason: z.enum([
|
|
358
|
+
'duplicate',
|
|
359
|
+
'fraudulent',
|
|
360
|
+
'requested_by_customer'
|
|
361
|
+
]).optional(),
|
|
362
|
+
metadata
|
|
304
363
|
}),
|
|
305
364
|
path: 'refunds',
|
|
306
|
-
map: ({ paymentIntentId, amount, reason, metadata })
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
options: {
|
|
365
|
+
map: ({ paymentIntentId, amount, reason, metadata })=>({
|
|
366
|
+
payment_intent: paymentIntentId,
|
|
367
|
+
amount: amount === undefined ? undefined : Math.round(amount * 100),
|
|
368
|
+
reason,
|
|
369
|
+
metadata
|
|
370
|
+
}),
|
|
371
|
+
options: {
|
|
372
|
+
paymentIntentId: paymentIntentOptions
|
|
373
|
+
}
|
|
313
374
|
});
|
|
314
375
|
export const createPaymentLink = action({
|
|
315
376
|
slug: 'createPaymentLink',
|
|
316
377
|
description: 'Create a Stripe-hosted payment link.',
|
|
317
378
|
input: z.object({
|
|
318
|
-
lineItems: z
|
|
319
|
-
|
|
320
|
-
.
|
|
321
|
-
|
|
379
|
+
lineItems: z.array(z.object({
|
|
380
|
+
priceId: z.string(),
|
|
381
|
+
quantity: z.number().int().positive()
|
|
382
|
+
})).min(1),
|
|
383
|
+
afterCompletion: z.enum([
|
|
384
|
+
'hosted_confirmation',
|
|
385
|
+
'redirect'
|
|
386
|
+
]).optional(),
|
|
322
387
|
redirectUrl: z.string().url().optional(),
|
|
323
388
|
allowPromotionCodes: z.boolean().optional(),
|
|
324
|
-
billingAddressCollection: z.enum([
|
|
325
|
-
|
|
389
|
+
billingAddressCollection: z.enum([
|
|
390
|
+
'auto',
|
|
391
|
+
'required'
|
|
392
|
+
]).optional(),
|
|
393
|
+
metadata
|
|
326
394
|
}),
|
|
327
395
|
path: 'payment_links',
|
|
328
|
-
map: ({ lineItems, afterCompletion, redirectUrl, allowPromotionCodes, billingAddressCollection, metadata
|
|
396
|
+
map: ({ lineItems, afterCompletion, redirectUrl, allowPromotionCodes, billingAddressCollection, metadata })=>{
|
|
329
397
|
if (afterCompletion === 'redirect' && !redirectUrl) {
|
|
330
398
|
throw new Error('Redirect URL is required for redirect completion.');
|
|
331
399
|
}
|
|
332
400
|
return {
|
|
333
|
-
line_items: lineItems.map(({ priceId, quantity })
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
:
|
|
401
|
+
line_items: lineItems.map(({ priceId, quantity })=>({
|
|
402
|
+
price: priceId,
|
|
403
|
+
quantity
|
|
404
|
+
})),
|
|
405
|
+
after_completion: afterCompletion ? {
|
|
406
|
+
type: afterCompletion,
|
|
407
|
+
redirect: afterCompletion === 'redirect' ? {
|
|
408
|
+
url: redirectUrl
|
|
409
|
+
} : undefined
|
|
410
|
+
} : undefined,
|
|
340
411
|
allow_promotion_codes: allowPromotionCodes,
|
|
341
412
|
billing_address_collection: billingAddressCollection,
|
|
342
|
-
metadata
|
|
413
|
+
metadata
|
|
343
414
|
};
|
|
344
|
-
}
|
|
415
|
+
}
|
|
345
416
|
});
|
|
346
417
|
export const deactivatePaymentLink = action({
|
|
347
418
|
slug: 'deactivatePaymentLink',
|
|
348
419
|
description: 'Deactivate a Stripe payment link.',
|
|
349
|
-
input: z.object({
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
420
|
+
input: z.object({
|
|
421
|
+
paymentLinkId: z.string()
|
|
422
|
+
}),
|
|
423
|
+
path: ({ paymentLinkId })=>`payment_links/${encodeURIComponent(paymentLinkId)}`,
|
|
424
|
+
map: ()=>({
|
|
425
|
+
active: false
|
|
426
|
+
}),
|
|
427
|
+
options: {
|
|
428
|
+
paymentLinkId: paymentLinkOptions
|
|
429
|
+
}
|
|
353
430
|
});
|
|
354
431
|
export const getPaymentIntent = action({
|
|
355
432
|
slug: 'getPaymentIntent',
|
|
356
433
|
description: 'Get a Stripe payment intent by ID.',
|
|
357
|
-
input: z.object({
|
|
358
|
-
|
|
434
|
+
input: z.object({
|
|
435
|
+
paymentIntentId: z.string()
|
|
436
|
+
}),
|
|
437
|
+
path: ({ paymentIntentId })=>`payment_intents/${encodeURIComponent(paymentIntentId)}`,
|
|
359
438
|
method: 'GET',
|
|
360
439
|
idempotent: true,
|
|
361
|
-
options: {
|
|
440
|
+
options: {
|
|
441
|
+
paymentIntentId: paymentIntentOptions
|
|
442
|
+
}
|
|
362
443
|
});
|
|
363
444
|
export const findInvoice = action({
|
|
364
445
|
slug: 'findInvoice',
|
|
365
446
|
description: 'Find a Stripe invoice from an explicitly supplied ID.',
|
|
366
447
|
input: getInvoiceInput,
|
|
367
|
-
path: ({ invoiceId })
|
|
448
|
+
path: ({ invoiceId })=>`invoices/${encodeURIComponent(invoiceId)}`,
|
|
368
449
|
method: 'GET',
|
|
369
|
-
idempotent: true
|
|
450
|
+
idempotent: true
|
|
370
451
|
});
|
|
371
452
|
const customOutput = z.object({
|
|
372
453
|
status: z.number().int(),
|
|
373
454
|
headers: z.record(z.string(), z.string()),
|
|
374
|
-
body: z.record(z.string(), z.json())
|
|
455
|
+
body: z.record(z.string(), z.json())
|
|
375
456
|
});
|
|
376
457
|
const customInput = z.object({
|
|
377
|
-
method: z.enum([
|
|
458
|
+
method: z.enum([
|
|
459
|
+
'DELETE',
|
|
460
|
+
'GET',
|
|
461
|
+
'POST'
|
|
462
|
+
]),
|
|
378
463
|
path: z.string().regex(/^\/(?!\/)/, 'Path must be relative to the Stripe API.'),
|
|
379
|
-
query: z.record(z.string(), z.union([
|
|
380
|
-
|
|
464
|
+
query: z.record(z.string(), z.union([
|
|
465
|
+
z.string(),
|
|
466
|
+
z.number(),
|
|
467
|
+
z.boolean()
|
|
468
|
+
])).optional(),
|
|
469
|
+
body: z.record(z.string(), z.unknown()).optional()
|
|
381
470
|
});
|
|
382
471
|
export const sendRequest = defineAction({
|
|
383
472
|
slug: 'sendRequest',
|
|
384
473
|
description: 'Send an authenticated request to the Stripe API.',
|
|
385
474
|
input: customInput,
|
|
386
475
|
output: customOutput,
|
|
387
|
-
async run({ client, input }) {
|
|
476
|
+
async run ({ client, input }) {
|
|
388
477
|
return client.requestResponse(input.path, input.method, input.method === 'GET' ? input.query : input.body);
|
|
389
|
-
}
|
|
478
|
+
}
|
|
390
479
|
});
|
|
391
480
|
export const stripeActionDefinitions = [
|
|
392
481
|
createCustomer,
|
|
@@ -407,6 +496,7 @@ export const stripeActionDefinitions = [
|
|
|
407
496
|
deactivatePaymentLink,
|
|
408
497
|
getPaymentIntent,
|
|
409
498
|
findInvoice,
|
|
410
|
-
sendRequest
|
|
499
|
+
sendRequest
|
|
411
500
|
];
|
|
501
|
+
|
|
412
502
|
//# sourceMappingURL=actions.js.map
|