Skip to content

Commit 7803fa1

Browse files
authored
[api] Add hold action to FulfillmentOrder resource (#660)
1 parent 6080d51 commit 7803fa1

File tree

8 files changed

+125
-1
lines changed

8 files changed

+125
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,13 @@ default.
482482
- fulfillmentOrder
483483
- `cancel(id, params)`
484484
- `close(id[, message])`
485+
- `fulfillments(id)`
485486
- `get(id)`
487+
- `hold(id, params)`
486488
- `list([params])`
487489
- `locationsForMove(id)`
488490
- `move(id, locationId)`
489491
- `setFulfillmentOrdersDeadline(params)`
490-
- `fulfillments(id)`
491492
- fulfillmentRequest
492493
- `accept(fulfillmentOrderId[, message])`
493494
- `create(fulfillmentOrderId, params)`

resources/fulfillment-order.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,21 @@ FulfillmentOrder.prototype.fulfillments = function fulfillments(id) {
127127
return this.shopify.request(url, 'GET', 'fulfillments');
128128
};
129129

130+
/**
131+
* Halts all fulfillment work on a fulfillment order with
132+
* status OPEN and changes the status of the fulfillment order to ON_HOLD.
133+
*
134+
* @param {Number} id Fulfillment Order ID
135+
* @param {Object} params An object containing the reason for the fulfillment
136+
hold and additional optional information
137+
* @return {Promise} Promise that resolves with the result
138+
* @public
139+
*/
140+
FulfillmentOrder.prototype.hold = function hold(id, params) {
141+
const url = this.buildUrl(`${id}/hold`);
142+
return this.shopify
143+
.request(url, 'POST', undefined, { fulfillment_hold: params })
144+
.then((body) => body[this.key]);
145+
};
146+
130147
module.exports = FulfillmentOrder;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"fulfillment_hold": {
3+
"reason": "inventory_out_of_stock",
4+
"reason_notes": "Not enough inventory to complete this work.",
5+
"fulfillment_order_line_items": [{ "id": 1058737493, "quantity": 1 }]
6+
}
7+
}

test/fixtures/fulfillment-order/req/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
exports.cancel = require('./cancel');
44
exports.close = require('./close');
5+
exports.hold = require('./hold');
56
exports.move = require('./move');
67
exports.setFulfillmentOrdersDeadline = require('./set-fulfillment-orders-deadline');
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"fulfillment_order": {
3+
"id": 1046000789,
4+
"shop_id": 548380009,
5+
"order_id": 450789469,
6+
"assigned_location_id": 24826418,
7+
"request_status": "unsubmitted",
8+
"status": "on_hold",
9+
"fulfill_at": null,
10+
"supported_actions": ["release_hold"],
11+
"destination": {
12+
"id": 1046000789,
13+
"address1": "Chestnut Street 92",
14+
"address2": "",
15+
"city": "Louisville",
16+
"company": null,
17+
"country": "United States",
18+
"email": "bob.norman@mail.example.com",
19+
"first_name": "Bob",
20+
"last_name": "Norman",
21+
"phone": "+1(502)-459-2181",
22+
"province": "Kentucky",
23+
"zip": "40202"
24+
},
25+
"line_items": [
26+
{
27+
"id": 1058737493,
28+
"shop_id": 548380009,
29+
"fulfillment_order_id": 1046000789,
30+
"quantity": 1,
31+
"line_item_id": 518995019,
32+
"inventory_item_id": 49148385,
33+
"fulfillable_quantity": 1,
34+
"variant_id": 49148385
35+
}
36+
],
37+
"international_duties": null,
38+
"fulfillment_holds": [
39+
{
40+
"reason": "inventory_out_of_stock",
41+
"reason_notes": "Not enough inventory to complete this work."
42+
}
43+
],
44+
"fulfill_by": null,
45+
"created_at": "2024-07-24T06:26:32-04:00",
46+
"updated_at": "2024-07-24T06:26:33-04:00",
47+
"delivery_method": null,
48+
"assigned_location": {
49+
"address1": null,
50+
"address2": null,
51+
"city": null,
52+
"country_code": "DE",
53+
"location_id": 24826418,
54+
"name": "Apple Api Shipwire",
55+
"phone": null,
56+
"province": null,
57+
"zip": null
58+
},
59+
"merchant_requests": []
60+
}
61+
}

test/fixtures/fulfillment-order/res/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ exports.close = require('./close');
77
exports.list = require('./list');
88
exports.move = require('./move');
99
exports.get = require('./get');
10+
exports.hold = require('./hold');

test/fulfillment-order.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,19 @@ describe('Shopify#fulfillmentOrder', () => {
134134
.fulfillments(1046000823)
135135
.then((data) => expect(data).to.deep.equal(output.fulfillments));
136136
});
137+
138+
it('applies a fulfillment hold on an open fulfillment order', () => {
139+
const input = fixtures.req.hold;
140+
const output = fixtures.res.hold;
141+
142+
scope
143+
.post('/admin/fulfillment_orders/1046000789/hold.json', input)
144+
.reply(200, output);
145+
146+
return shopify.fulfillmentOrder
147+
.hold(1046000789, input.fulfillment_hold)
148+
.then((data) => {
149+
expect(data).to.deep.equal(output.fulfillment_order);
150+
});
151+
});
137152
});

types/index.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ declare class Shopify {
389389
fulfillments: (
390390
id: number
391391
) => Promise<Shopify.IPaginatedResult<Shopify.IFulfillment>>;
392+
hold: (
393+
id: number,
394+
params: Shopify.IFulfillmentHold
395+
) => Promise<Shopify.IFulfillmentOrder>;
392396
};
393397
fulfillmentRequest: {
394398
accept: (
@@ -3567,4 +3571,21 @@ declare namespace Shopify {
35673571
};
35683572
updated_at: string;
35693573
}
3574+
3575+
interface IFulfillmentHoldFulfillmentOrderLineItem {
3576+
id: number;
3577+
quantity: number;
3578+
}
3579+
3580+
interface IFulfillmentHold {
3581+
reason:
3582+
| 'awaiting_payment'
3583+
| 'high_risk_of_fraud'
3584+
| 'incorrect_address'
3585+
| 'inventory_out_of_stock'
3586+
| 'other';
3587+
reason_notes?: string;
3588+
notify_merchant?: boolean;
3589+
fulfillment_order_line_items?: IFulfillmentHoldFulfillmentOrderLineItem[];
3590+
}
35703591
}

0 commit comments

Comments
 (0)