|
| 1 | +import { ConfigurationError } from "@pipedream/platform"; |
| 2 | +import { COUNTRY_OPTIONS } from "../../common/constants.mjs"; |
| 3 | +import { parseObject } from "../../common/utils.mjs"; |
| 4 | +import paazl from "../../paazl.app.mjs"; |
| 5 | + |
| 6 | +export default { |
| 7 | + key: "paazl-create-order", |
| 8 | + name: "Create Order", |
| 9 | + description: "Create a new order in Paazl. [See the documentation](https://support.paazl.com/hc/en-us/articles/360008633973-REST-API-reference#/Order/saveOrderUsingPOST)", |
| 10 | + version: "0.0.1", |
| 11 | + type: "action", |
| 12 | + props: { |
| 13 | + paazl, |
| 14 | + additionalInstruction: { |
| 15 | + type: "string", |
| 16 | + label: "Additional Instruction", |
| 17 | + description: "Additional instructions for the delivery of an order. E.g. `Call before delivery`.", |
| 18 | + optional: true, |
| 19 | + }, |
| 20 | + consigneeCompanyName: { |
| 21 | + type: "object", |
| 22 | + label: "Consignee - Company Name", |
| 23 | + description: "The name of a company to which an order is shipped.", |
| 24 | + optional: true, |
| 25 | + }, |
| 26 | + consigneeVatNumber: { |
| 27 | + type: "string", |
| 28 | + label: "Consignee - VAT Number", |
| 29 | + description: "The VAT number of the receiver. This is the tax identification number of the receiver, that can be used by B2B international shipments for customs, for some carriers.", |
| 30 | + optional: true, |
| 31 | + }, |
| 32 | + consigneeEmail: { |
| 33 | + type: "string", |
| 34 | + label: "Consignee - Email", |
| 35 | + description: "The email address of the person to whom an order is shipped.", |
| 36 | + optional: true, |
| 37 | + }, |
| 38 | + consigneeName: { |
| 39 | + type: "string", |
| 40 | + label: "Consignee - Name", |
| 41 | + description: "The name of the person to whom an order is shipped.", |
| 42 | + optional: true, |
| 43 | + }, |
| 44 | + consigneeOther: { |
| 45 | + type: "object", |
| 46 | + label: "Consignee - Other", |
| 47 | + description: "Additional details used to identify the person to whom an order is shipped.", |
| 48 | + optional: true, |
| 49 | + }, |
| 50 | + consigneePhone: { |
| 51 | + type: "string", |
| 52 | + label: "Consignee - Phone", |
| 53 | + description: "The phone number of the person to whom an order is shipped.", |
| 54 | + optional: true, |
| 55 | + }, |
| 56 | + consigneeLocale: { |
| 57 | + type: "string", |
| 58 | + label: "Consignee - Locale", |
| 59 | + description: "Specifies the language of the email templates used for track & trace notifications. `locale` is specified using the format `{language}_{country}`, where `{language}` is an [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code and `{country}` is an [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) country code. Example: `fr_FR`", |
| 60 | + optional: true, |
| 61 | + }, |
| 62 | + consigneeAddressCity: { |
| 63 | + type: "string", |
| 64 | + label: "Consignee - Address - City", |
| 65 | + description: "The city or town to which an order is shipped.", |
| 66 | + }, |
| 67 | + consigneeAddressCountry: { |
| 68 | + type: "string", |
| 69 | + label: "Consignee - Address - Country", |
| 70 | + description: "The [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) code for the country to which an order is shipped.", |
| 71 | + options: COUNTRY_OPTIONS, |
| 72 | + optional: true, |
| 73 | + }, |
| 74 | + consigneeAddressPostalCode: { |
| 75 | + type: "string", |
| 76 | + label: "Consignee - Address - Postal Code", |
| 77 | + description: "The postal code of the address to which an order is shipped. The code is used to get a more precise list of available shipping options.", |
| 78 | + optional: true, |
| 79 | + }, |
| 80 | + consigneeAddressProvince: { |
| 81 | + type: "string", |
| 82 | + label: "Consignee - Address - Province", |
| 83 | + description: "The last 2 letters of the [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) code for the province or state to which an order is shipped.", |
| 84 | + optional: true, |
| 85 | + }, |
| 86 | + consigneeAddressStreet: { |
| 87 | + type: "string", |
| 88 | + label: "Consignee - Address - Street", |
| 89 | + description: "The name of the street to which an order is shipped. See the note in the \"order\" endpoint description. Note If you provide \"street\" with a value, \"houseNumber\" is required.", |
| 90 | + optional: true, |
| 91 | + }, |
| 92 | + consigneeAddressStreetLines: { |
| 93 | + type: "string[]", |
| 94 | + label: "Consignee - Address - Street Lines", |
| 95 | + description: "The street name and house number of the address to which an order is shipped, specified as one or more strings. See the note in the \"order\" endpoint description. Note! Paazl does not parse the string to perform validation with any values that may be provided for the other parameters of a consignee address.", |
| 96 | + optional: true, |
| 97 | + }, |
| 98 | + consigneeAddressHouseNumber: { |
| 99 | + type: "string", |
| 100 | + label: "Consignee - Address - House Number", |
| 101 | + description: "The house number of the address to which an order is shipped. See the note in the order endpoint description.", |
| 102 | + optional: true, |
| 103 | + }, |
| 104 | + consigneeAddressHouseNumberExtension: { |
| 105 | + type: "string", |
| 106 | + label: "Consignee - Address - House Number Extension", |
| 107 | + description: "The house number extension (such as the \"-A\" in \"12-A\") of the address to which an order is shipped.", |
| 108 | + optional: true, |
| 109 | + }, |
| 110 | + reference: { |
| 111 | + type: "string", |
| 112 | + label: "Reference", |
| 113 | + description: "Your own order reference for a purchase transaction. For security reasons, the following special characters are not allowed: \\ and /. Note! The order reference must be unique within the webshop.", |
| 114 | + }, |
| 115 | + shippingOption: { |
| 116 | + type: "string", |
| 117 | + label: "Shipping - Option", |
| 118 | + description: "A shipping option's Paazl identifier. You will find a list of the identifiers of the shipping options available to your webshop in your webshop account under **Settings>Account>Overview of shipping options**. **Note!** If you have used [custom shipping option identifiers](https://support.paazl.com/hc/en-us/articles/360021787374-Customizing-shipping-option-identifiers%22), these will be returned instead of their Paazl equivalents.", |
| 119 | + }, |
| 120 | + shippingPickupLocationCode: { |
| 121 | + type: "string", |
| 122 | + label: "Shipping - Pickup Location Code", |
| 123 | + description: "A carrier's unique code for a pickup location.", |
| 124 | + }, |
| 125 | + shippingContract: { |
| 126 | + type: "string", |
| 127 | + label: "Shipping - Contract", |
| 128 | + description: "The identification code of your carrier contract for an outbound shipment. **Note!** If you don't have this code, contact [Paazl Customer Support]([email protected]).", |
| 129 | + optional: true, |
| 130 | + }, |
| 131 | + shippingReturnContract: { |
| 132 | + type: "string", |
| 133 | + label: "Shipping - Return Contract", |
| 134 | + description: "The identification code of your carrier contract for a return shipment. **Note!** If you don't have this code, contact [Paazl Customer Support]([email protected]).", |
| 135 | + optional: true, |
| 136 | + }, |
| 137 | + shippingPackageCount: { |
| 138 | + type: "integer", |
| 139 | + label: "Shipping - Package Count", |
| 140 | + description: "The number of packages in a shipment. **Note!** If `multiPackageShipment` is set to `true`, the default value of `packageCount` will be `2`.", |
| 141 | + optional: true, |
| 142 | + }, |
| 143 | + shippingMultiPackageShipment: { |
| 144 | + type: "boolean", |
| 145 | + label: "Shipping - Multi Package Shipment", |
| 146 | + description: "If `true`, Paazl will treat the shipment as consolidated. This setting affects how the packages in the shipment are numbered on its labels. The number of packages in a shipment is indicated by `packageCount`. So, for example, if `multiPackageShipment` is `true` and `packageCount` is `3`, then the labels will be numbered 1/3, 2/3, 3/3. **Note!** If `packageCount` > `1`, then the default value of `multiPackageShipment` will be `true`. If you don't want Paazl to treat a multi-package shipment as consolidated, you have to set `multiPackageShipment` to `false`.", |
| 147 | + optional: true, |
| 148 | + }, |
| 149 | + }, |
| 150 | + async run({ $ }) { |
| 151 | + if (!this.consigneeAddressStreet && !this.consigneeAddressStreetLines) { |
| 152 | + throw new ConfigurationError("**Consignee Address Street** or **Consignee Address Street Lines** is required."); |
| 153 | + } |
| 154 | + |
| 155 | + const response = await this.paazl.createOrder({ |
| 156 | + $, |
| 157 | + data: { |
| 158 | + additionalInstruction: this.additionalInstruction, |
| 159 | + consignee: { |
| 160 | + companyName: parseObject(this.consigneeCompanyName), |
| 161 | + vatNumber: this.consigneeVatNumber, |
| 162 | + email: this.consigneeEmail, |
| 163 | + name: this.consigneeName, |
| 164 | + other: parseObject(this.consigneeOther), |
| 165 | + phone: this.consigneePhone, |
| 166 | + locale: this.consigneeLocale, |
| 167 | + address: { |
| 168 | + city: this.consigneeAddressCity, |
| 169 | + country: this.consigneeAddressCountry, |
| 170 | + postalCode: this.consigneeAddressPostalCode, |
| 171 | + province: this.consigneeAddressProvince, |
| 172 | + street: this.consigneeAddressStreet, |
| 173 | + streetLines: parseObject(this.consigneeAddressStreetLines), |
| 174 | + houseNumber: this.consigneeAddressHouseNumber, |
| 175 | + houseNumberExtension: this.consigneeAddressHouseNumberExtension, |
| 176 | + }, |
| 177 | + }, |
| 178 | + reference: this.reference, |
| 179 | + shipping: { |
| 180 | + option: this.shippingOption, |
| 181 | + pickupLocation: { |
| 182 | + code: this.shippingPickupLocationCode, |
| 183 | + }, |
| 184 | + contract: this.shippingContract, |
| 185 | + returnContract: this.shippingReturnContract, |
| 186 | + packageCount: this.shippingPackageCount, |
| 187 | + multiPackageShipment: this.shippingMultiPackageShipment, |
| 188 | + }, |
| 189 | + }, |
| 190 | + }); |
| 191 | + return response; |
| 192 | + }, |
| 193 | +}; |
0 commit comments