hotfix(webshipper): adds option to specify which countries have CoO attached
This commit is contained in:
1 parent
95bcf34eff
commit
61e1a7d7f1
3 files changed
+23
-2
No files matched your search
@@ -1,2 +1,4 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
|
.env
|
||||||
@@ -12,4 +12,5 @@ A webhook listener is exposed at `/webshipper/shipments` to listen for shipment
|
|||||||
api_token: [a webshipper api token] (required)
|
api_token: [a webshipper api token] (required)
|
||||||
order_channel_id: [the channel id to register orders on] (required)
|
order_channel_id: [the channel id to register orders on] (required)
|
||||||
webhook_secret: [the webhook secret used to listen for shipments] (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")
|
||||||
```
|
```
|
||||||
@@ -9,6 +9,16 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
|||||||
|
|
||||||
this.options_ = options
|
this.options_ = options
|
||||||
|
|
||||||
|
if (!options.coo_countries) {
|
||||||
|
this.options_.coo_countries = ["all"]
|
||||||
|
} else if (Array.isArray(options.coo_countries)) {
|
||||||
|
this.options_.coo_countries = options.coo_countries.map((c) =>
|
||||||
|
c.toLowerCase()
|
||||||
|
)
|
||||||
|
} else if (typeof options.coo_countries === "string") {
|
||||||
|
this.options_.coo_countries = [options.coo_countries]
|
||||||
|
}
|
||||||
|
|
||||||
/** @private @const {logger} */
|
/** @private @const {logger} */
|
||||||
this.logger_ = logger
|
this.logger_ = logger
|
||||||
|
|
||||||
@@ -242,6 +252,8 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
|||||||
webshipperOrder = await this.client_.orders.retrieve(existing)
|
webshipperOrder = await this.client_.orders.retrieve(existing)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { shipping_address } = fromOrder
|
||||||
|
|
||||||
if (!webshipperOrder) {
|
if (!webshipperOrder) {
|
||||||
let invoice
|
let invoice
|
||||||
let certificateOfOrigin
|
let certificateOfOrigin
|
||||||
@@ -266,7 +278,14 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
|
|
||||||
if (this.invoiceGenerator_.createCertificateOfOrigin) {
|
const cooCountries = this.options_.coo_countries
|
||||||
|
if (
|
||||||
|
(cooCountries.includes("all") ||
|
||||||
|
cooCountries.includes(
|
||||||
|
shipping_address.country_code.toLowerCase()
|
||||||
|
)) &&
|
||||||
|
this.invoiceGenerator_.createCertificateOfOrigin
|
||||||
|
) {
|
||||||
const base64Coo = await this.invoiceGenerator_.createCertificateOfOrigin(
|
const base64Coo = await this.invoiceGenerator_.createCertificateOfOrigin(
|
||||||
fromOrder,
|
fromOrder,
|
||||||
fulfillmentItems
|
fulfillmentItems
|
||||||
@@ -297,7 +316,6 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
|||||||
visible_ref = `S-${fromOrder.display_id}`
|
visible_ref = `S-${fromOrder.display_id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const { shipping_address } = fromOrder
|
|
||||||
const newOrder = {
|
const newOrder = {
|
||||||
type: "orders",
|
type: "orders",
|
||||||
attributes: {
|
attributes: {
|
||||||
|
|||||||
Reference in new issue
Block a user