Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions payment-gateway/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

Run with:

node app.js -p 3000

and then visit:
http://localhost:3000/buy


98 changes: 98 additions & 0 deletions payment-gateway/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* Copyright (c) 2012-2013 Richard Rodger, MIT License */
"use strict";


var http = require('http')

var uuid = require('node-uuid');
var express = require('express');
var argv = require('optimist').argv;


// create a seneca instance
var seneca = require('seneca')({
log:'print'
})

// load configuration for plugins
// top level properties match plugin names
// copy template config.template.js to config.mine.js and customize
seneca.use('config',{file:'./config.mine.js'})


var conf = {
port: argv.p || 3000
}

/*
seneca.use('mongo-store',{
name:'seneca-pay',
host:'127.0.0.1',
port:27017
})
*/

seneca.use('seneca-pay')
seneca.use('seneca-stripe-pay')


// use the express module in the normal way
var app = express()
app.enable('trust proxy')

app.use(express.cookieParser())
app.use(express.query())
app.use(express.bodyParser())
app.use(express.methodOverride())
app.use(express.json())

app.use(express.session({secret:'seneca'}))

app.use(express.static(__dirname + '/public'))


// add any middleware provided by seneca plugins
app.use( seneca.service() )


// some express views
app.engine('ejs',require('ejs-locals'))
app.set('views', __dirname + '/views')
app.set('view engine','ejs')

app.get('/buy', function(req, res){
res.render('buy.ejs',{
currencyCode: 'USD',
amount: 399,
description: 'One marry Christmas',
refno: new Buffer(uuid.v1(null, [])).toString('hex')
})
})

app.get('/completed', function(req, res){
var refno = req.query['refno'];
seneca.act({role:'transaction', cmd:'find', q:{'refno':refno}}, function(err, out) {
if (err) {
res.render('completed.ejs', {output:'Transaction not available'})
}
else {
res.render('completed.ejs', { output:JSON.stringify(out.transaction) })
}
})
})

app.get('/cancelled', function(req, res){
res.render('cancelled.ejs',{})
})


// create a HTTP server using the core Node API
// this lets the admin plugin use web sockets
var server = http.createServer(app)
server.listen(conf.port)


// visit http://localhost[:port]/admin to see the admin page
// you'll need to logged in as an admin - user 'a1' above
seneca.use('admin',{server:server})

20 changes: 20 additions & 0 deletions payment-gateway/config.template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"pay": {
"paypal": {
"useSandbox": true/false,
"username": "PAYPAL_API_USERNAME",
"password": "PAYPAL_API_PASSWORD",
"signature": "PAYPAL_API_SIGNATURE"
},
"stripe": {
"secretKey": "STRIPE_SECRET_KEY",
"publishableKey": "STRIPE_PUBLISHABLE_KEY",
"showAddress": true/false
},
"redirect": {
"hostUrl": "http://localhost:3000",
"success": "/completed",
"fail": "/cancelled"
}
}
}
29 changes: 29 additions & 0 deletions payment-gateway/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "seneca-pay-example",
"version": "0.0.1",
"description": "Seneca payment module example",
"subdomain": "seneca-pay-example",
"main": "app.js",
"scripts": {
"start": "app.js"
},
"repository": "",
"author": "Cristian iantor",
"license": "MIT",
"dependencies": {
"express": "~3.1.0",
"optimist": "~0.3.5",
"node-uuid": "~1.4.0",
"ejs": "~0.8.3",
"ejs-locals": "~1.0.2",
"seneca": "~0.5.x",
"seneca-pay": "~0.0.1",
"seneca-stripe-pay": "~0.0.1"
},
"files": [
"app.js"
],
"engines": {
"node": "0.10.x"
}
}
66 changes: 66 additions & 0 deletions payment-gateway/views/buy.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<% layout('layout') -%>

<h1>Buy some</h1>
<form id="buy" method="post">

<p>
<label for="amount">Amount:</label><br />
<input id="amount" name="amount" value="<%-amount%>" />
</p>

<input type="hidden" id="description" name="description" value="<%-description%>" />
<input type="hidden" id="currencyCode" name="currencyCode" value="<%-currencyCode%>" />

<!-- leave this empty and a refno will be generated automatically -->
<input type="hidden" id="refno" name="refno" value="<%-refno%>" />

<p>
<button id="postPayPal">PayPal</button>
<button id="postStripe">Stripe</button>
<button id="openStripe">Stripe JS</button>
</p>

<script src="https://checkout.stripe.com/v2/checkout.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>

<script>
$('#postPayPal').click(function(){
$('form').attr('action', '/pay/paypal-express/pay');
$('form').submit()
})

$('#postStripe').click(function(){
$('form').attr('action', '/pay/stripe-checkout/pay');
$('form').submit()
})

$('#openStripe').click(function(){
$('form').attr('action', '/pay/stripe-checkout/callback-complete');
var token = function(res){
var $input = $('<input type=hidden name=stripeToken />').val(res.id);
$('form').append($input).submit();
};

StripeCheckout.open({
key: 'pk_test_1ccNWMm1bVQuLlNb0Hww4GOb',
address: true,
amount: parseFloat($('#amount').val())*100,
currency: $('#currencyCode').val(),
name: 'The magic store',
description: $('#description').val(),
panelLabel: 'Checkout',
token: token,
closed: stripeClosed
});

return false;
})

var stripeClosed = function() {
//
}

</script>

</form>

4 changes: 4 additions & 0 deletions payment-gateway/views/cancelled.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<% layout('layout') -%>

<h1>No game</h1>

7 changes: 7 additions & 0 deletions payment-gateway/views/completed.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% layout('layout') -%>

<h1>You just bought some</h1>

<p>
<%-output%>
</p>
9 changes: 9 additions & 0 deletions payment-gateway/views/layout.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<%- body %>
</body>
</html>

1 change: 1 addition & 0 deletions user-accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"optimist": "~0.3.5",
"ejs": "~0.8.3",
"ejs-locals": "~1.0.2",
"node-uuid": "~1.4.0",
"seneca": "~0.5.x",
"seneca-user": "~0.2.1",
"seneca-auth": "~0.2.4"
Expand Down