diff --git a/CHANGELOG.md b/CHANGELOG.md index dee27085..f23d0e7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -* +* Added create documents for shipping API - [ripe-pulse/#396](https://github.com/ripe-tech/ripe-pulse/issues/396) ### Changed diff --git a/src/js/api/shipment.js b/src/js/api/shipment.js index fa96f408..d99417cf 100644 --- a/src/js/api/shipment.js +++ b/src/js/api/shipment.js @@ -738,6 +738,42 @@ ripe.Ripe.prototype.createIssueShipmentP = function(number, issue, options) { }); }; +/** + * Creates mandatory shipping documents for the shipment with the provided number. + * + * @param {Number} number The number of the shipment to create the documents for. + * @param {Object} options An object of options to configure the request. + * @param {Function} callback Function with the result of the request. + * @returns {XMLHttpRequest} The XMLHttpRequest instance of the API request. + */ +ripe.Ripe.prototype.createDocumentsShipment = function(number, options, callback) { + callback = typeof options === "function" ? options : callback; + options = typeof options === "function" || options === undefined ? {} : options; + const url = `${this.url}shipments/${number}/documents`; + options = Object.assign(options, { + url: url, + method: "POST", + auth: true + }); + options = this._build(options); + return this._cacheURL(options.url, options, callback); +}; + +/** + * Creates mandatory shipping documents for the shipment with the provided number. + * + * @param {Number} number The number of the shipment to create the documents for. + * @param {Object} options An object of options to configure the request. + * @returns {Promise} The contents of the note instance that was created. + */ +ripe.Ripe.prototype.createDocumentsShipmentP = function(number, options) { + return new Promise((resolve, reject) => { + this.createDocumentsShipment(number, options, (result, isValid, request) => { + isValid ? resolve(result) : reject(new ripe.RemoteError(request, null, result)); + }); + }); +}; + /** * Creates a shipping waybill for the shipment with the provided number. *