diff --git a/lib/Internetmarke.js b/lib/Internetmarke.js index 92e15dc..710ab4d 100644 --- a/lib/Internetmarke.js +++ b/lib/Internetmarke.js @@ -92,7 +92,7 @@ class Internetmarke { * @returns {Promise.} - 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()) { @@ -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.} - 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], }); } @@ -125,6 +142,8 @@ class Internetmarke { }); } + + /** * Update galleries (public and private) and save results locally. * diff --git a/lib/Service/Soap/OneClickForApp.js b/lib/Service/Soap/OneClickForApp.js index 5e5c6bc..ffd3d96 100644 --- a/lib/Service/Soap/OneClickForApp.js +++ b/lib/Service/Soap/OneClickForApp.js @@ -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); @@ -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.} + */ + 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. *