From f21dae827ad64522fd1f4d6317740c6b0ded0536 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 8 Apr 2021 16:42:06 +0200 Subject: [PATCH] feat: adds support for certificate of origin --- .../src/services/webshipper-fulfillment.js | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/packages/medusa-fulfillment-webshipper/src/services/webshipper-fulfillment.js b/packages/medusa-fulfillment-webshipper/src/services/webshipper-fulfillment.js index 3504b906bc..7348c422c5 100644 --- a/packages/medusa-fulfillment-webshipper/src/services/webshipper-fulfillment.js +++ b/packages/medusa-fulfillment-webshipper/src/services/webshipper-fulfillment.js @@ -244,6 +244,8 @@ class WebshipperFulfillmentService extends FulfillmentService { if (!webshipperOrder) { let invoice + let certificateOfOrigin + if (this.invoiceGenerator_) { const base64Invoice = await this.invoiceGenerator_.createInvoice( fromOrder, @@ -263,6 +265,27 @@ class WebshipperFulfillmentService extends FulfillmentService { .catch((err) => { throw err }) + + if (this.invoiceGenerator_.createCertificateOfOrigin) { + const base64Coo = await this.invoiceGenerator_.createCertificateOfOrigin( + fromOrder, + fulfillmentItems + ) + + certificateOfOrigin = await this.client_.documents + .create({ + type: "documents", + attributes: { + document_size: this.options_.document_size || "A4", + document_format: "PDF", + base64: base64Coo, + document_type: "certificate", + }, + }) + .catch((err) => { + throw err + }) + } } let id = fulfillment.id @@ -335,14 +358,25 @@ class WebshipperFulfillmentService extends FulfillmentService { country_code: methodData.drop_point_country_code.toUpperCase(), } } - if (invoice) { + + if (invoice || certificateOfOrigin) { + const docData = [] + if (invoice) { + docData.push({ + id: invoice.data.id, + type: invoice.data.type, + }) + } + + if (certificateOfOrigin) { + docData.push({ + id: certificateOfOrigin.data.id, + type: certificateOfOrigin.data.type, + }) + } + newOrder.relationships.documents = { - data: [ - { - id: invoice.data.id, - type: invoice.data.type, - }, - ], + data: docData, } }