Permalink
Browse files

Find customer via route

  • Loading branch information...
minimul committed Sep 4, 2015
1 parent 5a6f807 commit 97c4a2d48a2fa6947ba328083df6fa97da0f52e0
Showing with 45 additions and 15 deletions.
  1. +32 −13 example/app.js
  2. +1 −0 example/package.json
  3. +10 −0 example/views/customer.ejs
  4. +2 −2 example/views/intuit.ejs
View
@@ -5,7 +5,7 @@ var http = require('http'),
util = require('util'),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
- session = require('express-session'),
+ cookieSession = require('cookie-session'),
express = require('express'),
app = express(),
QuickBooks = require('../index')
@@ -17,21 +17,31 @@ app.set('views', 'views')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}))
app.use(cookieParser('brad'))
-app.use(session({resave: false, saveUninitialized: false, secret: 'smith'}));
+//app.use(session({resave: false, saveUninitialized: false, secret: 'smith'}));
+app.use(cookieSession({name: 'session', keys: ['key1']}))
app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'))
})
// INSERT YOUR CONSUMER_KEY AND CONSUMER_SECRET HERE
-var consumerKey = '',
- consumerSecret = ''
+var consumerKey = process.env.MINIMULCASTS_CONSUMER_KEY,
+ consumerSecret = process.env.MINIMULCASTS_CONSUMER_SECRET
app.get('/start', function(req, res) {
res.render('intuit.ejs', {locals: {port:port, appCenter: QuickBooks.APP_CENTER_BASE}})
})
+app.get('/customer/:id', function (req, res) {
+ console.log(req.session);
+ var qbo = getQbo(req.session.qbo);
+ qbo.getCustomer(req.params.id, function(err, customer) {
+ console.log(customer);
+ res.render('customer.ejs', { locals: { customer: customer }})
+ })
+})
+
app.get('/requestToken', function(req, res) {
var postBody = {
url: QuickBooks.REQUEST_TOKEN_URL,
@@ -65,23 +75,32 @@ app.get('/callback', function(req, res) {
var accessToken = qs.parse(data)
console.log(accessToken)
console.log(postBody.oauth.realmId)
-
+ req.session.qbo = {
+ token: accessToken.oauth_token,
+ secret: accessToken.oauth_token_secret,
+ companyid: postBody.oauth.realmId
+ };
+ qbo = getQbo(req.session.qbo);
// save the access token somewhere on behalf of the logged in user
- qbo = new QuickBooks(consumerKey,
- consumerSecret,
- accessToken.oauth_token,
- accessToken.oauth_token_secret,
- postBody.oauth.realmId,
- true, // use the Sandbox
- true); // turn debugging on
// test out account access
qbo.findAccounts(function(_, accounts) {
accounts.QueryResponse.Account.forEach(function(account) {
console.log(account.Name)
})
})
+ res.send('<!DOCTYPE html><html lang="en"><head></head><body><script>window.opener.location.reload(); window.close();</script></body></html>')
})
- res.send('<!DOCTYPE html><html lang="en"><head></head><body><script>window.opener.location.reload(); window.close();</script></body></html>')
})
+var getQbo = function (args) {
+ return new QuickBooks(consumerKey,
+ consumerSecret,
+ args.token,
+ args.secret,
+ args.companyid,
+ true, // use the Sandbox
+ true); // turn debugging on
+
+};
+
View
@@ -13,6 +13,7 @@
"dependencies": {
"body-parser": "^1.13.3",
"cookie-parser": "^1.3.5",
+ "cookie-session": "^1.2.0",
"ejs": "0.7.2",
"express": "^4.13.3",
"node-quickbooks": "1.0.19"
View
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title></title>
+</head>
+<body>
+ <h1>Customer <%= customer.DisplayName %></h1>
+</body>
+</html>
View
@@ -9,12 +9,12 @@
grantUrl: 'http://localhost:' + <%= port %> + '/requestToken',
datasources: {
quickbooks : true, // set to false if NOT using Quickbooks API
- payments : true // set to true if using Payments API
+ payments : false // set to true if using Payments API
}
});
</script>
</head>
<body>
<ipp:connectToIntuit></ipp:connectToIntuit>
</body>
-</html>
+</html>

0 comments on commit 97c4a2d

Please sign in to comment.