@things-factory/integration-marketplace 4.0.7 → 4.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/pages/marketplace-store-woocommerce.js +4 -2
- package/dist-server/controllers/lazada/apis/get-store-order-item-transaction-details.js +88 -0
- package/dist-server/controllers/lazada/apis/get-store-order-item-transaction-details.js.map +1 -0
- package/dist-server/controllers/lazada/apis/get-store-order-items.js +52 -6
- package/dist-server/controllers/lazada/apis/get-store-order-items.js.map +1 -1
- package/dist-server/controllers/lazada/apis/get-store-orders.js +15 -3
- package/dist-server/controllers/lazada/apis/get-store-orders.js.map +1 -1
- package/dist-server/controllers/lazada/apis/get-store-refund-orders.js +50 -0
- package/dist-server/controllers/lazada/apis/get-store-refund-orders.js.map +1 -0
- package/dist-server/controllers/lazada/apis/index.js +2 -0
- package/dist-server/controllers/lazada/apis/index.js.map +1 -1
- package/dist-server/controllers/lazada/client/lazada.js +24 -4
- package/dist-server/controllers/lazada/client/lazada.js.map +1 -1
- package/dist-server/controllers/lazada/platform-action.js +19 -4
- package/dist-server/controllers/lazada/platform-action.js.map +1 -1
- package/dist-server/controllers/shopee/apis/get-store-order-transaction-details.js +32 -0
- package/dist-server/controllers/shopee/apis/get-store-order-transaction-details.js.map +1 -0
- package/dist-server/controllers/shopee/apis/get-store-order.js +25 -10
- package/dist-server/controllers/shopee/apis/get-store-order.js.map +1 -1
- package/dist-server/controllers/shopee/apis/get-store-refund-order-details.js +40 -0
- package/dist-server/controllers/shopee/apis/get-store-refund-order-details.js.map +1 -0
- package/dist-server/controllers/shopee/apis/get-store-refund-orders.js +43 -0
- package/dist-server/controllers/shopee/apis/get-store-refund-orders.js.map +1 -0
- package/dist-server/controllers/shopee/apis/index.js +3 -0
- package/dist-server/controllers/shopee/apis/index.js.map +1 -1
- package/dist-server/controllers/shopify/apis/get-store-orders.js +50 -11
- package/dist-server/controllers/shopify/apis/get-store-orders.js.map +1 -1
- package/dist-server/controllers/shopify/apis/get-store-products.js +2 -1
- package/dist-server/controllers/shopify/apis/get-store-products.js.map +1 -1
- package/dist-server/controllers/store-api/index.js +63 -0
- package/dist-server/controllers/store-api/index.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/get-store-order.js +21 -0
- package/dist-server/controllers/woocommerce/apis/get-store-order.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/get-store-product-categories.js +8 -44
- package/dist-server/controllers/woocommerce/apis/get-store-product-categories.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/index.js +10 -0
- package/dist-server/controllers/woocommerce/apis/index.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/update-order.js +37 -0
- package/dist-server/controllers/woocommerce/apis/update-order.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-product-attribute.js +20 -0
- package/dist-server/controllers/woocommerce/apis/update-product-attribute.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-price.js +23 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-price.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-stock.js +2 -2
- package/dist-server/controllers/woocommerce/apis/update-store-product-stock.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/update-store-product-variant-price.js +20 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variant-price.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variant-stock.js +20 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variant-stock.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js +23 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variation-stock.js +3 -3
- package/dist-server/controllers/woocommerce/apis/update-store-product-variation-stock.js.map +1 -1
- package/dist-server/controllers/woocommerce/platform-action.js +9 -3
- package/dist-server/controllers/woocommerce/platform-action.js.map +1 -1
- package/dist-server/controllers/woocommerce/woocommerce.js +7 -2
- package/dist-server/controllers/woocommerce/woocommerce.js.map +1 -1
- package/dist-server/routers/woocommerce-router.js +0 -7
- package/dist-server/routers/woocommerce-router.js.map +1 -1
- package/package.json +15 -15
- package/server/controllers/lazada/apis/get-store-order-item-transaction-details.ts +65 -0
- package/server/controllers/lazada/apis/get-store-order-items.ts +92 -5
- package/server/controllers/lazada/apis/get-store-orders.ts +17 -2
- package/server/controllers/lazada/apis/get-store-refund-orders.ts +52 -0
- package/server/controllers/lazada/apis/index.ts +2 -0
- package/server/controllers/lazada/client/lazada.ts +42 -12
- package/server/controllers/lazada/platform-action.ts +21 -2
- package/server/controllers/shopee/apis/get-store-order-transaction-details.ts +29 -0
- package/server/controllers/shopee/apis/get-store-order.ts +32 -7
- package/server/controllers/shopee/apis/get-store-refund-order-details.ts +41 -0
- package/server/controllers/shopee/apis/get-store-refund-orders.ts +47 -0
- package/server/controllers/shopee/apis/index.ts +3 -0
- package/server/controllers/shopify/apis/get-store-orders.ts +54 -12
- package/server/controllers/shopify/apis/get-store-products.ts +3 -1
- package/server/controllers/store-api/index.ts +28 -0
- package/server/controllers/woocommerce/apis/get-store-order.ts +17 -0
- package/server/controllers/woocommerce/apis/get-store-product-categories.ts +6 -48
- package/server/controllers/woocommerce/apis/index.ts +10 -0
- package/server/controllers/woocommerce/apis/update-order.ts +36 -0
- package/server/controllers/woocommerce/apis/update-product-attribute.ts +17 -0
- package/server/controllers/woocommerce/apis/update-store-product-price.ts +20 -0
- package/server/controllers/woocommerce/apis/update-store-product-stock.ts +2 -2
- package/server/controllers/woocommerce/apis/update-store-product-variant-price.ts +17 -0
- package/server/controllers/woocommerce/apis/update-store-product-variant-stock.ts +18 -0
- package/server/controllers/woocommerce/apis/update-store-product-variation-price.ts +20 -0
- package/server/controllers/woocommerce/apis/update-store-product-variation-stock.ts +3 -3
- package/server/controllers/woocommerce/platform-action.ts +9 -5
- package/server/controllers/woocommerce/woocommerce.ts +7 -2
- package/server/routers/woocommerce-router.ts +5 -7
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.4f406bbetGwYgx#/api?cid=26&path=/reverse/getreverseordersforseller */
|
|
2
|
+
|
|
3
|
+
export function getStoreRefundOrders() {
|
|
4
|
+
return {
|
|
5
|
+
method: 'get',
|
|
6
|
+
path: '/reverse/getreverseordersforseller',
|
|
7
|
+
denormalize(req) {
|
|
8
|
+
var { pagination } = req || {}
|
|
9
|
+
var { page, limit } = pagination || { page: 0, limit: 100 }
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
page_no: page + 1,
|
|
13
|
+
page_size: limit
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
normalize(res, { store }) {
|
|
17
|
+
var { items, total, page_size, page_no } = res
|
|
18
|
+
|
|
19
|
+
var more: boolean = false
|
|
20
|
+
if (page_size * page_no < total) {
|
|
21
|
+
more = true
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let results: any[] = []
|
|
25
|
+
|
|
26
|
+
items.forEach(async item => {
|
|
27
|
+
let refundItems = item.reverse_order_lines.map(item => {
|
|
28
|
+
let channelSku = item.product.product_sku
|
|
29
|
+
let { reverse_order_line_id: name, reverse_order_line_id: orderItemId, reverse_status: status } = item
|
|
30
|
+
name = name.toString()
|
|
31
|
+
orderItemId = orderItemId.toString()
|
|
32
|
+
return {
|
|
33
|
+
name,
|
|
34
|
+
orderItemId,
|
|
35
|
+
status,
|
|
36
|
+
channelSku
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const result = {
|
|
41
|
+
name: item.reverse_order_id.toString(),
|
|
42
|
+
orderNo: item.reverse_order_id.toString(),
|
|
43
|
+
originalOrderNo: item.trade_order_id.toString(),
|
|
44
|
+
items: refundItems
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
results.push({ ...result })
|
|
48
|
+
})
|
|
49
|
+
return { results, more }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -20,3 +20,5 @@ export * from './set-order-invoice-no'
|
|
|
20
20
|
export * from './update-store-product-stock'
|
|
21
21
|
export * from './update-store-product-variation-stock'
|
|
22
22
|
export * from './update-store-product'
|
|
23
|
+
export * from './get-store-refund-orders'
|
|
24
|
+
export * from './get-store-order-item-transaction-details'
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import FormData from 'form-data'
|
|
1
2
|
import fetch from 'node-fetch'
|
|
2
|
-
import {
|
|
3
|
+
import { getRepository } from 'typeorm'
|
|
4
|
+
|
|
5
|
+
import { MarketplaceStore } from '../../../entities'
|
|
3
6
|
import { makeSystemParameters } from './signature'
|
|
7
|
+
import { Endpoint, Parameter } from './types'
|
|
4
8
|
import { xmlize } from './xml'
|
|
5
|
-
import FormData from 'form-data'
|
|
6
9
|
|
|
7
10
|
export class Lazada {
|
|
8
11
|
endpoint: string
|
|
@@ -38,13 +41,13 @@ export class Lazada {
|
|
|
38
41
|
return await response.json()
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
async refreshAccessToken(payload: { refresh_token: string }) {
|
|
44
|
+
public static async refreshAccessToken(payload: { refresh_token: string }, appKey, appSecret, storeId) {
|
|
42
45
|
/* CONFIRM-ME not qualified */
|
|
43
46
|
const apiPath = '/auth/token/refresh'
|
|
44
47
|
|
|
45
48
|
const body = {
|
|
46
49
|
...payload,
|
|
47
|
-
...makeSystemParameters(
|
|
50
|
+
...makeSystemParameters(appKey, appSecret, apiPath, undefined, payload)
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
const response = await fetch(Endpoint.auth + apiPath, {
|
|
@@ -55,6 +58,25 @@ export class Lazada {
|
|
|
55
58
|
body: JSON.stringify(body)
|
|
56
59
|
})
|
|
57
60
|
|
|
61
|
+
const repository = getRepository(MarketplaceStore)
|
|
62
|
+
const store: MarketplaceStore = await repository.findOne({
|
|
63
|
+
where: { id: storeId }
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const refreshTokenInfo = await response.json()
|
|
67
|
+
const { access_token, refresh_token } = refreshTokenInfo
|
|
68
|
+
|
|
69
|
+
var patch = {
|
|
70
|
+
accessToken: access_token,
|
|
71
|
+
refreshToken: refresh_token,
|
|
72
|
+
accessInfo: JSON.stringify(refreshTokenInfo, null, 2)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
await repository.save({
|
|
76
|
+
...store,
|
|
77
|
+
...patch
|
|
78
|
+
})
|
|
79
|
+
|
|
58
80
|
return await response.json()
|
|
59
81
|
}
|
|
60
82
|
|
|
@@ -72,6 +94,10 @@ export class Lazada {
|
|
|
72
94
|
}
|
|
73
95
|
})
|
|
74
96
|
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
throw response
|
|
99
|
+
}
|
|
100
|
+
|
|
75
101
|
return await response.json()
|
|
76
102
|
}
|
|
77
103
|
|
|
@@ -80,13 +106,13 @@ export class Lazada {
|
|
|
80
106
|
params.payload = xmlize(params.payload)
|
|
81
107
|
}
|
|
82
108
|
|
|
83
|
-
const {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
const { app_key, timestamp, access_token, sign_method, sign } = makeSystemParameters(
|
|
110
|
+
this.appKey,
|
|
111
|
+
this.appSecret,
|
|
112
|
+
path,
|
|
113
|
+
accessToken || this.accessToken,
|
|
114
|
+
params
|
|
115
|
+
)
|
|
90
116
|
|
|
91
117
|
const body = new FormData()
|
|
92
118
|
|
|
@@ -96,7 +122,7 @@ export class Lazada {
|
|
|
96
122
|
body.append('sign_method', sign_method)
|
|
97
123
|
body.append('sign', sign)
|
|
98
124
|
|
|
99
|
-
for(let key in params) {
|
|
125
|
+
for (let key in params) {
|
|
100
126
|
body.append(key, params[key])
|
|
101
127
|
}
|
|
102
128
|
|
|
@@ -106,6 +132,10 @@ export class Lazada {
|
|
|
106
132
|
body
|
|
107
133
|
})
|
|
108
134
|
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
throw response
|
|
137
|
+
}
|
|
138
|
+
|
|
109
139
|
return await response.json()
|
|
110
140
|
}
|
|
111
141
|
}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
+
import { config } from '@things-factory/env'
|
|
2
|
+
|
|
1
3
|
import { Lazada } from './client'
|
|
2
4
|
|
|
3
|
-
import { config } from '@things-factory/env'
|
|
4
5
|
const lazadaConfig = config.get('marketplaceIntegrationLazada', {})
|
|
5
6
|
const { appKey, appSecret } = lazadaConfig
|
|
6
7
|
|
|
7
8
|
export const action = async ({ store, method = 'get', path, request }) => {
|
|
9
|
+
try {
|
|
10
|
+
return await _action({ store, method, path, request })
|
|
11
|
+
} catch (ex) {
|
|
12
|
+
if (ex.code === 'IllegalAccessToken') {
|
|
13
|
+
var refreshStore = await Lazada.refreshAccessToken(
|
|
14
|
+
{ refresh_token: store.refreshToken },
|
|
15
|
+
appKey,
|
|
16
|
+
appSecret,
|
|
17
|
+
store.id
|
|
18
|
+
)
|
|
19
|
+
return await _action({ store: refreshStore, method, path, request })
|
|
20
|
+
} else {
|
|
21
|
+
throw ex
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const _action = async ({ store, method = 'get', path, request }) => {
|
|
8
27
|
const client = new Lazada(store.countryCode, appKey, appSecret)
|
|
9
28
|
|
|
10
29
|
var response = await client[method == 'post' ? 'post' : 'get'](path, request, store.accessToken)
|
|
@@ -12,5 +31,5 @@ export const action = async ({ store, method = 'get', path, request }) => {
|
|
|
12
31
|
throw response
|
|
13
32
|
}
|
|
14
33
|
|
|
15
|
-
return response.data
|
|
34
|
+
return response?.data ? response.data : response.result
|
|
16
35
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* https://open.shopee.com/documents?module=4&type=1&id=396&version=1 */
|
|
2
|
+
|
|
3
|
+
export function getStoreOrderTransactionDetails() {
|
|
4
|
+
return {
|
|
5
|
+
method: 'post',
|
|
6
|
+
path: '/orders/my_income',
|
|
7
|
+
denormalize(req) {
|
|
8
|
+
var { orderNo } = req
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
ordersn: orderNo
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
normalize(res) {
|
|
15
|
+
var { order } = res
|
|
16
|
+
const result = {
|
|
17
|
+
voucherAmount: parseFloat(order.income_details.voucher_seller) || null,
|
|
18
|
+
shippingRebate: parseFloat(order.income_details.shipping_fee_rebate) || null,
|
|
19
|
+
commissionFee: parseFloat(order.income_details.commission_fee) || null,
|
|
20
|
+
serviceFee: parseFloat(order.income_details.service_fee) || null,
|
|
21
|
+
transactionFee: parseFloat(order.income_details.seller_transaction_fee) || null,
|
|
22
|
+
totalRealeasedAmount: parseFloat(order.income_details.escrow_amount) || null,
|
|
23
|
+
voucherCode: order.income_details.voucher_code,
|
|
24
|
+
shippingMode: order.shipping_carrier
|
|
25
|
+
}
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* https://open.shopee.com/documents?module=4&type=1&id=397 */
|
|
2
2
|
|
|
3
|
+
import { StoreAPI } from '../../store-api'
|
|
4
|
+
|
|
3
5
|
export function getStoreOrder() {
|
|
4
6
|
return {
|
|
5
7
|
path: '/orders/detail',
|
|
@@ -10,8 +12,17 @@ export function getStoreOrder() {
|
|
|
10
12
|
ordersn_list: [orderNo]
|
|
11
13
|
}
|
|
12
14
|
},
|
|
13
|
-
normalize(res) {
|
|
14
|
-
let results = res.orders.map(order => {
|
|
15
|
+
normalize(res, { store }) {
|
|
16
|
+
let results = res.orders.map(async order => {
|
|
17
|
+
if (order.pay_time) {
|
|
18
|
+
order.pay_time = new Date(order.pay_time * 1000)
|
|
19
|
+
}
|
|
20
|
+
if (order.estimated_shipping_fee) {
|
|
21
|
+
order.estimated_shipping_fee = parseFloat(order.estimated_shipping_fee)
|
|
22
|
+
}
|
|
23
|
+
if (order.actual_shipping_cost) {
|
|
24
|
+
order.actual_shipping_cost = parseFloat(order.actual_shipping_cost)
|
|
25
|
+
}
|
|
15
26
|
const {
|
|
16
27
|
ordersn: name,
|
|
17
28
|
ordersn: orderNo,
|
|
@@ -24,7 +35,11 @@ export function getStoreOrder() {
|
|
|
24
35
|
total_amount: totalAmount,
|
|
25
36
|
tracking_no,
|
|
26
37
|
recipient_address,
|
|
27
|
-
items
|
|
38
|
+
items,
|
|
39
|
+
buyer_username: buyerUsername,
|
|
40
|
+
pay_time: payTime,
|
|
41
|
+
estimated_shipping_fee: shippingFee,
|
|
42
|
+
actual_shipping_cost: actualShippingFee
|
|
28
43
|
} = order
|
|
29
44
|
var status = order_status.toLowerCase()
|
|
30
45
|
var orderUpdatedAt = new Date(update_time * 1000)
|
|
@@ -42,7 +57,8 @@ export function getStoreOrder() {
|
|
|
42
57
|
variation_discounted_price: variationDiscountedPrice,
|
|
43
58
|
promotion_type: promotionType,
|
|
44
59
|
promotion_id: promotionId,
|
|
45
|
-
is_wholesale: isWholesale
|
|
60
|
+
is_wholesale: isWholesale,
|
|
61
|
+
variation_original_price: variationOriginalPrice
|
|
46
62
|
} = item
|
|
47
63
|
var variationId = variation_id == 0 ? name : variation_id
|
|
48
64
|
return {
|
|
@@ -54,7 +70,9 @@ export function getStoreOrder() {
|
|
|
54
70
|
promotionType,
|
|
55
71
|
promotionId,
|
|
56
72
|
isWholesale,
|
|
57
|
-
docRefNo
|
|
73
|
+
docRefNo,
|
|
74
|
+
originalPrice: qty * variationOriginalPrice,
|
|
75
|
+
discount: qty * variationOriginalPrice - qty * variationDiscountedPrice
|
|
58
76
|
}
|
|
59
77
|
})
|
|
60
78
|
|
|
@@ -74,9 +92,13 @@ export function getStoreOrder() {
|
|
|
74
92
|
collectionCurrency: null,
|
|
75
93
|
attentionTo,
|
|
76
94
|
trackingNo,
|
|
77
|
-
transporter: shippingProvider
|
|
95
|
+
transporter: shippingProvider,
|
|
96
|
+
shippingFee: parseFloat(shippingFee) || null,
|
|
97
|
+
actualShippingFee: parseFloat(actualShippingFee) || null
|
|
78
98
|
}
|
|
79
99
|
|
|
100
|
+
let escrowDetails = await StoreAPI.getStoreOrderTransactionDetails(store, { orderNo })
|
|
101
|
+
|
|
80
102
|
return {
|
|
81
103
|
name,
|
|
82
104
|
orderNo,
|
|
@@ -92,7 +114,10 @@ export function getStoreOrder() {
|
|
|
92
114
|
shippingProvider,
|
|
93
115
|
itemCount,
|
|
94
116
|
orderItems,
|
|
95
|
-
orderShipping
|
|
117
|
+
orderShipping,
|
|
118
|
+
buyerUsername,
|
|
119
|
+
payTime,
|
|
120
|
+
...escrowDetails
|
|
96
121
|
}
|
|
97
122
|
})
|
|
98
123
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* https://open.shopee.com/documents?module=5&type=1&id=443&version=1 */
|
|
2
|
+
|
|
3
|
+
import { StoreAPI } from '../../store-api'
|
|
4
|
+
|
|
5
|
+
export function getStoreRefundOrderDetails() {
|
|
6
|
+
return {
|
|
7
|
+
path: '/returns/detail',
|
|
8
|
+
denormalize(req) {
|
|
9
|
+
var { refundOrderNo } = req
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
returnsn: refundOrderNo
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
async normalize(res, { store }) {
|
|
16
|
+
let refundItems = res.items.map(item => {
|
|
17
|
+
let { item_id: name, item_id: orderItemId, item_price: price, amount: qty, variation_id: variationId } = item
|
|
18
|
+
name = name.toString()
|
|
19
|
+
orderItemId = orderItemId.toString()
|
|
20
|
+
return {
|
|
21
|
+
name,
|
|
22
|
+
orderItemId,
|
|
23
|
+
price,
|
|
24
|
+
qty,
|
|
25
|
+
variationId
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
let results = {
|
|
30
|
+
name: res.returnsn.toString(),
|
|
31
|
+
orderNo: res.returnsn.toString(),
|
|
32
|
+
amount: res.refund_amount,
|
|
33
|
+
status: res.status,
|
|
34
|
+
items: refundItems,
|
|
35
|
+
variationId: res.variationId
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return results
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* https://open.shopee.com/documents?module=5&type=1&id=403&version=1 */
|
|
2
|
+
|
|
3
|
+
import { StoreAPI } from '../../store-api'
|
|
4
|
+
|
|
5
|
+
export function getStoreRefundOrders() {
|
|
6
|
+
return {
|
|
7
|
+
path: '/returns/get',
|
|
8
|
+
denormalize(req) {
|
|
9
|
+
var { pagination, fromDate, toDate } = req || {}
|
|
10
|
+
var { page = 0, limit = 100 } = pagination || {}
|
|
11
|
+
|
|
12
|
+
var create_time_from = Math.floor(new Date(fromDate).getTime() / 1000)
|
|
13
|
+
var create_time_to = Math.floor(new Date(toDate).getTime() / 1000)
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
pagination_entries_per_page: limit,
|
|
17
|
+
pagination_offset: page * limit,
|
|
18
|
+
create_time_from,
|
|
19
|
+
create_time_to
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
async normalize(res, { store }) {
|
|
23
|
+
// res.returns.push( // TO BE REMOVED
|
|
24
|
+
// {
|
|
25
|
+
// returnsn: 180529163852038,
|
|
26
|
+
// refund_amount: 122,
|
|
27
|
+
// status: 'CANCELLED',
|
|
28
|
+
// ordersn: '211104MSNDH3CD'
|
|
29
|
+
// }
|
|
30
|
+
// )
|
|
31
|
+
|
|
32
|
+
var { returns, more } = res
|
|
33
|
+
|
|
34
|
+
let results: any[] = []
|
|
35
|
+
|
|
36
|
+
for (var i = 0; i < returns?.length; i++) {
|
|
37
|
+
const refundOrder = returns[i]
|
|
38
|
+
const refundOrderNo = refundOrder.returnsn
|
|
39
|
+
|
|
40
|
+
const result = await StoreAPI.getStoreRefundOrderDetails(store, { refundOrderNo })
|
|
41
|
+
|
|
42
|
+
results.push({ ...result, originalOrderNo: refundOrder.ordersn })
|
|
43
|
+
}
|
|
44
|
+
return { results, more }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -24,3 +24,6 @@ export * from './split-order'
|
|
|
24
24
|
// export * from './update-store-product'
|
|
25
25
|
export * from './update-store-product-stock'
|
|
26
26
|
export * from './update-store-product-variation-stock'
|
|
27
|
+
export * from './get-store-refund-orders'
|
|
28
|
+
export * from './get-store-refund-order-details'
|
|
29
|
+
export * from './get-store-order-transaction-details'
|
|
@@ -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
|
|
|
@@ -42,6 +45,9 @@ export function getStoreOrders() {
|
|
|
42
45
|
.map(order => {
|
|
43
46
|
const orderId = order.id
|
|
44
47
|
const fulfillmentStatus = order.fulfillment_status
|
|
48
|
+
let orderStatus = order?.cancelled_at ? 'cancelled' : fulfillmentStatus ? fulfillmentStatus : 'unfulfilled'
|
|
49
|
+
|
|
50
|
+
let itemCount: Number = 0
|
|
45
51
|
let result: any
|
|
46
52
|
|
|
47
53
|
if (fulfillmentStatus != null) {
|
|
@@ -49,14 +55,14 @@ export function getStoreOrders() {
|
|
|
49
55
|
|
|
50
56
|
result = {
|
|
51
57
|
name: fulfillment.order_id,
|
|
52
|
-
orderNo: order.
|
|
58
|
+
orderNo: order.name,
|
|
53
59
|
currency: order.currency,
|
|
54
60
|
totalAmount: order.current_total_price,
|
|
55
61
|
remark: order.note,
|
|
56
62
|
orderCreatedAt: new Date(order.created_at).toUTCString(),
|
|
57
63
|
orderUpdatedAt: new Date(order.updated_at).toUTCString(),
|
|
58
64
|
discountValue: order.total_discounts,
|
|
59
|
-
status:
|
|
65
|
+
status: orderStatus,
|
|
60
66
|
trackingNo: fulfillment.tracking_number,
|
|
61
67
|
shippingProvider: fulfillment.tracking_company,
|
|
62
68
|
recipientAddress:
|
|
@@ -79,15 +85,33 @@ export function getStoreOrders() {
|
|
|
79
85
|
} else {
|
|
80
86
|
let lineItems = []
|
|
81
87
|
|
|
82
|
-
order.
|
|
83
|
-
|
|
84
|
-
const refundLineItems =
|
|
85
|
-
|
|
86
|
-
|
|
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)
|
|
87
101
|
}
|
|
88
|
-
})
|
|
89
102
|
|
|
90
|
-
|
|
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)
|
|
91
115
|
|
|
92
116
|
if (!matchedLineItem) {
|
|
93
117
|
lineItem = {
|
|
@@ -102,6 +126,19 @@ export function getStoreOrders() {
|
|
|
102
126
|
}
|
|
103
127
|
|
|
104
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)
|
|
105
142
|
}
|
|
106
143
|
})
|
|
107
144
|
|
|
@@ -109,13 +146,13 @@ export function getStoreOrders() {
|
|
|
109
146
|
name: orderId,
|
|
110
147
|
orderNo: order.name,
|
|
111
148
|
currency: order.currency,
|
|
112
|
-
totalAmount: order.current_total_price,
|
|
149
|
+
totalAmount: orderStatus == 'cancelled' ? order.total_price : order.current_total_price,
|
|
113
150
|
remark: order.note,
|
|
114
151
|
orderCreatedAt: new Date(order.created_at).toUTCString(),
|
|
115
152
|
orderUpdatedAt: new Date(order.updated_at).toUTCString(),
|
|
116
153
|
discountValue: order.total_discounts,
|
|
117
154
|
recipientAddress: order.billing_address,
|
|
118
|
-
status:
|
|
155
|
+
status: orderStatus,
|
|
119
156
|
reason: order.cancel_reason,
|
|
120
157
|
orderItems: lineItems
|
|
121
158
|
}
|
|
@@ -130,7 +167,8 @@ export function getStoreOrders() {
|
|
|
130
167
|
city,
|
|
131
168
|
country,
|
|
132
169
|
first_name,
|
|
133
|
-
last_name
|
|
170
|
+
last_name,
|
|
171
|
+
province: state
|
|
134
172
|
} = order?.shipping_address ? order.shipping_address : order.billing_address
|
|
135
173
|
|
|
136
174
|
var orderShipping = {
|
|
@@ -143,6 +181,7 @@ export function getStoreOrders() {
|
|
|
143
181
|
phone2: null,
|
|
144
182
|
postCode,
|
|
145
183
|
city,
|
|
184
|
+
state,
|
|
146
185
|
country: country === 'MY' ? 'Malaysia' : country,
|
|
147
186
|
collectionCurrency: null,
|
|
148
187
|
attentionTo: `${first_name} ${last_name}`
|
|
@@ -151,6 +190,9 @@ export function getStoreOrders() {
|
|
|
151
190
|
result.orderShipping = orderShipping
|
|
152
191
|
}
|
|
153
192
|
|
|
193
|
+
itemCount = result.orderItems.length
|
|
194
|
+
result.itemCount = itemCount
|
|
195
|
+
|
|
154
196
|
return result
|
|
155
197
|
})
|
|
156
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
|
|
|
@@ -151,4 +155,28 @@ export class StoreAPI {
|
|
|
151
155
|
|
|
152
156
|
@api
|
|
153
157
|
static splitOrder(store, req): any {}
|
|
158
|
+
|
|
159
|
+
@api
|
|
160
|
+
static getStoreRefundOrders(store, req): any {}
|
|
161
|
+
|
|
162
|
+
@api
|
|
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 {}
|
|
179
|
+
|
|
180
|
+
@api
|
|
181
|
+
static updateStoreProductPrice(store, req): any {}
|
|
154
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
|
+
}
|