fix/cancel-order (#120)

* fix: adds ability to cancel order

* passing tests

* chore: clean up unused code
This commit is contained in:
Sebastian Rindom
2020-10-06 14:00:47 +02:00
committed by GitHub
parent 4bbb2a2367
commit 11bedf8c6f
29 changed files with 240 additions and 97 deletions
@@ -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
@@ -83,6 +83,13 @@ class Webshipper {
},
}).then(({ data }) => data)
},
delete: async (id) => {
const path = `/v2/orders/${id}`
return this.client_({
method: "DELETE",
url: path,
}).then(({ data }) => data)
},
}
}