@things-factory/integration-marketplace 3.7.9 → 3.8.10

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 (85) hide show
  1. package/dist-server/controllers/lazada/apis/get-store-order-item-transaction-details.js +88 -0
  2. package/dist-server/controllers/lazada/apis/get-store-order-item-transaction-details.js.map +1 -0
  3. package/dist-server/controllers/lazada/apis/get-store-order-items.js +39 -7
  4. package/dist-server/controllers/lazada/apis/get-store-order-items.js.map +1 -1
  5. package/dist-server/controllers/lazada/apis/get-store-order.js +1 -0
  6. package/dist-server/controllers/lazada/apis/get-store-order.js.map +1 -1
  7. package/dist-server/controllers/lazada/apis/get-store-orders.js +2 -1
  8. package/dist-server/controllers/lazada/apis/get-store-orders.js.map +1 -1
  9. package/dist-server/controllers/lazada/apis/index.js +1 -1
  10. package/dist-server/controllers/lazada/apis/index.js.map +1 -1
  11. package/dist-server/controllers/lazada/client/lazada.js +24 -4
  12. package/dist-server/controllers/lazada/client/lazada.js.map +1 -1
  13. package/dist-server/controllers/lazada/platform-action.js +18 -3
  14. package/dist-server/controllers/lazada/platform-action.js.map +1 -1
  15. package/dist-server/controllers/shopee/apis/get-store-order-transaction-details.js +32 -0
  16. package/dist-server/controllers/shopee/apis/get-store-order-transaction-details.js.map +1 -0
  17. package/dist-server/controllers/shopee/apis/get-store-order.js +10 -9
  18. package/dist-server/controllers/shopee/apis/get-store-order.js.map +1 -1
  19. package/dist-server/controllers/shopee/apis/index.js +1 -0
  20. package/dist-server/controllers/shopee/apis/index.js.map +1 -1
  21. package/dist-server/controllers/shopify/apis/get-store-orders.js +46 -8
  22. package/dist-server/controllers/shopify/apis/get-store-orders.js.map +1 -1
  23. package/dist-server/controllers/shopify/apis/get-store-products.js +2 -1
  24. package/dist-server/controllers/shopify/apis/get-store-products.js.map +1 -1
  25. package/dist-server/controllers/store-api/index.js +42 -0
  26. package/dist-server/controllers/store-api/index.js.map +1 -1
  27. package/dist-server/controllers/woocommerce/apis/get-store-order.js +21 -0
  28. package/dist-server/controllers/woocommerce/apis/get-store-order.js.map +1 -0
  29. package/dist-server/controllers/woocommerce/apis/get-store-product-categories.js +8 -44
  30. package/dist-server/controllers/woocommerce/apis/get-store-product-categories.js.map +1 -1
  31. package/dist-server/controllers/woocommerce/apis/index.js +10 -0
  32. package/dist-server/controllers/woocommerce/apis/index.js.map +1 -1
  33. package/dist-server/controllers/woocommerce/apis/update-order.js +37 -0
  34. package/dist-server/controllers/woocommerce/apis/update-order.js.map +1 -0
  35. package/dist-server/controllers/woocommerce/apis/update-product-attribute.js +20 -0
  36. package/dist-server/controllers/woocommerce/apis/update-product-attribute.js.map +1 -0
  37. package/dist-server/controllers/woocommerce/apis/update-store-product-price.js +23 -0
  38. package/dist-server/controllers/woocommerce/apis/update-store-product-price.js.map +1 -0
  39. package/dist-server/controllers/woocommerce/apis/update-store-product-stock.js +2 -2
  40. package/dist-server/controllers/woocommerce/apis/update-store-product-stock.js.map +1 -1
  41. package/dist-server/controllers/woocommerce/apis/update-store-product-variant-price.js +20 -0
  42. package/dist-server/controllers/woocommerce/apis/update-store-product-variant-price.js.map +1 -0
  43. package/dist-server/controllers/woocommerce/apis/update-store-product-variant-stock.js +20 -0
  44. package/dist-server/controllers/woocommerce/apis/update-store-product-variant-stock.js.map +1 -0
  45. package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js +23 -0
  46. package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js.map +1 -0
  47. package/dist-server/controllers/woocommerce/apis/update-store-product-variation-stock.js +3 -3
  48. package/dist-server/controllers/woocommerce/apis/update-store-product-variation-stock.js.map +1 -1
  49. package/dist-server/controllers/woocommerce/woocommerce.js +2 -2
  50. package/dist-server/controllers/woocommerce/woocommerce.js.map +1 -1
  51. package/dist-server/graphql/resolvers/marketplace-setting/update-marketplace-setting.js +1 -1
  52. package/dist-server/graphql/resolvers/marketplace-setting/update-marketplace-setting.js.map +1 -1
  53. package/dist-server/routers/shopify-install-public-router.js +14 -4
  54. package/dist-server/routers/shopify-install-public-router.js.map +1 -1
  55. package/package.json +14 -14
  56. package/server/controllers/lazada/apis/get-store-order-item-transaction-details.ts +65 -0
  57. package/server/controllers/lazada/apis/get-store-order-items.ts +74 -6
  58. package/server/controllers/lazada/apis/get-store-order.ts +1 -0
  59. package/server/controllers/lazada/apis/get-store-orders.ts +2 -1
  60. package/server/controllers/lazada/apis/index.ts +1 -1
  61. package/server/controllers/lazada/client/lazada.ts +42 -12
  62. package/server/controllers/lazada/platform-action.ts +20 -1
  63. package/server/controllers/shopee/apis/get-store-order-transaction-details.ts +29 -0
  64. package/server/controllers/shopee/apis/get-store-order.ts +12 -6
  65. package/server/controllers/shopee/apis/index.ts +2 -1
  66. package/server/controllers/shopify/apis/get-store-orders.ts +49 -9
  67. package/server/controllers/shopify/apis/get-store-products.ts +3 -1
  68. package/server/controllers/store-api/index.ts +21 -2
  69. package/server/controllers/woocommerce/apis/get-store-order.ts +17 -0
  70. package/server/controllers/woocommerce/apis/get-store-product-categories.ts +6 -48
  71. package/server/controllers/woocommerce/apis/index.ts +10 -0
  72. package/server/controllers/woocommerce/apis/update-order.ts +36 -0
  73. package/server/controllers/woocommerce/apis/update-product-attribute.ts +17 -0
  74. package/server/controllers/woocommerce/apis/update-store-product-price.ts +20 -0
  75. package/server/controllers/woocommerce/apis/update-store-product-stock.ts +2 -2
  76. package/server/controllers/woocommerce/apis/update-store-product-variant-price.ts +17 -0
  77. package/server/controllers/woocommerce/apis/update-store-product-variant-stock.ts +18 -0
  78. package/server/controllers/woocommerce/apis/update-store-product-variation-price.ts +20 -0
  79. package/server/controllers/woocommerce/apis/update-store-product-variation-stock.ts +3 -3
  80. package/server/controllers/woocommerce/woocommerce.ts +2 -2
  81. package/server/graphql/resolvers/marketplace-setting/update-marketplace-setting.ts +1 -1
  82. package/server/routers/shopify-install-public-router.ts +18 -5
  83. package/dist-server/controllers/lazada/apis/get-store-order-item-payment-fee.js +0 -35
  84. package/dist-server/controllers/lazada/apis/get-store-order-item-payment-fee.js.map +0 -1
  85. package/server/controllers/lazada/apis/get-store-order-item-payment-fee.ts +0 -34
@@ -27,6 +27,9 @@ export function getStoreOrders() {
27
27
  },
28
28
  async normalize(res, { store }) {
29
29
  // return res.orders
30
+
31
+ // removed item -> fulfillable_quantity = 0
32
+
30
33
  const linkParams = res.link
31
34
  var more: boolean = false
32
35
 
@@ -44,6 +47,7 @@ export function getStoreOrders() {
44
47
  const fulfillmentStatus = order.fulfillment_status
45
48
  let orderStatus = order?.cancelled_at ? 'cancelled' : fulfillmentStatus ? fulfillmentStatus : 'unfulfilled'
46
49
 
50
+ let itemCount: Number = 0
47
51
  let result: any
48
52
 
49
53
  if (fulfillmentStatus != null) {
@@ -81,15 +85,33 @@ export function getStoreOrders() {
81
85
  } else {
82
86
  let lineItems = []
83
87
 
84
- order.line_items.map(lineItem => {
85
- const refundItems = order.refunds.map(refund => {
86
- const refundLineItems = refund.refund_line_items
87
- return {
88
- ...refundLineItems
88
+ const refundItems = order.refunds
89
+ .reduce((acc, curr) => {
90
+ const refundLineItems = curr.refund_line_items
91
+ acc.push(...refundLineItems)
92
+
93
+ return acc
94
+ }, [])
95
+ .reduce((acc, curr) => {
96
+ let sum = acc.findIndex(x => x.line_item_id === curr.line_item_id)
97
+ if (sum >= 0) {
98
+ acc[sum].quantity += curr.quantity
99
+ } else {
100
+ acc.push(curr)
89
101
  }
90
- })
91
102
 
92
- const matchedLineItem = refundItems.find(item => item[0].line_item_id == lineItem.id)
103
+ return acc
104
+ }, [])
105
+
106
+ let filteredLineItems = []
107
+ if (orderStatus == 'cancelled') {
108
+ filteredLineItems = order.line_items
109
+ } else {
110
+ filteredLineItems = order.line_items.filter(item => item.fulfillable_quantity > 0)
111
+ }
112
+
113
+ filteredLineItems.map(lineItem => {
114
+ const matchedLineItem = refundItems.find(item => item.line_item_id == lineItem.id)
93
115
 
94
116
  if (!matchedLineItem) {
95
117
  lineItem = {
@@ -104,6 +126,19 @@ export function getStoreOrders() {
104
126
  }
105
127
 
106
128
  lineItems.push(lineItem)
129
+ } else {
130
+ lineItem = {
131
+ name: lineItem.id.toString(),
132
+ qty: orderStatus == 'cancelled' ? lineItem.quantity : lineItem.quantity - matchedLineItem.quantity,
133
+ paidPrice: lineItem.price,
134
+ docRefNo: lineItem.id,
135
+ variationId: lineItem.product_exists === true ? lineItem.variant_id : lineItem.id.toString(),
136
+ variationSku: lineItem.sku,
137
+ channelSku: lineItem.sku,
138
+ variationName: lineItem.name
139
+ }
140
+
141
+ if (lineItem.qty >= 0) lineItems.push(lineItem)
107
142
  }
108
143
  })
109
144
 
@@ -111,7 +146,7 @@ export function getStoreOrders() {
111
146
  name: orderId,
112
147
  orderNo: order.name,
113
148
  currency: order.currency,
114
- totalAmount: order.current_total_price,
149
+ totalAmount: orderStatus == 'cancelled' ? order.total_price : order.current_total_price,
115
150
  remark: order.note,
116
151
  orderCreatedAt: new Date(order.created_at).toUTCString(),
117
152
  orderUpdatedAt: new Date(order.updated_at).toUTCString(),
@@ -132,7 +167,8 @@ export function getStoreOrders() {
132
167
  city,
133
168
  country,
134
169
  first_name,
135
- last_name
170
+ last_name,
171
+ province: state
136
172
  } = order?.shipping_address ? order.shipping_address : order.billing_address
137
173
 
138
174
  var orderShipping = {
@@ -145,6 +181,7 @@ export function getStoreOrders() {
145
181
  phone2: null,
146
182
  postCode,
147
183
  city,
184
+ state,
148
185
  country: country === 'MY' ? 'Malaysia' : country,
149
186
  collectionCurrency: null,
150
187
  attentionTo: `${first_name} ${last_name}`
@@ -153,6 +190,9 @@ export function getStoreOrders() {
153
190
  result.orderShipping = orderShipping
154
191
  }
155
192
 
193
+ itemCount = result.orderItems.length
194
+ result.itemCount = itemCount
195
+
156
196
  return result
157
197
  })
158
198
 
@@ -1,6 +1,7 @@
1
1
  /* https://shopify.dev/docs/admin-api/rest/reference/products/product?api[version]=2020-07#index-2020-07 */
2
2
 
3
3
  import { URL } from 'url'
4
+
4
5
  import { StoreAPI } from '../../store-api'
5
6
 
6
7
  export function getStoreProducts() {
@@ -68,6 +69,7 @@ export function getStoreProducts() {
68
69
  name: product.title,
69
70
  type: product.product_type,
70
71
  description: product.body_html,
72
+ marketplaceStatus: product.status,
71
73
  hasVariation: true,
72
74
  categoryId: product?.collection_id ? product.collection_id : null,
73
75
  attributes: [],
@@ -76,7 +78,7 @@ export function getStoreProducts() {
76
78
  variationId: variant.id,
77
79
  variationSku: variant.sku,
78
80
  channelSku: variant.sku,
79
- name: variant.title,
81
+ name: variant.title == 'Default Title' ? product.title : variant.title,
80
82
  qty: variant.inventory_quantity,
81
83
  inventoryPolicy: variant.inventory_policy,
82
84
  inventoryItemId: variant.inventory_item_id,
@@ -1,4 +1,5 @@
1
1
  import { getRepository } from 'typeorm'
2
+
2
3
  import { MarketplaceStore } from '../../entities'
3
4
  import { api } from './decorators'
4
5
 
@@ -80,6 +81,9 @@ export class StoreAPI {
80
81
  @api
81
82
  static updateStoreProduct(store, req): any {}
82
83
 
84
+ @api
85
+ static updateOrder(store, req): any {}
86
+
83
87
  @api
84
88
  static cancelStoreOrder(store, req): any {}
85
89
 
@@ -156,8 +160,23 @@ export class StoreAPI {
156
160
  static getStoreRefundOrders(store, req): any {}
157
161
 
158
162
  @api
159
- static getStoreRefundOrderDetails(store, req): any{}
163
+ static getStoreRefundOrderDetails(store, req): any {}
164
+
165
+ @api
166
+ static getStoreOrderItemPaymentFee(store, req): any {}
167
+
168
+ @api
169
+ static getStoreOrderItemTransactionDetails(store, req): any {}
170
+
171
+ @api
172
+ static updateProductAttribute(store, req): any {}
173
+
174
+ @api
175
+ static getStoreOrderTransactionDetails(store, req): any {}
176
+
177
+ @api
178
+ static updateStoreProductVariationPrice(store, req): any {}
160
179
 
161
180
  @api
162
- static getStoreOrderItemPaymentFee(store, req): any{}
181
+ static updateStoreProductPrice(store, req): any {}
163
182
  }
@@ -0,0 +1,17 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#retrieve-an-order */
2
+
3
+ export function getStoreOrder() {
4
+ return {
5
+ method: 'get',
6
+ path: '/orders/{orderId}',
7
+ denormalize(req) {
8
+ var { orderId } = req
9
+ return {
10
+ resource: { orderId }
11
+ }
12
+ },
13
+ normalize(res) {
14
+ return res.items
15
+ }
16
+ }
17
+ }
@@ -1,58 +1,16 @@
1
1
  /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#list-all-products /wp-json/wc/v3/categoriess */
2
2
 
3
- export function getStoreProducts() {
3
+ export function getStoreProductCategories() {
4
4
  return {
5
5
  method: 'get',
6
- path: '/categories',
6
+ path: '/products/categories',
7
7
  denormalize(req) {
8
- var { pagination } = req || {}
9
- var { page, limit } = pagination || { page: 0, limit: 100 }
10
-
11
- var payload: any = {
12
- per_page: limit,
13
- offset: page * limit
14
- }
15
-
16
- return { payload }
8
+ return { payload: {} }
17
9
  },
18
- async normalize(res, { store }) {
19
- // return res.products
20
-
21
- let results: any[] = []
22
- const totalProducts = res.totalProducts
23
-
24
- for (var i = 0; i < res.products.length; i++) {
25
- const product: any = res.products[i]
26
- const productVariations: any[] = product.variations
27
-
28
- const result = {
29
- itemId: product.id,
30
- name: product.name,
31
- type: product.type,
32
- description: product.description,
33
- hasVariation: true,
34
- categoryId: product?.categories.length > 0 ? product.categories[0].id : null,
35
- attributes: [],
36
- variations: productVariations.map(variant => {
37
- return {
38
- variationId: variant.id,
39
- variationSku: variant.sku,
40
- channelSku: variant.sku,
41
- name: product.name + ' (' + variant.attributes[0].options + ')',
42
- qty: variant.stock_quantity,
43
- primaryUnit: 'N/A',
44
- primaryUnitValue: variant.weight,
45
- costPrice: variant.price,
46
- sellPrice: variant.sale_price,
47
- attributes: variant.attributes
48
- }
49
- })
50
- }
51
-
52
- results.push({ ...result })
53
- }
10
+ normalize(res, { store }) {
11
+ const { items, totalItems } = res
54
12
 
55
- return { results, total: totalProducts }
13
+ return { results: items, total: totalItems }
56
14
  }
57
15
  }
58
16
  }
@@ -1,7 +1,17 @@
1
1
  export * from './echo'
2
2
  export * from './create-order-note'
3
+ export * from './get-store-product-categories'
3
4
  export * from './get-store-products'
4
5
  export * from './get-store-product-variations'
5
6
  export * from './get-store-orders'
6
7
  export * from './update-store-product-stock'
7
8
  export * from './update-store-product-variation-stock'
9
+ export * from './get-store-product-categories'
10
+ export * from './update-order'
11
+ export * from './update-product-attribute'
12
+ export * from './update-store-product-price'
13
+ export * from './update-store-product-variation-price'
14
+ export * from './get-store-order'
15
+ export * from './update-store-product-price'
16
+ export * from './update-store-product-variant-stock'
17
+ export * from './update-store-product-variant-price'
@@ -0,0 +1,36 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/#update-an-order */
2
+ /* /wp-json/wc/v3/orders/<id> */
3
+
4
+ import { StoreAPI } from '../../store-api'
5
+
6
+ export function updateOrder(req) {
7
+ return {
8
+ method: 'put',
9
+ path: '/orders/{orderId}',
10
+ async denormalize(req, { store }) {
11
+ var { status, orderId } = req || {}
12
+
13
+ const order = await StoreAPI.getStoreOrder(store, { orderId })
14
+
15
+ let orderStatus = status
16
+ if (orderStatus == 'PACKED') {
17
+ if (order.status == 'pending') {
18
+ orderStatus = 'on-hold'
19
+ } else {
20
+ orderStatus = order.status
21
+ }
22
+ }
23
+ if (orderStatus == 'READY_TO_SHIP') {
24
+ orderStatus = 'completed'
25
+ }
26
+ if (orderStatus == 'CANCELLED') {
27
+ orderStatus = 'cancelled'
28
+ }
29
+
30
+ return { resource: { orderId: orderId }, payload: { status: orderStatus } }
31
+ },
32
+ normalize(res) {
33
+ return res.items
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,17 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/#update-a-product-attribute */
2
+ /* /wp-json/wc/v3/attributes/<id> */
3
+
4
+ export function updateProductAttribute(req) {
5
+ return {
6
+ method: 'put',
7
+ path: '/products/attributes/{attributeId}',
8
+ denormalize(req) {
9
+ var { name, attributeId } = req || {}
10
+
11
+ return { resource: { attributeId: attributeId }, payload: { name } }
12
+ },
13
+ normalize(res) {
14
+ return res
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,20 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product */
2
+ /* /wp-json/wc/v3/products/<id> */
3
+
4
+ export function updateStoreProductPrice(req) {
5
+ return {
6
+ method: 'put',
7
+ path: '/products/{itemId}',
8
+ denormalize(req) {
9
+ var { costPrice, sellPrice, productId } = req || {}
10
+
11
+ return {
12
+ resource: { itemId: parseInt(productId) },
13
+ payload: { regular_price: costPrice?.toString(), sale_price: sellPrice?.toString() }
14
+ }
15
+ },
16
+ normalize(res) {
17
+ return res
18
+ }
19
+ }
20
+ }
@@ -6,12 +6,12 @@ export function updateStoreProductStock(req) {
6
6
  method: 'put',
7
7
  path: '/products/{itemId}',
8
8
  denormalize(req) {
9
- var { qty, itemId } = req[0] || {}
9
+ var { qty, itemId } = req || {}
10
10
 
11
11
  return { resource: { itemId: parseInt(itemId) }, payload: { stock_quantity: qty, manage_stock: true } }
12
12
  },
13
13
  normalize(res) {
14
- return res.items
14
+ return res
15
15
  }
16
16
  }
17
17
  }
@@ -0,0 +1,17 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
2
+ /* /wp-json/wc/v3/products/<product_id>/variations/<id> */
3
+
4
+ export function updateStoreProductVariantPrice(req) {
5
+ return {
6
+ method: 'put',
7
+ path: '/products/{itemId}/variations/{variantId}',
8
+ denormalize(req) {
9
+ var { cost_price, sell_price, product_id, variant_id } = req[0] || {}
10
+
11
+ return { resource: { itemId: parseInt(product_id), variantId: parseInt(variant_id) }, payload: { price: cost_price, sale_price: sell_price } }
12
+ },
13
+ normalize(res) {
14
+ return res.items
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,18 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
2
+ /* /wp-json/wc/v3/products/<product_id>/variations/<id> */
3
+
4
+ export function updateStoreProductVariantStock(req) {
5
+ return {
6
+ method: 'put',
7
+ path: '/products/{itemId}/variations/{variantId}',
8
+ denormalize(req) {
9
+ var { qty, product_id, variant_id } = req[0] || {}
10
+
11
+ return { resource: { itemId: parseInt(product_id), variantId: parseInt(variant_id) }, payload: { stock_quantity: qty, manage_stock: true } }
12
+ },
13
+ normalize(res) {
14
+ return res.items
15
+ }
16
+ }
17
+ }
18
+
@@ -0,0 +1,20 @@
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
2
+ /* /wp-json/wc/v3/products/<product_id>/variations/<id> */
3
+
4
+ export function updateStoreProductVariationPrice(req) {
5
+ return {
6
+ method: 'put',
7
+ path: '/products/{itemId}/variations/{variantId}',
8
+ denormalize(req) {
9
+ var { costPrice, sellPrice, productId, variationId } = req || {}
10
+
11
+ return {
12
+ resource: { itemId: parseInt(productId), variantId: parseInt(variationId) },
13
+ payload: { regular_price: costPrice?.toString(), sale_price: sellPrice?.toString() }
14
+ }
15
+ },
16
+ normalize(res) {
17
+ return res
18
+ }
19
+ }
20
+ }
@@ -1,4 +1,4 @@
1
- /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product */
1
+ /* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
2
2
  /* /wp-json/wc/v3/products/<product_id>/variations/<id> */
3
3
 
4
4
  export function updateStoreProductVariationStock(req) {
@@ -6,7 +6,7 @@ export function updateStoreProductVariationStock(req) {
6
6
  method: 'put',
7
7
  path: '/products/{itemId}/variations/{variationId}',
8
8
  denormalize(req) {
9
- var { qty, itemId, variationId } = req[0] || {}
9
+ var { qty, itemId, variationId } = req || {}
10
10
 
11
11
  return {
12
12
  resource: { itemId: parseInt(itemId), variationId: parseInt(variationId) },
@@ -14,7 +14,7 @@ export function updateStoreProductVariationStock(req) {
14
14
  }
15
15
  },
16
16
  normalize(res) {
17
- return res.items
17
+ return res
18
18
  }
19
19
  }
20
20
  }
@@ -24,13 +24,13 @@ export class Woocommerce {
24
24
  * X-WP-Total is to get the total items from the response
25
25
  */
26
26
  async get(path: string, data: any) {
27
- const { consumer_key, consumer_secret, storeURL } = this.config
27
+ const { consumer_key, consumer_secret, storeURL, queryStringAuth } = this.config
28
28
 
29
29
  const qs = Object.entries(data)
30
30
  .map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
31
31
  .join('&')
32
32
 
33
- const endpoint = `${storeURL}/wp-json/wc/v3${path}?consumer_key=${consumer_key}&consumer_secret=${consumer_secret}${
33
+ const endpoint = `${storeURL}/wp-json/wc/v3${path}?consumer_key=${consumer_key}&consumer_secret=${consumer_secret}&query_string_auth=${queryStringAuth}&${
34
34
  qs ? '&' + qs : ''
35
35
  }`
36
36
  debug('endpoint', endpoint)
@@ -10,7 +10,7 @@ export const updateMarketplaceSetting = {
10
10
  marketplaceSettingPatch.map(async settingPatch => {
11
11
  const marketplaceStore: MarketplaceStore = await marketplaceStoreRepo.findOne(settingPatch?.marketplaceStore.id)
12
12
  const marketplaceSetting: MarketplaceSetting = await marketplaceSettingRepo.findOne({
13
- where: { domain, marketplaceStore }
13
+ where: { domain, marketplaceStore, category: settingPatch.category }
14
14
  })
15
15
 
16
16
  await marketplaceSettingRepo.save({
@@ -1,8 +1,12 @@
1
1
  import Router from 'koa-router'
2
2
  import fetch from 'node-fetch'
3
+ import { getRepository } from 'typeorm'
4
+
3
5
  import { config } from '@things-factory/env'
4
6
  import { getUrlFromContext } from '@things-factory/shell'
7
+
5
8
  import { Shopify } from '../controllers/shopify'
9
+ import { MarketplaceStore } from '../entities'
6
10
 
7
11
  const debug = require('debug')('things-factory:integration-marketplace:shopify-install-public-router')
8
12
 
@@ -121,15 +125,19 @@ shopifyInstallPublicRouter.get('/callback-shopify-install', async (context, next
121
125
  })
122
126
 
123
127
  shopifyInstallPublicRouter.get('/install-shopify-private', async (context, next) => {
124
- const shopifyConfig = config.get('marketplaceIntegrationShopifyPrivate', {})
125
- const { apiKey, apiSecret } = shopifyConfig
126
-
127
128
  const { secure } = context
128
129
  const { shop: shopUrl } = context.query
129
130
  debug('shop', shopUrl)
130
131
  if (!shopUrl) {
131
132
  context.throw(400, 'shop not found from the request')
132
133
  }
134
+ const marketplaceStore: MarketplaceStore = await getRepository(MarketplaceStore).findOne({
135
+ where: { storeURL: shopUrl }
136
+ })
137
+
138
+ if (!marketplaceStore) context.throw(400, 'marketplace store not found')
139
+
140
+ const { accessKey: apiKey, accessSecret: apiSecret } = marketplaceStore
133
141
  const shop = shopUrl.replace('.myshopify.com', '')
134
142
 
135
143
  const shopify = new Shopify({ apiKey, apiSecret, shop })
@@ -147,8 +155,6 @@ shopifyInstallPublicRouter.get('/install-shopify-private', async (context, next)
147
155
  })
148
156
 
149
157
  shopifyInstallPublicRouter.get('/callback-shopify-install-private', async (context, next) => {
150
- const shopifyConfig = config.get('marketplaceIntegrationShopifyPrivate', {})
151
- const { apiKey, apiSecret } = shopifyConfig
152
158
  const { secure } = context
153
159
  const { shop: shopUrl, code, state } = context.query
154
160
  const stateCookie = context.cookies.get('shopify-install-state')
@@ -162,6 +168,13 @@ shopifyInstallPublicRouter.get('/callback-shopify-install-private', async (conte
162
168
  httpOnly: true
163
169
  })
164
170
 
171
+ const marketplaceStore: MarketplaceStore = await getRepository(MarketplaceStore).findOne({
172
+ where: { storeURL: shopUrl }
173
+ })
174
+
175
+ if (!marketplaceStore) context.throw(400, 'marketplace store not found')
176
+
177
+ const { accessKey: apiKey, accessSecret: apiSecret } = marketplaceStore
165
178
  const shop = shopUrl.replace('.myshopify.com', '')
166
179
 
167
180
  const shopify = new Shopify({ apiKey, apiSecret, shop })
@@ -1,35 +0,0 @@
1
- "use strict";
2
- /* https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.4f406bbetGwYgx#/api?cid=9&path=/finance/transaction/details/get */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getStoreOrderItemPaymentFee = void 0;
5
- function getStoreOrderItemPaymentFee() {
6
- return {
7
- method: 'get',
8
- path: '/finance/transaction/details/get',
9
- denormalize(req) {
10
- var { orderItemId, orderCreatedAt } = req;
11
- let startDate = new Date(orderCreatedAt);
12
- let endDate = new Date(orderCreatedAt);
13
- endDate.setDate(endDate.getDate() + 7);
14
- let currentDate = new Date;
15
- if (endDate > currentDate) {
16
- endDate = currentDate;
17
- }
18
- return {
19
- start_time: startDate.toISOString().replace(/T.*/, '').split('-').join('-'),
20
- end_time: endDate.toISOString().replace(/T.*/, '').split('-').join('-'),
21
- trade_order_line_id: orderItemId
22
- };
23
- },
24
- normalize(res) {
25
- let filtered = res.filter(item => item.fee_name === 'Payment Fee');
26
- let amount = 0;
27
- filtered.forEach(item => {
28
- amount += parseFloat(item.amount);
29
- });
30
- return amount;
31
- }
32
- };
33
- }
34
- exports.getStoreOrderItemPaymentFee = getStoreOrderItemPaymentFee;
35
- //# sourceMappingURL=get-store-order-item-payment-fee.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-store-order-item-payment-fee.js","sourceRoot":"","sources":["../../../../server/controllers/lazada/apis/get-store-order-item-payment-fee.ts"],"names":[],"mappings":";AAAA,gIAAgI;;;AAEhI,SAAgB,2BAA2B;IACvC,OAAO;QACL,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,kCAAkC;QACxC,WAAW,CAAC,GAAG;YACb,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,GAAG,CAAA;YACzC,IAAI,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,CAAA;YACxC,IAAI,OAAO,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,CAAA;YACtC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;YACtC,IAAI,WAAW,GAAG,IAAI,IAAI,CAAA;YAC1B,IAAI,OAAO,GAAG,WAAW,EAAE;gBACvB,OAAO,GAAG,WAAW,CAAA;aACxB;YAED,OAAO;gBACL,UAAU,EAAE,SAAS,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;gBAC1E,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;gBACtE,mBAAmB,EAAE,WAAW;aACjC,CAAA;QACH,CAAC;QACD,SAAS,CAAC,GAAG;YACX,IAAI,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAA;YAElE,IAAI,MAAM,GAAW,CAAC,CAAA;YACtB,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACtB,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACnC,CAAC,CAAC,CAAA;YACF,OAAO,MAAM,CAAA;QACf,CAAC;KACF,CAAA;AACH,CAAC;AA9BH,kEA8BG"}
@@ -1,34 +0,0 @@
1
- /* https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.4f406bbetGwYgx#/api?cid=9&path=/finance/transaction/details/get */
2
-
3
- export function getStoreOrderItemPaymentFee() {
4
- return {
5
- method: 'get',
6
- path: '/finance/transaction/details/get',
7
- denormalize(req) {
8
- var { orderItemId, orderCreatedAt } = req
9
- let startDate = new Date(orderCreatedAt)
10
- let endDate = new Date(orderCreatedAt)
11
- endDate.setDate(endDate.getDate() + 7)
12
- let currentDate = new Date
13
- if (endDate > currentDate) {
14
- endDate = currentDate
15
- }
16
-
17
- return {
18
- start_time: startDate.toISOString().replace(/T.*/,'').split('-').join('-'),
19
- end_time: endDate.toISOString().replace(/T.*/,'').split('-').join('-'),
20
- trade_order_line_id: orderItemId
21
- }
22
- },
23
- normalize(res) {
24
- let filtered = res.filter(item => item.fee_name === 'Payment Fee')
25
-
26
- let amount: number = 0
27
- filtered.forEach(item => {
28
- amount += parseFloat(item.amount)
29
- })
30
- return amount
31
- }
32
- }
33
- }
34
-