@23blocks/block-sales 5.2.1 → 6.0.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.
Files changed (67) hide show
  1. package/dist/index.esm.js +749 -537
  2. package/dist/src/lib/mappers/customer-subscription.mapper.d.ts.map +1 -1
  3. package/dist/src/lib/mappers/customer.mapper.d.ts.map +1 -1
  4. package/dist/src/lib/mappers/entity-subscription.mapper.d.ts.map +1 -1
  5. package/dist/src/lib/mappers/entity.mapper.d.ts.map +1 -1
  6. package/dist/src/lib/mappers/mercadopago.mapper.d.ts +2 -2
  7. package/dist/src/lib/mappers/mercadopago.mapper.d.ts.map +1 -1
  8. package/dist/src/lib/mappers/order-detail-vendor.mapper.d.ts.map +1 -1
  9. package/dist/src/lib/mappers/order-detail.mapper.d.ts.map +1 -1
  10. package/dist/src/lib/mappers/order-tax.mapper.d.ts.map +1 -1
  11. package/dist/src/lib/mappers/order.mapper.d.ts.map +1 -1
  12. package/dist/src/lib/mappers/payment.mapper.d.ts.map +1 -1
  13. package/dist/src/lib/mappers/subscription-model.mapper.d.ts.map +1 -1
  14. package/dist/src/lib/mappers/subscription.mapper.d.ts +2 -1
  15. package/dist/src/lib/mappers/subscription.mapper.d.ts.map +1 -1
  16. package/dist/src/lib/mappers/user.mapper.d.ts.map +1 -1
  17. package/dist/src/lib/mappers/vendor-payment.mapper.d.ts.map +1 -1
  18. package/dist/src/lib/sales.block.d.ts.map +1 -1
  19. package/dist/src/lib/services/customers.service.d.ts +0 -20
  20. package/dist/src/lib/services/customers.service.d.ts.map +1 -1
  21. package/dist/src/lib/services/entities.service.d.ts +0 -24
  22. package/dist/src/lib/services/entities.service.d.ts.map +1 -1
  23. package/dist/src/lib/services/mercadopago.service.d.ts +3 -15
  24. package/dist/src/lib/services/mercadopago.service.d.ts.map +1 -1
  25. package/dist/src/lib/services/order-details.service.d.ts +5 -18
  26. package/dist/src/lib/services/order-details.service.d.ts.map +1 -1
  27. package/dist/src/lib/services/order-taxes.service.d.ts +0 -19
  28. package/dist/src/lib/services/order-taxes.service.d.ts.map +1 -1
  29. package/dist/src/lib/services/orders.service.d.ts +5 -42
  30. package/dist/src/lib/services/orders.service.d.ts.map +1 -1
  31. package/dist/src/lib/services/payments.service.d.ts +3 -24
  32. package/dist/src/lib/services/payments.service.d.ts.map +1 -1
  33. package/dist/src/lib/services/stripe.service.d.ts +0 -43
  34. package/dist/src/lib/services/stripe.service.d.ts.map +1 -1
  35. package/dist/src/lib/services/subscription-models.service.d.ts +0 -16
  36. package/dist/src/lib/services/subscription-models.service.d.ts.map +1 -1
  37. package/dist/src/lib/services/subscriptions.service.d.ts +2 -38
  38. package/dist/src/lib/services/subscriptions.service.d.ts.map +1 -1
  39. package/dist/src/lib/services/users.service.d.ts +0 -51
  40. package/dist/src/lib/services/users.service.d.ts.map +1 -1
  41. package/dist/src/lib/services/vendor-payments.service.d.ts +2 -50
  42. package/dist/src/lib/services/vendor-payments.service.d.ts.map +1 -1
  43. package/dist/src/lib/types/customer.d.ts +37 -18
  44. package/dist/src/lib/types/customer.d.ts.map +1 -1
  45. package/dist/src/lib/types/entity.d.ts +25 -26
  46. package/dist/src/lib/types/entity.d.ts.map +1 -1
  47. package/dist/src/lib/types/mercadopago.d.ts +11 -51
  48. package/dist/src/lib/types/mercadopago.d.ts.map +1 -1
  49. package/dist/src/lib/types/order-detail.d.ts +83 -13
  50. package/dist/src/lib/types/order-detail.d.ts.map +1 -1
  51. package/dist/src/lib/types/order-tax.d.ts +17 -16
  52. package/dist/src/lib/types/order-tax.d.ts.map +1 -1
  53. package/dist/src/lib/types/order.d.ts +72 -51
  54. package/dist/src/lib/types/order.d.ts.map +1 -1
  55. package/dist/src/lib/types/payment.d.ts +76 -18
  56. package/dist/src/lib/types/payment.d.ts.map +1 -1
  57. package/dist/src/lib/types/stripe.d.ts +22 -107
  58. package/dist/src/lib/types/stripe.d.ts.map +1 -1
  59. package/dist/src/lib/types/subscription-model.d.ts +40 -37
  60. package/dist/src/lib/types/subscription-model.d.ts.map +1 -1
  61. package/dist/src/lib/types/subscription.d.ts +55 -38
  62. package/dist/src/lib/types/subscription.d.ts.map +1 -1
  63. package/dist/src/lib/types/user.d.ts +33 -46
  64. package/dist/src/lib/types/user.d.ts.map +1 -1
  65. package/dist/src/lib/types/vendor-payment.d.ts +81 -41
  66. package/dist/src/lib/types/vendor-payment.d.ts.map +1 -1
  67. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -117,39 +117,80 @@ const orderMapper = {
117
117
  uniqueId: parseString(resource.attributes['unique_id']) || '',
118
118
  createdAt: parseDate(resource.attributes['created_at']) || new Date(),
119
119
  updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
120
- displayId: parseString(resource.attributes['display_id']),
121
- userUniqueId: parseString(resource.attributes['user_unique_id']) || '',
120
+ code: parseString(resource.attributes['code']),
121
+ displayUniqueId: parseString(resource.attributes['display_unique_id']),
122
+ parentUniqueId: parseString(resource.attributes['parent_unique_id']),
122
123
  customerUniqueId: parseString(resource.attributes['customer_unique_id']),
124
+ customerName: parseString(resource.attributes['customer_name']),
125
+ customerEmail: parseString(resource.attributes['customer_email']),
126
+ customerPhone: parseString(resource.attributes['customer_phone']),
127
+ customerNotes: parseString(resource.attributes['customer_notes']),
123
128
  status: parseOrderStatus(resource.attributes['status']),
129
+ logisticsStatus: parseString(resource.attributes['logistics_status']),
124
130
  subtotal: parseNumber(resource.attributes['subtotal']),
125
- tax: parseNumber(resource.attributes['tax']),
126
- shipping: parseNumber(resource.attributes['shipping']),
127
- delivery: parseNumber(resource.attributes['delivery']) || undefined,
128
131
  discount: parseNumber(resource.attributes['discount']),
132
+ discountValue: parseNumber(resource.attributes['discount_value']) || undefined,
133
+ delivery: parseNumber(resource.attributes['delivery']) || undefined,
134
+ tax: parseNumber(resource.attributes['tax']),
135
+ taxValue: parseNumber(resource.attributes['tax_value']) || undefined,
136
+ fees: parseNumber(resource.attributes['fees']) || undefined,
137
+ feesValue: parseNumber(resource.attributes['fees_value']) || undefined,
138
+ vendorDiscount: parseNumber(resource.attributes['vendor_discount']) || undefined,
139
+ vendorDiscountValue: parseNumber(resource.attributes['vendor_discount_value']) || undefined,
140
+ vendorPrice: parseNumber(resource.attributes['vendor_price']) || undefined,
141
+ openPrice: parseNumber(resource.attributes['open_price']) || undefined,
142
+ openStock: parseNumber(resource.attributes['open_stock']) || undefined,
129
143
  total: parseNumber(resource.attributes['total']),
144
+ balance: parseNumber(resource.attributes['balance']) || undefined,
130
145
  source: parseString(resource.attributes['source']),
131
146
  sourceAlias: parseString(resource.attributes['source_alias']),
132
147
  sourceId: parseString(resource.attributes['source_id']),
133
148
  sourceType: parseString(resource.attributes['source_type']),
134
- code: parseString(resource.attributes['code']),
135
- discountValue: parseNumber(resource.attributes['discount_value']) || undefined,
136
- taxValue: parseNumber(resource.attributes['tax_value']) || undefined,
137
- fees: parseNumber(resource.attributes['fees']) || undefined,
138
- feesValue: parseNumber(resource.attributes['fees_value']) || undefined,
139
- promoCode: parseString(resource.attributes['promo_code']),
140
149
  internalNotes: parseString(resource.attributes['internal_notes']),
141
150
  cartUniqueId: parseString(resource.attributes['cart_unique_id']),
142
151
  referredBy: parseString(resource.attributes['referred_by']),
143
- shippingAddressUniqueId: parseString(resource.attributes['shipping_address_unique_id']),
144
- billingAddressUniqueId: parseString(resource.attributes['billing_address_unique_id']),
145
- notes: parseString(resource.attributes['notes']),
152
+ promoCode: parseString(resource.attributes['promo_code']),
153
+ tips: parseNumber(resource.attributes['tips']) || undefined,
154
+ tipsValue: parseNumber(resource.attributes['tips_value']) || undefined,
146
155
  paidAt: parseDate(resource.attributes['paid_at']),
147
156
  shippedAt: parseDate(resource.attributes['shipped_at']),
148
- deliveredAt: parseDate(resource.attributes['delivered_at']),
149
- payload: resource.attributes['payload']
157
+ deliveredAt: parseDate(resource.attributes['delivered_at'])
150
158
  })
151
159
  };
152
160
 
161
+ function buildOrderBody(data) {
162
+ const order = {};
163
+ if (data.code) order['code'] = data.code;
164
+ if (data.displayUniqueId) order['display_unique_id'] = data.displayUniqueId;
165
+ if (data.parentUniqueId) order['parent_unique_id'] = data.parentUniqueId;
166
+ if (data.customerUniqueId) order['customer_unique_id'] = data.customerUniqueId;
167
+ if (data.customerName) order['customer_name'] = data.customerName;
168
+ if (data.customerEmail) order['customer_email'] = data.customerEmail;
169
+ if (data.customerPhone) order['customer_phone'] = data.customerPhone;
170
+ if (data.customerNotes) order['customer_notes'] = data.customerNotes;
171
+ if (data.subtotal !== undefined) order['subtotal'] = data.subtotal;
172
+ if (data.discount !== undefined) order['discount'] = data.discount;
173
+ if (data.discountValue !== undefined) order['discount_value'] = data.discountValue;
174
+ if (data.delivery !== undefined) order['delivery'] = data.delivery;
175
+ if (data.tax !== undefined) order['tax'] = data.tax;
176
+ if (data.taxValue !== undefined) order['tax_value'] = data.taxValue;
177
+ if (data.fees !== undefined) order['fees'] = data.fees;
178
+ if (data.feesValue !== undefined) order['fees_value'] = data.feesValue;
179
+ if (data.vendorDiscount !== undefined) order['vendor_discount'] = data.vendorDiscount;
180
+ if (data.vendorDiscountValue !== undefined) order['vendor_discount_value'] = data.vendorDiscountValue;
181
+ if (data.vendorPrice !== undefined) order['vendor_price'] = data.vendorPrice;
182
+ if (data.openPrice !== undefined) order['open_price'] = data.openPrice;
183
+ if (data.openStock !== undefined) order['open_stock'] = data.openStock;
184
+ if (data.source) order['source'] = data.source;
185
+ if (data.sourceAlias) order['source_alias'] = data.sourceAlias;
186
+ if (data.sourceId) order['source_id'] = data.sourceId;
187
+ if (data.sourceType) order['source_type'] = data.sourceType;
188
+ if (data.internalNotes) order['internal_notes'] = data.internalNotes;
189
+ if (data.cartUniqueId) order['cart_unique_id'] = data.cartUniqueId;
190
+ if (data.referredBy) order['referred_by'] = data.referredBy;
191
+ if (data.promoCode) order['promo_code'] = data.promoCode;
192
+ return order;
193
+ }
153
194
  function createOrdersService(transport, _config) {
154
195
  return {
155
196
  async list (params) {
@@ -157,7 +198,11 @@ function createOrdersService(transport, _config) {
157
198
  if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
158
199
  if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
159
200
  if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
160
- if (params == null ? void 0 : params.userUniqueId) queryParams['user_unique_id'] = params.userUniqueId;
201
+ if (params == null ? void 0 : params.customerUniqueId) queryParams['customer_unique_id'] = params.customerUniqueId;
202
+ if (params == null ? void 0 : params.parentUniqueId) queryParams['parent_unique_id'] = params.parentUniqueId;
203
+ if (params == null ? void 0 : params.source) queryParams['source'] = params.source;
204
+ if (params == null ? void 0 : params.referredBy) queryParams['referred_by'] = params.referredBy;
205
+ if (params == null ? void 0 : params.promoCode) queryParams['promo_code'] = params.promoCode;
161
206
  if (params == null ? void 0 : params.startDate) queryParams['start_date'] = params.startDate.toISOString();
162
207
  if (params == null ? void 0 : params.endDate) queryParams['end_date'] = params.endDate.toISOString();
163
208
  if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
@@ -171,75 +216,67 @@ function createOrdersService(transport, _config) {
171
216
  return decodeOne(response, orderMapper);
172
217
  },
173
218
  async create (data) {
174
- const order = {};
175
- if (data.customerUniqueId) order['customer_unique_id'] = data.customerUniqueId;
176
- if (data.userUniqueId) order['user_unique_id'] = data.userUniqueId;
177
- if (data.subtotal !== undefined) order['subtotal'] = data.subtotal;
178
- if (data.source) order['source'] = data.source;
179
- if (data.sourceAlias) order['source_alias'] = data.sourceAlias;
180
- if (data.sourceId) order['source_id'] = data.sourceId;
181
- if (data.sourceType) order['source_type'] = data.sourceType;
182
- if (data.code) order['code'] = data.code;
183
- if (data.discount !== undefined) order['discount'] = data.discount;
184
- if (data.discountValue !== undefined) order['discount_value'] = data.discountValue;
185
- if (data.delivery !== undefined) order['delivery'] = data.delivery;
186
- if (data.tax !== undefined) order['tax'] = data.tax;
187
- if (data.taxValue !== undefined) order['tax_value'] = data.taxValue;
188
- if (data.fees !== undefined) order['fees'] = data.fees;
189
- if (data.feesValue !== undefined) order['fees_value'] = data.feesValue;
190
- if (data.promoCode) order['promo_code'] = data.promoCode;
191
- if (data.internalNotes) order['internal_notes'] = data.internalNotes;
192
- if (data.cartUniqueId) order['cart_unique_id'] = data.cartUniqueId;
193
- if (data.referredBy) order['referred_by'] = data.referredBy;
194
- if (data.shippingAddressUniqueId) order['shipping_address_unique_id'] = data.shippingAddressUniqueId;
195
- if (data.billingAddressUniqueId) order['billing_address_unique_id'] = data.billingAddressUniqueId;
196
- if (data.notes) order['notes'] = data.notes;
197
- if (data.payload) order['payload'] = data.payload;
198
219
  const response = await transport.post('/orders', {
199
- order
220
+ order: buildOrderBody(data)
200
221
  });
201
222
  return decodeOne(response, orderMapper);
202
223
  },
203
224
  async update (uniqueId, data) {
204
225
  const response = await transport.put(`/orders/${uniqueId}`, {
205
- order: {
206
- shipping_address_unique_id: data.shippingAddressUniqueId,
207
- billing_address_unique_id: data.billingAddressUniqueId,
208
- notes: data.notes,
209
- payload: data.payload
210
- }
226
+ order: buildOrderBody(data)
211
227
  });
212
228
  return decodeOne(response, orderMapper);
213
229
  },
214
- async cancel (uniqueId) {
215
- const response = await transport.put(`/orders/${uniqueId}/cancel`, {});
216
- return decodeOne(response, orderMapper);
217
- },
218
- async confirm (uniqueId) {
219
- const response = await transport.put(`/orders/${uniqueId}/confirm`, {});
230
+ async updateStatus (uniqueId, data) {
231
+ const body = {
232
+ status: data.status
233
+ };
234
+ if (data.source) body['source'] = data.source;
235
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
236
+ if (data.sourceId) body['source_id'] = data.sourceId;
237
+ if (data.sourceType) body['source_type'] = data.sourceType;
238
+ const response = await transport.put(`/orders/${uniqueId}/status`, {
239
+ order: body
240
+ });
220
241
  return decodeOne(response, orderMapper);
221
242
  },
222
- async ship (uniqueId, trackingNumber) {
223
- const response = await transport.put(`/orders/${uniqueId}/ship`, {
224
- order: {
225
- tracking_number: trackingNumber
226
- }
243
+ async updateLogistics (uniqueId, data) {
244
+ const body = {
245
+ logistics_status: data.logisticsStatus
246
+ };
247
+ if (data.source) body['source'] = data.source;
248
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
249
+ if (data.sourceId) body['source_id'] = data.sourceId;
250
+ if (data.sourceType) body['source_type'] = data.sourceType;
251
+ const response = await transport.put(`/orders/${uniqueId}/logistics`, {
252
+ order: body
227
253
  });
228
254
  return decodeOne(response, orderMapper);
229
255
  },
230
- async deliver (uniqueId) {
231
- const response = await transport.put(`/orders/${uniqueId}/deliver`, {});
256
+ async addTips (uniqueId, data) {
257
+ const body = {};
258
+ if (data.tips !== undefined) body['tips'] = data.tips;
259
+ if (data.tipsValue !== undefined) body['tips_value'] = data.tipsValue;
260
+ if (data.source) body['source'] = data.source;
261
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
262
+ if (data.sourceId) body['source_id'] = data.sourceId;
263
+ if (data.sourceType) body['source_type'] = data.sourceType;
264
+ const response = await transport.post(`/orders/${uniqueId}/tips/add`, {
265
+ order: body
266
+ });
232
267
  return decodeOne(response, orderMapper);
233
268
  },
234
- async listByUser (userUniqueId, params) {
235
- const queryParams = {};
269
+ async listByCustomer (customerUniqueId, params) {
270
+ const queryParams = {
271
+ customer_unique_id: customerUniqueId
272
+ };
236
273
  if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
237
274
  if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
238
275
  if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
239
276
  if (params == null ? void 0 : params.startDate) queryParams['start_date'] = params.startDate.toISOString();
240
277
  if (params == null ? void 0 : params.endDate) queryParams['end_date'] = params.endDate.toISOString();
241
278
  if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
242
- const response = await transport.get(`/users/${userUniqueId}/orders`, {
279
+ const response = await transport.get('/orders', {
243
280
  params: queryParams
244
281
  });
245
282
  return decodePageResult(response, orderMapper);
@@ -251,25 +288,85 @@ const orderDetailMapper = {
251
288
  type: 'OrderDetail',
252
289
  map: (resource)=>({
253
290
  id: resource.id,
254
- uniqueId: parseString(resource.attributes['unique_id']),
291
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
255
292
  createdAt: parseDate(resource.attributes['created_at']) || new Date(),
256
293
  updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
257
294
  orderUniqueId: parseString(resource.attributes['order_unique_id']) || '',
258
- productUniqueId: parseString(resource.attributes['product_unique_id']) || '',
259
- productVariationUniqueId: parseString(resource.attributes['product_variation_unique_id']),
260
- sku: parseString(resource.attributes['sku']) || '',
261
- name: parseString(resource.attributes['name']) || '',
295
+ source: parseString(resource.attributes['source']),
296
+ sourceAlias: parseString(resource.attributes['source_alias']),
297
+ sourceId: parseString(resource.attributes['source_id']),
298
+ sourceType: parseString(resource.attributes['source_type']),
299
+ productSku: parseString(resource.attributes['product_sku']),
300
+ productUniqueId: parseString(resource.attributes['product_unique_id']),
301
+ productName: parseString(resource.attributes['product_name']),
302
+ productDescription: parseString(resource.attributes['product_description']),
303
+ categoryName: parseString(resource.attributes['category_name']),
304
+ isVariation: resource.attributes['is_variation'] === true || resource.attributes['is_variation'] === 'true' || undefined,
305
+ variationSku: parseString(resource.attributes['variation_sku']),
306
+ productSize: parseString(resource.attributes['product_size']),
307
+ color: parseString(resource.attributes['color']),
308
+ extraVariation: parseString(resource.attributes['extra_variation']),
262
309
  quantity: parseNumber(resource.attributes['quantity']),
263
- unitPrice: parseNumber(resource.attributes['unit_price']),
310
+ notes: parseString(resource.attributes['notes']),
311
+ subtotal: parseNumber(resource.attributes['subtotal']),
264
312
  discount: parseNumber(resource.attributes['discount']),
313
+ discountValue: parseNumber(resource.attributes['discount_value']) || undefined,
265
314
  tax: parseNumber(resource.attributes['tax']),
315
+ taxValue: parseNumber(resource.attributes['tax_value']) || undefined,
316
+ fees: parseNumber(resource.attributes['fees']) || undefined,
317
+ feesValue: parseNumber(resource.attributes['fees_value']) || undefined,
318
+ tips: parseNumber(resource.attributes['tips']) || undefined,
319
+ tipsValue: parseNumber(resource.attributes['tips_value']) || undefined,
320
+ vendorDiscount: parseNumber(resource.attributes['vendor_discount']) || undefined,
321
+ vendorDiscountValue: parseNumber(resource.attributes['vendor_discount_value']) || undefined,
322
+ vendorPrice: parseNumber(resource.attributes['vendor_price']) || undefined,
266
323
  total: parseNumber(resource.attributes['total']),
267
- status: parseStatus(resource.attributes['status']),
268
- vendorUniqueId: parseString(resource.attributes['vendor_unique_id']),
269
- payload: resource.attributes['payload']
324
+ cartDetailUniqueId: parseString(resource.attributes['cart_detail_unique_id']),
325
+ referredBy: parseString(resource.attributes['referred_by']),
326
+ promoCode: parseString(resource.attributes['promo_code']),
327
+ orderCode: parseString(resource.attributes['order_code']),
328
+ status: parseString(resource.attributes['status']),
329
+ logisticsStatus: parseString(resource.attributes['logistics_status'])
270
330
  })
271
331
  };
272
332
 
333
+ function buildDetailBody(data) {
334
+ const detail = {};
335
+ if (data.source) detail['source'] = data.source;
336
+ if (data.sourceAlias) detail['source_alias'] = data.sourceAlias;
337
+ if (data.sourceId) detail['source_id'] = data.sourceId;
338
+ if (data.sourceType) detail['source_type'] = data.sourceType;
339
+ if (data.productSku) detail['product_sku'] = data.productSku;
340
+ if (data.productUniqueId) detail['product_unique_id'] = data.productUniqueId;
341
+ if (data.productName) detail['product_name'] = data.productName;
342
+ if (data.productDescription) detail['product_description'] = data.productDescription;
343
+ if (data.categoryName) detail['category_name'] = data.categoryName;
344
+ if (data.isVariation !== undefined) detail['is_variation'] = data.isVariation;
345
+ if (data.variationSku) detail['variation_sku'] = data.variationSku;
346
+ if (data.productSize) detail['product_size'] = data.productSize;
347
+ if (data.color) detail['color'] = data.color;
348
+ if (data.extraVariation) detail['extra_variation'] = data.extraVariation;
349
+ detail['quantity'] = data.quantity;
350
+ if (data.notes) detail['notes'] = data.notes;
351
+ if (data.subtotal !== undefined) detail['subtotal'] = data.subtotal;
352
+ if (data.discount !== undefined) detail['discount'] = data.discount;
353
+ if (data.discountValue !== undefined) detail['discount_value'] = data.discountValue;
354
+ if (data.tax !== undefined) detail['tax'] = data.tax;
355
+ if (data.taxValue !== undefined) detail['tax_value'] = data.taxValue;
356
+ if (data.fees !== undefined) detail['fees'] = data.fees;
357
+ if (data.feesValue !== undefined) detail['fees_value'] = data.feesValue;
358
+ if (data.tips !== undefined) detail['tips'] = data.tips;
359
+ if (data.tipsValue !== undefined) detail['tips_value'] = data.tipsValue;
360
+ if (data.vendorDiscount !== undefined) detail['vendor_discount'] = data.vendorDiscount;
361
+ if (data.vendorDiscountValue !== undefined) detail['vendor_discount_value'] = data.vendorDiscountValue;
362
+ if (data.vendorPrice !== undefined) detail['vendor_price'] = data.vendorPrice;
363
+ if (data.total !== undefined) detail['total'] = data.total;
364
+ if (data.cartDetailUniqueId) detail['cart_detail_unique_id'] = data.cartDetailUniqueId;
365
+ if (data.referredBy) detail['referred_by'] = data.referredBy;
366
+ if (data.promoCode) detail['promo_code'] = data.promoCode;
367
+ if (data.orderCode) detail['order_code'] = data.orderCode;
368
+ return detail;
369
+ }
273
370
  function createOrderDetailsService(transport, _config) {
274
371
  return {
275
372
  async list () {
@@ -280,15 +377,41 @@ function createOrderDetailsService(transport, _config) {
280
377
  const response = await transport.get(`/order_details/${uniqueId}`);
281
378
  return decodeOne(response, orderDetailMapper);
282
379
  },
283
- async update (uniqueId, data) {
284
- const response = await transport.put(`/order_details/${uniqueId}`, {
285
- details: {
286
- quantity: data.quantity,
287
- unit_price: data.unitPrice,
288
- discount: data.discount,
289
- tax: data.tax,
290
- payload: data.payload
291
- }
380
+ async create (orderUniqueId, data) {
381
+ const response = await transport.post(`/orders/${orderUniqueId}/details`, {
382
+ details: buildDetailBody(data)
383
+ });
384
+ return decodeOne(response, orderDetailMapper);
385
+ },
386
+ async update (orderUniqueId, detailUniqueId, data) {
387
+ const response = await transport.put(`/orders/${orderUniqueId}/details/${detailUniqueId}`, {
388
+ details: buildDetailBody(data)
389
+ });
390
+ return decodeOne(response, orderDetailMapper);
391
+ },
392
+ async updateStatus (orderUniqueId, detailUniqueId, data) {
393
+ const body = {
394
+ status: data.status
395
+ };
396
+ if (data.source) body['source'] = data.source;
397
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
398
+ if (data.sourceId) body['source_id'] = data.sourceId;
399
+ if (data.sourceType) body['source_type'] = data.sourceType;
400
+ const response = await transport.put(`/orders/${orderUniqueId}/details/${detailUniqueId}/status`, {
401
+ details: body
402
+ });
403
+ return decodeOne(response, orderDetailMapper);
404
+ },
405
+ async updateLogistics (orderUniqueId, detailUniqueId, data) {
406
+ const body = {
407
+ logistics_status: data.logisticsStatus
408
+ };
409
+ if (data.source) body['source'] = data.source;
410
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
411
+ if (data.sourceId) body['source_id'] = data.sourceId;
412
+ if (data.sourceType) body['source_type'] = data.sourceType;
413
+ const response = await transport.put(`/orders/${orderUniqueId}/details/${detailUniqueId}/logistics`, {
414
+ details: body
292
415
  });
293
416
  return decodeOne(response, orderDetailMapper);
294
417
  },
@@ -303,18 +426,33 @@ const orderTaxMapper = {
303
426
  type: 'OrderTax',
304
427
  map: (resource)=>({
305
428
  id: resource.id,
306
- uniqueId: parseString(resource.attributes['unique_id']),
307
- createdAt: parseDate(resource.attributes['created_at']) || new Date(),
308
- updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
429
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
309
430
  orderUniqueId: parseString(resource.attributes['order_unique_id']) || '',
310
- name: parseString(resource.attributes['name']) || '',
311
- rate: parseNumber(resource.attributes['rate']),
312
- amount: parseNumber(resource.attributes['amount']),
313
- type: parseString(resource.attributes['type']) || '',
314
- payload: resource.attributes['payload']
431
+ taxUniqueId: parseString(resource.attributes['tax_unique_id']),
432
+ name: parseString(resource.attributes['name']),
433
+ description: parseString(resource.attributes['description']),
434
+ level: parseString(resource.attributes['level']),
435
+ taxValue: parseNumber(resource.attributes['tax_value']) || undefined,
436
+ tax: parseNumber(resource.attributes['tax']) || undefined,
437
+ displayOrder: parseNumber(resource.attributes['display_order']) || undefined,
438
+ status: parseString(resource.attributes['status']),
439
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
440
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
315
441
  })
316
442
  };
317
443
 
444
+ function buildTaxBody(data) {
445
+ const body = {};
446
+ if (data.taxUniqueId) body['tax_unique_id'] = data.taxUniqueId;
447
+ if (data.name) body['name'] = data.name;
448
+ if (data.description) body['description'] = data.description;
449
+ if (data.level) body['level'] = data.level;
450
+ if (data.taxValue !== undefined) body['tax_value'] = data.taxValue;
451
+ if (data.tax !== undefined) body['tax'] = data.tax;
452
+ if (data.displayOrder !== undefined) body['display_order'] = data.displayOrder;
453
+ if (data.status) body['status'] = data.status;
454
+ return body;
455
+ }
318
456
  function createOrderTaxesService(transport, _config) {
319
457
  return {
320
458
  async list (orderUniqueId) {
@@ -327,25 +465,13 @@ function createOrderTaxesService(transport, _config) {
327
465
  },
328
466
  async create (orderUniqueId, data) {
329
467
  const response = await transport.post(`/orders/${orderUniqueId}/taxes`, {
330
- order_tax: {
331
- name: data.name,
332
- rate: data.rate,
333
- amount: data.amount,
334
- type: data.type,
335
- payload: data.payload
336
- }
468
+ order_tax: buildTaxBody(data)
337
469
  });
338
470
  return decodeOne(response, orderTaxMapper);
339
471
  },
340
472
  async update (orderUniqueId, uniqueId, data) {
341
473
  const response = await transport.put(`/orders/${orderUniqueId}/taxes/${uniqueId}`, {
342
- order_tax: {
343
- name: data.name,
344
- rate: data.rate,
345
- amount: data.amount,
346
- type: data.type,
347
- payload: data.payload
348
- }
474
+ order_tax: buildTaxBody(data)
349
475
  });
350
476
  return decodeOne(response, orderTaxMapper);
351
477
  },
@@ -359,21 +485,67 @@ const paymentMapper = {
359
485
  type: 'Payment',
360
486
  map: (resource)=>({
361
487
  id: resource.id,
362
- uniqueId: parseString(resource.attributes['unique_id']),
488
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
363
489
  createdAt: parseDate(resource.attributes['created_at']) || new Date(),
364
490
  updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
365
- orderUniqueId: parseString(resource.attributes['order_unique_id']) || '',
366
- paymentMethod: parseString(resource.attributes['payment_method']) || '',
367
- paymentProvider: parseString(resource.attributes['payment_provider']) || '',
368
- transactionId: parseString(resource.attributes['transaction_id']),
369
- amount: parseNumber(resource.attributes['amount']),
370
- currency: parseString(resource.attributes['currency']) || 'USD',
371
- status: parsePaymentStatus(resource.attributes['status']),
372
- paidAt: parseDate(resource.attributes['paid_at']),
373
- payload: resource.attributes['payload']
491
+ orderUniqueId: parseString(resource.attributes['order_unique_id']),
492
+ paymentType: parseString(resource.attributes['payment_type']),
493
+ gatewayUniqueId: parseString(resource.attributes['gateway_unique_id']),
494
+ gatewayName: parseString(resource.attributes['gateway_name']),
495
+ gatewayReference: parseString(resource.attributes['gateway_reference']),
496
+ gatewayOrderId: parseString(resource.attributes['gateway_order_id']),
497
+ gatewayFranchise: parseString(resource.attributes['gateway_franchise']),
498
+ gatewayPaymentType: parseString(resource.attributes['gateway_payment_type']),
499
+ gatewayTransactionId: parseString(resource.attributes['gateway_transaction_id']),
500
+ gatewayDescription: parseString(resource.attributes['gateway_description']),
501
+ gatewaySubtotal: parseNumber(resource.attributes['gateway_subtotal']) || undefined,
502
+ gatewayDiscount: parseNumber(resource.attributes['gateway_discount']) || undefined,
503
+ gatewayDiscountValue: parseNumber(resource.attributes['gateway_discount_value']) || undefined,
504
+ gatewayDelivery: parseNumber(resource.attributes['gateway_delivery']) || undefined,
505
+ gatewayTax: parseNumber(resource.attributes['gateway_tax']) || undefined,
506
+ gatewayTaxValue: parseNumber(resource.attributes['gateway_tax_value']) || undefined,
507
+ gatewayFees: parseNumber(resource.attributes['gateway_fees']) || undefined,
508
+ gatewayFeesValue: parseNumber(resource.attributes['gateway_fees_value']) || undefined,
509
+ gatewayTips: parseNumber(resource.attributes['gateway_tips']) || undefined,
510
+ gatewayTipsValue: parseNumber(resource.attributes['gateway_tips_value']) || undefined,
511
+ gatewayTotal: parseNumber(resource.attributes['gateway_total']) || undefined,
512
+ gatewayBalance: parseNumber(resource.attributes['gateway_balance']) || undefined,
513
+ gatewayPaidAt: parseDate(resource.attributes['gateway_paid_at']),
514
+ gatewayStatus: parseString(resource.attributes['gateway_status']),
515
+ gatewayResponse: parseString(resource.attributes['gateway_response']),
516
+ status: parseString(resource.attributes['status']),
517
+ paidAt: parseDate(resource.attributes['paid_at'])
374
518
  })
375
519
  };
376
520
 
521
+ function buildPaymentBody(data) {
522
+ const payment = {};
523
+ if (data.gatewayUniqueId) payment['gateway_unique_id'] = data.gatewayUniqueId;
524
+ if (data.gatewayName) payment['gateway_name'] = data.gatewayName;
525
+ if (data.gatewayReference) payment['gateway_reference'] = data.gatewayReference;
526
+ if (data.gatewayOrderId) payment['gateway_order_id'] = data.gatewayOrderId;
527
+ if (data.gatewayFranchise) payment['gateway_franchise'] = data.gatewayFranchise;
528
+ if (data.gatewayPaymentType) payment['gateway_payment_type'] = data.gatewayPaymentType;
529
+ if (data.gatewayTransactionId) payment['gateway_transaction_id'] = data.gatewayTransactionId;
530
+ if (data.gatewayDescription) payment['gateway_description'] = data.gatewayDescription;
531
+ if (data.gatewaySubtotal !== undefined) payment['gateway_subtotal'] = data.gatewaySubtotal;
532
+ if (data.gatewayDiscount !== undefined) payment['gateway_discount'] = data.gatewayDiscount;
533
+ if (data.gatewayDiscountValue !== undefined) payment['gateway_discount_value'] = data.gatewayDiscountValue;
534
+ if (data.gatewayDelivery !== undefined) payment['gateway_delivery'] = data.gatewayDelivery;
535
+ if (data.gatewayTax !== undefined) payment['gateway_tax'] = data.gatewayTax;
536
+ if (data.gatewayTaxValue !== undefined) payment['gateway_tax_value'] = data.gatewayTaxValue;
537
+ if (data.gatewayFees !== undefined) payment['gateway_fees'] = data.gatewayFees;
538
+ if (data.gatewayFeesValue !== undefined) payment['gateway_fees_value'] = data.gatewayFeesValue;
539
+ if (data.gatewayTips !== undefined) payment['gateway_tips'] = data.gatewayTips;
540
+ if (data.gatewayTipsValue !== undefined) payment['gateway_tips_value'] = data.gatewayTipsValue;
541
+ if (data.gatewayTotal !== undefined) payment['gateway_total'] = data.gatewayTotal;
542
+ if (data.gatewayBalance !== undefined) payment['gateway_balance'] = data.gatewayBalance;
543
+ if (data.gatewayPaidAt) payment['gateway_paid_at'] = data.gatewayPaidAt;
544
+ if (data.gatewayStatus) payment['gateway_status'] = data.gatewayStatus;
545
+ if (data.gatewayResponse) payment['gateway_response'] = data.gatewayResponse;
546
+ if (data.paymentType) payment['payment_type'] = data.paymentType;
547
+ return payment;
548
+ }
377
549
  function createPaymentsService(transport, _config) {
378
550
  return {
379
551
  async list (params) {
@@ -382,7 +554,7 @@ function createPaymentsService(transport, _config) {
382
554
  if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
383
555
  if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
384
556
  if (params == null ? void 0 : params.orderUniqueId) queryParams['order_unique_id'] = params.orderUniqueId;
385
- if (params == null ? void 0 : params.paymentMethod) queryParams['payment_method'] = params.paymentMethod;
557
+ if (params == null ? void 0 : params.paymentType) queryParams['payment_type'] = params.paymentType;
386
558
  if (params == null ? void 0 : params.startDate) queryParams['start_date'] = params.startDate.toISOString();
387
559
  if (params == null ? void 0 : params.endDate) queryParams['end_date'] = params.endDate.toISOString();
388
560
  if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
@@ -395,25 +567,36 @@ function createPaymentsService(transport, _config) {
395
567
  const response = await transport.get(`/payments/${uniqueId}`);
396
568
  return decodeOne(response, paymentMapper);
397
569
  },
398
- async create (data) {
399
- const response = await transport.post('/payments', {
400
- payment: {
401
- order_unique_id: data.orderUniqueId,
402
- payment_method: data.paymentMethod,
403
- payment_provider: data.paymentProvider,
404
- amount: data.amount,
405
- currency: data.currency,
406
- transaction_id: data.transactionId,
407
- payload: data.payload
408
- }
570
+ async create (orderUniqueId, data) {
571
+ const response = await transport.post(`/orders/${orderUniqueId}/payments`, {
572
+ payment: buildPaymentBody(data)
409
573
  });
410
574
  return decodeOne(response, paymentMapper);
411
575
  },
412
- async refund (uniqueId, amount) {
413
- const response = await transport.put(`/payments/${uniqueId}/refund`, {
414
- payment: {
415
- amount
416
- }
576
+ async createPaymentMethod (orderUniqueId, data) {
577
+ const body = {};
578
+ if (data.paymentType) body['payment_type'] = data.paymentType;
579
+ if (data.city) body['city'] = data.city;
580
+ if (data.country) body['country'] = data.country;
581
+ if (data.line1) body['line1'] = data.line1;
582
+ if (data.line2) body['line2'] = data.line2;
583
+ if (data.postalCode) body['postal_code'] = data.postalCode;
584
+ if (data.state) body['state'] = data.state;
585
+ if (data.brand) body['brand'] = data.brand;
586
+ if (data.cardCountry) body['card_country'] = data.cardCountry;
587
+ if (data.expMonth) body['exp_month'] = data.expMonth;
588
+ if (data.expYear) body['exp_year'] = data.expYear;
589
+ if (data.fingerprint) body['fingerprint'] = data.fingerprint;
590
+ if (data.last4) body['last4'] = data.last4;
591
+ if (data.paymentProcessorName) body['payment_processor_name'] = data.paymentProcessorName;
592
+ if (data.paymentProcessorId) body['payment_processor_id'] = data.paymentProcessorId;
593
+ if (data.customerUniqueId) body['customer_unique_id'] = data.customerUniqueId;
594
+ if (data.customerName) body['customer_name'] = data.customerName;
595
+ if (data.customerEmail) body['customer_email'] = data.customerEmail;
596
+ if (data.bankName) body['bank_name'] = data.bankName;
597
+ if (data.accountNumber) body['account_number'] = data.accountNumber;
598
+ const response = await transport.post(`/orders/${orderUniqueId}/payments/method`, {
599
+ payment: body
417
600
  });
418
601
  return decodeOne(response, paymentMapper);
419
602
  },
@@ -425,27 +608,80 @@ function createPaymentsService(transport, _config) {
425
608
  }
426
609
 
427
610
  const subscriptionMapper = {
428
- type: 'Subscription',
429
- map: (resource)=>({
611
+ type: 'subscription',
612
+ map: (resource)=>{
613
+ 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;
614
+ return {
430
615
  id: resource.id,
431
- uniqueId: parseString(resource.attributes['unique_id']),
432
- createdAt: parseDate(resource.attributes['created_at']) || new Date(),
433
- updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
434
- userUniqueId: parseString(resource.attributes['user_unique_id']) || '',
435
- planUniqueId: parseString(resource.attributes['plan_unique_id']) || '',
436
- planName: parseString(resource.attributes['plan_name']) || '',
437
- price: parseNumber(resource.attributes['price']),
438
- currency: parseString(resource.attributes['currency']) || 'USD',
439
- interval: parseSubscriptionInterval(resource.attributes['interval']),
440
- status: parseSubscriptionStatus(resource.attributes['status']),
441
- startDate: parseDate(resource.attributes['start_date']) || new Date(),
442
- endDate: parseDate(resource.attributes['end_date']),
443
- nextBillingDate: parseDate(resource.attributes['next_billing_date']),
444
- cancelledAt: parseDate(resource.attributes['cancelled_at']),
445
- payload: resource.attributes['payload']
446
- })
616
+ uniqueId: parseString((_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id']) || '',
617
+ stripeCustomerId: parseString((_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['stripe_customer_id']),
618
+ accountUniqueId: parseString((_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['account_unique_id']),
619
+ accountCode: parseString((_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['account_code']),
620
+ accountName: parseString((_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['account_name']),
621
+ currency: parseString((_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['currency']),
622
+ billingInterval: parseString((_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['billing_interval']),
623
+ trialPeriodDays: parseNumber((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['trial_period_days']) || undefined,
624
+ status: parseString((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['status']),
625
+ metadata: (_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['metadata'],
626
+ createdAt: parseDate((_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['created_at']) || new Date(),
627
+ updatedAt: parseDate((_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['updated_at']) || new Date()
628
+ };
629
+ }
630
+ };
631
+ const subscriptionItemMapper = {
632
+ type: 'subscription_item',
633
+ map: (resource)=>{
634
+ 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;
635
+ return {
636
+ id: resource.id,
637
+ uniqueId: parseString((_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id']) || '',
638
+ subscriptionUniqueId: parseString((_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['subscription_unique_id']),
639
+ stripePriceId: parseString((_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['stripe_price_id']),
640
+ stripeProductId: parseString((_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['stripe_product_id']),
641
+ blockCode: parseString((_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['block_code']),
642
+ blockName: parseString((_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['block_name']),
643
+ appUniqueId: parseString((_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['app_unique_id']),
644
+ appName: parseString((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['app_name']),
645
+ appBlockUniqueId: parseString((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['app_block_unique_id']),
646
+ amountCents: parseNumber((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['amount_cents']) || undefined,
647
+ quantity: parseNumber((_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['quantity']) || undefined,
648
+ status: parseString((_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['status']),
649
+ metadata: (_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['metadata'],
650
+ createdAt: parseDate((_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['created_at']) || new Date(),
651
+ updatedAt: parseDate((_resource_attributes14 = resource.attributes) == null ? void 0 : _resource_attributes14['updated_at']) || new Date()
652
+ };
653
+ }
447
654
  };
448
655
 
656
+ function buildItemBody(data) {
657
+ const body = {};
658
+ if (data.stripePriceId) body['stripe_price_id'] = data.stripePriceId;
659
+ if (data.stripeProductId) body['stripe_product_id'] = data.stripeProductId;
660
+ if (data.blockCode) body['block_code'] = data.blockCode;
661
+ if (data.blockName) body['block_name'] = data.blockName;
662
+ if (data.appUniqueId) body['app_unique_id'] = data.appUniqueId;
663
+ if (data.appName) body['app_name'] = data.appName;
664
+ if (data.appBlockUniqueId) body['app_block_unique_id'] = data.appBlockUniqueId;
665
+ if (data.amountCents !== undefined) body['amount_cents'] = data.amountCents;
666
+ if (data.quantity !== undefined) body['quantity'] = data.quantity;
667
+ if (data.metadata) body['metadata'] = data.metadata;
668
+ return body;
669
+ }
670
+ function buildSubscriptionBody$1(data) {
671
+ const body = {};
672
+ if (data.stripeCustomerId) body['stripe_customer_id'] = data.stripeCustomerId;
673
+ if (data.accountUniqueId) body['account_unique_id'] = data.accountUniqueId;
674
+ if (data.accountCode) body['account_code'] = data.accountCode;
675
+ if (data.accountName) body['account_name'] = data.accountName;
676
+ if (data.currency) body['currency'] = data.currency;
677
+ if (data.billingInterval) body['billing_interval'] = data.billingInterval;
678
+ if (data.trialPeriodDays !== undefined) body['trial_period_days'] = data.trialPeriodDays;
679
+ if (data.metadata) body['metadata'] = data.metadata;
680
+ if (data.items) {
681
+ body['items'] = data.items.map((item)=>buildItemBody(item));
682
+ }
683
+ return body;
684
+ }
449
685
  function createSubscriptionsService(transport, _config) {
450
686
  return {
451
687
  async list (params) {
@@ -453,9 +689,6 @@ function createSubscriptionsService(transport, _config) {
453
689
  if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
454
690
  if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
455
691
  if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
456
- if (params == null ? void 0 : params.userUniqueId) queryParams['user_unique_id'] = params.userUniqueId;
457
- if (params == null ? void 0 : params.planUniqueId) queryParams['plan_unique_id'] = params.planUniqueId;
458
- if (params == null ? void 0 : params.interval) queryParams['interval'] = params.interval;
459
692
  if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
460
693
  const response = await transport.get('/subscriptions', {
461
694
  params: queryParams
@@ -467,62 +700,16 @@ function createSubscriptionsService(transport, _config) {
467
700
  return decodeOne(response, subscriptionMapper);
468
701
  },
469
702
  async create (data) {
470
- var _data_startDate;
471
703
  const response = await transport.post('/subscriptions', {
472
- subscription: {
473
- user_unique_id: data.userUniqueId,
474
- plan_unique_id: data.planUniqueId,
475
- plan_name: data.planName,
476
- price: data.price,
477
- currency: data.currency,
478
- interval: data.interval,
479
- start_date: (_data_startDate = data.startDate) == null ? void 0 : _data_startDate.toISOString(),
480
- payload: data.payload
481
- }
704
+ subscription: buildSubscriptionBody$1(data)
482
705
  });
483
706
  return decodeOne(response, subscriptionMapper);
484
707
  },
485
- async update (uniqueId, data) {
486
- var _data_endDate, _data_nextBillingDate;
487
- const response = await transport.put(`/subscriptions/${uniqueId}`, {
488
- subscription: {
489
- plan_unique_id: data.planUniqueId,
490
- plan_name: data.planName,
491
- price: data.price,
492
- currency: data.currency,
493
- interval: data.interval,
494
- status: data.status,
495
- end_date: (_data_endDate = data.endDate) == null ? void 0 : _data_endDate.toISOString(),
496
- next_billing_date: (_data_nextBillingDate = data.nextBillingDate) == null ? void 0 : _data_nextBillingDate.toISOString(),
497
- payload: data.payload
498
- }
708
+ async addItem (subscriptionUniqueId, data) {
709
+ const response = await transport.post(`/subscriptions/${subscriptionUniqueId}/items`, {
710
+ item: buildItemBody(data)
499
711
  });
500
- return decodeOne(response, subscriptionMapper);
501
- },
502
- async cancel (uniqueId) {
503
- const response = await transport.put(`/subscriptions/${uniqueId}/cancel`, {});
504
- return decodeOne(response, subscriptionMapper);
505
- },
506
- async pause (uniqueId) {
507
- const response = await transport.put(`/subscriptions/${uniqueId}/pause`, {});
508
- return decodeOne(response, subscriptionMapper);
509
- },
510
- async resume (uniqueId) {
511
- const response = await transport.put(`/subscriptions/${uniqueId}/resume`, {});
512
- return decodeOne(response, subscriptionMapper);
513
- },
514
- async listByUser (userUniqueId, params) {
515
- const queryParams = {};
516
- if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
517
- if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
518
- if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
519
- if (params == null ? void 0 : params.planUniqueId) queryParams['plan_unique_id'] = params.planUniqueId;
520
- if (params == null ? void 0 : params.interval) queryParams['interval'] = params.interval;
521
- if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
522
- const response = await transport.get(`/users/${userUniqueId}/subscriptions`, {
523
- params: queryParams
524
- });
525
- return decodePageResult(response, subscriptionMapper);
712
+ return decodeOne(response, subscriptionItemMapper);
526
713
  }
527
714
  };
528
715
  }
@@ -530,31 +717,62 @@ function createSubscriptionsService(transport, _config) {
530
717
  const subscriptionModelMapper = {
531
718
  type: 'subscription_model',
532
719
  map: (resource)=>{
533
- 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;
534
- var _resource_attributes_allow_promotion_codes;
720
+ 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;
535
721
  return {
536
722
  id: resource.id,
537
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
538
- code: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['code'],
539
- name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
540
- description: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['description'],
541
- price: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['price'],
542
- currency: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['currency'],
543
- interval: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['interval'],
544
- intervalCount: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['interval_count'],
545
- trialDays: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['trial_days'],
546
- features: (_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['features'],
547
- limits: (_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['limits'],
548
- enabled: (_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['enabled'],
549
- allowPromotionCodes: (_resource_attributes_allow_promotion_codes = (_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['allow_promotion_codes']) != null ? _resource_attributes_allow_promotion_codes : false,
550
- status: (_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['status'],
551
- payload: (_resource_attributes14 = resource.attributes) == null ? void 0 : _resource_attributes14['payload'],
552
- createdAt: parseDate((_resource_attributes15 = resource.attributes) == null ? void 0 : _resource_attributes15['created_at']),
553
- updatedAt: parseDate((_resource_attributes16 = resource.attributes) == null ? void 0 : _resource_attributes16['updated_at'])
723
+ uniqueId: parseString((_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id']) || '',
724
+ code: parseString((_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['code']),
725
+ description: parseString((_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['description']),
726
+ promotional: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['promotional'],
727
+ programCode: parseString((_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['program_code']),
728
+ duration: parseNumber((_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['duration']) || undefined,
729
+ durationUnit: parseString((_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['duration_unit']),
730
+ durationDescription: parseString((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['duration_description']),
731
+ recurringPaymentFees: parseNumber((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['recurring_payment_fees']) || undefined,
732
+ recurringPaymentAmount: parseNumber((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['recurring_payment_amount']) || undefined,
733
+ contentUrl: parseString((_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['content_url']),
734
+ startAt: parseDate((_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['start_at']),
735
+ endAt: parseDate((_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['end_at']),
736
+ initialPayment: parseNumber((_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['initial_payment']) || undefined,
737
+ subscriptionType: parseString((_resource_attributes14 = resource.attributes) == null ? void 0 : _resource_attributes14['subscription_type']),
738
+ maxItems: parseNumber((_resource_attributes15 = resource.attributes) == null ? void 0 : _resource_attributes15['max_items']) || undefined,
739
+ stripeProductId: parseString((_resource_attributes16 = resource.attributes) == null ? void 0 : _resource_attributes16['stripe_product_id']),
740
+ productType: parseString((_resource_attributes17 = resource.attributes) == null ? void 0 : _resource_attributes17['product_type']),
741
+ trialPeriodDays: parseNumber((_resource_attributes18 = resource.attributes) == null ? void 0 : _resource_attributes18['trial_period_days']) || undefined,
742
+ allowPromotionCodes: (_resource_attributes19 = resource.attributes) == null ? void 0 : _resource_attributes19['allow_promotion_codes'],
743
+ features: (_resource_attributes20 = resource.attributes) == null ? void 0 : _resource_attributes20['features'],
744
+ status: parseString((_resource_attributes21 = resource.attributes) == null ? void 0 : _resource_attributes21['status']),
745
+ createdAt: parseDate((_resource_attributes22 = resource.attributes) == null ? void 0 : _resource_attributes22['created_at']) || new Date(),
746
+ updatedAt: parseDate((_resource_attributes23 = resource.attributes) == null ? void 0 : _resource_attributes23['updated_at']) || new Date()
554
747
  };
555
748
  }
556
749
  };
557
750
 
751
+ function buildSubModelBody(data) {
752
+ const body = {};
753
+ if (data.uniqueId) body['unique_id'] = data.uniqueId;
754
+ if (data.code) body['code'] = data.code;
755
+ if (data.description) body['description'] = data.description;
756
+ if (data.promotional !== undefined) body['promotional'] = data.promotional;
757
+ if (data.programCode) body['program_code'] = data.programCode;
758
+ if (data.duration !== undefined) body['duration'] = data.duration;
759
+ if (data.durationUnit) body['duration_unit'] = data.durationUnit;
760
+ if (data.durationDescription) body['duration_description'] = data.durationDescription;
761
+ if (data.recurringPaymentFees !== undefined) body['recurring_payment_fees'] = data.recurringPaymentFees;
762
+ if (data.recurringPaymentAmount !== undefined) body['recurring_payment_amount'] = data.recurringPaymentAmount;
763
+ if (data.contentUrl) body['content_url'] = data.contentUrl;
764
+ if (data.startAt) body['start_at'] = data.startAt;
765
+ if (data.endAt) body['end_at'] = data.endAt;
766
+ if (data.initialPayment !== undefined) body['initial_payment'] = data.initialPayment;
767
+ if (data.subscriptionType) body['subscription_type'] = data.subscriptionType;
768
+ if (data.maxItems !== undefined) body['max_items'] = data.maxItems;
769
+ if (data.stripeProductId) body['stripe_product_id'] = data.stripeProductId;
770
+ if (data.productType) body['product_type'] = data.productType;
771
+ if (data.trialPeriodDays !== undefined) body['trial_period_days'] = data.trialPeriodDays;
772
+ if (data.allowPromotionCodes !== undefined) body['allow_promotion_codes'] = data.allowPromotionCodes;
773
+ if (data.features) body['features'] = data.features;
774
+ return body;
775
+ }
558
776
  function createSubscriptionModelsService(transport, _config) {
559
777
  return {
560
778
  async list (params) {
@@ -575,40 +793,13 @@ function createSubscriptionModelsService(transport, _config) {
575
793
  },
576
794
  async create (data) {
577
795
  const response = await transport.post('/subscription_models', {
578
- subscription_model: {
579
- code: data.code,
580
- name: data.name,
581
- description: data.description,
582
- price: data.price,
583
- currency: data.currency,
584
- interval: data.interval,
585
- interval_count: data.intervalCount,
586
- trial_days: data.trialDays,
587
- features: data.features,
588
- limits: data.limits,
589
- payload: data.payload,
590
- allow_promotion_codes: data.allowPromotionCodes
591
- }
796
+ subscription_model: buildSubModelBody(data)
592
797
  });
593
798
  return decodeOne(response, subscriptionModelMapper);
594
799
  },
595
800
  async update (uniqueId, data) {
596
801
  const response = await transport.put(`/subscription_models/${uniqueId}`, {
597
- subscription_model: {
598
- name: data.name,
599
- description: data.description,
600
- price: data.price,
601
- currency: data.currency,
602
- interval: data.interval,
603
- interval_count: data.intervalCount,
604
- trial_days: data.trialDays,
605
- features: data.features,
606
- limits: data.limits,
607
- enabled: data.enabled,
608
- status: data.status,
609
- payload: data.payload,
610
- allow_promotion_codes: data.allowPromotionCodes
611
- }
802
+ subscription_model: buildSubModelBody(data)
612
803
  });
613
804
  return decodeOne(response, subscriptionModelMapper);
614
805
  }
@@ -618,18 +809,21 @@ function createSubscriptionModelsService(transport, _config) {
618
809
  const salesEntityMapper = {
619
810
  type: 'entity',
620
811
  map: (resource)=>{
621
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8;
812
+ 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;
622
813
  return {
623
814
  id: resource.id,
624
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
625
- code: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['code'],
626
- name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
627
- email: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['email'],
628
- phone: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['phone'],
629
- status: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['status'],
630
- payload: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['payload'],
631
- createdAt: parseDate((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['created_at']),
632
- updatedAt: parseDate((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['updated_at'])
815
+ uniqueId: parseString((_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id']) || '',
816
+ entityType: parseString((_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['entity_type']),
817
+ entityAlias: parseString((_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['entity_alias']),
818
+ entitySource: parseString((_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['entity_source']),
819
+ entityUrl: parseString((_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['entity_url']),
820
+ stripeId: parseString((_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['stripe_id']),
821
+ status: parseString((_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['status']),
822
+ timeZone: parseString((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['time_zone']),
823
+ preferredLanguage: parseString((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['preferred_language']),
824
+ avatarUrl: parseString((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['avatar_url']),
825
+ createdAt: parseDate((_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['created_at']) || new Date(),
826
+ updatedAt: parseDate((_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['updated_at']) || new Date()
633
827
  };
634
828
  }
635
829
  };
@@ -637,24 +831,38 @@ const salesEntityMapper = {
637
831
  const entitySubscriptionMapper = {
638
832
  type: 'EntitySubscription',
639
833
  map: (resource)=>{
640
- var _resource_attributes_subscription_unique_id, _resource_attributes_subscription_model_unique_id, _resource_attributes_start_at, _resource_attributes_end_at, _resource_attributes_closed_at, _resource_attributes_created_at, _parseDate, _resource_attributes_updated_at, _parseDate1;
834
+ var _resource_attributes_subscription_unique_id, _resource_attributes_subscription_model_unique_id, _resource_attributes_start_at, _resource_attributes_end_at, _resource_attributes_closed_at, _resource_attributes_created_at, _resource_attributes_updated_at;
641
835
  return {
642
836
  id: resource.id,
643
- uniqueId: (_resource_attributes_subscription_unique_id = resource.attributes['subscription_unique_id']) != null ? _resource_attributes_subscription_unique_id : resource.attributes['unique_id'],
644
- entityUniqueId: resource.attributes['entity_unique_id'],
645
- subscriptionModelUniqueId: (_resource_attributes_subscription_model_unique_id = resource.attributes['subscription_model_unique_id']) != null ? _resource_attributes_subscription_model_unique_id : resource.attributes['code'],
646
- status: resource.attributes['status'],
837
+ uniqueId: parseString((_resource_attributes_subscription_unique_id = resource.attributes['subscription_unique_id']) != null ? _resource_attributes_subscription_unique_id : resource.attributes['unique_id']) || '',
838
+ entityUniqueId: resource.attributes['entity_unique_id'] || '',
839
+ subscriptionModelUniqueId: parseString((_resource_attributes_subscription_model_unique_id = resource.attributes['subscription_model_unique_id']) != null ? _resource_attributes_subscription_model_unique_id : resource.attributes['code']) || '',
840
+ ownerUniqueId: parseString(resource.attributes['owner_unique_id']),
841
+ ownerType: parseString(resource.attributes['owner_type']),
842
+ status: resource.attributes['status'] || '',
647
843
  startDate: parseDate((_resource_attributes_start_at = resource.attributes['start_at']) != null ? _resource_attributes_start_at : resource.attributes['start_date']),
648
844
  endDate: parseDate((_resource_attributes_end_at = resource.attributes['end_at']) != null ? _resource_attributes_end_at : resource.attributes['end_date']),
649
845
  trialEndDate: parseDate(resource.attributes['trial_end_date']),
650
846
  cancelledAt: parseDate((_resource_attributes_closed_at = resource.attributes['closed_at']) != null ? _resource_attributes_closed_at : resource.attributes['cancelled_at']),
651
- payload: resource.attributes['payload'],
652
- createdAt: (_parseDate = parseDate((_resource_attributes_created_at = resource.attributes['created_at']) != null ? _resource_attributes_created_at : resource.attributes['subscribed_at'])) != null ? _parseDate : new Date(),
653
- updatedAt: (_parseDate1 = parseDate((_resource_attributes_updated_at = resource.attributes['updated_at']) != null ? _resource_attributes_updated_at : resource.attributes['subscribed_at'])) != null ? _parseDate1 : new Date()
847
+ createdAt: parseDate((_resource_attributes_created_at = resource.attributes['created_at']) != null ? _resource_attributes_created_at : resource.attributes['subscribed_at']) || new Date(),
848
+ updatedAt: parseDate((_resource_attributes_updated_at = resource.attributes['updated_at']) != null ? _resource_attributes_updated_at : resource.attributes['subscribed_at']) || new Date()
654
849
  };
655
850
  }
656
851
  };
657
852
 
853
+ function buildEntityBody(data) {
854
+ const body = {};
855
+ if (data.entityType) body['entity_type'] = data.entityType;
856
+ if (data.entityAlias) body['entity_alias'] = data.entityAlias;
857
+ if (data.entitySource) body['entity_source'] = data.entitySource;
858
+ if (data.entityUrl) body['entity_url'] = data.entityUrl;
859
+ if (data.stripeId) body['stripe_id'] = data.stripeId;
860
+ if (data.status) body['status'] = data.status;
861
+ if (data.timeZone) body['time_zone'] = data.timeZone;
862
+ if (data.preferredLanguage) body['preferred_language'] = data.preferredLanguage;
863
+ if (data.avatarUrl) body['avatar_url'] = data.avatarUrl;
864
+ return body;
865
+ }
658
866
  function createSalesEntitiesService(transport, _config) {
659
867
  return {
660
868
  async list (params) {
@@ -675,25 +883,13 @@ function createSalesEntitiesService(transport, _config) {
675
883
  },
676
884
  async register (uniqueId, data) {
677
885
  const response = await transport.post(`/entities/${uniqueId}/register`, {
678
- entity: {
679
- code: data == null ? void 0 : data.code,
680
- name: data == null ? void 0 : data.name,
681
- email: data == null ? void 0 : data.email,
682
- phone: data == null ? void 0 : data.phone,
683
- payload: data == null ? void 0 : data.payload
684
- }
886
+ entity: data ? buildEntityBody(data) : {}
685
887
  });
686
888
  return decodeOne(response, salesEntityMapper);
687
889
  },
688
890
  async update (uniqueId, data) {
689
891
  const response = await transport.put(`/entities/${uniqueId}`, {
690
- entity: {
691
- name: data.name,
692
- email: data.email,
693
- phone: data.phone,
694
- status: data.status,
695
- payload: data.payload
696
- }
892
+ entity: buildEntityBody(data)
697
893
  });
698
894
  return decodeOne(response, salesEntityMapper);
699
895
  },
@@ -701,9 +897,8 @@ function createSalesEntitiesService(transport, _config) {
701
897
  const response = await transport.post(`/entities/${uniqueId}/subscriptions`, {
702
898
  subscription: {
703
899
  subscription_model_unique_id: data.subscriptionModelUniqueId,
704
- start_date: data.startDate,
705
- trial_end_date: data.trialEndDate,
706
- payload: data.payload
900
+ owner_unique_id: data.ownerUniqueId,
901
+ owner_type: data.ownerType
707
902
  }
708
903
  });
709
904
  return decodeOne(response, entitySubscriptionMapper);
@@ -711,9 +906,9 @@ function createSalesEntitiesService(transport, _config) {
711
906
  async updateSubscription (uniqueId, subscriptionUniqueId, data) {
712
907
  const response = await transport.put(`/entities/${uniqueId}/subscriptions/${subscriptionUniqueId}`, {
713
908
  subscription: {
714
- status: data.status,
715
- end_date: data.endDate,
716
- payload: data.payload
909
+ subscription_model_unique_id: data.subscriptionModelUniqueId,
910
+ owner_unique_id: data.ownerUniqueId,
911
+ owner_type: data.ownerType
717
912
  }
718
913
  });
719
914
  return decodeOne(response, entitySubscriptionMapper);
@@ -724,17 +919,28 @@ function createSalesEntitiesService(transport, _config) {
724
919
  const salesUserMapper = {
725
920
  type: 'user',
726
921
  map: (resource)=>{
727
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7;
922
+ 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;
728
923
  return {
729
924
  id: resource.id,
730
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
731
- email: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['email'],
732
- name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
733
- phone: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['phone'],
734
- status: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['status'],
735
- payload: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['payload'],
736
- createdAt: parseDate((_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['created_at']),
737
- updatedAt: parseDate((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['updated_at'])
925
+ uniqueId: parseString((_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id']) || '',
926
+ name: parseString((_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['name']),
927
+ firstName: parseString((_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['first_name']),
928
+ lastName: parseString((_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['last_name']),
929
+ email: parseString((_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['email']),
930
+ phone: parseString((_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['phone']),
931
+ avatarUrl: parseString((_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['avatar_url']),
932
+ roleName: parseString((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['role_name']),
933
+ roleUniqueId: parseString((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['role_unique_id']),
934
+ stripeId: parseString((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['stripe_id']),
935
+ timeZone: parseString((_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['time_zone']),
936
+ preferredLanguage: parseString((_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['preferred_language']),
937
+ emailNotifications: (_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['email_notifications'],
938
+ smsNotifications: (_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['sms_notifications'],
939
+ whatsappNotifications: (_resource_attributes14 = resource.attributes) == null ? void 0 : _resource_attributes14['whatsapp_notifications'],
940
+ otherNotifications: (_resource_attributes15 = resource.attributes) == null ? void 0 : _resource_attributes15['other_notifications'],
941
+ status: parseString((_resource_attributes16 = resource.attributes) == null ? void 0 : _resource_attributes16['status']),
942
+ createdAt: parseDate((_resource_attributes17 = resource.attributes) == null ? void 0 : _resource_attributes17['created_at']) || new Date(),
943
+ updatedAt: parseDate((_resource_attributes18 = resource.attributes) == null ? void 0 : _resource_attributes18['updated_at']) || new Date()
738
944
  };
739
945
  }
740
946
  };
@@ -775,6 +981,25 @@ const userSubscriptionMapper = {
775
981
  }
776
982
  };
777
983
 
984
+ function buildUserBody(data) {
985
+ const body = {};
986
+ if (data.name) body['name'] = data.name;
987
+ if (data.firstName) body['first_name'] = data.firstName;
988
+ if (data.lastName) body['last_name'] = data.lastName;
989
+ if (data.email) body['email'] = data.email;
990
+ if (data.phone) body['phone'] = data.phone;
991
+ if (data.avatarUrl) body['avatar_url'] = data.avatarUrl;
992
+ if (data.roleName) body['role_name'] = data.roleName;
993
+ if (data.roleUniqueId) body['role_unique_id'] = data.roleUniqueId;
994
+ if (data.stripeId) body['stripe_id'] = data.stripeId;
995
+ if (data.timeZone) body['time_zone'] = data.timeZone;
996
+ if (data.preferredLanguage) body['preferred_language'] = data.preferredLanguage;
997
+ if (data.emailNotifications !== undefined) body['email_notifications'] = data.emailNotifications;
998
+ if (data.smsNotifications !== undefined) body['sms_notifications'] = data.smsNotifications;
999
+ if (data.whatsappNotifications !== undefined) body['whatsapp_notifications'] = data.whatsappNotifications;
1000
+ if (data.otherNotifications !== undefined) body['other_notifications'] = data.otherNotifications;
1001
+ return body;
1002
+ }
778
1003
  function createSalesUsersService(transport, _config) {
779
1004
  return {
780
1005
  async list (params) {
@@ -795,23 +1020,13 @@ function createSalesUsersService(transport, _config) {
795
1020
  },
796
1021
  async register (uniqueId, data) {
797
1022
  const response = await transport.post(`/users/${uniqueId}/register`, {
798
- user: {
799
- email: data == null ? void 0 : data.email,
800
- name: data == null ? void 0 : data.name,
801
- phone: data == null ? void 0 : data.phone,
802
- payload: data == null ? void 0 : data.payload
803
- }
1023
+ user: data ? buildUserBody(data) : {}
804
1024
  });
805
1025
  return decodeOne(response, salesUserMapper);
806
1026
  },
807
1027
  async update (uniqueId, data) {
808
1028
  const response = await transport.put(`/users/${uniqueId}`, {
809
- user: {
810
- name: data.name,
811
- phone: data.phone,
812
- status: data.status,
813
- payload: data.payload
814
- }
1029
+ user: buildUserBody(data)
815
1030
  });
816
1031
  return decodeOne(response, salesUserMapper);
817
1032
  },
@@ -848,8 +1063,7 @@ function createSalesUsersService(transport, _config) {
848
1063
  subscription: {
849
1064
  subscription_model_unique_id: data.subscriptionModelUniqueId,
850
1065
  subscription_number: data.subscriptionNumber,
851
- notes: data.notes,
852
- payload: data.payload
1066
+ notes: data.notes
853
1067
  }
854
1068
  });
855
1069
  return decodeOne(response, userSubscriptionMapper);
@@ -859,19 +1073,14 @@ function createSalesUsersService(transport, _config) {
859
1073
  subscription: {
860
1074
  subscription_model_unique_id: data.subscriptionModelUniqueId,
861
1075
  subscription_number: data.subscriptionNumber,
862
- notes: data.notes,
863
- payload: data.payload
1076
+ notes: data.notes
864
1077
  }
865
1078
  });
866
1079
  return decodeOne(response, userSubscriptionMapper);
867
1080
  },
868
1081
  async addConsumption (uniqueId, subscriptionUniqueId, data) {
869
1082
  const response = await transport.post(`/users/${uniqueId}/subscriptions/${subscriptionUniqueId}/consumption`, {
870
- consumption: {
871
- quantity: data.quantity,
872
- description: data.description,
873
- payload: data.payload
874
- }
1083
+ consumption: data.consumption
875
1084
  });
876
1085
  return decodeOne(response, userSubscriptionMapper);
877
1086
  },
@@ -888,19 +1097,29 @@ function createSalesUsersService(transport, _config) {
888
1097
  const salesCustomerMapper = {
889
1098
  type: 'customer',
890
1099
  map: (resource)=>{
891
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9;
1100
+ 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;
892
1101
  return {
893
1102
  id: resource.id,
894
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
895
- email: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['email'],
896
- name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
897
- phone: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['phone'],
898
- stripeCustomerId: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['stripe_customer_id'],
899
- mercadopagoCustomerId: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['mercadopago_customer_id'],
900
- status: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['status'],
901
- payload: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['payload'],
902
- createdAt: parseDate((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['created_at']),
903
- updatedAt: parseDate((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['updated_at'])
1103
+ uniqueId: parseString((_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id']) || '',
1104
+ name: parseString((_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['name']),
1105
+ email: parseString((_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['email']),
1106
+ phone: parseString((_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['phone']),
1107
+ companyUniqueId: parseString((_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['company_unique_id']),
1108
+ stripeId: parseString((_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['stripe_id']),
1109
+ status: parseString((_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['status']),
1110
+ timeZone: parseString((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['time_zone']),
1111
+ preferredLanguage: parseString((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['preferred_language']),
1112
+ avatarUrl: parseString((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['avatar_url']),
1113
+ emailNotifications: (_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['email_notifications'],
1114
+ smsNotifications: (_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['sms_notifications'],
1115
+ whatsappNotifications: (_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['whatsapp_notifications'],
1116
+ otherNotifications: (_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['other_notifications'],
1117
+ source: parseString((_resource_attributes14 = resource.attributes) == null ? void 0 : _resource_attributes14['source']),
1118
+ sourceAlias: parseString((_resource_attributes15 = resource.attributes) == null ? void 0 : _resource_attributes15['source_alias']),
1119
+ sourceId: parseString((_resource_attributes16 = resource.attributes) == null ? void 0 : _resource_attributes16['source_id']),
1120
+ sourceType: parseString((_resource_attributes17 = resource.attributes) == null ? void 0 : _resource_attributes17['source_type']),
1121
+ createdAt: parseDate((_resource_attributes18 = resource.attributes) == null ? void 0 : _resource_attributes18['created_at']) || new Date(),
1122
+ updatedAt: parseDate((_resource_attributes19 = resource.attributes) == null ? void 0 : _resource_attributes19['updated_at']) || new Date()
904
1123
  };
905
1124
  }
906
1125
  };
@@ -908,24 +1127,46 @@ const salesCustomerMapper = {
908
1127
  const customerSubscriptionMapper = {
909
1128
  type: 'CustomerSubscription',
910
1129
  map: (resource)=>{
911
- var _resource_attributes_subscription_unique_id, _resource_attributes_subscription_model_unique_id, _resource_attributes_start_at, _resource_attributes_end_at, _resource_attributes_closed_at, _resource_attributes_created_at, _parseDate, _resource_attributes_updated_at, _parseDate1;
1130
+ var _resource_attributes_subscription_unique_id, _resource_attributes_subscription_model_unique_id, _resource_attributes_start_at, _resource_attributes_end_at, _resource_attributes_closed_at, _resource_attributes_created_at, _resource_attributes_updated_at;
912
1131
  return {
913
1132
  id: resource.id,
914
- uniqueId: (_resource_attributes_subscription_unique_id = resource.attributes['subscription_unique_id']) != null ? _resource_attributes_subscription_unique_id : resource.attributes['unique_id'],
915
- customerUniqueId: resource.attributes['customer_unique_id'],
916
- subscriptionModelUniqueId: (_resource_attributes_subscription_model_unique_id = resource.attributes['subscription_model_unique_id']) != null ? _resource_attributes_subscription_model_unique_id : resource.attributes['code'],
917
- status: resource.attributes['status'],
1133
+ uniqueId: parseString((_resource_attributes_subscription_unique_id = resource.attributes['subscription_unique_id']) != null ? _resource_attributes_subscription_unique_id : resource.attributes['unique_id']) || '',
1134
+ customerUniqueId: resource.attributes['customer_unique_id'] || '',
1135
+ subscriptionModelUniqueId: parseString((_resource_attributes_subscription_model_unique_id = resource.attributes['subscription_model_unique_id']) != null ? _resource_attributes_subscription_model_unique_id : resource.attributes['code']) || '',
1136
+ subscriptionNumber: parseString(resource.attributes['subscription_number']),
1137
+ notes: parseString(resource.attributes['notes']),
1138
+ status: resource.attributes['status'] || '',
918
1139
  startDate: parseDate((_resource_attributes_start_at = resource.attributes['start_at']) != null ? _resource_attributes_start_at : resource.attributes['start_date']),
919
1140
  endDate: parseDate((_resource_attributes_end_at = resource.attributes['end_at']) != null ? _resource_attributes_end_at : resource.attributes['end_date']),
920
1141
  trialEndDate: parseDate(resource.attributes['trial_end_date']),
921
1142
  cancelledAt: parseDate((_resource_attributes_closed_at = resource.attributes['closed_at']) != null ? _resource_attributes_closed_at : resource.attributes['cancelled_at']),
922
- payload: resource.attributes['payload'],
923
- createdAt: (_parseDate = parseDate((_resource_attributes_created_at = resource.attributes['created_at']) != null ? _resource_attributes_created_at : resource.attributes['subscribed_at'])) != null ? _parseDate : new Date(),
924
- updatedAt: (_parseDate1 = parseDate((_resource_attributes_updated_at = resource.attributes['updated_at']) != null ? _resource_attributes_updated_at : resource.attributes['subscribed_at'])) != null ? _parseDate1 : new Date()
1143
+ createdAt: parseDate((_resource_attributes_created_at = resource.attributes['created_at']) != null ? _resource_attributes_created_at : resource.attributes['subscribed_at']) || new Date(),
1144
+ updatedAt: parseDate((_resource_attributes_updated_at = resource.attributes['updated_at']) != null ? _resource_attributes_updated_at : resource.attributes['subscribed_at']) || new Date()
925
1145
  };
926
1146
  }
927
1147
  };
928
1148
 
1149
+ function buildCustomerBody(data) {
1150
+ const body = {};
1151
+ if (data.name) body['name'] = data.name;
1152
+ if (data.email) body['email'] = data.email;
1153
+ if (data.phone) body['phone'] = data.phone;
1154
+ if (data.companyUniqueId) body['company_unique_id'] = data.companyUniqueId;
1155
+ if (data.stripeId) body['stripe_id'] = data.stripeId;
1156
+ if (data.status) body['status'] = data.status;
1157
+ if (data.timeZone) body['time_zone'] = data.timeZone;
1158
+ if (data.preferredLanguage) body['preferred_language'] = data.preferredLanguage;
1159
+ if (data.avatarUrl) body['avatar_url'] = data.avatarUrl;
1160
+ if (data.emailNotifications !== undefined) body['email_notifications'] = data.emailNotifications;
1161
+ if (data.smsNotifications !== undefined) body['sms_notifications'] = data.smsNotifications;
1162
+ if (data.whatsappNotifications !== undefined) body['whatsapp_notifications'] = data.whatsappNotifications;
1163
+ if (data.otherNotifications !== undefined) body['other_notifications'] = data.otherNotifications;
1164
+ if (data.source) body['source'] = data.source;
1165
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
1166
+ if (data.sourceId) body['source_id'] = data.sourceId;
1167
+ if (data.sourceType) body['source_type'] = data.sourceType;
1168
+ return body;
1169
+ }
929
1170
  function createSalesCustomersService(transport, _config) {
930
1171
  return {
931
1172
  async get (uniqueId) {
@@ -934,14 +1175,7 @@ function createSalesCustomersService(transport, _config) {
934
1175
  },
935
1176
  async register (uniqueId, data) {
936
1177
  const response = await transport.post(`/customers/${uniqueId}/register`, {
937
- customer: {
938
- email: data == null ? void 0 : data.email,
939
- name: data == null ? void 0 : data.name,
940
- phone: data == null ? void 0 : data.phone,
941
- stripe_customer_id: data == null ? void 0 : data.stripeCustomerId,
942
- mercadopago_customer_id: data == null ? void 0 : data.mercadopagoCustomerId,
943
- payload: data == null ? void 0 : data.payload
944
- }
1178
+ customer: data ? buildCustomerBody(data) : {}
945
1179
  });
946
1180
  return decodeOne(response, salesCustomerMapper);
947
1181
  },
@@ -953,9 +1187,8 @@ function createSalesCustomersService(transport, _config) {
953
1187
  const response = await transport.post(`/customers/${uniqueId}/subscriptions`, {
954
1188
  subscription: {
955
1189
  subscription_model_unique_id: data.subscriptionModelUniqueId,
956
- start_date: data.startDate,
957
- trial_end_date: data.trialEndDate,
958
- payload: data.payload
1190
+ subscription_number: data.subscriptionNumber,
1191
+ notes: data.notes
959
1192
  }
960
1193
  });
961
1194
  return decodeOne(response, customerSubscriptionMapper);
@@ -963,9 +1196,9 @@ function createSalesCustomersService(transport, _config) {
963
1196
  async updateSubscription (uniqueId, subscriptionUniqueId, data) {
964
1197
  const response = await transport.put(`/customers/${uniqueId}/subscriptions/${subscriptionUniqueId}`, {
965
1198
  subscription: {
966
- status: data.status,
967
- end_date: data.endDate,
968
- payload: data.payload
1199
+ subscription_model_unique_id: data.subscriptionModelUniqueId,
1200
+ subscription_number: data.subscriptionNumber,
1201
+ notes: data.notes
969
1202
  }
970
1203
  });
971
1204
  return decodeOne(response, customerSubscriptionMapper);
@@ -1253,58 +1486,58 @@ const stripeWebhookMapper = {
1253
1486
  }
1254
1487
  };
1255
1488
 
1489
+ function buildSubscriptionBody(data) {
1490
+ const body = {};
1491
+ if (data.customerId) body['customer_id'] = data.customerId;
1492
+ if (data.setupPriceId) body['setup_price_id'] = data.setupPriceId;
1493
+ if (data.subscriptionPriceId) body['subscription_price_id'] = data.subscriptionPriceId;
1494
+ if (data.priceUniqueId) body['price_unique_id'] = data.priceUniqueId;
1495
+ if (data.localPriceId) body['local_price_id'] = data.localPriceId;
1496
+ if (data.cardToken) body['card_token'] = data.cardToken;
1497
+ if (data.trialPeriodDays !== undefined) body['trial_period_days'] = data.trialPeriodDays;
1498
+ if (data.multipleSubscriptions !== undefined) body['multiple_subscriptions'] = data.multipleSubscriptions;
1499
+ if (data.appName) body['app_name'] = data.appName;
1500
+ if (data.parentName) body['parent_name'] = data.parentName;
1501
+ if (data.description) body['description'] = data.description;
1502
+ if (data.subscriptionType) body['subscription_type'] = data.subscriptionType;
1503
+ if (data.entityType) body['entity_type'] = data.entityType;
1504
+ if (data.entityId) body['entity_id'] = data.entityId;
1505
+ if (data.customerCompanyId) body['customer_company_id'] = data.customerCompanyId;
1506
+ return body;
1507
+ }
1256
1508
  function createStripeService(transport, _config) {
1257
1509
  return {
1258
1510
  async createCustomer (data) {
1259
1511
  const response = await transport.post('/stripe/customers', {
1260
1512
  customer: {
1261
- email: data.email,
1262
1513
  name: data.name,
1263
1514
  phone: data.phone,
1515
+ email: data.email,
1264
1516
  token: data.token,
1265
1517
  user_unique_id: data.userUniqueId,
1266
1518
  identity_type: data.identityType,
1267
1519
  company_unique_id: data.companyUniqueId,
1268
1520
  entity_unique_id: data.entityUniqueId,
1269
- entity_type: data.entityType,
1270
- metadata: data.metadata
1521
+ entity_type: data.entityType
1271
1522
  }
1272
1523
  });
1273
1524
  return decodeOne(response, stripeCustomerResponseMapper);
1274
1525
  },
1275
1526
  async createCheckoutSession (data) {
1276
- var _data_lineItems;
1277
1527
  const response = await transport.post('/stripe/sessions', {
1278
1528
  session: {
1279
- customer_unique_id: data.customerUniqueId,
1280
- stripe_customer_id: data.stripeCustomerId,
1529
+ price: data.price,
1281
1530
  success_url: data.successUrl,
1282
1531
  cancel_url: data.cancelUrl,
1283
1532
  mode: data.mode,
1284
- line_items: (_data_lineItems = data.lineItems) == null ? void 0 : _data_lineItems.map((item)=>({
1285
- price_id: item.priceId,
1286
- quantity: item.quantity,
1287
- price_data: item.priceData ? {
1288
- currency: item.priceData.currency,
1289
- unit_amount: item.priceData.unitAmount,
1290
- product_data: item.priceData.productData,
1291
- recurring: item.priceData.recurring
1292
- } : undefined
1293
- })),
1294
- subscription_data: data.subscriptionData ? {
1295
- trial_period_days: data.subscriptionData.trialPeriodDays,
1296
- metadata: data.subscriptionData.metadata
1297
- } : undefined,
1298
- metadata: data.metadata,
1299
- subscription_model_code: data.subscriptionModelCode,
1300
- price_unique_id: data.priceUniqueId,
1301
- price: data.price,
1302
1533
  customer: data.customer,
1303
1534
  quantity: data.quantity,
1304
1535
  trial_period_days: data.trialPeriodDays,
1305
1536
  subscription_type: data.subscriptionType,
1537
+ price_unique_id: data.priceUniqueId,
1306
1538
  identity_type: data.identityType,
1307
1539
  description: data.description,
1540
+ subscription_model_code: data.subscriptionModelCode,
1308
1541
  allow_promotion_codes: data.allowPromotionCodes,
1309
1542
  coupon_id: data.couponId
1310
1543
  }
@@ -1318,12 +1551,11 @@ function createStripeService(transport, _config) {
1318
1551
  async createPaymentIntent (data) {
1319
1552
  const response = await transport.post('/stripe/payments', {
1320
1553
  payment: {
1554
+ customer_id: data.customerId,
1321
1555
  currency: data.currency,
1322
1556
  order_unique_id: data.orderUniqueId,
1323
- order_id: data.orderId,
1324
1557
  identity_type: data.identityType,
1325
1558
  entity_type: data.entityType,
1326
- customer_id: data.customerId,
1327
1559
  entity_id: data.entityId
1328
1560
  }
1329
1561
  });
@@ -1332,8 +1564,8 @@ function createStripeService(transport, _config) {
1332
1564
  async createCustomerPortal (uniqueId, data) {
1333
1565
  const response = await transport.post(`/stripe/customers/${uniqueId}/portal`, {
1334
1566
  portal: {
1335
- return_url: data.returnUrl,
1336
- customer_id: data.customerId
1567
+ customer_id: data.customerId,
1568
+ return_url: data.returnUrl
1337
1569
  }
1338
1570
  });
1339
1571
  return decodeOne(response, stripeCustomerPortalMapper);
@@ -1351,35 +1583,13 @@ function createStripeService(transport, _config) {
1351
1583
  },
1352
1584
  async createSubscription (data) {
1353
1585
  const response = await transport.post('/stripe/subscriptions', {
1354
- subscription: {
1355
- customer_unique_id: data.customerUniqueId,
1356
- stripe_customer_id: data.stripeCustomerId,
1357
- price_id: data.priceId,
1358
- price_unique_id: data.priceUniqueId,
1359
- quantity: data.quantity,
1360
- trial_period_days: data.trialPeriodDays,
1361
- customer_id: data.customerId,
1362
- setup_price_id: data.setupPriceId,
1363
- subscription_price_id: data.subscriptionPriceId,
1364
- card_token: data.cardToken,
1365
- subscription_type: data.subscriptionType,
1366
- identity_type: data.identityType,
1367
- company_unique_id: data.companyUniqueId,
1368
- entity_unique_id: data.entityUniqueId,
1369
- entity_type: data.entityType,
1370
- metadata: data.metadata
1371
- }
1586
+ subscription: buildSubscriptionBody(data)
1372
1587
  });
1373
1588
  return decodeOne(response, stripeSubscriptionMapper);
1374
1589
  },
1375
1590
  async updateSubscription (stripeSubscriptionId, data) {
1376
1591
  const response = await transport.put(`/stripe/subscriptions/${stripeSubscriptionId}`, {
1377
- subscription: {
1378
- price_id: data.priceId,
1379
- quantity: data.quantity,
1380
- cancel_at_period_end: data.cancelAtPeriodEnd,
1381
- metadata: data.metadata
1382
- }
1592
+ subscription: buildSubscriptionBody(data)
1383
1593
  });
1384
1594
  return decodeOne(response, stripeSubscriptionMapper);
1385
1595
  },
@@ -1419,7 +1629,7 @@ const mercadoPagoPaymentMethodMapper = {
1419
1629
  processingModes: parseStringArray(resource.attributes['processing_modes'])
1420
1630
  })
1421
1631
  };
1422
- const mercadoPagoPaymentIntentMapper = {
1632
+ const mercadoPagoPaymentMapper = {
1423
1633
  type: 'MercadoPagoPaymentIntent',
1424
1634
  map: (resource)=>{
1425
1635
  var _parseDate;
@@ -1442,121 +1652,156 @@ const mercadoPagoPaymentIntentMapper = {
1442
1652
  }
1443
1653
  };
1444
1654
 
1655
+ function buildMercadoPagoBody(data) {
1656
+ const body = {};
1657
+ if (data.amount !== undefined) body['amount'] = data.amount;
1658
+ if (data.cardToken) body['card_token'] = data.cardToken;
1659
+ if (data.description) body['description'] = data.description;
1660
+ if (data.installments !== undefined) body['installments'] = data.installments;
1661
+ if (data.paymentMethodId) body['paymentMethodId'] = data.paymentMethodId;
1662
+ if (data.email) body['email'] = data.email;
1663
+ if (data.documentType) body['document_type'] = data.documentType;
1664
+ if (data.documentNumber) body['document_number'] = data.documentNumber;
1665
+ if (data.orderUniqueId) body['order_unique_id'] = data.orderUniqueId;
1666
+ if (data.displayUniqueId) body['display_unique_id'] = data.displayUniqueId;
1667
+ if (data.financialInstitution) body['financial_institution'] = data.financialInstitution;
1668
+ if (data.callbackUrl) body['callback_url'] = data.callbackUrl;
1669
+ return body;
1670
+ }
1445
1671
  function createMercadoPagoService(transport, _config) {
1446
1672
  return {
1447
1673
  async listPaymentMethods () {
1448
1674
  const response = await transport.get('/mercadopago');
1449
1675
  return decodeMany(response, mercadoPagoPaymentMethodMapper);
1450
1676
  },
1451
- async createPaymentIntent (data) {
1452
- var _data_additionalInfo_items;
1677
+ async createPayment (data) {
1453
1678
  const response = await transport.post('/mercadopago/payments', {
1454
- transaction_amount: data.transactionAmount,
1455
- description: data.description,
1456
- payment_method_id: data.paymentMethodId,
1457
- payer: {
1458
- email: data.payerEmail
1459
- },
1460
- installments: data.installments,
1461
- token: data.token,
1462
- issuer_id: data.issuerId,
1463
- external_reference: data.externalReference,
1464
- statement_descriptor: data.statementDescriptor,
1465
- notification_url: data.notificationUrl,
1466
- additional_info: data.additionalInfo ? {
1467
- items: (_data_additionalInfo_items = data.additionalInfo.items) == null ? void 0 : _data_additionalInfo_items.map((item)=>({
1468
- id: item.id,
1469
- title: item.title,
1470
- description: item.description,
1471
- picture_url: item.pictureUrl,
1472
- category_id: item.categoryId,
1473
- quantity: item.quantity,
1474
- unit_price: item.unitPrice
1475
- })),
1476
- payer: data.additionalInfo.payer ? {
1477
- first_name: data.additionalInfo.payer.firstName,
1478
- last_name: data.additionalInfo.payer.lastName,
1479
- email: data.additionalInfo.payer.email,
1480
- phone: data.additionalInfo.payer.phone,
1481
- identification: data.additionalInfo.payer.identification,
1482
- address: data.additionalInfo.payer.address ? {
1483
- zip_code: data.additionalInfo.payer.address.zipCode,
1484
- street_name: data.additionalInfo.payer.address.streetName,
1485
- street_number: data.additionalInfo.payer.address.streetNumber
1486
- } : undefined
1487
- } : undefined
1488
- } : undefined,
1489
- metadata: data.metadata
1490
- });
1491
- return decodeOne(response, mercadoPagoPaymentIntentMapper);
1492
- },
1493
- async createPSEIntent (data) {
1679
+ payment: buildMercadoPagoBody(data)
1680
+ });
1681
+ return decodeOne(response, mercadoPagoPaymentMapper);
1682
+ },
1683
+ async createPSEPayment (data) {
1494
1684
  const response = await transport.post('/mercadopago/payments/pse', {
1495
- transaction_amount: data.transactionAmount,
1496
- description: data.description,
1497
- payer: {
1498
- email: data.payerEmail,
1499
- identification: {
1500
- type: data.payerDocumentType,
1501
- number: data.payerDocumentNumber
1502
- }
1503
- },
1504
- transaction_details: {
1505
- financial_institution: data.financialInstitution
1506
- },
1507
- callback_url: data.callbackUrl,
1508
- external_reference: data.externalReference,
1509
- metadata: data.metadata
1685
+ payment: buildMercadoPagoBody(data)
1510
1686
  });
1511
- return decodeOne(response, mercadoPagoPaymentIntentMapper);
1687
+ return decodeOne(response, mercadoPagoPaymentMapper);
1512
1688
  }
1513
1689
  };
1514
1690
  }
1515
1691
 
1516
1692
  const vendorPaymentMapper = {
1517
1693
  type: 'VendorPayment',
1518
- map: (resource)=>{
1519
- var _parseDate, _parseDate1;
1520
- return {
1694
+ map: (resource)=>({
1521
1695
  id: resource.id,
1522
- uniqueId: resource.attributes['unique_id'],
1523
- orderUniqueId: resource.attributes['order_unique_id'],
1524
- detailUniqueId: resource.attributes['detail_unique_id'],
1525
- vendorUniqueId: resource.attributes['vendor_unique_id'],
1526
- amount: parseNumber(resource.attributes['amount']),
1527
- currency: resource.attributes['currency'],
1528
- status: resource.attributes['status'],
1696
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
1697
+ vendorUniqueId: parseString(resource.attributes['vendor_unique_id']),
1698
+ vendorName: parseString(resource.attributes['vendor_name']),
1699
+ vendorEmail: parseString(resource.attributes['vendor_email']),
1700
+ vendorPhone: parseString(resource.attributes['vendor_phone']),
1701
+ vendorContact: parseString(resource.attributes['vendor_contact']),
1702
+ paymentType: parseString(resource.attributes['payment_type']),
1703
+ price: parseNumber(resource.attributes['price']) || undefined,
1704
+ discount: parseNumber(resource.attributes['discount']) || undefined,
1705
+ discountValue: parseNumber(resource.attributes['discount_value']) || undefined,
1706
+ fees: parseNumber(resource.attributes['fees']) || undefined,
1707
+ feesValue: parseNumber(resource.attributes['fees_value']) || undefined,
1708
+ tips: parseNumber(resource.attributes['tips']) || undefined,
1709
+ tipsValue: parseNumber(resource.attributes['tips_value']) || undefined,
1710
+ subtotal: parseNumber(resource.attributes['subtotal']) || undefined,
1711
+ delivery: parseNumber(resource.attributes['delivery']) || undefined,
1712
+ tax: parseNumber(resource.attributes['tax']) || undefined,
1713
+ taxValue: parseNumber(resource.attributes['tax_value']) || undefined,
1714
+ status: parseString(resource.attributes['status']),
1529
1715
  paidAt: parseDate(resource.attributes['paid_at']),
1530
- reference: resource.attributes['reference'],
1531
- notes: resource.attributes['notes'],
1532
1716
  payload: resource.attributes['payload'],
1533
- createdAt: (_parseDate = parseDate(resource.attributes['created_at'])) != null ? _parseDate : new Date(),
1534
- updatedAt: (_parseDate1 = parseDate(resource.attributes['updated_at'])) != null ? _parseDate1 : new Date()
1535
- };
1536
- }
1717
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
1718
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
1719
+ })
1537
1720
  };
1538
1721
 
1539
1722
  const orderDetailVendorMapper = {
1540
1723
  type: 'OrderDetailVendor',
1541
- map: (resource)=>{
1542
- var _parseDate, _parseDate1;
1543
- return {
1724
+ map: (resource)=>({
1544
1725
  id: resource.id,
1545
- uniqueId: resource.attributes['unique_id'],
1546
- orderDetailUniqueId: resource.attributes['order_detail_unique_id'],
1547
- sourceId: resource.attributes['source_id'],
1548
- vendorUniqueId: resource.attributes['vendor_unique_id'],
1549
- vendorName: resource.attributes['vendor_name'],
1550
- amount: parseNumber(resource.attributes['amount']),
1551
- commission: parseOptionalNumber(resource.attributes['commission']),
1552
- status: resource.attributes['status'],
1553
- payload: resource.attributes['payload'],
1554
- createdAt: (_parseDate = parseDate(resource.attributes['created_at'])) != null ? _parseDate : new Date(),
1555
- updatedAt: (_parseDate1 = parseDate(resource.attributes['updated_at'])) != null ? _parseDate1 : new Date()
1556
- };
1557
- }
1726
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
1727
+ orderDetailUniqueId: parseString(resource.attributes['order_detail_unique_id']),
1728
+ vendorUniqueId: parseString(resource.attributes['vendor_unique_id']),
1729
+ vendorName: parseString(resource.attributes['vendor_name']),
1730
+ vendorEmail: parseString(resource.attributes['vendor_email']),
1731
+ vendorPhone: parseString(resource.attributes['vendor_phone']),
1732
+ vendorContact: parseString(resource.attributes['vendor_contact']),
1733
+ status: parseString(resource.attributes['status']),
1734
+ referredBy: parseString(resource.attributes['referred_by']),
1735
+ promoCode: parseString(resource.attributes['promo_code']),
1736
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
1737
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
1738
+ })
1558
1739
  };
1559
1740
 
1741
+ function buildVendorPaymentBody(data) {
1742
+ const body = {};
1743
+ if (data.vendorUniqueId) body['vendor_unique_id'] = data.vendorUniqueId;
1744
+ if (data.vendorName) body['vendor_name'] = data.vendorName;
1745
+ if (data.vendorEmail) body['vendor_email'] = data.vendorEmail;
1746
+ if (data.vendorPhone) body['vendor_phone'] = data.vendorPhone;
1747
+ if (data.vendorContact) body['vendor_contact'] = data.vendorContact;
1748
+ if (data.paymentType) body['payment_type'] = data.paymentType;
1749
+ if (data.price !== undefined) body['price'] = data.price;
1750
+ if (data.discount !== undefined) body['discount'] = data.discount;
1751
+ if (data.discountValue !== undefined) body['discount_value'] = data.discountValue;
1752
+ if (data.fees !== undefined) body['fees'] = data.fees;
1753
+ if (data.feesValue !== undefined) body['fees_value'] = data.feesValue;
1754
+ if (data.tips !== undefined) body['tips'] = data.tips;
1755
+ if (data.tipsValue !== undefined) body['tips_value'] = data.tipsValue;
1756
+ if (data.subtotal !== undefined) body['subtotal'] = data.subtotal;
1757
+ if (data.delivery !== undefined) body['delivery'] = data.delivery;
1758
+ if (data.tax !== undefined) body['tax'] = data.tax;
1759
+ if (data.taxValue !== undefined) body['tax_value'] = data.taxValue;
1760
+ if (data.payload) body['payload'] = data.payload;
1761
+ return body;
1762
+ }
1763
+ function buildPayBody(data) {
1764
+ const body = {};
1765
+ if (data.paymentType) body['payment_type'] = data.paymentType;
1766
+ if (data.gatewayUniqueId) body['gateway_unique_id'] = data.gatewayUniqueId;
1767
+ if (data.gatewayName) body['gateway_name'] = data.gatewayName;
1768
+ if (data.gatewayReference) body['gateway_reference'] = data.gatewayReference;
1769
+ if (data.gatewayOrderId) body['gateway_order_id'] = data.gatewayOrderId;
1770
+ if (data.gatewayFranchise) body['gateway_franchise'] = data.gatewayFranchise;
1771
+ if (data.gatewayPaymentType) body['gateway_payment_type'] = data.gatewayPaymentType;
1772
+ if (data.gatewayTransactionId) body['gateway_transaction_id'] = data.gatewayTransactionId;
1773
+ if (data.gatewayDescription) body['gateway_description'] = data.gatewayDescription;
1774
+ if (data.gatewayFees !== undefined) body['gateway_fees'] = data.gatewayFees;
1775
+ if (data.gatewayFeesValue !== undefined) body['gateway_fees_value'] = data.gatewayFeesValue;
1776
+ if (data.gatewayTips !== undefined) body['gateway_tips'] = data.gatewayTips;
1777
+ if (data.gatewayTipsValue !== undefined) body['gateway_tips_value'] = data.gatewayTipsValue;
1778
+ if (data.gatewaySubtotal !== undefined) body['gateway_subtotal'] = data.gatewaySubtotal;
1779
+ if (data.gatewayDiscount !== undefined) body['gateway_discount'] = data.gatewayDiscount;
1780
+ if (data.gatewayDiscountValue !== undefined) body['gateway_discount_value'] = data.gatewayDiscountValue;
1781
+ if (data.gatewayDelivery !== undefined) body['gateway_delivery'] = data.gatewayDelivery;
1782
+ if (data.gatewayTax !== undefined) body['gateway_tax'] = data.gatewayTax;
1783
+ if (data.gatewayTaxValue !== undefined) body['gateway_tax_value'] = data.gatewayTaxValue;
1784
+ if (data.gatewayTotal !== undefined) body['gateway_total'] = data.gatewayTotal;
1785
+ if (data.gatewayBalance !== undefined) body['gateway_balance'] = data.gatewayBalance;
1786
+ if (data.gatewayPaidAt) body['gateway_paid_at'] = data.gatewayPaidAt;
1787
+ if (data.gatewayStatus) body['gateway_status'] = data.gatewayStatus;
1788
+ if (data.gatewayResponse) body['gateway_response'] = data.gatewayResponse;
1789
+ if (data.gatewayPayload) body['gateway_payload'] = data.gatewayPayload;
1790
+ if (data.paidAt) body['paid_at'] = data.paidAt;
1791
+ return body;
1792
+ }
1793
+ function buildProviderBody(data) {
1794
+ const body = {};
1795
+ if (data.vendorUniqueId) body['vendor_unique_id'] = data.vendorUniqueId;
1796
+ if (data.vendorName) body['vendor_name'] = data.vendorName;
1797
+ if (data.vendorEmail) body['vendor_email'] = data.vendorEmail;
1798
+ if (data.vendorPhone) body['vendor_phone'] = data.vendorPhone;
1799
+ if (data.vendorContact) body['vendor_contact'] = data.vendorContact;
1800
+ if (data.status) body['status'] = data.status;
1801
+ if (data.referredBy) body['referred_by'] = data.referredBy;
1802
+ if (data.promoCode) body['promo_code'] = data.promoCode;
1803
+ return body;
1804
+ }
1560
1805
  function createVendorPaymentsService(transport, _config) {
1561
1806
  return {
1562
1807
  async get (paymentUniqueId) {
@@ -1565,30 +1810,20 @@ function createVendorPaymentsService(transport, _config) {
1565
1810
  },
1566
1811
  async create (orderUniqueId, detailUniqueId, vendorUniqueId, data) {
1567
1812
  const response = await transport.post(`/orders/${orderUniqueId}/details/${detailUniqueId}/vendors/${vendorUniqueId}/payments`, {
1568
- payment: {
1569
- amount: data.amount,
1570
- currency: data.currency,
1571
- reference: data.reference,
1572
- notes: data.notes,
1573
- payload: data.payload
1574
- }
1813
+ payment: buildVendorPaymentBody(data)
1575
1814
  });
1576
1815
  return decodeOne(response, vendorPaymentMapper);
1577
1816
  },
1578
1817
  async update (orderUniqueId, detailUniqueId, vendorUniqueId, paymentUniqueId, data) {
1579
1818
  const response = await transport.put(`/orders/${orderUniqueId}/details/${detailUniqueId}/vendors/${vendorUniqueId}/payments/${paymentUniqueId}`, {
1580
- payment: {
1581
- amount: data.amount,
1582
- reference: data.reference,
1583
- notes: data.notes,
1584
- status: data.status,
1585
- payload: data.payload
1586
- }
1819
+ payment: buildVendorPaymentBody(data)
1587
1820
  });
1588
1821
  return decodeOne(response, vendorPaymentMapper);
1589
1822
  },
1590
- async pay (orderUniqueId, detailUniqueId, vendorUniqueId, paymentUniqueId) {
1591
- const response = await transport.put(`/orders/${orderUniqueId}/details/${detailUniqueId}/vendors/${vendorUniqueId}/payments/${paymentUniqueId}/pay`, {});
1823
+ async pay (orderUniqueId, detailUniqueId, vendorUniqueId, paymentUniqueId, data) {
1824
+ const response = await transport.put(`/orders/${orderUniqueId}/details/${detailUniqueId}/vendors/${vendorUniqueId}/payments/${paymentUniqueId}/pay`, {
1825
+ payment: data ? buildPayBody(data) : {}
1826
+ });
1592
1827
  return decodeOne(response, vendorPaymentMapper);
1593
1828
  },
1594
1829
  async delete (orderUniqueId, detailUniqueId, vendorUniqueId, paymentUniqueId) {
@@ -1596,36 +1831,13 @@ function createVendorPaymentsService(transport, _config) {
1596
1831
  },
1597
1832
  async createProvider (orderUniqueId, orderDetailUniqueId, data) {
1598
1833
  const response = await transport.post(`/orders/${orderUniqueId}/details/${orderDetailUniqueId}/providers`, {
1599
- provider: {
1600
- vendor_unique_id: data.vendorUniqueId,
1601
- amount: data.amount,
1602
- commission: data.commission,
1603
- payload: data.payload
1604
- }
1605
- });
1606
- return decodeOne(response, orderDetailVendorMapper);
1607
- },
1608
- async createProviderBySource (sourceId, data) {
1609
- const response = await transport.post(`/sources/${sourceId}/providers`, {
1610
- provider: {
1611
- vendor_unique_id: data.vendorUniqueId,
1612
- order_unique_id: data.orderUniqueId,
1613
- order_detail_unique_id: data.orderDetailUniqueId,
1614
- amount: data.amount,
1615
- commission: data.commission,
1616
- payload: data.payload
1617
- }
1834
+ provider: buildProviderBody(data)
1618
1835
  });
1619
1836
  return decodeOne(response, orderDetailVendorMapper);
1620
1837
  },
1621
1838
  async updateProvider (orderUniqueId, orderDetailUniqueId, providerUniqueId, data) {
1622
1839
  const response = await transport.put(`/orders/${orderUniqueId}/details/${orderDetailUniqueId}/providers/${providerUniqueId}`, {
1623
- provider: {
1624
- amount: data.amount,
1625
- commission: data.commission,
1626
- status: data.status,
1627
- payload: data.payload
1628
- }
1840
+ provider: buildProviderBody(data)
1629
1841
  });
1630
1842
  return decodeOne(response, orderDetailVendorMapper);
1631
1843
  },
@@ -1822,4 +2034,4 @@ const salesBlockMetadata = {
1822
2034
  ]
1823
2035
  };
1824
2036
 
1825
- export { createFlexibleOrdersService, createMercadoPagoService, createOrderDetailsService, createOrderTaxesService, createOrdersService, createPaymentsService, createPurchasesService, createSalesBlock, createSalesCustomersService, createSalesEntitiesService, createSalesUsersService, createStripeService, createSubscriptionModelsService, createSubscriptionsService, createVendorPaymentsService, customerSubscriptionMapper, entitySubscriptionMapper, flexibleOrderMapper, mercadoPagoPaymentIntentMapper, mercadoPagoPaymentMethodMapper, orderDetailMapper, orderDetailVendorMapper, orderMapper, orderTaxMapper, parseBoolean, parseDate, parseNumber, parseOptionalNumber, parseOrderStatus, parsePaymentStatus, parseStatus, parseString, parseStringArray, parseSubscriptionInterval, parseSubscriptionStatus, paymentMapper, purchaseMapper, salesBlockMetadata, salesCustomerMapper, salesEntityMapper, salesUserMapper, stripeCheckoutSessionMapper, stripeCustomerPortalMapper, stripeCustomerResponseMapper, stripePaymentIntentMapper, stripeSubscriptionMapper, stripeWebhookMapper, subscriptionMapper, subscriptionModelMapper, userSubscriptionMapper, vendorPaymentMapper };
2037
+ export { createFlexibleOrdersService, createMercadoPagoService, createOrderDetailsService, createOrderTaxesService, createOrdersService, createPaymentsService, createPurchasesService, createSalesBlock, createSalesCustomersService, createSalesEntitiesService, createSalesUsersService, createStripeService, createSubscriptionModelsService, createSubscriptionsService, createVendorPaymentsService, customerSubscriptionMapper, entitySubscriptionMapper, flexibleOrderMapper, mercadoPagoPaymentMapper, mercadoPagoPaymentMethodMapper, orderDetailMapper, orderDetailVendorMapper, orderMapper, orderTaxMapper, parseBoolean, parseDate, parseNumber, parseOptionalNumber, parseOrderStatus, parsePaymentStatus, parseStatus, parseString, parseStringArray, parseSubscriptionInterval, parseSubscriptionStatus, paymentMapper, purchaseMapper, salesBlockMetadata, salesCustomerMapper, salesEntityMapper, salesUserMapper, stripeCheckoutSessionMapper, stripeCustomerPortalMapper, stripeCustomerResponseMapper, stripePaymentIntentMapper, stripeSubscriptionMapper, stripeWebhookMapper, subscriptionItemMapper, subscriptionMapper, subscriptionModelMapper, userSubscriptionMapper, vendorPaymentMapper };