Skip to content

Commit

Permalink
Merge pull request #523 from ripe-tech/jc/4853-update-shipments
Browse files Browse the repository at this point in the history
feat: create waybill and invoice for shipments
  • Loading branch information
3rdvision authored Oct 13, 2023
2 parents cf4ef5e + d8e9fc5 commit 1a99b5c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

*
* Added waybill and invoice creation methods to the `ShipmentAPI` - [#4853](https://github.com/ripe-tech/ripe-core/issues/4853)

### Changed

Expand Down
72 changes: 72 additions & 0 deletions src/js/api/shipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,75 @@ ripe.Ripe.prototype.deleteShipmentP = function(number, options) {
});
});
};

/**
* Creates a shipping waybill for the shipment with the provided number.
*
* @param {Number} number The number of the shipment to create the waybill 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.createWaybillShipment = function(number, options, callback) {
callback = typeof options === "function" ? options : callback;
options = typeof options === "function" || options === undefined ? {} : options;
const url = `${this.url}shipments/${number}/waybill`;
options = Object.assign(options, {
url: url,
method: "POST",
auth: true
});
options = this._build(options);
return this._cacheURL(options.url, options, callback);
};

/**
* Creates a shipping waybill for the shipment with the provided number.
*
* @param {Number} number The number of the shipment to create the waybill 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.createWaybillShipmentP = function(number, options) {
return new Promise((resolve, reject) => {
this.createWaybillShipment(number, options, (result, isValid, request) => {
isValid ? resolve(result) : reject(new ripe.RemoteError(request, null, result));
});
});
};

/**
* Creates an invoice for the shipment with the provided number.
*
* @param {Number} number The number of the shipment to create the invoice 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.createInvoiceShipment = function(number, options, callback) {
callback = typeof options === "function" ? options : callback;
options = typeof options === "function" || options === undefined ? {} : options;
const url = `${this.url}shipments/${number}/invoice`;
options = Object.assign(options, {
url: url,
method: "POST",
auth: true
});
options = this._build(options);
return this._cacheURL(options.url, options, callback);
};

/**
* Creates an invoice for the shipment with the provided number.
*
* @param {Number} number The number of the shipment to create the invoice 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.createInvoiceShipmentP = function(number, options) {
return new Promise((resolve, reject) => {
this.createInvoiceShipment(number, options, (result, isValid, request) => {
isValid ? resolve(result) : reject(new ripe.RemoteError(request, null, result));
});
});
};

1 comment on commit 1a99b5c

@vercel
Copy link

@vercel vercel bot commented on 1a99b5c Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ripe-sdk – ./

ripe-sdk-platforme.vercel.app
ripe-sdk-docs-csr.vercel.app
ripe-sdk-git-master-platforme.vercel.app

Please sign in to comment.