@pubflow/core 0.3.1 → 0.4.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/README.md +45 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/payments/client.d.ts +523 -0
- package/dist/payments/client.js +804 -0
- package/dist/payments/index.d.ts +7 -0
- package/dist/payments/index.js +11 -0
- package/dist/payments/types.d.ts +649 -0
- package/dist/payments/types.js +7 -0
- package/package.json +2 -2
|
@@ -0,0 +1,804 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bridge Payment Client
|
|
4
|
+
*
|
|
5
|
+
* Client for interacting with Bridge Payments API
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.BridgePaymentClient = void 0;
|
|
9
|
+
const client_1 = require("../api/client");
|
|
10
|
+
const adapter_1 = require("../storage/adapter");
|
|
11
|
+
/**
|
|
12
|
+
* Bridge Payment Client
|
|
13
|
+
*
|
|
14
|
+
* Provides a simple interface for interacting with Bridge Payments API
|
|
15
|
+
*/
|
|
16
|
+
class BridgePaymentClient {
|
|
17
|
+
/**
|
|
18
|
+
* Create a new Bridge Payment Client
|
|
19
|
+
*
|
|
20
|
+
* @param config Client configuration
|
|
21
|
+
*/
|
|
22
|
+
constructor(config) {
|
|
23
|
+
this.baseUrl = config.baseUrl;
|
|
24
|
+
this.guestToken = config.guestToken;
|
|
25
|
+
this.organizationId = config.organizationId;
|
|
26
|
+
// Create API client with Pubflow configuration
|
|
27
|
+
this.apiClient = new client_1.ApiClient({
|
|
28
|
+
id: config.instanceId || 'bridge-payments',
|
|
29
|
+
baseUrl: config.baseUrl,
|
|
30
|
+
headers: config.headers || {},
|
|
31
|
+
storageConfig: {
|
|
32
|
+
prefix: 'pubflow',
|
|
33
|
+
sessionKey: 'session_id'
|
|
34
|
+
}
|
|
35
|
+
}, config.storage || new adapter_1.MemoryStorageAdapter());
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Make a request to the Bridge Payments API
|
|
39
|
+
*
|
|
40
|
+
* @param endpoint API endpoint
|
|
41
|
+
* @param method HTTP method
|
|
42
|
+
* @param body Request body
|
|
43
|
+
* @param options Request options
|
|
44
|
+
* @returns Response data
|
|
45
|
+
*/
|
|
46
|
+
async request(endpoint, method, body, options) {
|
|
47
|
+
const requestOptions = {
|
|
48
|
+
headers: {},
|
|
49
|
+
includeSession: true,
|
|
50
|
+
...options,
|
|
51
|
+
};
|
|
52
|
+
// 1. Guest Token (if available) - Uses X-Guest-Token header
|
|
53
|
+
if (this.guestToken || (options === null || options === void 0 ? void 0 : options.guestToken)) {
|
|
54
|
+
const token = (options === null || options === void 0 ? void 0 : options.guestToken) || this.guestToken;
|
|
55
|
+
if (token) {
|
|
56
|
+
requestOptions.headers['X-Guest-Token'] = token;
|
|
57
|
+
requestOptions.includeSession = false; // Don't include session for guests
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// 2. Organization ID (if available) - Included in body
|
|
61
|
+
// ⚠️ NOTE: Only works in Subscriptions and Customers currently
|
|
62
|
+
// Addresses, Payments and Payment Methods have organization_id hardcoded to null in backend
|
|
63
|
+
if (body && (this.organizationId || (options === null || options === void 0 ? void 0 : options.organizationId))) {
|
|
64
|
+
const orgId = (options === null || options === void 0 ? void 0 : options.organizationId) || this.organizationId;
|
|
65
|
+
// Only include organization_id in endpoints that support it
|
|
66
|
+
if (endpoint.includes('/subscriptions') || endpoint.includes('/customers')) {
|
|
67
|
+
body.organization_id = orgId;
|
|
68
|
+
}
|
|
69
|
+
// For other endpoints, backend ignores it (hardcoded null)
|
|
70
|
+
// When implemented in backend, it will work automatically
|
|
71
|
+
}
|
|
72
|
+
// 3. ApiClient automatically handles X-Session-ID for authenticated users
|
|
73
|
+
const response = await this.apiClient.request(`/bridge-payment${endpoint}`, method, body, requestOptions);
|
|
74
|
+
if (!response.success) {
|
|
75
|
+
throw new Error(response.error || 'Request failed');
|
|
76
|
+
}
|
|
77
|
+
return response.data;
|
|
78
|
+
}
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// PAYMENT INTENTS
|
|
81
|
+
// ============================================================================
|
|
82
|
+
/**
|
|
83
|
+
* Create a payment intent
|
|
84
|
+
*
|
|
85
|
+
* @param data Payment intent data
|
|
86
|
+
* @param options Request options
|
|
87
|
+
* @returns Payment intent
|
|
88
|
+
*/
|
|
89
|
+
async createPaymentIntent(data, options) {
|
|
90
|
+
return this.request('/payments/intents', 'POST', data, options);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get a payment intent by ID
|
|
94
|
+
*
|
|
95
|
+
* @param id Payment intent ID
|
|
96
|
+
* @param options Request options
|
|
97
|
+
* @returns Payment intent
|
|
98
|
+
*/
|
|
99
|
+
async getPaymentIntent(id, options) {
|
|
100
|
+
return this.request(`/payments/intents/${id}`, 'GET', undefined, options);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* List payments
|
|
104
|
+
*
|
|
105
|
+
* @param params Pagination parameters
|
|
106
|
+
* @param options Request options
|
|
107
|
+
* @returns List of payments
|
|
108
|
+
*/
|
|
109
|
+
async listPayments(params, options) {
|
|
110
|
+
const queryParams = new URLSearchParams();
|
|
111
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
112
|
+
queryParams.set('page', params.page.toString());
|
|
113
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
114
|
+
queryParams.set('limit', params.limit.toString());
|
|
115
|
+
const endpoint = `/payments${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
116
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get a payment by ID
|
|
120
|
+
*
|
|
121
|
+
* @param id Payment ID
|
|
122
|
+
* @param options Request options
|
|
123
|
+
* @returns Payment
|
|
124
|
+
*/
|
|
125
|
+
async getPayment(id, options) {
|
|
126
|
+
return this.request(`/payments/${id}`, 'GET', undefined, options);
|
|
127
|
+
}
|
|
128
|
+
// ============================================================================
|
|
129
|
+
// PAYMENT METHODS
|
|
130
|
+
// ============================================================================
|
|
131
|
+
/**
|
|
132
|
+
* List payment methods
|
|
133
|
+
*
|
|
134
|
+
* @param params Pagination parameters
|
|
135
|
+
* @param options Request options
|
|
136
|
+
* @returns List of payment methods
|
|
137
|
+
*/
|
|
138
|
+
async listPaymentMethods(params, options) {
|
|
139
|
+
const queryParams = new URLSearchParams();
|
|
140
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
141
|
+
queryParams.set('page', params.page.toString());
|
|
142
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
143
|
+
queryParams.set('limit', params.limit.toString());
|
|
144
|
+
const endpoint = `/payment-methods${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
145
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get a payment method by ID
|
|
149
|
+
*
|
|
150
|
+
* @param id Payment method ID
|
|
151
|
+
* @param options Request options
|
|
152
|
+
* @returns Payment method
|
|
153
|
+
*/
|
|
154
|
+
async getPaymentMethod(id, options) {
|
|
155
|
+
return this.request(`/payment-methods/${id}`, 'GET', undefined, options);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Update a payment method
|
|
159
|
+
*
|
|
160
|
+
* @param id Payment method ID
|
|
161
|
+
* @param data Update data
|
|
162
|
+
* @param options Request options
|
|
163
|
+
* @returns Updated payment method
|
|
164
|
+
*/
|
|
165
|
+
async updatePaymentMethod(id, data, options) {
|
|
166
|
+
return this.request(`/payment-methods/${id}`, 'PUT', data, options);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Delete a payment method
|
|
170
|
+
*
|
|
171
|
+
* @param id Payment method ID
|
|
172
|
+
* @param options Request options
|
|
173
|
+
*/
|
|
174
|
+
async deletePaymentMethod(id, options) {
|
|
175
|
+
await this.request(`/payment-methods/${id}`, 'DELETE', undefined, options);
|
|
176
|
+
}
|
|
177
|
+
// ============================================================================
|
|
178
|
+
// ADDRESSES
|
|
179
|
+
// ============================================================================
|
|
180
|
+
/**
|
|
181
|
+
* Create an address
|
|
182
|
+
*
|
|
183
|
+
* @param data Address data
|
|
184
|
+
* @param options Request options
|
|
185
|
+
* @returns Created address
|
|
186
|
+
*/
|
|
187
|
+
async createAddress(data, options) {
|
|
188
|
+
return this.request('/addresses', 'POST', data, options);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* List addresses
|
|
192
|
+
*
|
|
193
|
+
* @param params Pagination parameters
|
|
194
|
+
* @param options Request options
|
|
195
|
+
* @returns List of addresses
|
|
196
|
+
*/
|
|
197
|
+
async listAddresses(params, options) {
|
|
198
|
+
const queryParams = new URLSearchParams();
|
|
199
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
200
|
+
queryParams.set('page', params.page.toString());
|
|
201
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
202
|
+
queryParams.set('limit', params.limit.toString());
|
|
203
|
+
const endpoint = `/addresses${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
204
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get an address by ID
|
|
208
|
+
*
|
|
209
|
+
* @param id Address ID
|
|
210
|
+
* @param options Request options
|
|
211
|
+
* @returns Address
|
|
212
|
+
*/
|
|
213
|
+
async getAddress(id, options) {
|
|
214
|
+
return this.request(`/addresses/${id}`, 'GET', undefined, options);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Update an address
|
|
218
|
+
*
|
|
219
|
+
* @param id Address ID
|
|
220
|
+
* @param data Update data
|
|
221
|
+
* @param options Request options
|
|
222
|
+
* @returns Updated address
|
|
223
|
+
*/
|
|
224
|
+
async updateAddress(id, data, options) {
|
|
225
|
+
return this.request(`/addresses/${id}`, 'PUT', data, options);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Delete an address
|
|
229
|
+
*
|
|
230
|
+
* @param id Address ID
|
|
231
|
+
* @param options Request options
|
|
232
|
+
*/
|
|
233
|
+
async deleteAddress(id, options) {
|
|
234
|
+
await this.request(`/addresses/${id}`, 'DELETE', undefined, options);
|
|
235
|
+
}
|
|
236
|
+
// ============================================================================
|
|
237
|
+
// CUSTOMERS
|
|
238
|
+
// ============================================================================
|
|
239
|
+
/**
|
|
240
|
+
* Create a customer
|
|
241
|
+
*
|
|
242
|
+
* @param data Customer data
|
|
243
|
+
* @param options Request options
|
|
244
|
+
* @returns Created customer
|
|
245
|
+
*/
|
|
246
|
+
async createCustomer(data, options) {
|
|
247
|
+
return this.request('/customers', 'POST', data, options);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* List customers
|
|
251
|
+
*
|
|
252
|
+
* @param params Pagination parameters
|
|
253
|
+
* @param options Request options
|
|
254
|
+
* @returns List of customers
|
|
255
|
+
*/
|
|
256
|
+
async listCustomers(params, options) {
|
|
257
|
+
const queryParams = new URLSearchParams();
|
|
258
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
259
|
+
queryParams.set('page', params.page.toString());
|
|
260
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
261
|
+
queryParams.set('limit', params.limit.toString());
|
|
262
|
+
const endpoint = `/customers${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
263
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get a customer by ID
|
|
267
|
+
*
|
|
268
|
+
* @param id Customer ID
|
|
269
|
+
* @param options Request options
|
|
270
|
+
* @returns Customer
|
|
271
|
+
*/
|
|
272
|
+
async getCustomer(id, options) {
|
|
273
|
+
return this.request(`/customers/${id}`, 'GET', undefined, options);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Update a customer
|
|
277
|
+
*
|
|
278
|
+
* @param id Customer ID
|
|
279
|
+
* @param data Update data
|
|
280
|
+
* @param options Request options
|
|
281
|
+
* @returns Updated customer
|
|
282
|
+
*/
|
|
283
|
+
async updateCustomer(id, data, options) {
|
|
284
|
+
return this.request(`/customers/${id}`, 'PUT', data, options);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Delete a customer
|
|
288
|
+
*
|
|
289
|
+
* @param id Customer ID
|
|
290
|
+
* @param options Request options
|
|
291
|
+
*/
|
|
292
|
+
async deleteCustomer(id, options) {
|
|
293
|
+
await this.request(`/customers/${id}`, 'DELETE', undefined, options);
|
|
294
|
+
}
|
|
295
|
+
// ============================================================================
|
|
296
|
+
// SUBSCRIPTIONS
|
|
297
|
+
// ============================================================================
|
|
298
|
+
/**
|
|
299
|
+
* Create a subscription
|
|
300
|
+
*
|
|
301
|
+
* @param data Subscription data
|
|
302
|
+
* @param options Request options
|
|
303
|
+
* @returns Created subscription
|
|
304
|
+
*/
|
|
305
|
+
async createSubscription(data, options) {
|
|
306
|
+
return this.request('/subscriptions', 'POST', data, options);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* List subscriptions
|
|
310
|
+
*
|
|
311
|
+
* @param params Pagination parameters
|
|
312
|
+
* @param options Request options
|
|
313
|
+
* @returns List of subscriptions
|
|
314
|
+
*/
|
|
315
|
+
async listSubscriptions(params, options) {
|
|
316
|
+
const queryParams = new URLSearchParams();
|
|
317
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
318
|
+
queryParams.set('page', params.page.toString());
|
|
319
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
320
|
+
queryParams.set('limit', params.limit.toString());
|
|
321
|
+
const endpoint = `/subscriptions${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
322
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get a subscription by ID
|
|
326
|
+
*
|
|
327
|
+
* @param id Subscription ID
|
|
328
|
+
* @param options Request options
|
|
329
|
+
* @returns Subscription
|
|
330
|
+
*/
|
|
331
|
+
async getSubscription(id, options) {
|
|
332
|
+
return this.request(`/subscriptions/${id}`, 'GET', undefined, options);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Cancel a subscription
|
|
336
|
+
*
|
|
337
|
+
* @param id Subscription ID
|
|
338
|
+
* @param data Cancel data
|
|
339
|
+
* @param options Request options
|
|
340
|
+
* @returns Canceled subscription
|
|
341
|
+
*/
|
|
342
|
+
async cancelSubscription(id, data, options) {
|
|
343
|
+
return this.request(`/subscriptions/${id}/cancel`, 'POST', data, options);
|
|
344
|
+
}
|
|
345
|
+
// ============================================================================
|
|
346
|
+
// ORGANIZATIONS
|
|
347
|
+
// ============================================================================
|
|
348
|
+
/**
|
|
349
|
+
* Create an organization
|
|
350
|
+
*
|
|
351
|
+
* @param data Organization data
|
|
352
|
+
* @param options Request options
|
|
353
|
+
* @returns Created organization
|
|
354
|
+
*/
|
|
355
|
+
async createOrganization(data, options) {
|
|
356
|
+
return this.request('/organizations', 'POST', data, options);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* List organizations
|
|
360
|
+
*
|
|
361
|
+
* @param params Pagination parameters
|
|
362
|
+
* @param options Request options
|
|
363
|
+
* @returns List of organizations
|
|
364
|
+
*/
|
|
365
|
+
async listOrganizations(params, options) {
|
|
366
|
+
const queryParams = new URLSearchParams();
|
|
367
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
368
|
+
queryParams.set('page', params.page.toString());
|
|
369
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
370
|
+
queryParams.set('limit', params.limit.toString());
|
|
371
|
+
const endpoint = `/organizations${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
372
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Get an organization by ID
|
|
376
|
+
*
|
|
377
|
+
* @param id Organization ID
|
|
378
|
+
* @param options Request options
|
|
379
|
+
* @returns Organization
|
|
380
|
+
*/
|
|
381
|
+
async getOrganization(id, options) {
|
|
382
|
+
return this.request(`/organizations/${id}`, 'GET', undefined, options);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Update an organization
|
|
386
|
+
*
|
|
387
|
+
* @param id Organization ID
|
|
388
|
+
* @param data Update data
|
|
389
|
+
* @param options Request options
|
|
390
|
+
* @returns Updated organization
|
|
391
|
+
*/
|
|
392
|
+
async updateOrganization(id, data, options) {
|
|
393
|
+
return this.request(`/organizations/${id}`, 'PUT', data, options);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Delete an organization
|
|
397
|
+
*
|
|
398
|
+
* @param id Organization ID
|
|
399
|
+
* @param options Request options
|
|
400
|
+
*/
|
|
401
|
+
async deleteOrganization(id, options) {
|
|
402
|
+
await this.request(`/organizations/${id}`, 'DELETE', undefined, options);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* List organization members
|
|
406
|
+
*
|
|
407
|
+
* @param organizationId Organization ID
|
|
408
|
+
* @param params Pagination parameters
|
|
409
|
+
* @param options Request options
|
|
410
|
+
* @returns List of organization members
|
|
411
|
+
*/
|
|
412
|
+
async listOrganizationMembers(organizationId, params, options) {
|
|
413
|
+
const queryParams = new URLSearchParams();
|
|
414
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
415
|
+
queryParams.set('page', params.page.toString());
|
|
416
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
417
|
+
queryParams.set('limit', params.limit.toString());
|
|
418
|
+
const endpoint = `/organizations/${organizationId}/members${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
419
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Add an organization member
|
|
423
|
+
*
|
|
424
|
+
* @param organizationId Organization ID
|
|
425
|
+
* @param data Member data
|
|
426
|
+
* @param options Request options
|
|
427
|
+
* @returns Added member
|
|
428
|
+
*/
|
|
429
|
+
async addOrganizationMember(organizationId, data, options) {
|
|
430
|
+
return this.request(`/organizations/${organizationId}/members`, 'POST', data, options);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Update an organization member role
|
|
434
|
+
*
|
|
435
|
+
* @param organizationId Organization ID
|
|
436
|
+
* @param memberId Member ID
|
|
437
|
+
* @param data Update data
|
|
438
|
+
* @param options Request options
|
|
439
|
+
* @returns Updated member
|
|
440
|
+
*/
|
|
441
|
+
async updateOrganizationMemberRole(organizationId, memberId, data, options) {
|
|
442
|
+
return this.request(`/organizations/${organizationId}/members/${memberId}`, 'PUT', data, options);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Remove an organization member
|
|
446
|
+
*
|
|
447
|
+
* @param organizationId Organization ID
|
|
448
|
+
* @param memberId Member ID
|
|
449
|
+
* @param options Request options
|
|
450
|
+
*/
|
|
451
|
+
async removeOrganizationMember(organizationId, memberId, options) {
|
|
452
|
+
await this.request(`/organizations/${organizationId}/members/${memberId}`, 'DELETE', undefined, options);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Leave an organization
|
|
456
|
+
*
|
|
457
|
+
* @param organizationId Organization ID
|
|
458
|
+
* @param options Request options
|
|
459
|
+
*/
|
|
460
|
+
async leaveOrganization(organizationId, options) {
|
|
461
|
+
await this.request(`/organizations/${organizationId}/leave`, 'POST', undefined, options);
|
|
462
|
+
}
|
|
463
|
+
// ============================================================================
|
|
464
|
+
// GUEST CONVERSION
|
|
465
|
+
// ============================================================================
|
|
466
|
+
/**
|
|
467
|
+
* Convert guest to user
|
|
468
|
+
*
|
|
469
|
+
* @param data Conversion data
|
|
470
|
+
* @param options Request options
|
|
471
|
+
* @returns Conversion result
|
|
472
|
+
*/
|
|
473
|
+
async convertGuestToUser(data, options) {
|
|
474
|
+
return this.request('/guest/convert', 'POST', data, options);
|
|
475
|
+
}
|
|
476
|
+
// ============================================================================
|
|
477
|
+
// BILLING SCHEDULES
|
|
478
|
+
// ============================================================================
|
|
479
|
+
/**
|
|
480
|
+
* List my billing schedules
|
|
481
|
+
*
|
|
482
|
+
* @param params Pagination parameters
|
|
483
|
+
* @param options Request options
|
|
484
|
+
* @returns List of billing schedules
|
|
485
|
+
*/
|
|
486
|
+
async listMySchedules(params, options) {
|
|
487
|
+
const queryParams = new URLSearchParams();
|
|
488
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
489
|
+
queryParams.set('page', params.page.toString());
|
|
490
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
491
|
+
queryParams.set('limit', params.limit.toString());
|
|
492
|
+
const endpoint = `/billing-schedules/me${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
493
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Get a billing schedule by ID
|
|
497
|
+
*
|
|
498
|
+
* @param id Schedule ID
|
|
499
|
+
* @param options Request options
|
|
500
|
+
* @returns Billing schedule
|
|
501
|
+
*/
|
|
502
|
+
async getSchedule(id, options) {
|
|
503
|
+
return this.request(`/billing-schedules/${id}`, 'GET', undefined, options);
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Create a billing schedule
|
|
507
|
+
*
|
|
508
|
+
* @param data Schedule data
|
|
509
|
+
* @param options Request options
|
|
510
|
+
* @returns Created billing schedule
|
|
511
|
+
*/
|
|
512
|
+
async createSchedule(data, options) {
|
|
513
|
+
return this.request('/billing-schedules', 'POST', data, options);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Update a billing schedule
|
|
517
|
+
*
|
|
518
|
+
* @param id Schedule ID
|
|
519
|
+
* @param data Update data
|
|
520
|
+
* @param options Request options
|
|
521
|
+
* @returns Updated billing schedule
|
|
522
|
+
*/
|
|
523
|
+
async updateSchedule(id, data, options) {
|
|
524
|
+
return this.request(`/billing-schedules/${id}`, 'PUT', data, options);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Pause a billing schedule
|
|
528
|
+
*
|
|
529
|
+
* @param id Schedule ID
|
|
530
|
+
* @param options Request options
|
|
531
|
+
* @returns Updated billing schedule
|
|
532
|
+
*/
|
|
533
|
+
async pauseSchedule(id, options) {
|
|
534
|
+
return this.request(`/billing-schedules/${id}/pause`, 'POST', undefined, options);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Resume a billing schedule
|
|
538
|
+
*
|
|
539
|
+
* @param id Schedule ID
|
|
540
|
+
* @param options Request options
|
|
541
|
+
* @returns Updated billing schedule
|
|
542
|
+
*/
|
|
543
|
+
async resumeSchedule(id, options) {
|
|
544
|
+
return this.request(`/billing-schedules/${id}/resume`, 'POST', undefined, options);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Delete a billing schedule
|
|
548
|
+
*
|
|
549
|
+
* @param id Schedule ID
|
|
550
|
+
* @param options Request options
|
|
551
|
+
*/
|
|
552
|
+
async deleteSchedule(id, options) {
|
|
553
|
+
await this.request(`/billing-schedules/${id}`, 'DELETE', undefined, options);
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Get execution history for a billing schedule
|
|
557
|
+
*
|
|
558
|
+
* @param id Schedule ID
|
|
559
|
+
* @param params Pagination parameters
|
|
560
|
+
* @param options Request options
|
|
561
|
+
* @returns List of billing executions
|
|
562
|
+
*/
|
|
563
|
+
async getScheduleExecutions(id, params, options) {
|
|
564
|
+
const queryParams = new URLSearchParams();
|
|
565
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
566
|
+
queryParams.set('page', params.page.toString());
|
|
567
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
568
|
+
queryParams.set('limit', params.limit.toString());
|
|
569
|
+
const endpoint = `/billing-schedules/${id}/executions${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
570
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
571
|
+
}
|
|
572
|
+
// ============================================================================
|
|
573
|
+
// ACCOUNT BALANCE
|
|
574
|
+
// ============================================================================
|
|
575
|
+
/**
|
|
576
|
+
* List my account balances
|
|
577
|
+
*
|
|
578
|
+
* @param params Pagination parameters
|
|
579
|
+
* @param options Request options
|
|
580
|
+
* @returns List of account balances
|
|
581
|
+
*/
|
|
582
|
+
async listMyBalances(params, options) {
|
|
583
|
+
const queryParams = new URLSearchParams();
|
|
584
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
585
|
+
queryParams.set('page', params.page.toString());
|
|
586
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
587
|
+
queryParams.set('limit', params.limit.toString());
|
|
588
|
+
const endpoint = `/account-balance/me/balances${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
589
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Get an account balance by ID
|
|
593
|
+
*
|
|
594
|
+
* @param id Balance ID
|
|
595
|
+
* @param options Request options
|
|
596
|
+
* @returns Account balance
|
|
597
|
+
*/
|
|
598
|
+
async getBalance(id, options) {
|
|
599
|
+
return this.request(`/account-balance/${id}`, 'GET', undefined, options);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Create an account balance
|
|
603
|
+
*
|
|
604
|
+
* @param data Balance data
|
|
605
|
+
* @param options Request options
|
|
606
|
+
* @returns Created account balance
|
|
607
|
+
*/
|
|
608
|
+
async createBalance(data, options) {
|
|
609
|
+
return this.request('/account-balance', 'POST', data, options);
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Credit an account balance
|
|
613
|
+
*
|
|
614
|
+
* @param id Balance ID
|
|
615
|
+
* @param data Credit data
|
|
616
|
+
* @param options Request options
|
|
617
|
+
* @returns Updated balance and transaction
|
|
618
|
+
*/
|
|
619
|
+
async creditBalance(id, data, options) {
|
|
620
|
+
return this.request(`/account-balance/${id}/credit`, 'POST', data, options);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Debit an account balance
|
|
624
|
+
*
|
|
625
|
+
* @param id Balance ID
|
|
626
|
+
* @param data Debit data
|
|
627
|
+
* @param options Request options
|
|
628
|
+
* @returns Updated balance and transaction
|
|
629
|
+
*/
|
|
630
|
+
async debitBalance(id, data, options) {
|
|
631
|
+
return this.request(`/account-balance/${id}/debit`, 'POST', data, options);
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Update an account balance
|
|
635
|
+
*
|
|
636
|
+
* @param id Balance ID
|
|
637
|
+
* @param data Update data
|
|
638
|
+
* @param options Request options
|
|
639
|
+
* @returns Updated account balance
|
|
640
|
+
*/
|
|
641
|
+
async updateBalance(id, data, options) {
|
|
642
|
+
return this.request(`/account-balance/${id}`, 'PUT', data, options);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Delete an account balance
|
|
646
|
+
*
|
|
647
|
+
* @param id Balance ID
|
|
648
|
+
* @param options Request options
|
|
649
|
+
*/
|
|
650
|
+
async deleteBalance(id, options) {
|
|
651
|
+
await this.request(`/account-balance/${id}`, 'DELETE', undefined, options);
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* List my account transactions
|
|
655
|
+
*
|
|
656
|
+
* @param params Pagination parameters
|
|
657
|
+
* @param options Request options
|
|
658
|
+
* @returns List of account transactions
|
|
659
|
+
*/
|
|
660
|
+
async listMyTransactions(params, options) {
|
|
661
|
+
const queryParams = new URLSearchParams();
|
|
662
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
663
|
+
queryParams.set('page', params.page.toString());
|
|
664
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
665
|
+
queryParams.set('limit', params.limit.toString());
|
|
666
|
+
const endpoint = `/account-balance/me/transactions${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
667
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Get transactions for a specific balance
|
|
671
|
+
*
|
|
672
|
+
* @param id Balance ID
|
|
673
|
+
* @param params Pagination parameters
|
|
674
|
+
* @param options Request options
|
|
675
|
+
* @returns List of account transactions
|
|
676
|
+
*/
|
|
677
|
+
async getBalanceTransactions(id, params, options) {
|
|
678
|
+
const queryParams = new URLSearchParams();
|
|
679
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
680
|
+
queryParams.set('page', params.page.toString());
|
|
681
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
682
|
+
queryParams.set('limit', params.limit.toString());
|
|
683
|
+
const endpoint = `/account-balance/${id}/transactions${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
684
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
685
|
+
}
|
|
686
|
+
// ============================================================================
|
|
687
|
+
// COST TRACKING
|
|
688
|
+
// ============================================================================
|
|
689
|
+
/**
|
|
690
|
+
* Get all costs for a product
|
|
691
|
+
*
|
|
692
|
+
* @param productId Product ID
|
|
693
|
+
* @param params Pagination parameters
|
|
694
|
+
* @param options Request options
|
|
695
|
+
* @returns List of product costs
|
|
696
|
+
*/
|
|
697
|
+
async getProductCosts(productId, params, options) {
|
|
698
|
+
const queryParams = new URLSearchParams();
|
|
699
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
700
|
+
queryParams.set('page', params.page.toString());
|
|
701
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
702
|
+
queryParams.set('limit', params.limit.toString());
|
|
703
|
+
const endpoint = `/cost-tracking/products/${productId}/costs${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
704
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Get active cost for a product
|
|
708
|
+
*
|
|
709
|
+
* @param productId Product ID
|
|
710
|
+
* @param date Date to check (ISO 8601)
|
|
711
|
+
* @param options Request options
|
|
712
|
+
* @returns Active product cost
|
|
713
|
+
*/
|
|
714
|
+
async getActiveProductCost(productId, date, options) {
|
|
715
|
+
const queryParams = new URLSearchParams();
|
|
716
|
+
if (date)
|
|
717
|
+
queryParams.set('date', date);
|
|
718
|
+
const endpoint = `/cost-tracking/products/${productId}/costs/active${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
719
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Get total cost for a product
|
|
723
|
+
*
|
|
724
|
+
* @param productId Product ID
|
|
725
|
+
* @param date Date to check (ISO 8601)
|
|
726
|
+
* @param options Request options
|
|
727
|
+
* @returns Total cost response
|
|
728
|
+
*/
|
|
729
|
+
async getTotalProductCost(productId, date, options) {
|
|
730
|
+
const queryParams = new URLSearchParams();
|
|
731
|
+
if (date)
|
|
732
|
+
queryParams.set('date', date);
|
|
733
|
+
const endpoint = `/cost-tracking/products/${productId}/costs/total${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
734
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Create a product cost
|
|
738
|
+
*
|
|
739
|
+
* @param data Product cost data
|
|
740
|
+
* @param options Request options
|
|
741
|
+
* @returns Created product cost
|
|
742
|
+
*/
|
|
743
|
+
async createProductCost(data, options) {
|
|
744
|
+
return this.request('/cost-tracking/products/costs', 'POST', data, options);
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Update a product cost
|
|
748
|
+
*
|
|
749
|
+
* @param id Cost ID
|
|
750
|
+
* @param data Update data
|
|
751
|
+
* @param options Request options
|
|
752
|
+
* @returns Updated product cost
|
|
753
|
+
*/
|
|
754
|
+
async updateProductCost(id, data, options) {
|
|
755
|
+
return this.request(`/cost-tracking/products/costs/${id}`, 'PUT', data, options);
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Delete a product cost
|
|
759
|
+
*
|
|
760
|
+
* @param id Cost ID
|
|
761
|
+
* @param options Request options
|
|
762
|
+
*/
|
|
763
|
+
async deleteProductCost(id, options) {
|
|
764
|
+
await this.request(`/cost-tracking/products/costs/${id}`, 'DELETE', undefined, options);
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Get all costs for an order
|
|
768
|
+
*
|
|
769
|
+
* @param orderId Order ID
|
|
770
|
+
* @param params Pagination parameters
|
|
771
|
+
* @param options Request options
|
|
772
|
+
* @returns List of order costs
|
|
773
|
+
*/
|
|
774
|
+
async getOrderCosts(orderId, params, options) {
|
|
775
|
+
const queryParams = new URLSearchParams();
|
|
776
|
+
if (params === null || params === void 0 ? void 0 : params.page)
|
|
777
|
+
queryParams.set('page', params.page.toString());
|
|
778
|
+
if (params === null || params === void 0 ? void 0 : params.limit)
|
|
779
|
+
queryParams.set('limit', params.limit.toString());
|
|
780
|
+
const endpoint = `/cost-tracking/orders/${orderId}/costs${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
781
|
+
return this.request(endpoint, 'GET', undefined, options);
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Get total cost for an order
|
|
785
|
+
*
|
|
786
|
+
* @param orderId Order ID
|
|
787
|
+
* @param options Request options
|
|
788
|
+
* @returns Total cost response
|
|
789
|
+
*/
|
|
790
|
+
async getTotalOrderCost(orderId, options) {
|
|
791
|
+
return this.request(`/cost-tracking/orders/${orderId}/costs/total`, 'GET', undefined, options);
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Create an order cost
|
|
795
|
+
*
|
|
796
|
+
* @param data Order cost data
|
|
797
|
+
* @param options Request options
|
|
798
|
+
* @returns Created order cost
|
|
799
|
+
*/
|
|
800
|
+
async createOrderCost(data, options) {
|
|
801
|
+
return this.request('/cost-tracking/orders/costs', 'POST', data, options);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
exports.BridgePaymentClient = BridgePaymentClient;
|