Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: void waybills shipments #531

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

*
* Shipment API `voidWaybillShipment` and `voidReturnWaybillShipment`

### 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 @@ -882,6 +882,78 @@ ripe.Ripe.prototype.createInvoiceShipmentP = function(number, options) {
});
};

/**
* Voids the waybill for the shipment with the provided number.
*
* @param {Number} number The number of the shipment to void 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.voidWaybillShipment = 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: "DELETE",
auth: true
});
options = this._build(options);
return this._cacheURL(options.url, options, callback);
};

/**
* Voids the waybill for the shipment with the provided number.
*
* @param {Number} number The number of the shipment to void the waybill for.
* @param {Object} options An object of options to configure the request.
* @returns {Promise} The result of the waybill deletion.
*/
ripe.Ripe.prototype.voidWaybillShipmentP = function(number, options) {
return new Promise((resolve, reject) => {
this.voidWaybillShipment(number, options, (result, isValid, request) => {
isValid ? resolve(result) : reject(new ripe.RemoteError(request, null, result));
});
});
};

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

/**
* Voids the return waybill for the shipment with the provided number.
*
* @param {Number} number The number of the shipment to void the return waybill for.
* @param {Object} options An object of options to configure the request.
* @returns {Promise} The result of the waybill deletion.
*/
ripe.Ripe.prototype.voidReturnWaybillShipmentP = function(number, options) {
return new Promise((resolve, reject) => {
this.voidReturnWaybillShipment(number, options, (result, isValid, request) => {
isValid ? resolve(result) : reject(new ripe.RemoteError(request, null, result));
});
});
};

/**
* Manually trigger a shipment shipping status refresh.
*
Expand Down
Loading