Skip to content

Commit

Permalink
Merge pull request #17 from TourCMS/release/1.2.0
Browse files Browse the repository at this point in the history
Merge Release/1.2.0 back into master
  • Loading branch information
paulslugocki authored Jul 4, 2018
2 parents db55c1d + 0dc192b commit 1d23ff7
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 7 deletions.
86 changes: 80 additions & 6 deletions node-tourcms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
};

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"api"
],
"homepage": "https://github.com/tourcms/node-tourcms",
"version": "1.1.2",
"version": "1.2.0",
"author": "TourCMS <[email protected]> (http://www.tourcms.com)",
"contributors": [
"Paul Slugocki <[email protected]> (https://github.com/paulslugocki)"
Expand Down
45 changes: 45 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 &amp; Enquiry APIs](#customer--enquiry-apis)
* [Show Customer](#show-customer)
* [Create Customer/Enquiry](#create-customerenquiry)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1d23ff7

Please sign in to comment.