fix/cancel-order (#120)
* fix: adds ability to cancel order * passing tests * chore: clean up unused code
This commit is contained in:
1 parent
4bbb2a2367
commit
11bedf8c6f
29 files changed
+240
-97
No files matched your search
@@ -236,6 +236,25 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
||||
url: link,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels a fulfillment. If the fulfillment has already been canceled this
|
||||
* is idemptotent. Can only cancel pending orders.
|
||||
* @param {object} data - the fulfilment data
|
||||
* @return {Promise<object>} the result of the cancellation
|
||||
*/
|
||||
async cancelFulfillment(data) {
|
||||
const order = await this.client_.orders.retrieve(data.id)
|
||||
|
||||
if (order.attributes.status !== "pending") {
|
||||
if (order.attributes.status === "cancelled") {
|
||||
return Promise.resolve(order)
|
||||
}
|
||||
throw new Error("Cannot cancel order")
|
||||
}
|
||||
|
||||
return this.client_.orders.delete(data.id)
|
||||
}
|
||||
}
|
||||
|
||||
export default WebshipperFulfillmentService
|
||||
Reference in new issue
Block a user