@things-factory/integration-marketplace 3.7.7 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-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 +39 -7
- package/dist-server/controllers/lazada/apis/get-store-order-items.js.map +1 -1
- package/dist-server/controllers/lazada/apis/index.js +1 -1
- 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 +18 -3
- 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 +19 -11
- package/dist-server/controllers/shopee/apis/get-store-order.js.map +1 -1
- package/dist-server/controllers/shopee/apis/index.js +1 -0
- package/dist-server/controllers/shopee/apis/index.js.map +1 -1
- package/dist-server/controllers/shopify/apis/get-store-orders.js +46 -8
- 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 +42 -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/woocommerce.js +2 -2
- package/dist-server/controllers/woocommerce/woocommerce.js.map +1 -1
- package/package.json +14 -14
- package/server/controllers/lazada/apis/get-store-order-item-transaction-details.ts +65 -0
- package/server/controllers/lazada/apis/get-store-order-items.ts +74 -6
- package/server/controllers/lazada/apis/index.ts +1 -1
- package/server/controllers/lazada/client/lazada.ts +42 -12
- package/server/controllers/lazada/platform-action.ts +20 -1
- package/server/controllers/shopee/apis/get-store-order-transaction-details.ts +29 -0
- package/server/controllers/shopee/apis/get-store-order.ts +21 -8
- package/server/controllers/shopee/apis/index.ts +2 -1
- package/server/controllers/shopify/apis/get-store-orders.ts +49 -9
- package/server/controllers/shopify/apis/get-store-products.ts +3 -1
- package/server/controllers/store-api/index.ts +21 -2
- 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/woocommerce.ts +2 -2
- package/dist-server/controllers/lazada/apis/get-store-order-item-payment-fee.js +0 -35
- package/dist-server/controllers/lazada/apis/get-store-order-item-payment-fee.js.map +0 -1
- package/server/controllers/lazada/apis/get-store-order-item-payment-fee.ts +0 -34
|
@@ -0,0 +1,65 @@
|
|
|
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 getStoreOrderItemTransactionDetails() {
|
|
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() + 14)
|
|
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 payment_fee = 0
|
|
25
|
+
let commission_fee = 0
|
|
26
|
+
let promotional_charges = 0
|
|
27
|
+
let shipping_fee_paid_by_customer = 0
|
|
28
|
+
let item_price_credit = 0
|
|
29
|
+
let orders_marketplace_fees_total = 0
|
|
30
|
+
let orders_sales_total = 0
|
|
31
|
+
let orders_marketing_fees_total = 0
|
|
32
|
+
let orders_logistics_total = 0
|
|
33
|
+
let promotional_charges_flexi_combo = 0
|
|
34
|
+
let auto_shipping_subsidy_marketplace = 0
|
|
35
|
+
|
|
36
|
+
res.forEach(item => {
|
|
37
|
+
if (item.fee_name == 'Payment Fee') { payment_fee += parseFloat(item.amount) || 0 }
|
|
38
|
+
if (item.fee_name == 'Commission') { commission_fee += parseFloat(item.amount) || 0 }
|
|
39
|
+
if (item.fee_name == 'Item Price Credit') { item_price_credit += parseFloat(item.amount) || 0 }
|
|
40
|
+
if (item.fee_name == 'Promotional Charges Vouchers') { promotional_charges += parseFloat(item.amount) || 0 }
|
|
41
|
+
if (item.fee_name == 'Shipping Fee (Paid By Customer)') { shipping_fee_paid_by_customer += parseFloat(item.amount) || 0 }
|
|
42
|
+
if (item.fee_name == 'Promotional Charges Flexi-Combo') { promotional_charges_flexi_combo += parseFloat(item.amount) || 0 }
|
|
43
|
+
if (item.fee_name == 'Auto. Shipping fee subsidy (by Lazada)') { auto_shipping_subsidy_marketplace += parseFloat(item.amount) || 0 }
|
|
44
|
+
|
|
45
|
+
if (item.transaction_type == 'Orders-Lazada Fees') { orders_marketplace_fees_total += parseFloat(item.amount) || 0 }
|
|
46
|
+
if (item.transaction_type == 'Orders-Sales') { orders_sales_total += parseFloat(item.amount) || 0 }
|
|
47
|
+
if (item.transaction_type == 'Orders-Marketing Fees') { orders_marketing_fees_total += parseFloat(item.amount) || 0 }
|
|
48
|
+
if (item.transaction_type == 'Orders-Logistics') { orders_logistics_total += parseFloat(item.amount) || 0 }
|
|
49
|
+
})
|
|
50
|
+
return {
|
|
51
|
+
payment_fee: Math.trunc(payment_fee * 100) / 100,
|
|
52
|
+
commission_fee: Math.trunc(commission_fee * 100) / 100,
|
|
53
|
+
promotional_charges: Math.trunc(promotional_charges * 100) / 100,
|
|
54
|
+
shipping_fee_paid_by_customer: Math.trunc(shipping_fee_paid_by_customer * 100) / 100,
|
|
55
|
+
item_price_credit: Math.trunc(item_price_credit * 100) / 100,
|
|
56
|
+
orders_marketplace_fees_total: Math.trunc(orders_marketplace_fees_total * 100) / 100,
|
|
57
|
+
orders_sales_total: Math.trunc(orders_sales_total * 100) / 100,
|
|
58
|
+
orders_marketing_fees_total: Math.trunc(orders_marketing_fees_total * 100) / 100,
|
|
59
|
+
orders_logistics_total: Math.trunc(orders_logistics_total * 100) / 100,
|
|
60
|
+
promotional_charges_flexi_combo: Math.trunc(promotional_charges_flexi_combo * 100) / 100,
|
|
61
|
+
auto_shipping_subsidy_marketplace: Math.trunc(auto_shipping_subsidy_marketplace * 100) / 100
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -20,8 +20,11 @@ export function getStoreOrderItems() {
|
|
|
20
20
|
orderItemId: item.order_item_id,
|
|
21
21
|
orderCreatedAt: item.created_at
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
res[i]
|
|
23
|
+
let transactionDetails = await StoreAPI.getStoreOrderItemTransactionDetails(store, req)
|
|
24
|
+
res[i] = {
|
|
25
|
+
...res[i],
|
|
26
|
+
...transactionDetails
|
|
27
|
+
}
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
let results = res
|
|
@@ -41,12 +44,28 @@ export function getStoreOrderItems() {
|
|
|
41
44
|
paid_price: item.paid_price,
|
|
42
45
|
item_price: item.item_price,
|
|
43
46
|
payment_fee: item.payment_fee,
|
|
47
|
+
commission_fee: item.commission_fee,
|
|
48
|
+
promotional_charges: item.promotional_charges,
|
|
49
|
+
shipping_fee_paid_by_customer: item.shipping_fee_paid_by_customer,
|
|
50
|
+
item_price_credit: item.item_price_credit,
|
|
51
|
+
orders_marketplace_fees_total: item.orders_marketplace_fees_total,
|
|
52
|
+
orders_sales_total: item.orders_sales_total,
|
|
53
|
+
orders_marketing_fees_total: item.orders_marketing_fees_total,
|
|
54
|
+
orders_logistics_total: item.orders_logistics_total,
|
|
44
55
|
qty: 1,
|
|
45
56
|
shipment_provider: item.shipment_provider,
|
|
46
57
|
tracking_code: JSON.stringify(
|
|
47
58
|
item.tracking_code ? [{ order_item_id: item.order_item_id, tracking_code: item.tracking_code }] : []
|
|
48
59
|
),
|
|
49
|
-
status: item.status
|
|
60
|
+
status: item.status,
|
|
61
|
+
voucher_platform_lpi: item.voucher_platform_lpi,
|
|
62
|
+
voucher_seller_lpi: item.voucher_seller_lpi,
|
|
63
|
+
shipping_fee_discount_platform: item.shipping_fee_discount_platform,
|
|
64
|
+
shipping_fee_discount_seller: item.shipping_fee_discount_seller,
|
|
65
|
+
promotional_charges_flexi_combo: item.promotional_charges_flexi_combo,
|
|
66
|
+
auto_shipping_subsidy_marketplace: item.auto_shipping_subsidy_marketplace,
|
|
67
|
+
shipping_fee_original: item.shipping_fee_original,
|
|
68
|
+
tax_amount: item.tax_amount
|
|
50
69
|
}
|
|
51
70
|
|
|
52
71
|
newItem.push(data)
|
|
@@ -58,12 +77,29 @@ export function getStoreOrderItems() {
|
|
|
58
77
|
qty: existingItem.qty + 1,
|
|
59
78
|
paid_price: item.paid_price + existingItem.paid_price,
|
|
60
79
|
item_price: item.item_price + existingItem.item_price,
|
|
80
|
+
payment_fee: item.payment_fee + existingItem.payment_fee,
|
|
81
|
+
commission_fee: item.commission_fee + existingItem.commission_fee,
|
|
82
|
+
promotional_charges: item.promotional_charges + existingItem.promotional_charges,
|
|
83
|
+
shipping_fee_paid_by_customer: item.shipping_fee_paid_by_customer + existingItem.shipping_fee_paid_by_customer,
|
|
84
|
+
item_price_credit: item.item_price_credit + existingItem.item_price_credit,
|
|
85
|
+
orders_marketplace_fees_total: item.orders_marketplace_fees_total + existingItem.orders_marketplace_fees_total,
|
|
86
|
+
orders_sales_total: item.orders_sales_total + existingItem.orders_sales_total,
|
|
87
|
+
orders_marketing_fees_total: item.orders_marketing_fees_total + existingItem.orders_marketing_fees_total,
|
|
88
|
+
orders_logistics_total: item.orders_logistics_total + existingItem.orders_logistics_total,
|
|
61
89
|
tracking_code: item.tracking_code
|
|
62
90
|
? JSON.stringify([
|
|
63
91
|
...JSON.parse(existingItem.tracking_code),
|
|
64
92
|
{ order_item_id: item.order_item_id, tracking_code: item.tracking_code }
|
|
65
93
|
])
|
|
66
|
-
: existingItem.tracking_code
|
|
94
|
+
: existingItem.tracking_code,
|
|
95
|
+
voucher_platform_lpi: item.voucher_platform_lpi + existingItem.voucher_platform_lpi,
|
|
96
|
+
voucher_seller_lpi: item.voucher_seller_lpi + existingItem.voucher_seller_lpi,
|
|
97
|
+
shipping_fee_discount_platform: item.shipping_fee_discount_platform + existingItem.shipping_fee_discount_platform,
|
|
98
|
+
shipping_fee_discount_seller: item.shipping_fee_discount_seller + existingItem.shipping_fee_discount_seller,
|
|
99
|
+
promotional_charges_flexi_combo: item.promotional_charges_flexi_combo + existingItem.promotional_charges_flexi_combo,
|
|
100
|
+
auto_shipping_subsidy_marketplace: item.auto_shipping_subsidy_marketplace + existingItem.auto_shipping_subsidy_marketplace,
|
|
101
|
+
shipping_fee_original: item.shipping_fee_original + existingItem.shipping_fee_original,
|
|
102
|
+
tax_amount: item.tax_amount + existingItem.tax_amount
|
|
67
103
|
}
|
|
68
104
|
}
|
|
69
105
|
return newItem
|
|
@@ -83,7 +119,23 @@ export function getStoreOrderItems() {
|
|
|
83
119
|
tracking_code,
|
|
84
120
|
status,
|
|
85
121
|
item_price: originalPrice,
|
|
86
|
-
payment_fee: paymentFee
|
|
122
|
+
payment_fee: paymentFee,
|
|
123
|
+
commission_fee: commissionFee,
|
|
124
|
+
promotional_charges: promotionalCharges,
|
|
125
|
+
shipping_fee_paid_by_customer: shippingFeePaidByCustomer,
|
|
126
|
+
item_price_credit: itemPriceCredit,
|
|
127
|
+
orders_marketplace_fees_total: ordersMarketplaceFeesTotal,
|
|
128
|
+
orders_sales_total: ordersSalesTotal,
|
|
129
|
+
orders_marketing_fees_total: ordersMarketingFeesTotal,
|
|
130
|
+
orders_logistics_total: ordersLogisticsTotal,
|
|
131
|
+
voucher_platform_lpi: marketplaceBonus,
|
|
132
|
+
voucher_seller_lpi: marketplaceBonusSeller,
|
|
133
|
+
shipping_fee_discount_platform: shippingFeeDiscountMarketplace,
|
|
134
|
+
shipping_fee_discount_seller: shippingFeeDiscountSeller,
|
|
135
|
+
promotional_charges_flexi_combo: promotionalChargesFlexiCombo,
|
|
136
|
+
auto_shipping_subsidy_marketplace: autoShippingSubsidyMarketplace,
|
|
137
|
+
shipping_fee_original: originalShippingFee,
|
|
138
|
+
tax_amount: taxAmount
|
|
87
139
|
} = orderItem
|
|
88
140
|
var trackingNo = tracking_code === '' ? null : tracking_code
|
|
89
141
|
|
|
@@ -101,7 +153,23 @@ export function getStoreOrderItems() {
|
|
|
101
153
|
trackingNo,
|
|
102
154
|
status,
|
|
103
155
|
originalPrice,
|
|
104
|
-
paymentFee
|
|
156
|
+
paymentFee,
|
|
157
|
+
commissionFee,
|
|
158
|
+
promotionalCharges,
|
|
159
|
+
shippingFeePaidByCustomer,
|
|
160
|
+
itemPriceCredit,
|
|
161
|
+
ordersMarketplaceFeesTotal,
|
|
162
|
+
ordersSalesTotal,
|
|
163
|
+
ordersMarketingFeesTotal,
|
|
164
|
+
ordersLogisticsTotal,
|
|
165
|
+
marketplaceBonus,
|
|
166
|
+
marketplaceBonusSeller,
|
|
167
|
+
shippingFeeDiscountMarketplace,
|
|
168
|
+
shippingFeeDiscountSeller,
|
|
169
|
+
promotionalChargesFlexiCombo,
|
|
170
|
+
autoShippingSubsidyMarketplace,
|
|
171
|
+
originalShippingFee,
|
|
172
|
+
taxAmount
|
|
105
173
|
}
|
|
106
174
|
})
|
|
107
175
|
|
|
@@ -21,4 +21,4 @@ export * from './update-store-product-stock'
|
|
|
21
21
|
export * from './update-store-product-variation-stock'
|
|
22
22
|
export * from './update-store-product'
|
|
23
23
|
export * from './get-store-refund-orders'
|
|
24
|
-
export * from './get-store-order-item-
|
|
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)
|
|
@@ -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,9 +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
|
-
|
|
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
|
+
}
|
|
16
26
|
const {
|
|
17
27
|
ordersn: name,
|
|
18
28
|
ordersn: orderNo,
|
|
@@ -48,7 +58,7 @@ export function getStoreOrder() {
|
|
|
48
58
|
promotion_type: promotionType,
|
|
49
59
|
promotion_id: promotionId,
|
|
50
60
|
is_wholesale: isWholesale,
|
|
51
|
-
variation_original_price: variationOriginalPrice
|
|
61
|
+
variation_original_price: variationOriginalPrice
|
|
52
62
|
} = item
|
|
53
63
|
var variationId = variation_id == 0 ? name : variation_id
|
|
54
64
|
return {
|
|
@@ -62,7 +72,7 @@ export function getStoreOrder() {
|
|
|
62
72
|
isWholesale,
|
|
63
73
|
docRefNo,
|
|
64
74
|
originalPrice: qty * variationOriginalPrice,
|
|
65
|
-
discount:
|
|
75
|
+
discount: qty * variationOriginalPrice - qty * variationDiscountedPrice
|
|
66
76
|
}
|
|
67
77
|
})
|
|
68
78
|
|
|
@@ -83,10 +93,12 @@ export function getStoreOrder() {
|
|
|
83
93
|
attentionTo,
|
|
84
94
|
trackingNo,
|
|
85
95
|
transporter: shippingProvider,
|
|
86
|
-
shippingFee: parseFloat(shippingFee),
|
|
87
|
-
actualShippingFee: parseFloat(actualShippingFee)
|
|
96
|
+
shippingFee: parseFloat(shippingFee) || null,
|
|
97
|
+
actualShippingFee: parseFloat(actualShippingFee) || null
|
|
88
98
|
}
|
|
89
99
|
|
|
100
|
+
let escrowDetails = await StoreAPI.getStoreOrderTransactionDetails(store, { orderNo })
|
|
101
|
+
|
|
90
102
|
return {
|
|
91
103
|
name,
|
|
92
104
|
orderNo,
|
|
@@ -104,7 +116,8 @@ export function getStoreOrder() {
|
|
|
104
116
|
orderItems,
|
|
105
117
|
orderShipping,
|
|
106
118
|
buyerUsername,
|
|
107
|
-
payTime
|
|
119
|
+
payTime,
|
|
120
|
+
...escrowDetails
|
|
108
121
|
}
|
|
109
122
|
})
|
|
110
123
|
|
|
@@ -25,4 +25,5 @@ export * from './split-order'
|
|
|
25
25
|
export * from './update-store-product-stock'
|
|
26
26
|
export * from './update-store-product-variation-stock'
|
|
27
27
|
export * from './get-store-refund-orders'
|
|
28
|
-
export * from './get-store-refund-order-details'
|
|
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
|
|
|
@@ -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.
|
|
85
|
-
|
|
86
|
-
const refundLineItems =
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
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
|
|
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
|
+
}
|