UNPKG

shopee-client

Version:
284 lines (283 loc) 13.1 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var BaseModule_1 = __importDefault(require("../BaseModule")); var hmac_1 = __importDefault(require("../../helper/hmac")); var handleReject_1 = __importDefault(require("../../helper/handleReject")); var OrderModule = /** @class */ (function (_super) { __extends(OrderModule, _super); function OrderModule() { return _super !== null && _super.apply(this, arguments) || this; } /** * GetOrdersList is the recommended call to use for order management. * Use this call to retrieve basic information of all orders which are updated within specific period of time. * More details of each order can be retrieved from GetOrderDetails. * [Only the recent one month orders can be fetch through this API. Please use GetOrderBySatus API to fetch more orders.] * @param request */ OrderModule.prototype.getOrderList = function (request) { var full_url = this.client.defaults.baseURL + 'orders/basics'; var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) }); var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/basics', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * GetOrdersByStatus is the recommended call to use for order management. * Use this call to retrieve basic information of all orders which are specific status. * More details of each order can be retrieved from GetOrderDetails. * @param request */ OrderModule.prototype.getOrderByStatus = function (request) { var full_url = this.client.defaults.baseURL + 'orders/get'; var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) }); var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/get', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this call to retrieve detailed information about one or more orders based on OrderSN. * @param ordersn_list The set of ordersn. You can specify up to 50 ordersns in this call. */ OrderModule.prototype.getOrderDetail = function (ordersn_list) { var full_url = this.client.defaults.baseURL + 'orders/detail'; var params = { ordersn_list: ordersn_list, partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000), }; var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/detail', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this call to retrieve detailed escrow information about one order based on OrderSN. * @param ordersn Shopee's unique identifier for an order. */ OrderModule.prototype.getEscrowDetail = function (ordersn) { var full_url = this.client.defaults.baseURL + 'orders/my_income'; var params = { ordersn: ordersn, partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000), }; var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/my_income', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this call to accept buyer cancellation * @param ordersn Shopee's unique identifier for an order. */ OrderModule.prototype.acceptBuyerCancel = function (ordersn) { var full_url = this.client.defaults.baseURL + 'orders/buyer_cancellation/accept'; var params = { ordersn: ordersn, partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000), }; var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/buyer_cancellation/accept', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this call to reject buyer cancellation * @param ordersn Shopee's unique identifier for an order. */ OrderModule.prototype.rejectBuyerCancel = function (ordersn) { var full_url = this.client.defaults.baseURL + 'orders/buyer_cancellation/reject'; var params = { ordersn: ordersn, partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000), }; var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/buyer_cancellation/reject', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this call to retrieve detailed information of all the fulfill orders(forder) under a single regular order based on ordersn. * @param ordersn Shopee's unique identifier for an order. */ OrderModule.prototype.getForderInfo = function (ordersn) { var full_url = this.client.defaults.baseURL + 'orders/forder/get'; var params = { ordersn: ordersn, partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000), }; var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/forder/get', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this API to cancel split order from the seller side. * @param ordersn Shopee's unique identifier for an order. */ OrderModule.prototype.undoSplitOrder = function (ordersn) { var full_url = this.client.defaults.baseURL + 'orders/unsplit'; var params = { ordersn: ordersn, partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000), }; var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/unsplit', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this call to add note for an order * @param ordersn Shopee's unique identifier for an order. * @param note The note seller made for own reference. */ OrderModule.prototype.addOrderNote = function (ordersn, note) { var full_url = this.client.defaults.baseURL + 'orders/note/add'; var params = { ordersn: ordersn, note: note, partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000), }; var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/note/add', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this API to fetch the accounting detail of order. * @param ordersn Shopee's unique identifier for an order. */ OrderModule.prototype.getIncome = function (ordersn) { var full_url = this.client.defaults.baseURL + 'orders/income'; var params = { ordersn: ordersn, partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000), }; var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/income', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this call to cancel an order from the seller side. * @param request */ OrderModule.prototype.cancelOrder = function (request) { var full_url = this.client.defaults.baseURL + 'orders/cancel'; var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) }); var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/cancel', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this api to get orders' release time and escrow amount. * @param request */ OrderModule.prototype.getEscrowReleasedOrder = function (request) { var full_url = this.client.defaults.baseURL + 'orders/get_escrow_detail'; var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) }); var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/get_escrow_detail', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this API to split order into fulfillment orders. This feature is only enabled for whitelisted shops. * @param request */ OrderModule.prototype.splitOrder = function (request) { var full_url = this.client.defaults.baseURL + 'orders/split'; var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) }); var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/split', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; /** * Use this call to get a list of unbind orders. * @param request */ OrderModule.prototype.getUnbindOrderList = function (request) { var full_url = this.client.defaults.baseURL + 'orders/unbind/list'; var params = __assign(__assign({}, request), { partner_id: Number(this.config.partner_id), shopid: Number(this.config.shop_id), timestamp: Math.round(Date.now() / 1000) }); var hmac = hmac_1.default(this.config.partner_key || '', full_url + '|' + JSON.stringify(params)); return this.client.post('orders/unbind/list', params, { headers: { Authorization: hmac } }).then(handleReject_1.default); }; return OrderModule; }(BaseModule_1.default)); exports.default = OrderModule;