├── Procfile ├── .gitignore ├── public ├── lang-logo.png ├── stylesheets │ └── main.css └── node.svg ├── README.md ├── simplify.js ├── pg.sql ├── app.json ├── views ├── pages │ ├── db.ejs │ ├── index.ejs │ └── card-token.ejs └── partials │ ├── header.ejs │ └── nav.ejs ├── db.js ├── curl.sh ├── package.json ├── payments.js ├── customers.js └── index.js /Procfile: -------------------------------------------------------------------------------- 1 | web: node index.js 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | Dockerfile 4 | docker-compose.yml 5 | .idea/ 6 | *.iml 7 | .env 8 | -------------------------------------------------------------------------------- /public/lang-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siddii/simplify-node-server/master/public/lang-logo.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simplify SDK module on Heroku node instance 2 | 3 | ## Deploying to Heroku 4 | 5 | ``` 6 | $ heroku create 7 | $ git push heroku master 8 | $ heroku open 9 | ``` 10 | -------------------------------------------------------------------------------- /simplify.js: -------------------------------------------------------------------------------- 1 | var Simplify = require("simplify-commerce"); 2 | 3 | 4 | exports.client = Simplify.getClient({ 5 | publicKey: process.env.SIMPLIFY_API_PUBLIC_KEY, 6 | privateKey: process.env.SIMPLIFY_API_PRIVATE_KEY 7 | }); 8 | -------------------------------------------------------------------------------- /pg.sql: -------------------------------------------------------------------------------- 1 | create table customers(id varchar(15) primary key, name varchar (50), email varchar (100)); 2 | 3 | create table payments(id varchar(15) primary key, customer_id varchar (50) references customers(id), amount integer not null, status varchar (50)); 4 | 5 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Node.js Getting Started", 3 | "description": "A barebones Node.js app using Express 4", 4 | "repository": "https://github.com/heroku/node-js-getting-started", 5 | "logo": "http://node-js-sample.herokuapp.com/node.svg", 6 | "keywords": ["node", "express", "static"], 7 | "image": "heroku/nodejs" 8 | } 9 | -------------------------------------------------------------------------------- /views/pages/db.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <% include ../partials/header.ejs %> 5 | 6 | 7 | 8 | 9 | <% include ../partials/nav.ejs %> 10 | 11 |
12 |

Database Results

13 | 14 | 19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /views/partials/header.ejs: -------------------------------------------------------------------------------- 1 | Getting Started 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /db.js: -------------------------------------------------------------------------------- 1 | var pg = require('pg'); 2 | 3 | 4 | exports.runQuery = function (query, params, cb) { 5 | pg.connect(process.env.DATABASE_URL, function (err, client, done) { 6 | client.query(query, params, function (err, result) { 7 | done(); 8 | if (err) { 9 | console.error(err); 10 | cb(true, err); 11 | } 12 | else { 13 | cb(false, result); 14 | } 15 | }); 16 | }); 17 | }; 18 | -------------------------------------------------------------------------------- /curl.sh: -------------------------------------------------------------------------------- 1 | 2 | # Create customer 3 | curl -H "Content-Type: application/json" -X POST -d '{"name":"John Doe","email":"john.doe@email.com", "token": "6ed97f6e-7fcc-464f-9edf-2be6f205706c"}' http://localhost:5000/addCustomer 4 | 5 | # List customers 6 | https://simplify-qr-node.herokuapp.com/customers 7 | 8 | # Make payments 9 | # Make sure the id, referenced here is what we got from the last call 10 | curl -H "Content-Type: application/json" -X POST -d '{"amount":155,"customer":"rga7r949", "description": "Test payment from node instance"}' http://localhost:5000/pay 11 | 12 | #List payments 13 | https://simplify-qr-node.herokuapp.com/payments 14 | 15 | -------------------------------------------------------------------------------- /public/stylesheets/main.css: -------------------------------------------------------------------------------- 1 | .jumbotron { 2 | background: #532F8C; 3 | color: white; 4 | padding-bottom: 80px; } 5 | .jumbotron .btn-primary { 6 | background: #845ac7; 7 | border-color: #845ac7; } 8 | .jumbotron .btn-primary:hover { 9 | background: #7646c1; } 10 | .jumbotron p { 11 | color: #d9ccee; 12 | max-width: 75%; 13 | margin: 1em auto 2em; } 14 | .navbar + .jumbotron { 15 | margin-top: -20px; } 16 | .jumbotron .lang-logo { 17 | display: block; 18 | background: #B01302; 19 | border-radius: 50%; 20 | overflow: hidden; 21 | width: 100px; 22 | height: 100px; 23 | margin: auto; 24 | border: 2px solid white; } 25 | .jumbotron .lang-logo img { 26 | max-width: 100%; } 27 | 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "SimplifyQR", 3 | "version": "0.0.1", 4 | "description": "Simplify Module for QR", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "dependencies": { 10 | "ejs": "2.5.5", 11 | "express": "4.13.3", 12 | "body-parser": "*", 13 | "simplify-commerce": "^1.3.0", 14 | "cool-ascii-faces": "~1.3.x", 15 | "pg": "4.x", 16 | "async": "*" 17 | }, 18 | "engines": { 19 | "node": "0.12.7" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "https://github.com/heroku/node-js-getting-started" 24 | }, 25 | "keywords": [ 26 | "node", 27 | "heroku", 28 | "express" 29 | ], 30 | "license": "MIT" 31 | } 32 | -------------------------------------------------------------------------------- /payments.js: -------------------------------------------------------------------------------- 1 | var simplifyClient = require('./simplify').client; 2 | var db = require('./db'); 3 | var async = require('async'); 4 | 5 | exports.create = function (amount, description, customer, cb) { 6 | simplifyClient.payment.create({ 7 | amount: amount, 8 | description: description, 9 | customer: customer, 10 | currency: "USD" 11 | }, function (error, data) { 12 | if (error) { 13 | console.error(JSON.stringify(error)); 14 | cb(error); 15 | } 16 | cb(data); 17 | }); 18 | }; 19 | 20 | function getPayment(id, cb) { 21 | simplifyClient.payment.find(id, function (error, data) { 22 | if (error) { 23 | console.error(JSON.stringify(error)); 24 | cb(true, error); 25 | } 26 | cb(false, data); 27 | }); 28 | } 29 | 30 | exports.listPayments = function (request, response) { 31 | db.runQuery('SELECT * FROM payments', null, function (error, result) { 32 | if (!error && result.rows) { 33 | var responseArray = []; 34 | async.forEachSeries(result.rows, function iterator(item, callback) { 35 | getPayment(item.id, function (error, data) { 36 | if (!error) { 37 | responseArray.push(data); 38 | } 39 | callback(error); 40 | }) 41 | }, function done() { 42 | response.json(responseArray); 43 | }); 44 | } 45 | else { 46 | response.status(500).send("Error listing payments!"); 47 | } 48 | }); 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /public/node.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 12 | 17 | 18 | -------------------------------------------------------------------------------- /customers.js: -------------------------------------------------------------------------------- 1 | var simplify = require('./simplify'); 2 | var db = require('./db'); 3 | var async = require('async'); 4 | 5 | 6 | exports.create = function (name, email, token, cb) { 7 | console.log("#### name = ", name, email, token); 8 | simplify.client.customer.create({ 9 | name: name, 10 | email: email, 11 | token: token 12 | }, function (error, data) { 13 | console.log("##### data = ", data, error); 14 | if (error) { 15 | console.error(JSON.stringify(error)); 16 | cb(error); 17 | } 18 | cb(data); 19 | }); 20 | }; 21 | 22 | function getCustomer(id, cb) { 23 | simplify.client.customer.find(id, function (error, data) { 24 | if (error) { 25 | console.error(JSON.stringify(error)); 26 | cb(true, error); 27 | } 28 | cb(false, data); 29 | }); 30 | } 31 | 32 | exports.listCustomers = function (request, response) { 33 | db.runQuery('SELECT * FROM customers', null, function (error, result) { 34 | if (!error && result.rows) { 35 | var responseArray = []; 36 | async.forEachSeries(result.rows, function iterator(item, callback) { 37 | getCustomer(item.id, function (error, data) { 38 | if (!error) { 39 | responseArray.push(data); 40 | } 41 | callback(error); 42 | }) 43 | }, function done() { 44 | response.json(responseArray); 45 | }); 46 | } 47 | else { 48 | response.status(500).send("Error listing customers!"); 49 | } 50 | }); 51 | }; 52 | 53 | 54 | -------------------------------------------------------------------------------- /views/partials/nav.ejs: -------------------------------------------------------------------------------- 1 | 34 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var app = express(); 3 | var bodyParser = require('body-parser'); 4 | 5 | var cool = require('cool-ascii-faces'); 6 | var db = require('./db'); 7 | 8 | var payments = require('./payments'); 9 | var customers = require('./customers'); 10 | 11 | app.set('port', (process.env.PORT || 5000)); 12 | 13 | app.use(express.static(__dirname + '/public')); 14 | 15 | app.use(bodyParser.urlencoded({ extended: false })); 16 | app.use(bodyParser.json()); 17 | 18 | // views is directory for all template files 19 | app.set('views', __dirname + '/views'); 20 | app.set('view engine', 'ejs'); 21 | 22 | app.get('/', function (request, response) { 23 | response.render('pages/index'); 24 | }); 25 | 26 | app.get('/generateCardToken', function (request, response) { 27 | response.render('pages/card-token.ejs', {publicKey: process.env.SIMPLIFY_API_PUBLIC_KEY}); 28 | }); 29 | 30 | app.get('/cool', function (request, response) { 31 | response.send(cool()); 32 | }); 33 | 34 | function errorResponse(response, error) { 35 | response.status(500).send(error); 36 | } 37 | 38 | app.get('/db', function (request, response) { 39 | db.runQuery('SELECT * FROM test_table', function (error, result) { 40 | if (!error) { 41 | response.render('pages/db', {results: result.rows}); 42 | } 43 | else { 44 | response.send("Error " + error); 45 | } 46 | }); 47 | }); 48 | 49 | app.get('/payments', payments.listPayments); 50 | 51 | app.post('/pay', function (request, response) { 52 | payments.create(request.body.amount, request.body.description, request.body.customer, function (data) { 53 | if (data.id) { 54 | db.runQuery("insert into payments(id, amount, status) values($1, $2, $3)", [data.id, request.body.amount, data.paymentStatus], function (error, result) { 55 | if (!error) { 56 | response.json(data); 57 | } 58 | }) 59 | } 60 | else { 61 | errorResponse(response, "Error making payment!"); 62 | } 63 | }) 64 | }); 65 | 66 | app.get('/customers', customers.listCustomers); 67 | 68 | app.post('/addCustomer', function (request, response) { 69 | console.log("###### request.body.token = ", request.body.token); 70 | customers.create(request.body.name, request.body.email, request.body.token, function (data) { 71 | if (data.id) { 72 | db.runQuery("insert into customers(id, name, email) values($1, $2, $3)", [data.id, request.body.name, request.body.email], function (error, result) { 73 | if (!error) { 74 | response.json(data); 75 | } 76 | else { 77 | errorResponse(response, "Error creating customers!"); 78 | } 79 | }) 80 | } 81 | }) 82 | }); 83 | 84 | app.listen(app.get('port'), function () { 85 | console.log('Node app is running on port', app.get('port')); 86 | }); 87 | 88 | 89 | -------------------------------------------------------------------------------- /views/pages/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <% include ../partials/header.ejs %> 5 | 6 | 7 | 8 | 9 | <% include ../partials/nav.ejs %> 10 | 11 |
12 |
13 | 16 |

Getting Started with Node on Heroku

17 |

This is a sample Node application deployed to Heroku. It's a reasonably simple app - but a good foundation for understanding how to get the most out of the Heroku platform.

18 | Getting Started with Node 19 | Source on GitHub 20 |
21 |
22 |
23 | 26 |
27 |
28 |
29 |

How this sample app works

30 |
    31 |
  • This app was deployed to Heroku, either using Git or by using Heroku Button on the repository.
  • 32 | 33 |
  • When Heroku received the source code, it grabbed all the dependencies in the package.json.
  • 34 |
  • The platform then spins up a dyno, a lightweight container that provides an isolated environment in which the slug can be mounted and executed.
  • 35 |
  • You can scale your app, manage it, and deploy over 150 add-on services, from the Dashboard or CLI.
  • 36 |
  • Check out the Getting Started guide to learn more!
  • 37 |
38 |
39 |
40 |

Helpful Links

41 | 47 |
48 |
49 | 52 |
53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /views/pages/card-token.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 53 | 54 | 55 | 56 | 57 |
58 |
59 | 60 | 61 | 62 | 66 | 67 | 68 | 69 | 72 | 73 | 74 | 75 | 93 | 94 | 95 | 98 | 99 |
63 | 65 |
70 | 71 |
76 | 90 | 92 |
96 | 97 |
100 |
101 | 102 |

103 |
104 | 105 | 106 | --------------------------------------------------------------------------------