fix/cancel-order (#120)
* fix: adds ability to cancel order * passing tests * chore: clean up unused code
This commit is contained in:
@@ -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)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user