Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from RappidDevelopment/mm/enhancement/#12/qbXM…
Browse files Browse the repository at this point in the history
…L-Handler

qbXML Handler
  • Loading branch information
MattMorgis authored Nov 14, 2016
2 parents a282d50 + 17c85d9 commit f017896
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 915 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,47 @@ QB_COMPANY_FILE='C:\\Users\\Public\\Documents\\Intuit\\QuickBooks\\Sample Compan
```
_For easy `env` variable management checkout the [dotenv package](https://www.npmjs.com/package/dotenv)_.

### qbXML Handler
You must addtionally create your own `qbXMLHandler` that will send the SOAP Server a queue of requests to pass to QBWC. It will addtionally handle the qbXML responses and any errors that may be returned.

There is an [example class here](https://github.com/RappidDevelopment/quickbooks-js/blob/master/bin/qbXMLHandler/index).

```javascript
// Public
module.exports = {

/**
* Builds an array of qbXML commands
* to be run by QBWC.
*
* @param callback(err, requestArray)
*/
fetchRequests: function(callback) {
return callback(null, []);
},

/**
* Called when a qbXML response
* is returned from QBWC.
*
* @param response - qbXML response
*/
handleResponse: function(response) {
console.log(response);
},

/**
* Called when there is an error
* returned processing qbXML from QBWC.
*
* @param error - qbXML error response
*/
didReceiveError: function(error) {
console.log(error);
}
};
```

### SOAP Server Setup
To start the service from the command line simply run:
```
Expand All @@ -44,7 +85,9 @@ npm install quickbooks-js --save
Then start the service from your `app.js` with:
```
var Server = require('quickbooks-js');
var qbXMLHandler = require('./qbXMLHandler');
var soapServer = new Server();
quickbooksServer.setQBXMLHandler(qbXMLHandler);
soapServer.run();
```
### QBWC Setup
Expand Down
69 changes: 69 additions & 0 deletions bin/qbXMLHandler/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* This file is part of quickbooks-js
* https://github.com/RappidDevelopment/quickbooks-js
*
* Based on qbws: https://github.com/johnballantyne/qbws
*
* (c) 2015 johnballantyne
* (c) 2016 Rappid Development LLC
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

var data2xml = require('data2xml');
var convert = data2xml({
xmlHeader: '<?xml version="1.0" encoding="utf-8"?>\n<?qbxml version="13.0"?>\n'
});

// Public
module.exports = {

/**
* Builds an array of qbXML commands
* to be run by QBWC.
*
* @param callback(err, requestArray)
*/
fetchRequests: function(callback) {
buildRequests(callback);
},

/**
* Called when a qbXML response
* is returned from QBWC.
*
* @param response - qbXML response
*/
handleResponse: function(response) {
console.log(response);
},

/**
* Called when there is an error
* returned processing qbXML from QBWC.
*
* @param error - qbXML error response
*/
didReceiveError: function(error) {
console.log(error);
}
};

function buildRequests(callback) {
var requests = new Array();
var xml = convert(
'QBXML',
{
QBXMLMsgsRq : {
_attr : { onError : 'stopOnError' },
ItemInventoryQueryRq : {
MaxReturned: 1000,
},
},
}
);
requests.push(xml);

return callback(null, requests);
}
2 changes: 2 additions & 0 deletions bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

var QuickbooksServer = require('../index');
var quickbooksServer = new QuickbooksServer();
var qbXMLHandler = require('./qbXMLHandler');
quickbooksServer.setQBXMLHandler(qbXMLHandler);
quickbooksServer.run();
Loading

0 comments on commit f017896

Please sign in to comment.