Skip to content

Commit

Permalink
Merge pull request #3 from Vilango/master
Browse files Browse the repository at this point in the history
Added the retrieveOrder method call
  • Loading branch information
schaechinger committed Mar 24, 2018
2 parents 46ee8cb + 37d081f commit a174d50
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
23 changes: 21 additions & 2 deletions lib/Internetmarke.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Internetmarke {
* @returns {Promise.<Object>} - The shopping cart with the link to the zip
* archive, the order id and the coucher ids.
*/
checkout({ orderId = null } = {}) {
checkout({ orderId = null, outputFormat = null } = {}) {
let order = this._order.getCheckout({ orderId });

if (order.total > this[_USER].getBalance()) {
Expand All @@ -102,7 +102,24 @@ class Internetmarke {
return this._1C4AService.checkout({
order,
user: this[_USER],
outputFormat: this._config.outputFormat
outputFormat: outputFormat || this._config.outputFormat,
});
}

/**
* Retrieve an existing order.
*
* @param {Object} options
* @param {number} [options.orderId] - Shopping cart number of the INTERNETMARKE shop
* @returns {Promise.<Object>} - The shopping cart with the link to the zip
* archive, the order id and the voucher ids.
*/
retrieveOrder({ orderId = null } = {}) {
let order = { shopOrderId: orderId };

return this._1C4AService.retrieveOrder({
order,
user: this[_USER],
});
}

Expand All @@ -125,6 +142,8 @@ class Internetmarke {
});
}



/**
* Update galleries (public and private) and save results locally.
*
Expand Down
35 changes: 34 additions & 1 deletion lib/Service/Soap/OneClickForApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class OneClickForAppService extends SoapService {
return this._getSoapClient()
.then(client => {
const method = `checkoutShoppingCart${outputFormat}Async`;

order = Object.assign({
userToken: this._user.getToken()
}, order);
Expand Down Expand Up @@ -120,6 +119,40 @@ class OneClickForAppService extends SoapService {
});
}

/**
* Performs a checkout and retrieves the ordered vouchers.
*
* @param {Object} data
* @param {Object} data.order - The order information that hold the data about
* the vouchers.
* @returns {Promise.<Object>}
*/
retrieveOrder({ order }) {
return this._getSoapClient()
.then(client => {
order = Object.assign({
userToken: this._user.getToken(),
}, order);
return client.retrieveOrderAsync(order);
})
.then(response => {
const result = {
orderId: response.shoppingCart.shopOrderId,
link: response.link,
vouchers: []
};

response.shoppingCart.voucherList.voucher.forEach(voucher => {
const data = { id: voucher.voucherId };
if (voucher.trackId) {
data.trackingCode = voucher.trackId;
}
result.vouchers.push(data);
});
return result;
});
}

/**
* Create a globally unique order id from the api.
*
Expand Down

0 comments on commit a174d50

Please sign in to comment.