fix(webshipper): allow cancelling WS orders with error status (#1755)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# medusa-fulfillment-webshipper
|
||||
|
||||
Adds Webshipper as a fulfilment provider in Medusa Commerce.
|
||||
Adds Webshipper as a fulfilment provider in Medusa Commerce.
|
||||
|
||||
On each new fulfillment an order is created in Webshipper. The plugin listens for shipment events and updated the shipment accordingly.
|
||||
A webhook listener is exposed at `/webshipper/shipments` to listen for shipment creations. You must create this webhook in Webshipper to have Medusa listen for shipment events.
|
||||
@@ -13,4 +13,5 @@ A webhook listener is exposed at `/webshipper/shipments` to listen for shipment
|
||||
order_channel_id: [the channel id to register orders on] (required)
|
||||
webhook_secret: [the webhook secret used to listen for shipments] (required)
|
||||
coo_countries: [an array of countries in which a Certificate of Origin will be attached] (default: "all")
|
||||
delete_on_cancel [determines whether Webshipper orders are deleted when a Medusa fulfillment is canceled] (default: false)
|
||||
```
|
||||
|
||||
@@ -623,19 +623,17 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
if (order) {
|
||||
if (
|
||||
order.data.attributes.status !== "pending" &&
|
||||
order.data.attributes.status !== "missing_rate"
|
||||
) {
|
||||
if (order.data.attributes.status === "cancelled") {
|
||||
return Promise.resolve(order)
|
||||
}
|
||||
throw new Error("Cannot cancel order")
|
||||
}
|
||||
if (this.options_.delete_on_cancel) {
|
||||
return await this.client_.orders.delete(data.id)
|
||||
}
|
||||
|
||||
return this.client_.orders.delete(data.id)
|
||||
return await this.client_.orders.update(data.id, {
|
||||
id: data.id,
|
||||
type: "orders",
|
||||
attributes: {
|
||||
status: "cancelled",
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,16 @@ class Webshipper {
|
||||
},
|
||||
}).then(({ data }) => data)
|
||||
},
|
||||
update: async (id, data) => {
|
||||
const path = `/v2/orders/${id}`
|
||||
return this.client_({
|
||||
method: "PATCH",
|
||||
url: path,
|
||||
data: {
|
||||
data,
|
||||
},
|
||||
}).then(({ data }) => data)
|
||||
},
|
||||
delete: async (id) => {
|
||||
const path = `/v2/orders/${id}`
|
||||
return this.client_({
|
||||
|
||||
Reference in New Issue
Block a user