diff --git a/node-tourcms.js b/node-tourcms.js index 5ab246c..4e73b73 100644 --- a/node-tourcms.js +++ b/node-tourcms.js @@ -68,7 +68,7 @@ TourCMS.prototype.makeRequest = function(a) { 'x-tourcms-date': outboundTime, 'Authorization': 'TourCMS ' + a.channelId + ':' + this.options.marketplaceId + ':' + signature, 'Content-type': 'text/xml;charset="utf-8"', - 'Content-length': apiParams.length + 'Content-length': Buffer.byteLength(apiParams, 'utf8') } }; @@ -693,14 +693,16 @@ TourCMS.prototype.startNewBooking = function(a) { // POST a.verb = 'POST'; - // Sanitise response, custmers is an array + // Sanitise response, customers is an array a.processor = function(response, callback) { // Ensure we have an array of custom fields - if(typeof response.booking.customers !== "undefined") - response.booking.customers.customer = [].concat(response.booking.customers.customer); - else - response.booking.customers = {customer:[]}; + if(response.error == "OK" && response.booking){ + if(typeof response.booking.customers !== "undefined") + response.booking.customers.customer = [].concat(response.booking.customers.customer); + else + response.booking.customers = {customer:[]}; + } callback(response); @@ -1079,6 +1081,78 @@ TourCMS.prototype.createSpreedlyPayment = function(a) { }; +// Seach Enquiries +TourCMS.prototype.listPayments = function(a) { + + if(typeof a === 'undefined') + a = {}; + + // Convert/set search params + // If undefined + if(typeof a.qs === "undefined") + a.qs = {}; + + a.qs = querystring.stringify(a.qs); + + // Channel ID + // If undefined, use object level channelId + if(typeof a.channelId === "undefined") + a.channelId = this.options.channelId; + + a.path = '/c/booking/payment/list.xml?' + a.qs; + + // Sanitise response, total_enquiries_count always set + // Enquiries is an array if empty + + a.processor = function(response, callback) { + + // Ensure we have a total tour count + if(typeof response.total_payments === 'undefined') + response.total_payments = '0'; + else + // Ensure we have an array of tours + response.payment = [].concat(response.payment); + + callback(response); + + }; + + this.makeRequest(a); + +}; + + +// Seach Enquiries +TourCMS.prototype.listStaffMembers = function(a) { + + if(typeof a === 'undefined') + a = {}; + + // Channel ID + // If undefined, use object level channelId + if(typeof a.channelId === "undefined") + a.channelId = this.options.channelId; + + a.path = '/c/staff/list.xml'; + + // Sanitise response, total_enquiries_count always set + // Enquiries is an array if empty + + a.processor = function(response, callback) { + + // Ensure we have a total tour count + if(typeof response.total_users === 'undefined') + response.total_users = '0'; + else + response.users.user = [].concat(response.users.user); + + callback(response); + + }; + + this.makeRequest(a); + +}; // Customers // Show Customer diff --git a/package.json b/package.json index 7526725..49af444 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "api" ], "homepage": "https://github.com/tourcms/node-tourcms", - "version": "1.1.2", + "version": "1.2.0", "author": "TourCMS (http://www.tourcms.com)", "contributors": [ "Paul Slugocki (https://github.com/paulslugocki)" diff --git a/readme.md b/readme.md index 058f5bf..3699ca1 100644 --- a/readme.md +++ b/readme.md @@ -10,6 +10,7 @@ Node wrapper for the [TourCMS](http://www.tourcms.com/) [API](http://www.tourcms * [General / Housekeeping APIs](#general--housekeeping-apis) * [API Rate Limit Status](#api-rate-limit-status) * [Generic API request](#generic-api-request) + * [List staff members](#list-staff-members) * [Channel APIs](#channel-apis) * [List Channels](#list-channels) * [Show Channel](#show-channel) @@ -46,6 +47,7 @@ Node wrapper for the [TourCMS](http://www.tourcms.com/) [API](http://www.tourcms * [Payment APIs](#payment-apis) * [Create Payment / Refund](#create-payment--refund) * [Create Spreedly Payment](#create-spreedly-payment) + * [List Payments](#list-Payments) * [Customer & Enquiry APIs](#customer--enquiry-apis) * [Show Customer](#show-customer) * [Create Customer/Enquiry](#create-customerenquiry) @@ -115,6 +117,21 @@ TourCMS.genericRequest({ ``` Can also provide a `verb` (default is 'GET') and `postData`, which - if provided - must be an object representing the XML data to post to the API. +#### List staff members + +List of staff members connected to the channel requested. To be use only for operators, no travel agents. + +http://www.tourcms.com/support/api/mp/staff_members_list.php + +```js +TourCMS.listStaffMembers({ + channelId: 3930, + callback: function(response) { + console.log(response); + } +}) +``` + ### Channel APIs #### List Channels @@ -760,6 +777,34 @@ TourCMS.createSpreedlyPayment({ }); ``` +#### List Payments + +List of payments made during a specifif period and/or from staff member. + +http://www.tourcms.com/support/api/mp/payments_list.php + +This example shows booking id, value and currency payments. + +```js +TourCMS.listPayments({ + channelId: 3930, + qs: { + from_date: "2018-03-23", + to_date: "2018-03-26" + }, + callback: function(response, status) { + if (response.total_payments == 0) + console.log("No payments made"); + else{ + //Loop through each component and output its component key + response.payments.payment.forEach(function(payment) { + console.log("Booking " + payment.booking_id + ": " + payment.payment_value + "(" + payment.payment_currency + ")"); + }); + } + } +}); +``` + ### Customer & Enquiry APIs #### Show Customer