digital-tools 2.0.2 → 2.1.1
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/CHANGELOG.md +17 -0
- package/package.json +3 -4
- package/src/define.js +267 -0
- package/src/entities/advertising.js +999 -0
- package/src/entities/ai.js +756 -0
- package/src/entities/analytics.js +1588 -0
- package/src/entities/automation.js +601 -0
- package/src/entities/communication.js +1150 -0
- package/src/entities/crm.js +1386 -0
- package/src/entities/design.js +546 -0
- package/src/entities/development.js +2212 -0
- package/src/entities/document.js +874 -0
- package/src/entities/ecommerce.js +1429 -0
- package/src/entities/experiment.js +1039 -0
- package/src/entities/finance.js +3478 -0
- package/src/entities/forms.js +1892 -0
- package/src/entities/hr.js +661 -0
- package/src/entities/identity.js +997 -0
- package/src/entities/index.js +282 -0
- package/src/entities/infrastructure.js +1153 -0
- package/src/entities/knowledge.js +1438 -0
- package/src/entities/marketing.js +1610 -0
- package/src/entities/media.js +1634 -0
- package/src/entities/notification.js +1199 -0
- package/src/entities/presentation.js +1274 -0
- package/src/entities/productivity.js +1317 -0
- package/src/entities/project-management.js +1136 -0
- package/src/entities/recruiting.js +736 -0
- package/src/entities/shipping.js +509 -0
- package/src/entities/signature.js +1102 -0
- package/src/entities/site.js +222 -0
- package/src/entities/spreadsheet.js +1341 -0
- package/src/entities/storage.js +1198 -0
- package/src/entities/support.js +1166 -0
- package/src/entities/video-conferencing.js +1750 -0
- package/src/entities/video.js +950 -0
- package/src/entities.js +1663 -0
- package/src/index.js +74 -0
- package/src/providers/analytics/index.js +17 -0
- package/src/providers/analytics/mixpanel.js +255 -0
- package/src/providers/calendar/cal-com.js +303 -0
- package/src/providers/calendar/google-calendar.js +335 -0
- package/src/providers/calendar/index.js +20 -0
- package/src/providers/crm/hubspot.js +566 -0
- package/src/providers/crm/index.js +17 -0
- package/src/providers/development/github.js +472 -0
- package/src/providers/development/index.js +17 -0
- package/src/providers/ecommerce/index.js +17 -0
- package/src/providers/ecommerce/shopify.js +378 -0
- package/src/providers/email/index.js +20 -0
- package/src/providers/email/resend.js +258 -0
- package/src/providers/email/sendgrid.js +161 -0
- package/src/providers/finance/index.js +17 -0
- package/src/providers/finance/stripe.js +549 -0
- package/src/providers/forms/index.js +17 -0
- package/src/providers/forms/typeform.js +500 -0
- package/src/providers/index.js +123 -0
- package/src/providers/knowledge/index.js +17 -0
- package/src/providers/knowledge/notion.js +389 -0
- package/src/providers/marketing/index.js +17 -0
- package/src/providers/marketing/mailchimp.js +443 -0
- package/src/providers/media/cloudinary.js +318 -0
- package/src/providers/media/index.js +17 -0
- package/src/providers/messaging/index.js +20 -0
- package/src/providers/messaging/slack.js +393 -0
- package/src/providers/messaging/twilio-sms.js +249 -0
- package/src/providers/project-management/index.js +17 -0
- package/src/providers/project-management/linear.js +575 -0
- package/src/providers/registry.js +86 -0
- package/src/providers/spreadsheet/google-sheets.js +375 -0
- package/src/providers/spreadsheet/index.js +20 -0
- package/src/providers/spreadsheet/xlsx.js +423 -0
- package/src/providers/storage/index.js +24 -0
- package/src/providers/storage/s3.js +419 -0
- package/src/providers/support/index.js +17 -0
- package/src/providers/support/zendesk.js +373 -0
- package/src/providers/tasks/index.js +17 -0
- package/src/providers/tasks/todoist.js +286 -0
- package/src/providers/types.js +9 -0
- package/src/providers/video-conferencing/google-meet.js +286 -0
- package/src/providers/video-conferencing/index.js +31 -0
- package/src/providers/video-conferencing/jitsi.js +254 -0
- package/src/providers/video-conferencing/teams.js +270 -0
- package/src/providers/video-conferencing/zoom.js +332 -0
- package/src/registry.js +128 -0
- package/src/tools/communication.js +184 -0
- package/src/tools/data.js +205 -0
- package/src/tools/index.js +11 -0
- package/src/tools/web.js +137 -0
- package/src/types.js +10 -0
- package/test/define.test.js +306 -0
- package/test/registry.test.js +357 -0
- package/test/tools.test.js +363 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe Finance Provider
|
|
3
|
+
*
|
|
4
|
+
* Concrete implementation of FinanceProvider using Stripe API.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import { defineProvider } from '../registry.js';
|
|
9
|
+
const STRIPE_API_URL = 'https://api.stripe.com/v1';
|
|
10
|
+
/**
|
|
11
|
+
* Stripe provider info
|
|
12
|
+
*/
|
|
13
|
+
export const stripeInfo = {
|
|
14
|
+
id: 'finance.stripe',
|
|
15
|
+
name: 'Stripe',
|
|
16
|
+
description: 'Stripe payment processing and invoicing platform',
|
|
17
|
+
category: 'finance',
|
|
18
|
+
website: 'https://stripe.com',
|
|
19
|
+
docsUrl: 'https://stripe.com/docs/api',
|
|
20
|
+
requiredConfig: ['apiKey'],
|
|
21
|
+
optionalConfig: ['webhookSecret'],
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Create Stripe finance provider
|
|
25
|
+
*/
|
|
26
|
+
export function createStripeProvider(config) {
|
|
27
|
+
let apiKey;
|
|
28
|
+
/**
|
|
29
|
+
* Helper to make Stripe API requests
|
|
30
|
+
*/
|
|
31
|
+
async function stripeRequest(endpoint, options = {}) {
|
|
32
|
+
const { method = 'GET', body, params } = options;
|
|
33
|
+
const url = new URL(`${STRIPE_API_URL}${endpoint}`);
|
|
34
|
+
// Add query params for GET requests
|
|
35
|
+
if (params && method === 'GET') {
|
|
36
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
37
|
+
if (value !== undefined) {
|
|
38
|
+
url.searchParams.append(key, value);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const headers = {
|
|
43
|
+
Authorization: `Bearer ${apiKey}`,
|
|
44
|
+
};
|
|
45
|
+
let requestBody;
|
|
46
|
+
if (body && method !== 'GET') {
|
|
47
|
+
// Stripe uses form-encoded data
|
|
48
|
+
const params = new URLSearchParams();
|
|
49
|
+
Object.entries(body).forEach(([key, value]) => {
|
|
50
|
+
params.append(key, String(value));
|
|
51
|
+
});
|
|
52
|
+
requestBody = params.toString();
|
|
53
|
+
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
54
|
+
}
|
|
55
|
+
const response = await fetch(url.toString(), {
|
|
56
|
+
method,
|
|
57
|
+
headers,
|
|
58
|
+
body: requestBody,
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
const error = await response.json().catch(() => ({}));
|
|
62
|
+
throw new Error(error?.error?.message || `Stripe API error: ${response.status}`);
|
|
63
|
+
}
|
|
64
|
+
return response.json();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Convert Stripe nested params to form format
|
|
68
|
+
*/
|
|
69
|
+
function flattenParams(obj, prefix = '') {
|
|
70
|
+
const result = {};
|
|
71
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
72
|
+
const fullKey = prefix ? `${prefix}[${key}]` : key;
|
|
73
|
+
if (value === null || value === undefined) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
else if (Array.isArray(value)) {
|
|
77
|
+
value.forEach((item, index) => {
|
|
78
|
+
if (typeof item === 'object' && item !== null) {
|
|
79
|
+
Object.assign(result, flattenParams(item, `${fullKey}[${index}]`));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
result[`${fullKey}[${index}]`] = String(item);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else if (typeof value === 'object') {
|
|
87
|
+
Object.assign(result, flattenParams(value, fullKey));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
result[fullKey] = String(value);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Make Stripe API request with nested params support
|
|
97
|
+
*/
|
|
98
|
+
async function stripeRequestWithParams(endpoint, options = {}) {
|
|
99
|
+
const { method = 'GET', data, params } = options;
|
|
100
|
+
const url = new URL(`${STRIPE_API_URL}${endpoint}`);
|
|
101
|
+
// Add query params for GET requests
|
|
102
|
+
if (params && method === 'GET') {
|
|
103
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
104
|
+
if (value !== undefined) {
|
|
105
|
+
url.searchParams.append(key, value);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const headers = {
|
|
110
|
+
Authorization: `Bearer ${apiKey}`,
|
|
111
|
+
};
|
|
112
|
+
let requestBody;
|
|
113
|
+
if (data && method !== 'GET') {
|
|
114
|
+
// Flatten nested objects for Stripe's form format
|
|
115
|
+
const flatParams = flattenParams(data);
|
|
116
|
+
requestBody = new URLSearchParams(flatParams).toString();
|
|
117
|
+
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
118
|
+
}
|
|
119
|
+
const response = await fetch(url.toString(), {
|
|
120
|
+
method,
|
|
121
|
+
headers,
|
|
122
|
+
body: requestBody,
|
|
123
|
+
});
|
|
124
|
+
if (!response.ok) {
|
|
125
|
+
const error = await response.json().catch(() => ({}));
|
|
126
|
+
throw new Error(error?.error?.message || `Stripe API error: ${response.status}`);
|
|
127
|
+
}
|
|
128
|
+
return response.json();
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
info: stripeInfo,
|
|
132
|
+
async initialize(cfg) {
|
|
133
|
+
apiKey = cfg.apiKey;
|
|
134
|
+
if (!apiKey) {
|
|
135
|
+
throw new Error('Stripe API key is required');
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
async healthCheck() {
|
|
139
|
+
const start = Date.now();
|
|
140
|
+
try {
|
|
141
|
+
// Use balance endpoint to verify API key
|
|
142
|
+
await stripeRequest('/balance');
|
|
143
|
+
return {
|
|
144
|
+
healthy: true,
|
|
145
|
+
latencyMs: Date.now() - start,
|
|
146
|
+
message: 'Connected',
|
|
147
|
+
checkedAt: new Date(),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return {
|
|
152
|
+
healthy: false,
|
|
153
|
+
latencyMs: Date.now() - start,
|
|
154
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
155
|
+
checkedAt: new Date(),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
async dispose() {
|
|
160
|
+
// No cleanup needed
|
|
161
|
+
},
|
|
162
|
+
async createInvoice(invoice) {
|
|
163
|
+
const data = {
|
|
164
|
+
customer: invoice.customerId,
|
|
165
|
+
currency: invoice.currency || 'usd',
|
|
166
|
+
auto_advance: false, // Don't auto-finalize
|
|
167
|
+
};
|
|
168
|
+
if (invoice.dueDate) {
|
|
169
|
+
data.due_date = Math.floor(invoice.dueDate.getTime() / 1000);
|
|
170
|
+
}
|
|
171
|
+
if (invoice.memo) {
|
|
172
|
+
data.description = invoice.memo;
|
|
173
|
+
}
|
|
174
|
+
// Create the invoice
|
|
175
|
+
const stripeInvoice = await stripeRequestWithParams('/invoices', {
|
|
176
|
+
method: 'POST',
|
|
177
|
+
data,
|
|
178
|
+
});
|
|
179
|
+
// Add line items
|
|
180
|
+
for (const item of invoice.lineItems) {
|
|
181
|
+
await stripeRequestWithParams('/invoiceitems', {
|
|
182
|
+
method: 'POST',
|
|
183
|
+
data: {
|
|
184
|
+
customer: invoice.customerId,
|
|
185
|
+
invoice: stripeInvoice.id,
|
|
186
|
+
description: item.description,
|
|
187
|
+
quantity: item.quantity,
|
|
188
|
+
unit_amount: Math.round(item.unitPrice * 100), // Convert to cents
|
|
189
|
+
currency: invoice.currency || 'usd',
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
// Retrieve updated invoice with line items
|
|
194
|
+
const updatedInvoice = await stripeRequest(`/invoices/${stripeInvoice.id}`);
|
|
195
|
+
return {
|
|
196
|
+
id: updatedInvoice.id,
|
|
197
|
+
number: updatedInvoice.number || updatedInvoice.id,
|
|
198
|
+
customerId: updatedInvoice.customer,
|
|
199
|
+
status: mapStripeInvoiceStatus(updatedInvoice.status),
|
|
200
|
+
currency: updatedInvoice.currency,
|
|
201
|
+
subtotal: updatedInvoice.subtotal / 100,
|
|
202
|
+
tax: updatedInvoice.tax ? updatedInvoice.tax / 100 : undefined,
|
|
203
|
+
total: updatedInvoice.total / 100,
|
|
204
|
+
amountDue: updatedInvoice.amount_due / 100,
|
|
205
|
+
amountPaid: updatedInvoice.amount_paid / 100,
|
|
206
|
+
dueDate: updatedInvoice.due_date ? new Date(updatedInvoice.due_date * 1000) : undefined,
|
|
207
|
+
paidAt: updatedInvoice.status_transitions?.paid_at
|
|
208
|
+
? new Date(updatedInvoice.status_transitions.paid_at * 1000)
|
|
209
|
+
: undefined,
|
|
210
|
+
url: updatedInvoice.hosted_invoice_url,
|
|
211
|
+
createdAt: new Date(updatedInvoice.created * 1000),
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
async getInvoice(invoiceId) {
|
|
215
|
+
try {
|
|
216
|
+
const invoice = await stripeRequest(`/invoices/${invoiceId}`);
|
|
217
|
+
return {
|
|
218
|
+
id: invoice.id,
|
|
219
|
+
number: invoice.number || invoice.id,
|
|
220
|
+
customerId: invoice.customer,
|
|
221
|
+
status: mapStripeInvoiceStatus(invoice.status),
|
|
222
|
+
currency: invoice.currency,
|
|
223
|
+
subtotal: invoice.subtotal / 100,
|
|
224
|
+
tax: invoice.tax ? invoice.tax / 100 : undefined,
|
|
225
|
+
total: invoice.total / 100,
|
|
226
|
+
amountDue: invoice.amount_due / 100,
|
|
227
|
+
amountPaid: invoice.amount_paid / 100,
|
|
228
|
+
dueDate: invoice.due_date ? new Date(invoice.due_date * 1000) : undefined,
|
|
229
|
+
paidAt: invoice.status_transitions?.paid_at
|
|
230
|
+
? new Date(invoice.status_transitions.paid_at * 1000)
|
|
231
|
+
: undefined,
|
|
232
|
+
url: invoice.hosted_invoice_url,
|
|
233
|
+
createdAt: new Date(invoice.created * 1000),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
async updateInvoice(invoiceId, updates) {
|
|
241
|
+
const data = {};
|
|
242
|
+
if (updates.dueDate) {
|
|
243
|
+
data.due_date = Math.floor(updates.dueDate.getTime() / 1000);
|
|
244
|
+
}
|
|
245
|
+
if (updates.memo) {
|
|
246
|
+
data.description = updates.memo;
|
|
247
|
+
}
|
|
248
|
+
const invoice = await stripeRequestWithParams(`/invoices/${invoiceId}`, {
|
|
249
|
+
method: 'POST',
|
|
250
|
+
data,
|
|
251
|
+
});
|
|
252
|
+
return {
|
|
253
|
+
id: invoice.id,
|
|
254
|
+
number: invoice.number || invoice.id,
|
|
255
|
+
customerId: invoice.customer,
|
|
256
|
+
status: mapStripeInvoiceStatus(invoice.status),
|
|
257
|
+
currency: invoice.currency,
|
|
258
|
+
subtotal: invoice.subtotal / 100,
|
|
259
|
+
tax: invoice.tax ? invoice.tax / 100 : undefined,
|
|
260
|
+
total: invoice.total / 100,
|
|
261
|
+
amountDue: invoice.amount_due / 100,
|
|
262
|
+
amountPaid: invoice.amount_paid / 100,
|
|
263
|
+
dueDate: invoice.due_date ? new Date(invoice.due_date * 1000) : undefined,
|
|
264
|
+
paidAt: invoice.status_transitions?.paid_at
|
|
265
|
+
? new Date(invoice.status_transitions.paid_at * 1000)
|
|
266
|
+
: undefined,
|
|
267
|
+
url: invoice.hosted_invoice_url,
|
|
268
|
+
createdAt: new Date(invoice.created * 1000),
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
async listInvoices(options = {}) {
|
|
272
|
+
const params = {};
|
|
273
|
+
if (options.limit) {
|
|
274
|
+
params.limit = String(options.limit);
|
|
275
|
+
}
|
|
276
|
+
if (options.cursor) {
|
|
277
|
+
params.starting_after = options.cursor;
|
|
278
|
+
}
|
|
279
|
+
if (options.customerId) {
|
|
280
|
+
params.customer = options.customerId;
|
|
281
|
+
}
|
|
282
|
+
if (options.status) {
|
|
283
|
+
params.status = options.status;
|
|
284
|
+
}
|
|
285
|
+
const response = await stripeRequest('/invoices', { params });
|
|
286
|
+
return {
|
|
287
|
+
items: response.data.map((invoice) => ({
|
|
288
|
+
id: invoice.id,
|
|
289
|
+
number: invoice.number || invoice.id,
|
|
290
|
+
customerId: invoice.customer,
|
|
291
|
+
status: mapStripeInvoiceStatus(invoice.status),
|
|
292
|
+
currency: invoice.currency,
|
|
293
|
+
subtotal: invoice.subtotal / 100,
|
|
294
|
+
tax: invoice.tax ? invoice.tax / 100 : undefined,
|
|
295
|
+
total: invoice.total / 100,
|
|
296
|
+
amountDue: invoice.amount_due / 100,
|
|
297
|
+
amountPaid: invoice.amount_paid / 100,
|
|
298
|
+
dueDate: invoice.due_date ? new Date(invoice.due_date * 1000) : undefined,
|
|
299
|
+
paidAt: invoice.status_transitions?.paid_at
|
|
300
|
+
? new Date(invoice.status_transitions.paid_at * 1000)
|
|
301
|
+
: undefined,
|
|
302
|
+
url: invoice.hosted_invoice_url,
|
|
303
|
+
createdAt: new Date(invoice.created * 1000),
|
|
304
|
+
})),
|
|
305
|
+
hasMore: response.has_more,
|
|
306
|
+
nextCursor: response.has_more ? response.data[response.data.length - 1]?.id : undefined,
|
|
307
|
+
};
|
|
308
|
+
},
|
|
309
|
+
async sendInvoice(invoiceId) {
|
|
310
|
+
try {
|
|
311
|
+
// First finalize the invoice if it's a draft
|
|
312
|
+
const invoice = await stripeRequest(`/invoices/${invoiceId}`);
|
|
313
|
+
if (invoice.status === 'draft') {
|
|
314
|
+
await stripeRequestWithParams(`/invoices/${invoiceId}/finalize`, {
|
|
315
|
+
method: 'POST',
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
// Send the invoice
|
|
319
|
+
await stripeRequestWithParams(`/invoices/${invoiceId}/send`, {
|
|
320
|
+
method: 'POST',
|
|
321
|
+
});
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
async voidInvoice(invoiceId) {
|
|
329
|
+
try {
|
|
330
|
+
await stripeRequestWithParams(`/invoices/${invoiceId}/void`, {
|
|
331
|
+
method: 'POST',
|
|
332
|
+
});
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
async createPayment(payment) {
|
|
340
|
+
const data = {
|
|
341
|
+
amount: Math.round(payment.amount * 100), // Convert to cents
|
|
342
|
+
currency: payment.currency,
|
|
343
|
+
payment_method: payment.paymentMethod,
|
|
344
|
+
confirm: true,
|
|
345
|
+
};
|
|
346
|
+
if (payment.customerId) {
|
|
347
|
+
data.customer = payment.customerId;
|
|
348
|
+
}
|
|
349
|
+
if (payment.description) {
|
|
350
|
+
data.description = payment.description;
|
|
351
|
+
}
|
|
352
|
+
// For Stripe, we create a PaymentIntent
|
|
353
|
+
const intent = await stripeRequestWithParams('/payment_intents', {
|
|
354
|
+
method: 'POST',
|
|
355
|
+
data,
|
|
356
|
+
});
|
|
357
|
+
return {
|
|
358
|
+
id: intent.id,
|
|
359
|
+
amount: intent.amount / 100,
|
|
360
|
+
currency: intent.currency,
|
|
361
|
+
status: mapStripePaymentStatus(intent.status),
|
|
362
|
+
customerId: intent.customer || undefined,
|
|
363
|
+
invoiceId: intent.invoice || undefined,
|
|
364
|
+
paymentMethod: payment.paymentMethod,
|
|
365
|
+
description: intent.description,
|
|
366
|
+
createdAt: new Date(intent.created * 1000),
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
async getPayment(paymentId) {
|
|
370
|
+
try {
|
|
371
|
+
const intent = await stripeRequest(`/payment_intents/${paymentId}`);
|
|
372
|
+
return {
|
|
373
|
+
id: intent.id,
|
|
374
|
+
amount: intent.amount / 100,
|
|
375
|
+
currency: intent.currency,
|
|
376
|
+
status: mapStripePaymentStatus(intent.status),
|
|
377
|
+
customerId: intent.customer || undefined,
|
|
378
|
+
invoiceId: intent.invoice || undefined,
|
|
379
|
+
paymentMethod: intent.payment_method || 'unknown',
|
|
380
|
+
description: intent.description,
|
|
381
|
+
createdAt: new Date(intent.created * 1000),
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
async listPayments(options = {}) {
|
|
389
|
+
const params = {};
|
|
390
|
+
if (options.limit) {
|
|
391
|
+
params.limit = String(options.limit);
|
|
392
|
+
}
|
|
393
|
+
if (options.cursor) {
|
|
394
|
+
params.starting_after = options.cursor;
|
|
395
|
+
}
|
|
396
|
+
if (options.customerId) {
|
|
397
|
+
params.customer = options.customerId;
|
|
398
|
+
}
|
|
399
|
+
const response = await stripeRequest('/payment_intents', { params });
|
|
400
|
+
return {
|
|
401
|
+
items: response.data.map((intent) => ({
|
|
402
|
+
id: intent.id,
|
|
403
|
+
amount: intent.amount / 100,
|
|
404
|
+
currency: intent.currency,
|
|
405
|
+
status: mapStripePaymentStatus(intent.status),
|
|
406
|
+
customerId: intent.customer || undefined,
|
|
407
|
+
invoiceId: intent.invoice || undefined,
|
|
408
|
+
paymentMethod: intent.payment_method || 'unknown',
|
|
409
|
+
description: intent.description,
|
|
410
|
+
createdAt: new Date(intent.created * 1000),
|
|
411
|
+
})),
|
|
412
|
+
hasMore: response.has_more,
|
|
413
|
+
nextCursor: response.has_more ? response.data[response.data.length - 1]?.id : undefined,
|
|
414
|
+
};
|
|
415
|
+
},
|
|
416
|
+
async refundPayment(paymentId, amount) {
|
|
417
|
+
const data = {
|
|
418
|
+
payment_intent: paymentId,
|
|
419
|
+
};
|
|
420
|
+
if (amount !== undefined) {
|
|
421
|
+
data.amount = Math.round(amount * 100);
|
|
422
|
+
}
|
|
423
|
+
const refund = await stripeRequestWithParams('/refunds', {
|
|
424
|
+
method: 'POST',
|
|
425
|
+
data,
|
|
426
|
+
});
|
|
427
|
+
return {
|
|
428
|
+
id: refund.id,
|
|
429
|
+
paymentId: refund.payment_intent,
|
|
430
|
+
amount: refund.amount / 100,
|
|
431
|
+
status: refund.status,
|
|
432
|
+
createdAt: new Date(refund.created * 1000),
|
|
433
|
+
};
|
|
434
|
+
},
|
|
435
|
+
async createCustomer(customer) {
|
|
436
|
+
const data = {
|
|
437
|
+
name: customer.name,
|
|
438
|
+
};
|
|
439
|
+
if (customer.email) {
|
|
440
|
+
data.email = customer.email;
|
|
441
|
+
}
|
|
442
|
+
if (customer.phone) {
|
|
443
|
+
data.phone = customer.phone;
|
|
444
|
+
}
|
|
445
|
+
if (customer.address) {
|
|
446
|
+
data.address = {
|
|
447
|
+
line1: customer.address.line1,
|
|
448
|
+
line2: customer.address.line2,
|
|
449
|
+
city: customer.address.city,
|
|
450
|
+
state: customer.address.state,
|
|
451
|
+
postal_code: customer.address.postalCode,
|
|
452
|
+
country: customer.address.country,
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
const stripeCustomer = await stripeRequestWithParams('/customers', {
|
|
456
|
+
method: 'POST',
|
|
457
|
+
data,
|
|
458
|
+
});
|
|
459
|
+
return {
|
|
460
|
+
id: stripeCustomer.id,
|
|
461
|
+
name: stripeCustomer.name,
|
|
462
|
+
email: stripeCustomer.email,
|
|
463
|
+
phone: stripeCustomer.phone,
|
|
464
|
+
balance: stripeCustomer.balance ? stripeCustomer.balance / 100 : undefined,
|
|
465
|
+
createdAt: new Date(stripeCustomer.created * 1000),
|
|
466
|
+
};
|
|
467
|
+
},
|
|
468
|
+
async getCustomer(customerId) {
|
|
469
|
+
try {
|
|
470
|
+
const customer = await stripeRequest(`/customers/${customerId}`);
|
|
471
|
+
return {
|
|
472
|
+
id: customer.id,
|
|
473
|
+
name: customer.name,
|
|
474
|
+
email: customer.email,
|
|
475
|
+
phone: customer.phone,
|
|
476
|
+
balance: customer.balance ? customer.balance / 100 : undefined,
|
|
477
|
+
createdAt: new Date(customer.created * 1000),
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
async listCustomers(options = {}) {
|
|
485
|
+
const params = {};
|
|
486
|
+
if (options.limit) {
|
|
487
|
+
params.limit = String(options.limit);
|
|
488
|
+
}
|
|
489
|
+
if (options.cursor) {
|
|
490
|
+
params.starting_after = options.cursor;
|
|
491
|
+
}
|
|
492
|
+
const response = await stripeRequest('/customers', { params });
|
|
493
|
+
return {
|
|
494
|
+
items: response.data.map((customer) => ({
|
|
495
|
+
id: customer.id,
|
|
496
|
+
name: customer.name,
|
|
497
|
+
email: customer.email,
|
|
498
|
+
phone: customer.phone,
|
|
499
|
+
balance: customer.balance ? customer.balance / 100 : undefined,
|
|
500
|
+
createdAt: new Date(customer.created * 1000),
|
|
501
|
+
})),
|
|
502
|
+
hasMore: response.has_more,
|
|
503
|
+
nextCursor: response.has_more ? response.data[response.data.length - 1]?.id : undefined,
|
|
504
|
+
};
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Map Stripe invoice status to standard status
|
|
510
|
+
*/
|
|
511
|
+
function mapStripeInvoiceStatus(status) {
|
|
512
|
+
switch (status) {
|
|
513
|
+
case 'draft':
|
|
514
|
+
return 'draft';
|
|
515
|
+
case 'open':
|
|
516
|
+
return 'open';
|
|
517
|
+
case 'paid':
|
|
518
|
+
return 'paid';
|
|
519
|
+
case 'void':
|
|
520
|
+
return 'void';
|
|
521
|
+
case 'uncollectible':
|
|
522
|
+
return 'uncollectible';
|
|
523
|
+
default:
|
|
524
|
+
return 'draft';
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Map Stripe payment status to standard status
|
|
529
|
+
*/
|
|
530
|
+
function mapStripePaymentStatus(status) {
|
|
531
|
+
switch (status) {
|
|
532
|
+
case 'requires_payment_method':
|
|
533
|
+
case 'requires_confirmation':
|
|
534
|
+
case 'requires_action':
|
|
535
|
+
case 'processing':
|
|
536
|
+
return 'pending';
|
|
537
|
+
case 'succeeded':
|
|
538
|
+
return 'succeeded';
|
|
539
|
+
case 'canceled':
|
|
540
|
+
case 'requires_capture':
|
|
541
|
+
return 'failed';
|
|
542
|
+
default:
|
|
543
|
+
return 'pending';
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Stripe provider definition
|
|
548
|
+
*/
|
|
549
|
+
export const stripeProvider = defineProvider(stripeInfo, async (config) => createStripeProvider(config));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forms Providers
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { typeformInfo, typeformProvider, createTypeformProvider } from './typeform.js';
|
|
7
|
+
import { typeformProvider } from './typeform.js';
|
|
8
|
+
/**
|
|
9
|
+
* Register all forms providers
|
|
10
|
+
*/
|
|
11
|
+
export function registerFormsProviders() {
|
|
12
|
+
typeformProvider.register();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* All forms providers
|
|
16
|
+
*/
|
|
17
|
+
export const formsProviders = [typeformProvider];
|