shopee-v2-api
Version:
120 lines (103 loc) • 3.4 kB
JavaScript
/* Imports */
/* -------------------------------------------------------------------------- */
const _ = require('lodash');
/* -------------------------------------------------------------------------- */
/* Constants */
/* -------------------------------------------------------------------------- */
const {
constants
} = require('./constants');
/* -------------------------------------------------------------------------- */
/* Common / Auth */
/* -------------------------------------------------------------------------- */
const {
buildSignKey,
buildUrl,
get,
post,
RefreshToken
} = require('./auth');
/* -------------------------------------------------------------------------- */
/* API */
/* -------------------------------------------------------------------------- */
/**
* 주문 회계 세부 사항
* @param {*} userShop
* @param {*} ordersn
* @returns
*/
exports.GetEscrowDetail = async (userShop, ordresn) => {
try {
// access token 유효 확인
let {
shop_id,
accessToken
} = await RefreshToken(userShop);
// uri
const uri = '/api/v2/payment/get_escrow_detail';
// sign key
const {
signKey,
currentTimeStamp
} = buildSignKey(uri, accessToken, shop_id);
// url
const url = buildUrl(uri, {
partner_id: constants.partnerId,
timestamp: currentTimeStamp,
sign: signKey,
access_token: accessToken,
shop_id: shop_id,
order_sn: ordersn
});
// request && response data
const responseData = await get(url);
// 데이터 형식 변경
if (responseData.response && responseData.response.order_income) {
return responseData.response.order_income;
} else {
return [];
}
} catch (err) {
throw err;
}
}
/**
* 주문 회계 세부 사항 배치 요청
* @param {*} userShop
* @param {*} ordersnList
* @returns
*/
exports.GetEscrowDetailBatch = async (userShop, ordersnList) => {
try {
// access token 유효 확인
let {
shop_id,
accessToken
} = await RefreshToken(userShop);
// uri
const uri = '/api/v2/payment/get_escrow_detail';
// sign key
const {
signKey,
currentTimeStamp
} = buildSignKey(uri, accessToken, shop_id);
// url
const url = buildUrl(uri, {
partner_id: constants.partnerId,
timestamp: currentTimeStamp,
sign: signKey,
access_token: accessToken,
shop_id: shop_id
});
// request && response data
const responseData = await post(url, JSON.stringify({ order_sn_list: ordersnList }));
// 데이터 형식 변경
if (responseData.response && responseData.response.order_income) {
return responseData.response.order_income;
} else {
return [];
}
} catch (err) {
throw err;
}
}