@23blocks/block-sales 1.0.4 → 2.1.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/index.esm.js +1375 -81
- package/dist/src/lib/mappers/customer.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/customer.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/entity.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/entity.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/flexible-order.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/flexible-order.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/index.d.ts +5 -0
- package/dist/src/lib/mappers/index.d.ts.map +1 -1
- package/dist/src/lib/mappers/subscription-model.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/subscription-model.mapper.d.ts.map +1 -0
- package/dist/src/lib/mappers/user.mapper.d.ts +4 -0
- package/dist/src/lib/mappers/user.mapper.d.ts.map +1 -0
- package/dist/src/lib/sales.block.d.ts +9 -1
- package/dist/src/lib/sales.block.d.ts.map +1 -1
- package/dist/src/lib/services/customers.service.d.ts +13 -0
- package/dist/src/lib/services/customers.service.d.ts.map +1 -0
- package/dist/src/lib/services/entities.service.d.ts +14 -0
- package/dist/src/lib/services/entities.service.d.ts.map +1 -0
- package/dist/src/lib/services/flexible-orders.service.d.ts +24 -0
- package/dist/src/lib/services/flexible-orders.service.d.ts.map +1 -0
- package/dist/src/lib/services/index.d.ts +8 -0
- package/dist/src/lib/services/index.d.ts.map +1 -1
- package/dist/src/lib/services/mercadopago.service.d.ts +11 -0
- package/dist/src/lib/services/mercadopago.service.d.ts.map +1 -0
- package/dist/src/lib/services/order-details.service.d.ts.map +1 -1
- package/dist/src/lib/services/orders.service.d.ts.map +1 -1
- package/dist/src/lib/services/payments.service.d.ts.map +1 -1
- package/dist/src/lib/services/stripe.service.d.ts +18 -0
- package/dist/src/lib/services/stripe.service.d.ts.map +1 -0
- package/dist/src/lib/services/subscription-models.service.d.ts +12 -0
- package/dist/src/lib/services/subscription-models.service.d.ts.map +1 -0
- package/dist/src/lib/services/subscriptions.service.d.ts.map +1 -1
- package/dist/src/lib/services/users.service.d.ts +25 -0
- package/dist/src/lib/services/users.service.d.ts.map +1 -0
- package/dist/src/lib/services/vendor-payments.service.d.ts +21 -0
- package/dist/src/lib/services/vendor-payments.service.d.ts.map +1 -0
- package/dist/src/lib/types/customer.d.ts +47 -0
- package/dist/src/lib/types/customer.d.ts.map +1 -0
- package/dist/src/lib/types/entity.d.ts +60 -0
- package/dist/src/lib/types/entity.d.ts.map +1 -0
- package/dist/src/lib/types/flexible-order.d.ts +119 -0
- package/dist/src/lib/types/flexible-order.d.ts.map +1 -0
- package/dist/src/lib/types/index.d.ts +10 -0
- package/dist/src/lib/types/index.d.ts.map +1 -1
- package/dist/src/lib/types/mercadopago.d.ts +86 -0
- package/dist/src/lib/types/mercadopago.d.ts.map +1 -0
- package/dist/src/lib/types/order-tax.d.ts +27 -0
- package/dist/src/lib/types/order-tax.d.ts.map +1 -0
- package/dist/src/lib/types/report.d.ts +159 -0
- package/dist/src/lib/types/report.d.ts.map +1 -0
- package/dist/src/lib/types/stripe.d.ts +119 -0
- package/dist/src/lib/types/stripe.d.ts.map +1 -0
- package/dist/src/lib/types/subscription-model.d.ts +55 -0
- package/dist/src/lib/types/subscription-model.d.ts.map +1 -0
- package/dist/src/lib/types/user.d.ts +75 -0
- package/dist/src/lib/types/user.d.ts.map +1 -0
- package/dist/src/lib/types/vendor-payment.d.ts +65 -0
- package/dist/src/lib/types/vendor-payment.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -126,36 +126,30 @@ function createOrdersService(transport, _config) {
|
|
|
126
126
|
},
|
|
127
127
|
async create (data) {
|
|
128
128
|
const response = await transport.post('/orders', {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
notes: data.notes,
|
|
142
|
-
payload: data.payload
|
|
143
|
-
}
|
|
129
|
+
order: {
|
|
130
|
+
user_unique_id: data.userUniqueId,
|
|
131
|
+
items: data.items.map((item)=>({
|
|
132
|
+
product_unique_id: item.productUniqueId,
|
|
133
|
+
product_variation_unique_id: item.productVariationUniqueId,
|
|
134
|
+
quantity: item.quantity,
|
|
135
|
+
unit_price: item.unitPrice
|
|
136
|
+
})),
|
|
137
|
+
shipping_address_unique_id: data.shippingAddressUniqueId,
|
|
138
|
+
billing_address_unique_id: data.billingAddressUniqueId,
|
|
139
|
+
notes: data.notes,
|
|
140
|
+
payload: data.payload
|
|
144
141
|
}
|
|
145
142
|
});
|
|
146
143
|
return decodeOne(response, orderMapper);
|
|
147
144
|
},
|
|
148
145
|
async update (uniqueId, data) {
|
|
149
146
|
const response = await transport.put(`/orders/${uniqueId}`, {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
notes: data.notes,
|
|
157
|
-
payload: data.payload
|
|
158
|
-
}
|
|
147
|
+
order: {
|
|
148
|
+
status: data.status,
|
|
149
|
+
shipping_address_unique_id: data.shippingAddressUniqueId,
|
|
150
|
+
billing_address_unique_id: data.billingAddressUniqueId,
|
|
151
|
+
notes: data.notes,
|
|
152
|
+
payload: data.payload
|
|
159
153
|
}
|
|
160
154
|
});
|
|
161
155
|
return decodeOne(response, orderMapper);
|
|
@@ -170,11 +164,8 @@ function createOrdersService(transport, _config) {
|
|
|
170
164
|
},
|
|
171
165
|
async ship (uniqueId, trackingNumber) {
|
|
172
166
|
const response = await transport.put(`/orders/${uniqueId}/ship`, {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
attributes: {
|
|
176
|
-
tracking_number: trackingNumber
|
|
177
|
-
}
|
|
167
|
+
order: {
|
|
168
|
+
tracking_number: trackingNumber
|
|
178
169
|
}
|
|
179
170
|
});
|
|
180
171
|
return decodeOne(response, orderMapper);
|
|
@@ -234,16 +225,13 @@ function createOrderDetailsService(transport, _config) {
|
|
|
234
225
|
},
|
|
235
226
|
async update (uniqueId, data) {
|
|
236
227
|
const response = await transport.put(`/order_details/${uniqueId}`, {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
status: data.status,
|
|
245
|
-
payload: data.payload
|
|
246
|
-
}
|
|
228
|
+
details: {
|
|
229
|
+
quantity: data.quantity,
|
|
230
|
+
unit_price: data.unitPrice,
|
|
231
|
+
discount: data.discount,
|
|
232
|
+
tax: data.tax,
|
|
233
|
+
status: data.status,
|
|
234
|
+
payload: data.payload
|
|
247
235
|
}
|
|
248
236
|
});
|
|
249
237
|
return decodeOne(response, orderDetailMapper);
|
|
@@ -297,28 +285,22 @@ function createPaymentsService(transport, _config) {
|
|
|
297
285
|
},
|
|
298
286
|
async create (data) {
|
|
299
287
|
const response = await transport.post('/payments', {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
transaction_id: data.transactionId,
|
|
309
|
-
payload: data.payload
|
|
310
|
-
}
|
|
288
|
+
payment: {
|
|
289
|
+
order_unique_id: data.orderUniqueId,
|
|
290
|
+
payment_method: data.paymentMethod,
|
|
291
|
+
payment_provider: data.paymentProvider,
|
|
292
|
+
amount: data.amount,
|
|
293
|
+
currency: data.currency,
|
|
294
|
+
transaction_id: data.transactionId,
|
|
295
|
+
payload: data.payload
|
|
311
296
|
}
|
|
312
297
|
});
|
|
313
298
|
return decodeOne(response, paymentMapper);
|
|
314
299
|
},
|
|
315
300
|
async refund (uniqueId, amount) {
|
|
316
301
|
const response = await transport.put(`/payments/${uniqueId}/refund`, {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
attributes: {
|
|
320
|
-
amount
|
|
321
|
-
}
|
|
302
|
+
payment: {
|
|
303
|
+
amount
|
|
322
304
|
}
|
|
323
305
|
});
|
|
324
306
|
return decodeOne(response, paymentMapper);
|
|
@@ -375,18 +357,15 @@ function createSubscriptionsService(transport, _config) {
|
|
|
375
357
|
async create (data) {
|
|
376
358
|
var _data_startDate;
|
|
377
359
|
const response = await transport.post('/subscriptions', {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
start_date: (_data_startDate = data.startDate) == null ? void 0 : _data_startDate.toISOString(),
|
|
388
|
-
payload: data.payload
|
|
389
|
-
}
|
|
360
|
+
subscription: {
|
|
361
|
+
user_unique_id: data.userUniqueId,
|
|
362
|
+
plan_unique_id: data.planUniqueId,
|
|
363
|
+
plan_name: data.planName,
|
|
364
|
+
price: data.price,
|
|
365
|
+
currency: data.currency,
|
|
366
|
+
interval: data.interval,
|
|
367
|
+
start_date: (_data_startDate = data.startDate) == null ? void 0 : _data_startDate.toISOString(),
|
|
368
|
+
payload: data.payload
|
|
390
369
|
}
|
|
391
370
|
});
|
|
392
371
|
return decodeOne(response, subscriptionMapper);
|
|
@@ -394,19 +373,16 @@ function createSubscriptionsService(transport, _config) {
|
|
|
394
373
|
async update (uniqueId, data) {
|
|
395
374
|
var _data_endDate, _data_nextBillingDate;
|
|
396
375
|
const response = await transport.put(`/subscriptions/${uniqueId}`, {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
next_billing_date: (_data_nextBillingDate = data.nextBillingDate) == null ? void 0 : _data_nextBillingDate.toISOString(),
|
|
408
|
-
payload: data.payload
|
|
409
|
-
}
|
|
376
|
+
subscription: {
|
|
377
|
+
plan_unique_id: data.planUniqueId,
|
|
378
|
+
plan_name: data.planName,
|
|
379
|
+
price: data.price,
|
|
380
|
+
currency: data.currency,
|
|
381
|
+
interval: data.interval,
|
|
382
|
+
status: data.status,
|
|
383
|
+
end_date: (_data_endDate = data.endDate) == null ? void 0 : _data_endDate.toISOString(),
|
|
384
|
+
next_billing_date: (_data_nextBillingDate = data.nextBillingDate) == null ? void 0 : _data_nextBillingDate.toISOString(),
|
|
385
|
+
payload: data.payload
|
|
410
386
|
}
|
|
411
387
|
});
|
|
412
388
|
return decodeOne(response, subscriptionMapper);
|
|
@@ -439,12 +415,1330 @@ function createSubscriptionsService(transport, _config) {
|
|
|
439
415
|
};
|
|
440
416
|
}
|
|
441
417
|
|
|
418
|
+
const subscriptionModelMapper = {
|
|
419
|
+
type: 'subscription_model',
|
|
420
|
+
map: (resource)=>{
|
|
421
|
+
var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10, _resource_attributes11, _resource_attributes12, _resource_attributes13, _resource_attributes14, _resource_attributes15;
|
|
422
|
+
return {
|
|
423
|
+
id: resource.id,
|
|
424
|
+
uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
|
|
425
|
+
code: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['code'],
|
|
426
|
+
name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
|
|
427
|
+
description: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['description'],
|
|
428
|
+
price: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['price'],
|
|
429
|
+
currency: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['currency'],
|
|
430
|
+
interval: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['interval'],
|
|
431
|
+
intervalCount: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['interval_count'],
|
|
432
|
+
trialDays: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['trial_days'],
|
|
433
|
+
features: (_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['features'],
|
|
434
|
+
limits: (_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['limits'],
|
|
435
|
+
enabled: (_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['enabled'],
|
|
436
|
+
status: (_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['status'],
|
|
437
|
+
payload: (_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['payload'],
|
|
438
|
+
createdAt: parseDate((_resource_attributes14 = resource.attributes) == null ? void 0 : _resource_attributes14['created_at']),
|
|
439
|
+
updatedAt: parseDate((_resource_attributes15 = resource.attributes) == null ? void 0 : _resource_attributes15['updated_at'])
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
function createSubscriptionModelsService(transport, _config) {
|
|
445
|
+
return {
|
|
446
|
+
async list (params) {
|
|
447
|
+
const queryParams = {};
|
|
448
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
449
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
450
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
451
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
452
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
453
|
+
const response = await transport.get('/subscription_models', {
|
|
454
|
+
params: queryParams
|
|
455
|
+
});
|
|
456
|
+
return decodePageResult(response, subscriptionModelMapper);
|
|
457
|
+
},
|
|
458
|
+
async get (uniqueId) {
|
|
459
|
+
const response = await transport.get(`/subscription_models/${uniqueId}`);
|
|
460
|
+
return decodeOne(response, subscriptionModelMapper);
|
|
461
|
+
},
|
|
462
|
+
async create (data) {
|
|
463
|
+
const response = await transport.post('/subscription_models', {
|
|
464
|
+
subscription_model: {
|
|
465
|
+
code: data.code,
|
|
466
|
+
name: data.name,
|
|
467
|
+
description: data.description,
|
|
468
|
+
price: data.price,
|
|
469
|
+
currency: data.currency,
|
|
470
|
+
interval: data.interval,
|
|
471
|
+
interval_count: data.intervalCount,
|
|
472
|
+
trial_days: data.trialDays,
|
|
473
|
+
features: data.features,
|
|
474
|
+
limits: data.limits,
|
|
475
|
+
payload: data.payload
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
return decodeOne(response, subscriptionModelMapper);
|
|
479
|
+
},
|
|
480
|
+
async update (uniqueId, data) {
|
|
481
|
+
const response = await transport.put(`/subscription_models/${uniqueId}`, {
|
|
482
|
+
subscription_model: {
|
|
483
|
+
name: data.name,
|
|
484
|
+
description: data.description,
|
|
485
|
+
price: data.price,
|
|
486
|
+
currency: data.currency,
|
|
487
|
+
interval: data.interval,
|
|
488
|
+
interval_count: data.intervalCount,
|
|
489
|
+
trial_days: data.trialDays,
|
|
490
|
+
features: data.features,
|
|
491
|
+
limits: data.limits,
|
|
492
|
+
enabled: data.enabled,
|
|
493
|
+
status: data.status,
|
|
494
|
+
payload: data.payload
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
return decodeOne(response, subscriptionModelMapper);
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const salesEntityMapper = {
|
|
503
|
+
type: 'entity',
|
|
504
|
+
map: (resource)=>{
|
|
505
|
+
var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8;
|
|
506
|
+
return {
|
|
507
|
+
id: resource.id,
|
|
508
|
+
uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
|
|
509
|
+
code: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['code'],
|
|
510
|
+
name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
|
|
511
|
+
email: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['email'],
|
|
512
|
+
phone: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['phone'],
|
|
513
|
+
status: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['status'],
|
|
514
|
+
payload: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['payload'],
|
|
515
|
+
createdAt: parseDate((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['created_at']),
|
|
516
|
+
updatedAt: parseDate((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['updated_at'])
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
function createSalesEntitiesService(transport, _config) {
|
|
522
|
+
return {
|
|
523
|
+
async list (params) {
|
|
524
|
+
const queryParams = {};
|
|
525
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
526
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
527
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
528
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
529
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
530
|
+
const response = await transport.get('/entities', {
|
|
531
|
+
params: queryParams
|
|
532
|
+
});
|
|
533
|
+
return decodePageResult(response, salesEntityMapper);
|
|
534
|
+
},
|
|
535
|
+
async get (uniqueId) {
|
|
536
|
+
const response = await transport.get(`/entities/${uniqueId}`);
|
|
537
|
+
return decodeOne(response, salesEntityMapper);
|
|
538
|
+
},
|
|
539
|
+
async register (uniqueId, data) {
|
|
540
|
+
const response = await transport.post(`/entities/${uniqueId}/register`, {
|
|
541
|
+
entity: {
|
|
542
|
+
code: data == null ? void 0 : data.code,
|
|
543
|
+
name: data == null ? void 0 : data.name,
|
|
544
|
+
email: data == null ? void 0 : data.email,
|
|
545
|
+
phone: data == null ? void 0 : data.phone,
|
|
546
|
+
payload: data == null ? void 0 : data.payload
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
return decodeOne(response, salesEntityMapper);
|
|
550
|
+
},
|
|
551
|
+
async update (uniqueId, data) {
|
|
552
|
+
const response = await transport.put(`/entities/${uniqueId}`, {
|
|
553
|
+
entity: {
|
|
554
|
+
name: data.name,
|
|
555
|
+
email: data.email,
|
|
556
|
+
phone: data.phone,
|
|
557
|
+
status: data.status,
|
|
558
|
+
payload: data.payload
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
return decodeOne(response, salesEntityMapper);
|
|
562
|
+
},
|
|
563
|
+
async createSubscription (uniqueId, data) {
|
|
564
|
+
const response = await transport.post(`/entities/${uniqueId}/subscriptions`, {
|
|
565
|
+
subscription: {
|
|
566
|
+
subscription_model_unique_id: data.subscriptionModelUniqueId,
|
|
567
|
+
start_date: data.startDate,
|
|
568
|
+
trial_end_date: data.trialEndDate,
|
|
569
|
+
payload: data.payload
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
return {
|
|
573
|
+
id: response.id,
|
|
574
|
+
uniqueId: response.unique_id,
|
|
575
|
+
entityUniqueId: response.entity_unique_id,
|
|
576
|
+
subscriptionModelUniqueId: response.subscription_model_unique_id,
|
|
577
|
+
status: response.status,
|
|
578
|
+
startDate: response.start_date ? new Date(response.start_date) : undefined,
|
|
579
|
+
endDate: response.end_date ? new Date(response.end_date) : undefined,
|
|
580
|
+
trialEndDate: response.trial_end_date ? new Date(response.trial_end_date) : undefined,
|
|
581
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
582
|
+
payload: response.payload,
|
|
583
|
+
createdAt: new Date(response.created_at),
|
|
584
|
+
updatedAt: new Date(response.updated_at)
|
|
585
|
+
};
|
|
586
|
+
},
|
|
587
|
+
async updateSubscription (uniqueId, subscriptionUniqueId, data) {
|
|
588
|
+
const response = await transport.put(`/entities/${uniqueId}/subscriptions/${subscriptionUniqueId}`, {
|
|
589
|
+
subscription: {
|
|
590
|
+
status: data.status,
|
|
591
|
+
end_date: data.endDate,
|
|
592
|
+
payload: data.payload
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
return {
|
|
596
|
+
id: response.id,
|
|
597
|
+
uniqueId: response.unique_id,
|
|
598
|
+
entityUniqueId: response.entity_unique_id,
|
|
599
|
+
subscriptionModelUniqueId: response.subscription_model_unique_id,
|
|
600
|
+
status: response.status,
|
|
601
|
+
startDate: response.start_date ? new Date(response.start_date) : undefined,
|
|
602
|
+
endDate: response.end_date ? new Date(response.end_date) : undefined,
|
|
603
|
+
trialEndDate: response.trial_end_date ? new Date(response.trial_end_date) : undefined,
|
|
604
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
605
|
+
payload: response.payload,
|
|
606
|
+
createdAt: new Date(response.created_at),
|
|
607
|
+
updatedAt: new Date(response.updated_at)
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const salesUserMapper = {
|
|
614
|
+
type: 'user',
|
|
615
|
+
map: (resource)=>{
|
|
616
|
+
var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7;
|
|
617
|
+
return {
|
|
618
|
+
id: resource.id,
|
|
619
|
+
uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
|
|
620
|
+
email: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['email'],
|
|
621
|
+
name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
|
|
622
|
+
phone: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['phone'],
|
|
623
|
+
status: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['status'],
|
|
624
|
+
payload: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['payload'],
|
|
625
|
+
createdAt: parseDate((_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['created_at']),
|
|
626
|
+
updatedAt: parseDate((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['updated_at'])
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
function createSalesUsersService(transport, _config) {
|
|
632
|
+
return {
|
|
633
|
+
async list (params) {
|
|
634
|
+
const queryParams = {};
|
|
635
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
636
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
637
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
638
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
639
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
640
|
+
const response = await transport.get('/users', {
|
|
641
|
+
params: queryParams
|
|
642
|
+
});
|
|
643
|
+
return decodePageResult(response, salesUserMapper);
|
|
644
|
+
},
|
|
645
|
+
async get (uniqueId) {
|
|
646
|
+
const response = await transport.get(`/users/${uniqueId}`);
|
|
647
|
+
return decodeOne(response, salesUserMapper);
|
|
648
|
+
},
|
|
649
|
+
async register (uniqueId, data) {
|
|
650
|
+
const response = await transport.post(`/users/${uniqueId}/register`, {
|
|
651
|
+
user: {
|
|
652
|
+
email: data == null ? void 0 : data.email,
|
|
653
|
+
name: data == null ? void 0 : data.name,
|
|
654
|
+
phone: data == null ? void 0 : data.phone,
|
|
655
|
+
payload: data == null ? void 0 : data.payload
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
return decodeOne(response, salesUserMapper);
|
|
659
|
+
},
|
|
660
|
+
async update (uniqueId, data) {
|
|
661
|
+
const response = await transport.put(`/users/${uniqueId}`, {
|
|
662
|
+
user: {
|
|
663
|
+
name: data.name,
|
|
664
|
+
phone: data.phone,
|
|
665
|
+
status: data.status,
|
|
666
|
+
payload: data.payload
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
return decodeOne(response, salesUserMapper);
|
|
670
|
+
},
|
|
671
|
+
async listOrders (uniqueId, params) {
|
|
672
|
+
const queryParams = {};
|
|
673
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
674
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
675
|
+
const response = await transport.get(`/users/${uniqueId}/orders`, {
|
|
676
|
+
params: queryParams
|
|
677
|
+
});
|
|
678
|
+
return decodePageResult(response, orderMapper);
|
|
679
|
+
},
|
|
680
|
+
async getOrder (uniqueId, orderUniqueId) {
|
|
681
|
+
const response = await transport.get(`/users/${uniqueId}/orders/${orderUniqueId}`);
|
|
682
|
+
return decodeOne(response, orderMapper);
|
|
683
|
+
},
|
|
684
|
+
async listSubscriptions (uniqueId, params) {
|
|
685
|
+
var _response_meta, _response_meta1, _response_meta2, _response_meta3;
|
|
686
|
+
const queryParams = {};
|
|
687
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
688
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
689
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
690
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
691
|
+
const response = await transport.get(`/users/${uniqueId}/subscriptions`, {
|
|
692
|
+
params: queryParams
|
|
693
|
+
});
|
|
694
|
+
const data = response.data || [];
|
|
695
|
+
return {
|
|
696
|
+
data: data.map((s)=>({
|
|
697
|
+
id: s.id,
|
|
698
|
+
uniqueId: s.unique_id,
|
|
699
|
+
userUniqueId: s.user_unique_id,
|
|
700
|
+
subscriptionModelUniqueId: s.subscription_model_unique_id,
|
|
701
|
+
status: s.status,
|
|
702
|
+
startDate: s.start_date ? new Date(s.start_date) : undefined,
|
|
703
|
+
endDate: s.end_date ? new Date(s.end_date) : undefined,
|
|
704
|
+
trialEndDate: s.trial_end_date ? new Date(s.trial_end_date) : undefined,
|
|
705
|
+
cancelledAt: s.cancelled_at ? new Date(s.cancelled_at) : undefined,
|
|
706
|
+
consumptions: (s.consumptions || []).map((c)=>({
|
|
707
|
+
id: c.id,
|
|
708
|
+
quantity: c.quantity,
|
|
709
|
+
description: c.description,
|
|
710
|
+
consumedAt: new Date(c.consumed_at)
|
|
711
|
+
})),
|
|
712
|
+
payload: s.payload,
|
|
713
|
+
createdAt: new Date(s.created_at),
|
|
714
|
+
updatedAt: new Date(s.updated_at)
|
|
715
|
+
})),
|
|
716
|
+
meta: {
|
|
717
|
+
totalCount: ((_response_meta = response.meta) == null ? void 0 : _response_meta.total_count) || data.length,
|
|
718
|
+
page: ((_response_meta1 = response.meta) == null ? void 0 : _response_meta1.page) || 1,
|
|
719
|
+
perPage: ((_response_meta2 = response.meta) == null ? void 0 : _response_meta2.per_page) || data.length,
|
|
720
|
+
totalPages: ((_response_meta3 = response.meta) == null ? void 0 : _response_meta3.total_pages) || 1
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
},
|
|
724
|
+
async getSubscription (uniqueId, subscriptionUniqueId) {
|
|
725
|
+
const response = await transport.get(`/users/${uniqueId}/subscriptions/${subscriptionUniqueId}`);
|
|
726
|
+
return {
|
|
727
|
+
id: response.id,
|
|
728
|
+
uniqueId: response.unique_id,
|
|
729
|
+
userUniqueId: response.user_unique_id,
|
|
730
|
+
subscriptionModelUniqueId: response.subscription_model_unique_id,
|
|
731
|
+
status: response.status,
|
|
732
|
+
startDate: response.start_date ? new Date(response.start_date) : undefined,
|
|
733
|
+
endDate: response.end_date ? new Date(response.end_date) : undefined,
|
|
734
|
+
trialEndDate: response.trial_end_date ? new Date(response.trial_end_date) : undefined,
|
|
735
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
736
|
+
consumptions: (response.consumptions || []).map((c)=>({
|
|
737
|
+
id: c.id,
|
|
738
|
+
quantity: c.quantity,
|
|
739
|
+
description: c.description,
|
|
740
|
+
consumedAt: new Date(c.consumed_at)
|
|
741
|
+
})),
|
|
742
|
+
payload: response.payload,
|
|
743
|
+
createdAt: new Date(response.created_at),
|
|
744
|
+
updatedAt: new Date(response.updated_at)
|
|
745
|
+
};
|
|
746
|
+
},
|
|
747
|
+
async createSubscription (uniqueId, subscriptionUniqueId, data) {
|
|
748
|
+
const response = await transport.post(`/users/${uniqueId}/subscriptions/${subscriptionUniqueId}`, {
|
|
749
|
+
subscription: {
|
|
750
|
+
start_date: data == null ? void 0 : data.startDate,
|
|
751
|
+
trial_end_date: data == null ? void 0 : data.trialEndDate,
|
|
752
|
+
payload: data == null ? void 0 : data.payload
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
return {
|
|
756
|
+
id: response.id,
|
|
757
|
+
uniqueId: response.unique_id,
|
|
758
|
+
userUniqueId: response.user_unique_id,
|
|
759
|
+
subscriptionModelUniqueId: response.subscription_model_unique_id,
|
|
760
|
+
status: response.status,
|
|
761
|
+
startDate: response.start_date ? new Date(response.start_date) : undefined,
|
|
762
|
+
endDate: response.end_date ? new Date(response.end_date) : undefined,
|
|
763
|
+
trialEndDate: response.trial_end_date ? new Date(response.trial_end_date) : undefined,
|
|
764
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
765
|
+
payload: response.payload,
|
|
766
|
+
createdAt: new Date(response.created_at),
|
|
767
|
+
updatedAt: new Date(response.updated_at)
|
|
768
|
+
};
|
|
769
|
+
},
|
|
770
|
+
async updateSubscription (uniqueId, subscriptionUniqueId, data) {
|
|
771
|
+
const response = await transport.put(`/users/${uniqueId}/subscriptions/${subscriptionUniqueId}`, {
|
|
772
|
+
subscription: {
|
|
773
|
+
status: data.status,
|
|
774
|
+
end_date: data.endDate,
|
|
775
|
+
payload: data.payload
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
return {
|
|
779
|
+
id: response.id,
|
|
780
|
+
uniqueId: response.unique_id,
|
|
781
|
+
userUniqueId: response.user_unique_id,
|
|
782
|
+
subscriptionModelUniqueId: response.subscription_model_unique_id,
|
|
783
|
+
status: response.status,
|
|
784
|
+
startDate: response.start_date ? new Date(response.start_date) : undefined,
|
|
785
|
+
endDate: response.end_date ? new Date(response.end_date) : undefined,
|
|
786
|
+
trialEndDate: response.trial_end_date ? new Date(response.trial_end_date) : undefined,
|
|
787
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
788
|
+
payload: response.payload,
|
|
789
|
+
createdAt: new Date(response.created_at),
|
|
790
|
+
updatedAt: new Date(response.updated_at)
|
|
791
|
+
};
|
|
792
|
+
},
|
|
793
|
+
async addConsumption (uniqueId, subscriptionUniqueId, data) {
|
|
794
|
+
const response = await transport.post(`/users/${uniqueId}/subscriptions/${subscriptionUniqueId}/consumption`, {
|
|
795
|
+
consumption: {
|
|
796
|
+
quantity: data.quantity,
|
|
797
|
+
description: data.description,
|
|
798
|
+
payload: data.payload
|
|
799
|
+
}
|
|
800
|
+
});
|
|
801
|
+
return {
|
|
802
|
+
id: response.id,
|
|
803
|
+
uniqueId: response.unique_id,
|
|
804
|
+
userUniqueId: response.user_unique_id,
|
|
805
|
+
subscriptionModelUniqueId: response.subscription_model_unique_id,
|
|
806
|
+
status: response.status,
|
|
807
|
+
startDate: response.start_date ? new Date(response.start_date) : undefined,
|
|
808
|
+
endDate: response.end_date ? new Date(response.end_date) : undefined,
|
|
809
|
+
trialEndDate: response.trial_end_date ? new Date(response.trial_end_date) : undefined,
|
|
810
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
811
|
+
consumptions: (response.consumptions || []).map((c)=>({
|
|
812
|
+
id: c.id,
|
|
813
|
+
quantity: c.quantity,
|
|
814
|
+
description: c.description,
|
|
815
|
+
consumedAt: new Date(c.consumed_at)
|
|
816
|
+
})),
|
|
817
|
+
payload: response.payload,
|
|
818
|
+
createdAt: new Date(response.created_at),
|
|
819
|
+
updatedAt: new Date(response.updated_at)
|
|
820
|
+
};
|
|
821
|
+
},
|
|
822
|
+
async cancelSubscription (uniqueId, subscriptionUniqueId) {
|
|
823
|
+
const response = await transport.put(`/users/${uniqueId}/subscriptions/${subscriptionUniqueId}/cancel`, {});
|
|
824
|
+
return {
|
|
825
|
+
id: response.id,
|
|
826
|
+
uniqueId: response.unique_id,
|
|
827
|
+
userUniqueId: response.user_unique_id,
|
|
828
|
+
subscriptionModelUniqueId: response.subscription_model_unique_id,
|
|
829
|
+
status: response.status,
|
|
830
|
+
startDate: response.start_date ? new Date(response.start_date) : undefined,
|
|
831
|
+
endDate: response.end_date ? new Date(response.end_date) : undefined,
|
|
832
|
+
trialEndDate: response.trial_end_date ? new Date(response.trial_end_date) : undefined,
|
|
833
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
834
|
+
payload: response.payload,
|
|
835
|
+
createdAt: new Date(response.created_at),
|
|
836
|
+
updatedAt: new Date(response.updated_at)
|
|
837
|
+
};
|
|
838
|
+
},
|
|
839
|
+
async deleteSubscription (uniqueId, subscriptionUniqueId) {
|
|
840
|
+
await transport.delete(`/users/${uniqueId}/subscriptions/${subscriptionUniqueId}`);
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
const salesCustomerMapper = {
|
|
846
|
+
type: 'customer',
|
|
847
|
+
map: (resource)=>{
|
|
848
|
+
var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9;
|
|
849
|
+
return {
|
|
850
|
+
id: resource.id,
|
|
851
|
+
uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
|
|
852
|
+
email: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['email'],
|
|
853
|
+
name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
|
|
854
|
+
phone: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['phone'],
|
|
855
|
+
stripeCustomerId: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['stripe_customer_id'],
|
|
856
|
+
mercadopagoCustomerId: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['mercadopago_customer_id'],
|
|
857
|
+
status: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['status'],
|
|
858
|
+
payload: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['payload'],
|
|
859
|
+
createdAt: parseDate((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['created_at']),
|
|
860
|
+
updatedAt: parseDate((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['updated_at'])
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
function createSalesCustomersService(transport, _config) {
|
|
866
|
+
return {
|
|
867
|
+
async get (uniqueId) {
|
|
868
|
+
const response = await transport.get(`/customers/${uniqueId}`);
|
|
869
|
+
return decodeOne(response, salesCustomerMapper);
|
|
870
|
+
},
|
|
871
|
+
async register (uniqueId, data) {
|
|
872
|
+
const response = await transport.post(`/customers/${uniqueId}/register`, {
|
|
873
|
+
customer: {
|
|
874
|
+
email: data == null ? void 0 : data.email,
|
|
875
|
+
name: data == null ? void 0 : data.name,
|
|
876
|
+
phone: data == null ? void 0 : data.phone,
|
|
877
|
+
stripe_customer_id: data == null ? void 0 : data.stripeCustomerId,
|
|
878
|
+
mercadopago_customer_id: data == null ? void 0 : data.mercadopagoCustomerId,
|
|
879
|
+
payload: data == null ? void 0 : data.payload
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
return decodeOne(response, salesCustomerMapper);
|
|
883
|
+
},
|
|
884
|
+
async getSubscription (uniqueId, subscriptionUniqueId) {
|
|
885
|
+
const response = await transport.get(`/customers/${uniqueId}/subscriptions/${subscriptionUniqueId}`);
|
|
886
|
+
return {
|
|
887
|
+
id: response.id,
|
|
888
|
+
uniqueId: response.unique_id,
|
|
889
|
+
customerUniqueId: response.customer_unique_id,
|
|
890
|
+
subscriptionModelUniqueId: response.subscription_model_unique_id,
|
|
891
|
+
status: response.status,
|
|
892
|
+
startDate: response.start_date ? new Date(response.start_date) : undefined,
|
|
893
|
+
endDate: response.end_date ? new Date(response.end_date) : undefined,
|
|
894
|
+
trialEndDate: response.trial_end_date ? new Date(response.trial_end_date) : undefined,
|
|
895
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
896
|
+
payload: response.payload,
|
|
897
|
+
createdAt: new Date(response.created_at),
|
|
898
|
+
updatedAt: new Date(response.updated_at)
|
|
899
|
+
};
|
|
900
|
+
},
|
|
901
|
+
async createSubscription (uniqueId, data) {
|
|
902
|
+
const response = await transport.post(`/customers/${uniqueId}/subscriptions`, {
|
|
903
|
+
subscription: {
|
|
904
|
+
subscription_model_unique_id: data.subscriptionModelUniqueId,
|
|
905
|
+
start_date: data.startDate,
|
|
906
|
+
trial_end_date: data.trialEndDate,
|
|
907
|
+
payload: data.payload
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
return {
|
|
911
|
+
id: response.id,
|
|
912
|
+
uniqueId: response.unique_id,
|
|
913
|
+
customerUniqueId: response.customer_unique_id,
|
|
914
|
+
subscriptionModelUniqueId: response.subscription_model_unique_id,
|
|
915
|
+
status: response.status,
|
|
916
|
+
startDate: response.start_date ? new Date(response.start_date) : undefined,
|
|
917
|
+
endDate: response.end_date ? new Date(response.end_date) : undefined,
|
|
918
|
+
trialEndDate: response.trial_end_date ? new Date(response.trial_end_date) : undefined,
|
|
919
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
920
|
+
payload: response.payload,
|
|
921
|
+
createdAt: new Date(response.created_at),
|
|
922
|
+
updatedAt: new Date(response.updated_at)
|
|
923
|
+
};
|
|
924
|
+
},
|
|
925
|
+
async updateSubscription (uniqueId, subscriptionUniqueId, data) {
|
|
926
|
+
const response = await transport.put(`/customers/${uniqueId}/subscriptions/${subscriptionUniqueId}`, {
|
|
927
|
+
subscription: {
|
|
928
|
+
status: data.status,
|
|
929
|
+
end_date: data.endDate,
|
|
930
|
+
payload: data.payload
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
return {
|
|
934
|
+
id: response.id,
|
|
935
|
+
uniqueId: response.unique_id,
|
|
936
|
+
customerUniqueId: response.customer_unique_id,
|
|
937
|
+
subscriptionModelUniqueId: response.subscription_model_unique_id,
|
|
938
|
+
status: response.status,
|
|
939
|
+
startDate: response.start_date ? new Date(response.start_date) : undefined,
|
|
940
|
+
endDate: response.end_date ? new Date(response.end_date) : undefined,
|
|
941
|
+
trialEndDate: response.trial_end_date ? new Date(response.trial_end_date) : undefined,
|
|
942
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
943
|
+
payload: response.payload,
|
|
944
|
+
createdAt: new Date(response.created_at),
|
|
945
|
+
updatedAt: new Date(response.updated_at)
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
const flexibleOrderMapper = {
|
|
952
|
+
type: 'flexible_order',
|
|
953
|
+
map: (resource)=>{
|
|
954
|
+
var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10, _resource_attributes11, _resource_attributes12, _resource_attributes13, _resource_attributes14, _resource_attributes15, _resource_attributes16, _resource_attributes17, _resource_attributes18, _resource_attributes19, _resource_attributes20, _resource_attributes21, _resource_attributes22, _resource_attributes23, _resource_attributes24, _resource_attributes25, _resource_attributes26, _resource_attributes27;
|
|
955
|
+
return {
|
|
956
|
+
id: resource.id,
|
|
957
|
+
uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
|
|
958
|
+
customerUniqueId: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['customer_unique_id'],
|
|
959
|
+
userUniqueId: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['user_unique_id'],
|
|
960
|
+
entityUniqueId: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['entity_unique_id'],
|
|
961
|
+
orderNumber: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['order_number'],
|
|
962
|
+
subtotal: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['subtotal'],
|
|
963
|
+
tax: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['tax'],
|
|
964
|
+
tips: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['tips'],
|
|
965
|
+
total: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['total'],
|
|
966
|
+
currency: (_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['currency'],
|
|
967
|
+
status: (_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['status'],
|
|
968
|
+
details: (((_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['details']) || []).map((d)=>({
|
|
969
|
+
id: d.id,
|
|
970
|
+
uniqueId: d.unique_id,
|
|
971
|
+
name: d.name,
|
|
972
|
+
description: d.description,
|
|
973
|
+
quantity: d.quantity,
|
|
974
|
+
unitPrice: d.unit_price,
|
|
975
|
+
subtotal: d.subtotal,
|
|
976
|
+
tax: d.tax,
|
|
977
|
+
total: d.total,
|
|
978
|
+
status: d.status,
|
|
979
|
+
logistics: d.logistics ? {
|
|
980
|
+
carrier: d.logistics.carrier,
|
|
981
|
+
trackingNumber: d.logistics.tracking_number,
|
|
982
|
+
trackingUrl: d.logistics.tracking_url,
|
|
983
|
+
shippedAt: d.logistics.shipped_at ? parseDate(d.logistics.shipped_at) : undefined,
|
|
984
|
+
deliveredAt: d.logistics.delivered_at ? parseDate(d.logistics.delivered_at) : undefined,
|
|
985
|
+
estimatedDelivery: d.logistics.estimated_delivery ? parseDate(d.logistics.estimated_delivery) : undefined,
|
|
986
|
+
address: d.logistics.address,
|
|
987
|
+
payload: d.logistics.payload
|
|
988
|
+
} : undefined,
|
|
989
|
+
payload: d.payload
|
|
990
|
+
})),
|
|
991
|
+
payments: (((_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['payments']) || []).map((p)=>({
|
|
992
|
+
id: p.id,
|
|
993
|
+
uniqueId: p.unique_id,
|
|
994
|
+
amount: p.amount,
|
|
995
|
+
currency: p.currency,
|
|
996
|
+
method: p.method,
|
|
997
|
+
status: p.status,
|
|
998
|
+
confirmedAt: p.confirmed_at ? parseDate(p.confirmed_at) : undefined,
|
|
999
|
+
payload: p.payload
|
|
1000
|
+
})),
|
|
1001
|
+
logistics: ((_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['logistics']) ? {
|
|
1002
|
+
carrier: ((_resource_attributes14 = resource.attributes) == null ? void 0 : _resource_attributes14['logistics']).carrier,
|
|
1003
|
+
trackingNumber: ((_resource_attributes15 = resource.attributes) == null ? void 0 : _resource_attributes15['logistics']).tracking_number,
|
|
1004
|
+
trackingUrl: ((_resource_attributes16 = resource.attributes) == null ? void 0 : _resource_attributes16['logistics']).tracking_url,
|
|
1005
|
+
shippedAt: ((_resource_attributes17 = resource.attributes) == null ? void 0 : _resource_attributes17['logistics']).shipped_at ? parseDate(((_resource_attributes18 = resource.attributes) == null ? void 0 : _resource_attributes18['logistics']).shipped_at) : undefined,
|
|
1006
|
+
deliveredAt: ((_resource_attributes19 = resource.attributes) == null ? void 0 : _resource_attributes19['logistics']).delivered_at ? parseDate(((_resource_attributes20 = resource.attributes) == null ? void 0 : _resource_attributes20['logistics']).delivered_at) : undefined,
|
|
1007
|
+
estimatedDelivery: ((_resource_attributes21 = resource.attributes) == null ? void 0 : _resource_attributes21['logistics']).estimated_delivery ? parseDate(((_resource_attributes22 = resource.attributes) == null ? void 0 : _resource_attributes22['logistics']).estimated_delivery) : undefined,
|
|
1008
|
+
address: ((_resource_attributes23 = resource.attributes) == null ? void 0 : _resource_attributes23['logistics']).address,
|
|
1009
|
+
payload: ((_resource_attributes24 = resource.attributes) == null ? void 0 : _resource_attributes24['logistics']).payload
|
|
1010
|
+
} : undefined,
|
|
1011
|
+
payload: (_resource_attributes25 = resource.attributes) == null ? void 0 : _resource_attributes25['payload'],
|
|
1012
|
+
createdAt: parseDate((_resource_attributes26 = resource.attributes) == null ? void 0 : _resource_attributes26['created_at']),
|
|
1013
|
+
updatedAt: parseDate((_resource_attributes27 = resource.attributes) == null ? void 0 : _resource_attributes27['updated_at'])
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
function createFlexibleOrdersService(transport, _config) {
|
|
1019
|
+
return {
|
|
1020
|
+
async list (params) {
|
|
1021
|
+
const queryParams = {};
|
|
1022
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
1023
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
1024
|
+
if (params == null ? void 0 : params.customerUniqueId) queryParams['customer_unique_id'] = params.customerUniqueId;
|
|
1025
|
+
if (params == null ? void 0 : params.userUniqueId) queryParams['user_unique_id'] = params.userUniqueId;
|
|
1026
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
1027
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
1028
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
1029
|
+
const response = await transport.get('/flexible_orders', {
|
|
1030
|
+
params: queryParams
|
|
1031
|
+
});
|
|
1032
|
+
return decodePageResult(response, flexibleOrderMapper);
|
|
1033
|
+
},
|
|
1034
|
+
async get (uniqueId) {
|
|
1035
|
+
const response = await transport.get(`/flexible_orders/${uniqueId}`);
|
|
1036
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1037
|
+
},
|
|
1038
|
+
async create (data) {
|
|
1039
|
+
const response = await transport.post('/flexible_orders', {
|
|
1040
|
+
flexible_order: {
|
|
1041
|
+
customer_unique_id: data.customerUniqueId,
|
|
1042
|
+
user_unique_id: data.userUniqueId,
|
|
1043
|
+
entity_unique_id: data.entityUniqueId,
|
|
1044
|
+
currency: data.currency,
|
|
1045
|
+
payload: data.payload
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1049
|
+
},
|
|
1050
|
+
async update (uniqueId, data) {
|
|
1051
|
+
const response = await transport.put(`/flexible_orders/${uniqueId}`, {
|
|
1052
|
+
flexible_order: {
|
|
1053
|
+
status: data.status,
|
|
1054
|
+
payload: data.payload
|
|
1055
|
+
}
|
|
1056
|
+
});
|
|
1057
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1058
|
+
},
|
|
1059
|
+
async addDetails (uniqueId, data) {
|
|
1060
|
+
const response = await transport.post(`/flexible_orders/${uniqueId}/details`, {
|
|
1061
|
+
detail: {
|
|
1062
|
+
name: data.name,
|
|
1063
|
+
description: data.description,
|
|
1064
|
+
quantity: data.quantity,
|
|
1065
|
+
unit_price: data.unitPrice,
|
|
1066
|
+
tax: data.tax,
|
|
1067
|
+
payload: data.payload
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1071
|
+
},
|
|
1072
|
+
async addTips (uniqueId, data) {
|
|
1073
|
+
const response = await transport.post(`/flexible_orders/${uniqueId}/tips/add`, {
|
|
1074
|
+
amount: data.amount,
|
|
1075
|
+
payload: data.payload
|
|
1076
|
+
});
|
|
1077
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1078
|
+
},
|
|
1079
|
+
async addPaymentMethod (uniqueId, data) {
|
|
1080
|
+
const response = await transport.post(`/flexible_orders/${uniqueId}/payments/method`, {
|
|
1081
|
+
method: data.method,
|
|
1082
|
+
payload: data.payload
|
|
1083
|
+
});
|
|
1084
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1085
|
+
},
|
|
1086
|
+
async addPayment (uniqueId, data) {
|
|
1087
|
+
const response = await transport.post(`/flexible_orders/${uniqueId}/payments`, {
|
|
1088
|
+
payment: {
|
|
1089
|
+
amount: data.amount,
|
|
1090
|
+
method: data.method,
|
|
1091
|
+
payload: data.payload
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1095
|
+
},
|
|
1096
|
+
async confirmPayment (uniqueId, paymentUniqueId) {
|
|
1097
|
+
const response = await transport.put(`/flexible_orders/${uniqueId}/payments/${paymentUniqueId}/confirm`, {});
|
|
1098
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1099
|
+
},
|
|
1100
|
+
async updateStatus (uniqueId, status) {
|
|
1101
|
+
const response = await transport.put(`/flexible_orders/${uniqueId}/status`, {
|
|
1102
|
+
status
|
|
1103
|
+
});
|
|
1104
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1105
|
+
},
|
|
1106
|
+
async updateDetailStatus (uniqueId, detailUniqueId, status) {
|
|
1107
|
+
const response = await transport.put(`/flexible_orders/${uniqueId}/details/${detailUniqueId}/status`, {
|
|
1108
|
+
status
|
|
1109
|
+
});
|
|
1110
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1111
|
+
},
|
|
1112
|
+
async cancel (uniqueId) {
|
|
1113
|
+
await transport.delete(`/flexible_orders/${uniqueId}/cancel`);
|
|
1114
|
+
},
|
|
1115
|
+
async updateLogistics (uniqueId, data) {
|
|
1116
|
+
const response = await transport.put(`/flexible_orders/${uniqueId}/logistics`, {
|
|
1117
|
+
logistics: {
|
|
1118
|
+
carrier: data.carrier,
|
|
1119
|
+
tracking_number: data.trackingNumber,
|
|
1120
|
+
tracking_url: data.trackingUrl,
|
|
1121
|
+
shipped_at: data.shippedAt,
|
|
1122
|
+
delivered_at: data.deliveredAt,
|
|
1123
|
+
estimated_delivery: data.estimatedDelivery,
|
|
1124
|
+
address: data.address,
|
|
1125
|
+
payload: data.payload
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1129
|
+
},
|
|
1130
|
+
async updateDetailLogistics (uniqueId, detailUniqueId, data) {
|
|
1131
|
+
const response = await transport.put(`/flexible_orders/${uniqueId}/details/${detailUniqueId}/logistics`, {
|
|
1132
|
+
logistics: {
|
|
1133
|
+
carrier: data.carrier,
|
|
1134
|
+
tracking_number: data.trackingNumber,
|
|
1135
|
+
tracking_url: data.trackingUrl,
|
|
1136
|
+
shipped_at: data.shippedAt,
|
|
1137
|
+
delivered_at: data.deliveredAt,
|
|
1138
|
+
estimated_delivery: data.estimatedDelivery,
|
|
1139
|
+
address: data.address,
|
|
1140
|
+
payload: data.payload
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
return decodeOne(response, flexibleOrderMapper);
|
|
1144
|
+
},
|
|
1145
|
+
async getPayments (uniqueId) {
|
|
1146
|
+
const response = await transport.get(`/flexible_orders/${uniqueId}/payments`);
|
|
1147
|
+
return decodePageResult(response, paymentMapper);
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
function createStripeService(transport, _config) {
|
|
1153
|
+
return {
|
|
1154
|
+
async createCustomer (data) {
|
|
1155
|
+
const response = await transport.post('/stripe/customers', {
|
|
1156
|
+
email: data.email,
|
|
1157
|
+
name: data.name,
|
|
1158
|
+
phone: data.phone,
|
|
1159
|
+
metadata: data.metadata
|
|
1160
|
+
});
|
|
1161
|
+
return {
|
|
1162
|
+
customerId: response.customer_id,
|
|
1163
|
+
customer: {
|
|
1164
|
+
id: response.customer.id,
|
|
1165
|
+
stripeId: response.customer.stripe_id,
|
|
1166
|
+
email: response.customer.email,
|
|
1167
|
+
name: response.customer.name,
|
|
1168
|
+
defaultPaymentMethod: response.customer.default_payment_method,
|
|
1169
|
+
metadata: response.customer.metadata,
|
|
1170
|
+
createdAt: new Date(response.customer.created_at)
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
},
|
|
1174
|
+
async createCheckoutSession (data) {
|
|
1175
|
+
var _data_lineItems;
|
|
1176
|
+
const response = await transport.post('/stripe/sessions', {
|
|
1177
|
+
customer_unique_id: data.customerUniqueId,
|
|
1178
|
+
stripe_customer_id: data.stripeCustomerId,
|
|
1179
|
+
success_url: data.successUrl,
|
|
1180
|
+
cancel_url: data.cancelUrl,
|
|
1181
|
+
mode: data.mode,
|
|
1182
|
+
line_items: (_data_lineItems = data.lineItems) == null ? void 0 : _data_lineItems.map((item)=>({
|
|
1183
|
+
price_id: item.priceId,
|
|
1184
|
+
quantity: item.quantity,
|
|
1185
|
+
price_data: item.priceData ? {
|
|
1186
|
+
currency: item.priceData.currency,
|
|
1187
|
+
unit_amount: item.priceData.unitAmount,
|
|
1188
|
+
product_data: item.priceData.productData,
|
|
1189
|
+
recurring: item.priceData.recurring
|
|
1190
|
+
} : undefined
|
|
1191
|
+
})),
|
|
1192
|
+
subscription_data: data.subscriptionData ? {
|
|
1193
|
+
trial_period_days: data.subscriptionData.trialPeriodDays,
|
|
1194
|
+
metadata: data.subscriptionData.metadata
|
|
1195
|
+
} : undefined,
|
|
1196
|
+
metadata: data.metadata
|
|
1197
|
+
});
|
|
1198
|
+
return {
|
|
1199
|
+
id: response.id,
|
|
1200
|
+
url: response.url,
|
|
1201
|
+
status: response.status,
|
|
1202
|
+
expiresAt: response.expires_at ? new Date(response.expires_at) : undefined
|
|
1203
|
+
};
|
|
1204
|
+
},
|
|
1205
|
+
async createPaymentIntent (data) {
|
|
1206
|
+
const response = await transport.post('/stripe/payments', {
|
|
1207
|
+
amount: data.amount,
|
|
1208
|
+
currency: data.currency,
|
|
1209
|
+
customer_unique_id: data.customerUniqueId,
|
|
1210
|
+
stripe_customer_id: data.stripeCustomerId,
|
|
1211
|
+
payment_method_types: data.paymentMethodTypes,
|
|
1212
|
+
metadata: data.metadata
|
|
1213
|
+
});
|
|
1214
|
+
return {
|
|
1215
|
+
id: response.id,
|
|
1216
|
+
clientSecret: response.client_secret,
|
|
1217
|
+
status: response.status,
|
|
1218
|
+
amount: response.amount,
|
|
1219
|
+
currency: response.currency
|
|
1220
|
+
};
|
|
1221
|
+
},
|
|
1222
|
+
async createCustomerPortal (uniqueId, data) {
|
|
1223
|
+
const response = await transport.post(`/stripe/customers/${uniqueId}/portal`, {
|
|
1224
|
+
return_url: data.returnUrl
|
|
1225
|
+
});
|
|
1226
|
+
return {
|
|
1227
|
+
id: response.id,
|
|
1228
|
+
url: response.url
|
|
1229
|
+
};
|
|
1230
|
+
},
|
|
1231
|
+
async listSubscriptions (params) {
|
|
1232
|
+
var _response_meta, _response_meta1, _response_meta2, _response_meta3;
|
|
1233
|
+
const queryParams = {};
|
|
1234
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
1235
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
1236
|
+
if (params == null ? void 0 : params.customerId) queryParams['customer_id'] = params.customerId;
|
|
1237
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
1238
|
+
const response = await transport.get('/stripe/subscriptions', {
|
|
1239
|
+
params: queryParams
|
|
1240
|
+
});
|
|
1241
|
+
const data = response.data || [];
|
|
1242
|
+
return {
|
|
1243
|
+
data: data.map((s)=>({
|
|
1244
|
+
id: s.id,
|
|
1245
|
+
stripeId: s.stripe_id,
|
|
1246
|
+
customerId: s.customer_id,
|
|
1247
|
+
status: s.status,
|
|
1248
|
+
currentPeriodStart: s.current_period_start ? new Date(s.current_period_start) : undefined,
|
|
1249
|
+
currentPeriodEnd: s.current_period_end ? new Date(s.current_period_end) : undefined,
|
|
1250
|
+
cancelAtPeriodEnd: s.cancel_at_period_end,
|
|
1251
|
+
cancelledAt: s.cancelled_at ? new Date(s.cancelled_at) : undefined,
|
|
1252
|
+
metadata: s.metadata
|
|
1253
|
+
})),
|
|
1254
|
+
meta: {
|
|
1255
|
+
totalCount: ((_response_meta = response.meta) == null ? void 0 : _response_meta.total_count) || data.length,
|
|
1256
|
+
page: ((_response_meta1 = response.meta) == null ? void 0 : _response_meta1.page) || 1,
|
|
1257
|
+
perPage: ((_response_meta2 = response.meta) == null ? void 0 : _response_meta2.per_page) || data.length,
|
|
1258
|
+
totalPages: ((_response_meta3 = response.meta) == null ? void 0 : _response_meta3.total_pages) || 1
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
},
|
|
1262
|
+
async createSubscription (data) {
|
|
1263
|
+
const response = await transport.post('/stripe/subscriptions', {
|
|
1264
|
+
customer_unique_id: data.customerUniqueId,
|
|
1265
|
+
stripe_customer_id: data.stripeCustomerId,
|
|
1266
|
+
price_id: data.priceId,
|
|
1267
|
+
quantity: data.quantity,
|
|
1268
|
+
trial_period_days: data.trialPeriodDays,
|
|
1269
|
+
metadata: data.metadata
|
|
1270
|
+
});
|
|
1271
|
+
return {
|
|
1272
|
+
id: response.id,
|
|
1273
|
+
stripeId: response.stripe_id,
|
|
1274
|
+
customerId: response.customer_id,
|
|
1275
|
+
status: response.status,
|
|
1276
|
+
currentPeriodStart: response.current_period_start ? new Date(response.current_period_start) : undefined,
|
|
1277
|
+
currentPeriodEnd: response.current_period_end ? new Date(response.current_period_end) : undefined,
|
|
1278
|
+
cancelAtPeriodEnd: response.cancel_at_period_end,
|
|
1279
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
1280
|
+
metadata: response.metadata
|
|
1281
|
+
};
|
|
1282
|
+
},
|
|
1283
|
+
async updateSubscription (stripeSubscriptionId, data) {
|
|
1284
|
+
const response = await transport.put(`/stripe/subscriptions/${stripeSubscriptionId}`, {
|
|
1285
|
+
price_id: data.priceId,
|
|
1286
|
+
quantity: data.quantity,
|
|
1287
|
+
cancel_at_period_end: data.cancelAtPeriodEnd,
|
|
1288
|
+
metadata: data.metadata
|
|
1289
|
+
});
|
|
1290
|
+
return {
|
|
1291
|
+
id: response.id,
|
|
1292
|
+
stripeId: response.stripe_id,
|
|
1293
|
+
customerId: response.customer_id,
|
|
1294
|
+
status: response.status,
|
|
1295
|
+
currentPeriodStart: response.current_period_start ? new Date(response.current_period_start) : undefined,
|
|
1296
|
+
currentPeriodEnd: response.current_period_end ? new Date(response.current_period_end) : undefined,
|
|
1297
|
+
cancelAtPeriodEnd: response.cancel_at_period_end,
|
|
1298
|
+
cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
|
|
1299
|
+
metadata: response.metadata
|
|
1300
|
+
};
|
|
1301
|
+
},
|
|
1302
|
+
async cancelSubscription (stripeSubscriptionId) {
|
|
1303
|
+
await transport.delete(`/stripe/subscriptions/${stripeSubscriptionId}`);
|
|
1304
|
+
},
|
|
1305
|
+
async listWebhooks () {
|
|
1306
|
+
const response = await transport.get('/stripe/webhooks');
|
|
1307
|
+
return (response.webhooks || response || []).map((w)=>({
|
|
1308
|
+
id: w.id,
|
|
1309
|
+
url: w.url,
|
|
1310
|
+
enabledEvents: w.enabled_events,
|
|
1311
|
+
status: w.status,
|
|
1312
|
+
createdAt: new Date(w.created_at)
|
|
1313
|
+
}));
|
|
1314
|
+
},
|
|
1315
|
+
async createWebhook (data) {
|
|
1316
|
+
const response = await transport.post('/stripe/webhooks', {
|
|
1317
|
+
url: data.url,
|
|
1318
|
+
enabled_events: data.enabledEvents
|
|
1319
|
+
});
|
|
1320
|
+
return {
|
|
1321
|
+
id: response.id,
|
|
1322
|
+
url: response.url,
|
|
1323
|
+
enabledEvents: response.enabled_events,
|
|
1324
|
+
status: response.status,
|
|
1325
|
+
createdAt: new Date(response.created_at)
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
function createMercadoPagoService(transport, _config) {
|
|
1332
|
+
return {
|
|
1333
|
+
async listPaymentMethods () {
|
|
1334
|
+
const response = await transport.get('/mercadopago');
|
|
1335
|
+
return (response.payment_methods || response || []).map((pm)=>({
|
|
1336
|
+
id: pm.id,
|
|
1337
|
+
name: pm.name,
|
|
1338
|
+
paymentTypeId: pm.payment_type_id,
|
|
1339
|
+
status: pm.status,
|
|
1340
|
+
secureThumbnail: pm.secure_thumbnail,
|
|
1341
|
+
thumbnail: pm.thumbnail,
|
|
1342
|
+
deferredCapture: pm.deferred_capture,
|
|
1343
|
+
settings: pm.settings,
|
|
1344
|
+
additionalInfoNeeded: pm.additional_info_needed,
|
|
1345
|
+
minAllowedAmount: pm.min_allowed_amount,
|
|
1346
|
+
maxAllowedAmount: pm.max_allowed_amount,
|
|
1347
|
+
processingModes: pm.processing_modes
|
|
1348
|
+
}));
|
|
1349
|
+
},
|
|
1350
|
+
async createPaymentIntent (data) {
|
|
1351
|
+
var _data_additionalInfo_items;
|
|
1352
|
+
const response = await transport.post('/mercadopago/payments', {
|
|
1353
|
+
transaction_amount: data.transactionAmount,
|
|
1354
|
+
description: data.description,
|
|
1355
|
+
payment_method_id: data.paymentMethodId,
|
|
1356
|
+
payer: {
|
|
1357
|
+
email: data.payerEmail
|
|
1358
|
+
},
|
|
1359
|
+
installments: data.installments,
|
|
1360
|
+
token: data.token,
|
|
1361
|
+
issuer_id: data.issuerId,
|
|
1362
|
+
external_reference: data.externalReference,
|
|
1363
|
+
statement_descriptor: data.statementDescriptor,
|
|
1364
|
+
notification_url: data.notificationUrl,
|
|
1365
|
+
additional_info: data.additionalInfo ? {
|
|
1366
|
+
items: (_data_additionalInfo_items = data.additionalInfo.items) == null ? void 0 : _data_additionalInfo_items.map((item)=>({
|
|
1367
|
+
id: item.id,
|
|
1368
|
+
title: item.title,
|
|
1369
|
+
description: item.description,
|
|
1370
|
+
picture_url: item.pictureUrl,
|
|
1371
|
+
category_id: item.categoryId,
|
|
1372
|
+
quantity: item.quantity,
|
|
1373
|
+
unit_price: item.unitPrice
|
|
1374
|
+
})),
|
|
1375
|
+
payer: data.additionalInfo.payer ? {
|
|
1376
|
+
first_name: data.additionalInfo.payer.firstName,
|
|
1377
|
+
last_name: data.additionalInfo.payer.lastName,
|
|
1378
|
+
email: data.additionalInfo.payer.email,
|
|
1379
|
+
phone: data.additionalInfo.payer.phone,
|
|
1380
|
+
identification: data.additionalInfo.payer.identification,
|
|
1381
|
+
address: data.additionalInfo.payer.address ? {
|
|
1382
|
+
zip_code: data.additionalInfo.payer.address.zipCode,
|
|
1383
|
+
street_name: data.additionalInfo.payer.address.streetName,
|
|
1384
|
+
street_number: data.additionalInfo.payer.address.streetNumber
|
|
1385
|
+
} : undefined
|
|
1386
|
+
} : undefined
|
|
1387
|
+
} : undefined,
|
|
1388
|
+
metadata: data.metadata
|
|
1389
|
+
});
|
|
1390
|
+
return {
|
|
1391
|
+
id: response.id,
|
|
1392
|
+
status: response.status,
|
|
1393
|
+
statusDetail: response.status_detail,
|
|
1394
|
+
externalReference: response.external_reference,
|
|
1395
|
+
transactionAmount: response.transaction_amount,
|
|
1396
|
+
currencyId: response.currency_id,
|
|
1397
|
+
paymentMethodId: response.payment_method_id,
|
|
1398
|
+
paymentTypeId: response.payment_type_id,
|
|
1399
|
+
installments: response.installments,
|
|
1400
|
+
initPoint: response.init_point,
|
|
1401
|
+
qrCodeBase64: response.qr_code_base64,
|
|
1402
|
+
ticketUrl: response.ticket_url,
|
|
1403
|
+
dateCreated: new Date(response.date_created),
|
|
1404
|
+
dateApproved: response.date_approved ? new Date(response.date_approved) : undefined
|
|
1405
|
+
};
|
|
1406
|
+
},
|
|
1407
|
+
async createPSEIntent (data) {
|
|
1408
|
+
const response = await transport.post('/mercadopago/payments/pse', {
|
|
1409
|
+
transaction_amount: data.transactionAmount,
|
|
1410
|
+
description: data.description,
|
|
1411
|
+
payer: {
|
|
1412
|
+
email: data.payerEmail,
|
|
1413
|
+
identification: {
|
|
1414
|
+
type: data.payerDocumentType,
|
|
1415
|
+
number: data.payerDocumentNumber
|
|
1416
|
+
}
|
|
1417
|
+
},
|
|
1418
|
+
transaction_details: {
|
|
1419
|
+
financial_institution: data.financialInstitution
|
|
1420
|
+
},
|
|
1421
|
+
callback_url: data.callbackUrl,
|
|
1422
|
+
external_reference: data.externalReference,
|
|
1423
|
+
metadata: data.metadata
|
|
1424
|
+
});
|
|
1425
|
+
return {
|
|
1426
|
+
id: response.id,
|
|
1427
|
+
status: response.status,
|
|
1428
|
+
statusDetail: response.status_detail,
|
|
1429
|
+
externalReference: response.external_reference,
|
|
1430
|
+
transactionAmount: response.transaction_amount,
|
|
1431
|
+
currencyId: response.currency_id,
|
|
1432
|
+
paymentMethodId: response.payment_method_id,
|
|
1433
|
+
paymentTypeId: response.payment_type_id,
|
|
1434
|
+
initPoint: response.init_point,
|
|
1435
|
+
ticketUrl: response.ticket_url,
|
|
1436
|
+
dateCreated: new Date(response.date_created),
|
|
1437
|
+
dateApproved: response.date_approved ? new Date(response.date_approved) : undefined
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
function createVendorPaymentsService(transport, _config) {
|
|
1444
|
+
return {
|
|
1445
|
+
async get (paymentUniqueId) {
|
|
1446
|
+
const response = await transport.get(`/payables/${paymentUniqueId}`);
|
|
1447
|
+
return {
|
|
1448
|
+
id: response.id,
|
|
1449
|
+
uniqueId: response.unique_id,
|
|
1450
|
+
orderUniqueId: response.order_unique_id,
|
|
1451
|
+
detailUniqueId: response.detail_unique_id,
|
|
1452
|
+
vendorUniqueId: response.vendor_unique_id,
|
|
1453
|
+
amount: response.amount,
|
|
1454
|
+
currency: response.currency,
|
|
1455
|
+
status: response.status,
|
|
1456
|
+
paidAt: response.paid_at ? new Date(response.paid_at) : undefined,
|
|
1457
|
+
reference: response.reference,
|
|
1458
|
+
notes: response.notes,
|
|
1459
|
+
payload: response.payload,
|
|
1460
|
+
createdAt: new Date(response.created_at),
|
|
1461
|
+
updatedAt: new Date(response.updated_at)
|
|
1462
|
+
};
|
|
1463
|
+
},
|
|
1464
|
+
async create (orderUniqueId, detailUniqueId, vendorUniqueId, data) {
|
|
1465
|
+
const response = await transport.post(`/orders/${orderUniqueId}/details/${detailUniqueId}/vendors/${vendorUniqueId}/payments`, {
|
|
1466
|
+
payment: {
|
|
1467
|
+
amount: data.amount,
|
|
1468
|
+
currency: data.currency,
|
|
1469
|
+
reference: data.reference,
|
|
1470
|
+
notes: data.notes,
|
|
1471
|
+
payload: data.payload
|
|
1472
|
+
}
|
|
1473
|
+
});
|
|
1474
|
+
return {
|
|
1475
|
+
id: response.id,
|
|
1476
|
+
uniqueId: response.unique_id,
|
|
1477
|
+
orderUniqueId: response.order_unique_id,
|
|
1478
|
+
detailUniqueId: response.detail_unique_id,
|
|
1479
|
+
vendorUniqueId: response.vendor_unique_id,
|
|
1480
|
+
amount: response.amount,
|
|
1481
|
+
currency: response.currency,
|
|
1482
|
+
status: response.status,
|
|
1483
|
+
paidAt: response.paid_at ? new Date(response.paid_at) : undefined,
|
|
1484
|
+
reference: response.reference,
|
|
1485
|
+
notes: response.notes,
|
|
1486
|
+
payload: response.payload,
|
|
1487
|
+
createdAt: new Date(response.created_at),
|
|
1488
|
+
updatedAt: new Date(response.updated_at)
|
|
1489
|
+
};
|
|
1490
|
+
},
|
|
1491
|
+
async update (orderUniqueId, detailUniqueId, vendorUniqueId, paymentUniqueId, data) {
|
|
1492
|
+
const response = await transport.put(`/orders/${orderUniqueId}/details/${detailUniqueId}/vendors/${vendorUniqueId}/payments/${paymentUniqueId}`, {
|
|
1493
|
+
payment: {
|
|
1494
|
+
amount: data.amount,
|
|
1495
|
+
reference: data.reference,
|
|
1496
|
+
notes: data.notes,
|
|
1497
|
+
status: data.status,
|
|
1498
|
+
payload: data.payload
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
return {
|
|
1502
|
+
id: response.id,
|
|
1503
|
+
uniqueId: response.unique_id,
|
|
1504
|
+
orderUniqueId: response.order_unique_id,
|
|
1505
|
+
detailUniqueId: response.detail_unique_id,
|
|
1506
|
+
vendorUniqueId: response.vendor_unique_id,
|
|
1507
|
+
amount: response.amount,
|
|
1508
|
+
currency: response.currency,
|
|
1509
|
+
status: response.status,
|
|
1510
|
+
paidAt: response.paid_at ? new Date(response.paid_at) : undefined,
|
|
1511
|
+
reference: response.reference,
|
|
1512
|
+
notes: response.notes,
|
|
1513
|
+
payload: response.payload,
|
|
1514
|
+
createdAt: new Date(response.created_at),
|
|
1515
|
+
updatedAt: new Date(response.updated_at)
|
|
1516
|
+
};
|
|
1517
|
+
},
|
|
1518
|
+
async pay (orderUniqueId, detailUniqueId, vendorUniqueId, paymentUniqueId) {
|
|
1519
|
+
const response = await transport.put(`/orders/${orderUniqueId}/details/${detailUniqueId}/vendors/${vendorUniqueId}/payments/${paymentUniqueId}/pay`, {});
|
|
1520
|
+
return {
|
|
1521
|
+
id: response.id,
|
|
1522
|
+
uniqueId: response.unique_id,
|
|
1523
|
+
orderUniqueId: response.order_unique_id,
|
|
1524
|
+
detailUniqueId: response.detail_unique_id,
|
|
1525
|
+
vendorUniqueId: response.vendor_unique_id,
|
|
1526
|
+
amount: response.amount,
|
|
1527
|
+
currency: response.currency,
|
|
1528
|
+
status: response.status,
|
|
1529
|
+
paidAt: response.paid_at ? new Date(response.paid_at) : undefined,
|
|
1530
|
+
reference: response.reference,
|
|
1531
|
+
notes: response.notes,
|
|
1532
|
+
payload: response.payload,
|
|
1533
|
+
createdAt: new Date(response.created_at),
|
|
1534
|
+
updatedAt: new Date(response.updated_at)
|
|
1535
|
+
};
|
|
1536
|
+
},
|
|
1537
|
+
async delete (orderUniqueId, detailUniqueId, vendorUniqueId, paymentUniqueId) {
|
|
1538
|
+
await transport.delete(`/orders/${orderUniqueId}/details/${detailUniqueId}/vendors/${vendorUniqueId}/payments/${paymentUniqueId}`);
|
|
1539
|
+
},
|
|
1540
|
+
async createProvider (orderUniqueId, orderDetailUniqueId, data) {
|
|
1541
|
+
const response = await transport.post(`/orders/${orderUniqueId}/details/${orderDetailUniqueId}/providers`, {
|
|
1542
|
+
provider: {
|
|
1543
|
+
vendor_unique_id: data.vendorUniqueId,
|
|
1544
|
+
amount: data.amount,
|
|
1545
|
+
commission: data.commission,
|
|
1546
|
+
payload: data.payload
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1549
|
+
return {
|
|
1550
|
+
id: response.id,
|
|
1551
|
+
uniqueId: response.unique_id,
|
|
1552
|
+
orderDetailUniqueId: response.order_detail_unique_id,
|
|
1553
|
+
vendorUniqueId: response.vendor_unique_id,
|
|
1554
|
+
vendorName: response.vendor_name,
|
|
1555
|
+
amount: response.amount,
|
|
1556
|
+
commission: response.commission,
|
|
1557
|
+
status: response.status,
|
|
1558
|
+
payload: response.payload,
|
|
1559
|
+
createdAt: new Date(response.created_at),
|
|
1560
|
+
updatedAt: new Date(response.updated_at)
|
|
1561
|
+
};
|
|
1562
|
+
},
|
|
1563
|
+
async createProviderBySource (sourceId, data) {
|
|
1564
|
+
const response = await transport.post(`/sources/${sourceId}/providers`, {
|
|
1565
|
+
provider: {
|
|
1566
|
+
vendor_unique_id: data.vendorUniqueId,
|
|
1567
|
+
order_unique_id: data.orderUniqueId,
|
|
1568
|
+
order_detail_unique_id: data.orderDetailUniqueId,
|
|
1569
|
+
amount: data.amount,
|
|
1570
|
+
commission: data.commission,
|
|
1571
|
+
payload: data.payload
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1574
|
+
return {
|
|
1575
|
+
id: response.id,
|
|
1576
|
+
uniqueId: response.unique_id,
|
|
1577
|
+
sourceId: response.source_id,
|
|
1578
|
+
orderDetailUniqueId: response.order_detail_unique_id,
|
|
1579
|
+
vendorUniqueId: response.vendor_unique_id,
|
|
1580
|
+
vendorName: response.vendor_name,
|
|
1581
|
+
amount: response.amount,
|
|
1582
|
+
commission: response.commission,
|
|
1583
|
+
status: response.status,
|
|
1584
|
+
payload: response.payload,
|
|
1585
|
+
createdAt: new Date(response.created_at),
|
|
1586
|
+
updatedAt: new Date(response.updated_at)
|
|
1587
|
+
};
|
|
1588
|
+
},
|
|
1589
|
+
async updateProvider (orderUniqueId, orderDetailUniqueId, providerUniqueId, data) {
|
|
1590
|
+
const response = await transport.put(`/orders/${orderUniqueId}/details/${orderDetailUniqueId}/providers/${providerUniqueId}`, {
|
|
1591
|
+
provider: {
|
|
1592
|
+
amount: data.amount,
|
|
1593
|
+
commission: data.commission,
|
|
1594
|
+
status: data.status,
|
|
1595
|
+
payload: data.payload
|
|
1596
|
+
}
|
|
1597
|
+
});
|
|
1598
|
+
return {
|
|
1599
|
+
id: response.id,
|
|
1600
|
+
uniqueId: response.unique_id,
|
|
1601
|
+
orderDetailUniqueId: response.order_detail_unique_id,
|
|
1602
|
+
vendorUniqueId: response.vendor_unique_id,
|
|
1603
|
+
vendorName: response.vendor_name,
|
|
1604
|
+
amount: response.amount,
|
|
1605
|
+
commission: response.commission,
|
|
1606
|
+
status: response.status,
|
|
1607
|
+
payload: response.payload,
|
|
1608
|
+
createdAt: new Date(response.created_at),
|
|
1609
|
+
updatedAt: new Date(response.updated_at)
|
|
1610
|
+
};
|
|
1611
|
+
},
|
|
1612
|
+
async reportList (params) {
|
|
1613
|
+
const response = await transport.post('/reports/vendors/payments/list', {
|
|
1614
|
+
start_date: params.startDate,
|
|
1615
|
+
end_date: params.endDate,
|
|
1616
|
+
vendor_unique_id: params.vendorUniqueId,
|
|
1617
|
+
status: params.status,
|
|
1618
|
+
page: params.page,
|
|
1619
|
+
per_page: params.perPage
|
|
1620
|
+
});
|
|
1621
|
+
return {
|
|
1622
|
+
payments: (response.payments || []).map((p)=>({
|
|
1623
|
+
uniqueId: p.unique_id,
|
|
1624
|
+
orderUniqueId: p.order_unique_id,
|
|
1625
|
+
vendorName: p.vendor_name,
|
|
1626
|
+
amount: p.amount,
|
|
1627
|
+
status: p.status,
|
|
1628
|
+
paidAt: p.paid_at ? new Date(p.paid_at) : undefined,
|
|
1629
|
+
createdAt: new Date(p.created_at)
|
|
1630
|
+
})),
|
|
1631
|
+
summary: {
|
|
1632
|
+
totalPayments: response.summary.total_payments,
|
|
1633
|
+
totalAmount: response.summary.total_amount,
|
|
1634
|
+
totalPending: response.summary.total_pending,
|
|
1635
|
+
totalPaid: response.summary.total_paid,
|
|
1636
|
+
paymentsByStatus: response.summary.payments_by_status,
|
|
1637
|
+
currency: response.summary.currency,
|
|
1638
|
+
period: {
|
|
1639
|
+
startDate: new Date(response.summary.period.start_date),
|
|
1640
|
+
endDate: new Date(response.summary.period.end_date)
|
|
1641
|
+
}
|
|
1642
|
+
},
|
|
1643
|
+
meta: {
|
|
1644
|
+
totalCount: response.meta.total_count,
|
|
1645
|
+
page: response.meta.page,
|
|
1646
|
+
perPage: response.meta.per_page,
|
|
1647
|
+
totalPages: response.meta.total_pages
|
|
1648
|
+
}
|
|
1649
|
+
};
|
|
1650
|
+
},
|
|
1651
|
+
async reportSummary (params) {
|
|
1652
|
+
const response = await transport.post('/reports/vendors/payments/summary', {
|
|
1653
|
+
start_date: params.startDate,
|
|
1654
|
+
end_date: params.endDate,
|
|
1655
|
+
vendor_unique_id: params.vendorUniqueId,
|
|
1656
|
+
status: params.status
|
|
1657
|
+
});
|
|
1658
|
+
return {
|
|
1659
|
+
totalPayments: response.total_payments,
|
|
1660
|
+
totalAmount: response.total_amount,
|
|
1661
|
+
totalPending: response.total_pending,
|
|
1662
|
+
totalPaid: response.total_paid,
|
|
1663
|
+
paymentsByStatus: response.payments_by_status,
|
|
1664
|
+
currency: response.currency,
|
|
1665
|
+
period: {
|
|
1666
|
+
startDate: new Date(response.period.start_date),
|
|
1667
|
+
endDate: new Date(response.period.end_date)
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
},
|
|
1671
|
+
async providerReportList (params) {
|
|
1672
|
+
const response = await transport.post('/reports/orders/providers/list', {
|
|
1673
|
+
start_date: params.startDate,
|
|
1674
|
+
end_date: params.endDate,
|
|
1675
|
+
vendor_unique_id: params.vendorUniqueId,
|
|
1676
|
+
status: params.status,
|
|
1677
|
+
page: params.page,
|
|
1678
|
+
per_page: params.perPage
|
|
1679
|
+
});
|
|
1680
|
+
return {
|
|
1681
|
+
providers: (response.providers || []).map((p)=>({
|
|
1682
|
+
uniqueId: p.unique_id,
|
|
1683
|
+
vendorName: p.vendor_name,
|
|
1684
|
+
amount: p.amount,
|
|
1685
|
+
commission: p.commission,
|
|
1686
|
+
status: p.status,
|
|
1687
|
+
createdAt: new Date(p.created_at)
|
|
1688
|
+
})),
|
|
1689
|
+
summary: {
|
|
1690
|
+
totalProviders: response.summary.total_providers,
|
|
1691
|
+
totalAmount: response.summary.total_amount,
|
|
1692
|
+
totalCommission: response.summary.total_commission,
|
|
1693
|
+
providersByStatus: response.summary.providers_by_status,
|
|
1694
|
+
period: {
|
|
1695
|
+
startDate: new Date(response.summary.period.start_date),
|
|
1696
|
+
endDate: new Date(response.summary.period.end_date)
|
|
1697
|
+
}
|
|
1698
|
+
},
|
|
1699
|
+
meta: {
|
|
1700
|
+
totalCount: response.meta.total_count,
|
|
1701
|
+
page: response.meta.page,
|
|
1702
|
+
perPage: response.meta.per_page,
|
|
1703
|
+
totalPages: response.meta.total_pages
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
},
|
|
1707
|
+
async providerReportSummary (params) {
|
|
1708
|
+
const response = await transport.post('/reports/orders/providers/summary', {
|
|
1709
|
+
start_date: params.startDate,
|
|
1710
|
+
end_date: params.endDate,
|
|
1711
|
+
vendor_unique_id: params.vendorUniqueId,
|
|
1712
|
+
status: params.status
|
|
1713
|
+
});
|
|
1714
|
+
return {
|
|
1715
|
+
totalProviders: response.total_providers,
|
|
1716
|
+
totalAmount: response.total_amount,
|
|
1717
|
+
totalCommission: response.total_commission,
|
|
1718
|
+
providersByStatus: response.providers_by_status,
|
|
1719
|
+
period: {
|
|
1720
|
+
startDate: new Date(response.period.start_date),
|
|
1721
|
+
endDate: new Date(response.period.end_date)
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
|
|
442
1728
|
function createSalesBlock(transport, config) {
|
|
443
1729
|
return {
|
|
444
1730
|
orders: createOrdersService(transport),
|
|
445
1731
|
orderDetails: createOrderDetailsService(transport),
|
|
446
1732
|
payments: createPaymentsService(transport),
|
|
447
|
-
subscriptions: createSubscriptionsService(transport)
|
|
1733
|
+
subscriptions: createSubscriptionsService(transport),
|
|
1734
|
+
subscriptionModels: createSubscriptionModelsService(transport),
|
|
1735
|
+
entities: createSalesEntitiesService(transport),
|
|
1736
|
+
users: createSalesUsersService(transport),
|
|
1737
|
+
customers: createSalesCustomersService(transport),
|
|
1738
|
+
flexibleOrders: createFlexibleOrdersService(transport),
|
|
1739
|
+
stripe: createStripeService(transport),
|
|
1740
|
+
mercadopago: createMercadoPagoService(transport),
|
|
1741
|
+
vendorPayments: createVendorPaymentsService(transport)
|
|
448
1742
|
};
|
|
449
1743
|
}
|
|
450
1744
|
const salesBlockMetadata = {
|