forked from MONEI/Shopify-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.js
78 lines (68 loc) · 1.75 KB
/
order.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
const assign = require('lodash/assign');
const base = require('../mixins/base');
/**
* Creates an Order instance.
*
* @param {Shopify} shopify Reference to the Shopify instance
* @constructor
* @public
*/
function Order(shopify) {
this.shopify = shopify;
this.name = 'orders';
this.key = 'order';
}
assign(Order.prototype, base);
/**
* Closes an order.
*
* @param {Number} id Order ID
* @return {Promise} Promise that resolves with the result
* @public
*/
Order.prototype.close = function close(id) {
const url = this.buildUrl(`${id}/close`);
return this.shopify
.request(url, 'POST', undefined, {})
.then((body) => body[this.key]);
};
/**
* Re-opens a closed order.
*
* @param {Number} id Order ID
* @return {Promise} Promise that resolves with the result
* @public
*/
Order.prototype.open = function open(id) {
const url = this.buildUrl(`${id}/open`);
return this.shopify
.request(url, 'POST', undefined, {})
.then((body) => body[this.key]);
};
/**
* Cancels an order.
*
* @param {Number} id Order ID
* @params {Object} [params] Cancel options
* @return {Promise} Promise that resolves with the result
* @public
*/
Order.prototype.cancel = function cancel(id, params) {
const url = this.buildUrl(`${id}/cancel`);
return this.shopify
.request(url, 'POST', undefined, params)
.then((body) => body[this.key]);
};
/**
* Retrieves a list of all fulfillment orders for an order.
*
* @param {Number} id Order ID
* @return {Promise} Promise that resolves with the result
* @public
*/
Order.prototype.fulfillmentOrders = function fulfillmentOrders(id) {
const url = this.buildUrl(`${id}/fulfillment_orders`);
return this.shopify.request(url, 'GET', 'fulfillment_orders');
};
module.exports = Order;