Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
4c8dcb6
Update docs links to github and docs.
bowerman0 Mar 10, 2015
d806638
Correct copy-paste error.
bowerman0 Mar 10, 2015
4863c09
Add gitignore
bowerman0 Mar 10, 2015
35e7587
Hello World starter.
bowerman0 Mar 10, 2015
5c9664a
Node module stubs.
bowerman0 Mar 10, 2015
59eedfc
First pass stubs. Unit tests.
bowerman0 Mar 10, 2015
d47e490
Fix lints.
bowerman0 Mar 10, 2015
9b92fd1
Add hapi and unit testing. Prepare for red/green refactor.
bowerman0 Mar 11, 2015
48c1b01
Add main.js to start hapi server.
bowerman0 Mar 11, 2015
5d7e256
Serve up static index.html (broken), and add bootstrap dependency.
bowerman0 Mar 11, 2015
72b70e0
Serve up static index.html (broken), and add bootstrap dependency. (2)
bowerman0 Mar 11, 2015
e2918da
update css link in index.html, still need to fix js links.
bowerman0 Mar 12, 2015
9e3a6de
Fix the bootstrap stub index.html. Add a copy of bootstrap things to …
bowerman0 Mar 12, 2015
965630c
Update Gruntfile.js to add watches.
bowerman0 Mar 12, 2015
d145687
Change index.html to form.
bowerman0 Mar 12, 2015
9220ced
Fix lint errors.
bowerman0 Mar 12, 2015
344b9fc
update travis.yml to remove v0.8 build. Update Gruntfile.js to remove…
bowerman0 Mar 12, 2015
9d1d420
Start reformat of index.html.
bowerman0 Mar 12, 2015
5ef4f61
Add money field and CC to form. TODO: Validation and testing for mone…
bowerman0 Mar 12, 2015
cd9beca
Update README.md to link to correct Travis CI build.
bowerman0 Mar 13, 2015
fed43f8
rename main.js to server.js. comment out broken code.
bowerman0 Mar 13, 2015
11089b3
Add process.env.PORT to connections.
bowerman0 Mar 13, 2015
303e74a
Add route directly to bootstrap rather than copy.
bowerman0 Mar 13, 2015
49d8609
Update README.md with links.
bowerman0 Mar 13, 2015
9dd7326
Add functionality to the button. Start with server route.
bowerman0 Mar 13, 2015
c855f01
Start to put logic into functions.
bowerman0 Mar 15, 2015
ec83133
Commit stub for get paypal CC.
bowerman0 Mar 15, 2015
f03ba8f
Add path to local files for server. (Remove implicit assumption of re…
bowerman0 Mar 15, 2015
cefcf45
Update README.md with usage instructions and link to the deployed ser…
bowerman0 Mar 15, 2015
1b57a65
Add create paypal payment stubs.
bowerman0 Mar 15, 2015
de96112
Implement helper function for: if amex, then paypal; and helper for: …
bowerman0 Mar 16, 2015
2b771f9
Add unit tests for braintree business rules. Needs cleanup, and needs…
bowerman0 Mar 16, 2015
5524a74
Fix markdown README.md errors.
bowerman0 Mar 16, 2015
6f578ad
Move link to deployment to the top.
bowerman0 Mar 16, 2015
17898f3
Add dependency on paypal-rest and braintree api.
bowerman0 Mar 17, 2015
9c314a6
Commit david-dm update to README.md
bowerman0 Mar 18, 2015
9500b72
Update badge formatting
bowerman0 Mar 18, 2015
481bf17
Add process.nextTick() and update unit tests to handle parallel behav…
bowerman0 Mar 20, 2015
b52ad6a
Update style to prefer code reuse.
bowerman0 Mar 22, 2015
a7bc4cc
Improve unit tests and start adding objects.
bowerman0 Mar 24, 2015
a36fa2e
Add paypal object.
bowerman0 Mar 24, 2015
bbaa5f1
Add processor and server objects.
bowerman0 Mar 24, 2015
2cc83b3
Add payment validator file.
bowerman0 Mar 24, 2015
fa72615
Create module for Braintree.
bowerman0 Mar 25, 2015
9495ac1
Create separate test for Braintree payment.
bowerman0 Mar 26, 2015
14cc93f
Make the BraintreePayment module an object to improve encapsulation a…
bowerman0 Mar 27, 2015
745d2fc
Update Braintree object missed in last checkin.
bowerman0 Mar 28, 2015
63bd569
Create paypal module.
bowerman0 Mar 28, 2015
b19965f
Add .js to require
bowerman0 Mar 28, 2015
8aa903b
Start adding coveralls.
bowerman0 Mar 28, 2015
684d948
Create PaymentProcessor module.
bowerman0 Mar 28, 2015
930a4e7
Create PaymentServer module. remove last of js-Round1 remnants.
bowerman0 Mar 28, 2015
03fd22d
Improve PaymentServer interface.
bowerman0 Mar 28, 2015
f733996
Add more jscoverage pieces, still WIP.
bowerman0 Mar 29, 2015
e607420
Fix the copy/paste errors and cleanup.
bowerman0 Mar 29, 2015
2f1de4d
Fix server.js to match interface change.
bowerman0 Mar 29, 2015
672b9af
Hook in stubbed post data. Needs to populate from form and needs vali…
bowerman0 Apr 8, 2015
db0faec
Commit WIP hapi validation.
bowerman0 Apr 8, 2015
d6904c9
Basic validation of JSON input. Will need refining and organization.
bowerman0 Apr 8, 2015
646d72f
remove 100 width and add joi to dependencies.
bowerman0 Apr 8, 2015
22126e2
update form to use input data.
bowerman0 Apr 8, 2015
abd1885
fix regression to add port 80 for server.
bowerman0 Apr 8, 2015
6350d0a
Begin stubbing to isolate units.
bowerman0 Apr 11, 2015
52d810b
add extended matching to prepare for calling the paypal api.
bowerman0 Apr 12, 2015
d1c79b9
First commit of paypal. Test env vars in production.
bowerman0 Apr 12, 2015
188ba6f
Add IISNode.yml for diagnostic purposes.
bowerman0 Apr 13, 2015
cfc11bd
Add some diagnostics for paypal.
bowerman0 Apr 13, 2015
3cb1091
PaypalPayment diagnostics.
bowerman0 Apr 13, 2015
84b25a5
log json on error.
bowerman0 Apr 13, 2015
be96069
add util.inspect() for logging.
bowerman0 Apr 13, 2015
7015984
add util.inspect() to error
bowerman0 Apr 13, 2015
72cefcf
Prepend 20 to years in index.
bowerman0 Apr 13, 2015
25d5fc8
update fake page to subtotal+tax=total
bowerman0 Apr 13, 2015
1b18041
Disable IISNode debugging.
bowerman0 Apr 13, 2015
962f4de
Remove items from json stub.
bowerman0 Apr 14, 2015
73ad964
Start adding more robust logging capability.
bowerman0 Apr 14, 2015
1d34a47
rename logger.js to log.js
bowerman0 Apr 15, 2015
5fe6908
migrate to bower
bowerman0 Apr 15, 2015
1c2647c
remove bootstrap-helpers experiment.
bowerman0 Apr 15, 2015
bb42c5a
Corrections to README.md
bowerman0 Apr 16, 2015
220ee96
Correct the deployment link.
bowerman0 Apr 16, 2015
2114c6c
Update deployment script for azure+bower
bowerman0 Apr 16, 2015
7017e88
debug IISNode.yml
bowerman0 Apr 16, 2015
7bd61bd
turn off debug
bowerman0 Apr 16, 2015
e3dd523
Fix link typo in README.md
bowerman0 Apr 16, 2015
543db70
Add devDependencies badge to README.md
bowerman0 Apr 16, 2015
048ffe1
Fix dev dependency formatting
bowerman0 Apr 16, 2015
3940a8e
Fix dev dependency image
bowerman0 Apr 16, 2015
6730747
Remove silliness with third-party money field.
bowerman0 Apr 16, 2015
9e67da2
Paypal code paths completed.
bowerman0 Apr 16, 2015
1711b1b
Add support for non-visa cc types
bowerman0 Apr 16, 2015
b87db0a
fix copy-pasta for bower in deploy.sh
bowerman0 Apr 21, 2015
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
Prev Previous commit
Next Next commit
Improve unit tests and start adding objects.
  • Loading branch information
bowerman0 committed Mar 24, 2015
commit a7bc4cca7945f62f49ad7bda635c8e4e181a1cea
107 changes: 57 additions & 50 deletions lib/js-Round1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,60 @@

'use strict';

exports.retrieve_token = function() {
throw new Error("Not Implemented.");
var paymentValidator = {
validateCreatePaymentJson: function(create_payment_json, reply) {
process.nextTick( function() {
//error = Error("Validation failed.");
var error;
process.nextTick( function() { reply(error, "valid."); });
});
}
};

// TODO: fix the confusing reply true/false meaning
exports.validateCreatePaymentJson = function(createPaymentJson, reply) {
process.nextTick( function() {
reply(false);
});

};
//exports.paymentValidator = paymentValidator;

exports.createBraintreePaymentInner = function(create_payment_json, reply) {
var cc_type = create_payment_json.payer.funding_instruments[0].credit_card.type;
reply( cc_type + " payment succeeded with braintree.");
};
var braintreePayment = {

// TODO: Enable 'create' from braintree api
exports.createBraintreePayment = function(create_payment_json, reply) {
exports.validateCreatePaymentJson(create_payment_json,
function(error) {
if(error) {
process.nextTick( function() {
reply("Payment failed.");
});
}
else {
var cc_type = create_payment_json.payer.funding_instruments[0].credit_card.type;
if(cc_type === "visa" ) {
createBraintreePaymentInner: function(create_payment_json, reply) {
var cc_type = create_payment_json.payer.funding_instruments[0].credit_card.type;
var error;
process.nextTick( function() {
reply( error, cc_type + " payment succeeded with braintree.");
});
},

// TODO: Enable 'create' from braintree api
createBraintreePayment: function(create_payment_json, reply) {
paymentValidator.validateCreatePaymentJson(create_payment_json,
function(error, message) {
if(error) {
process.nextTick( function() {
exports.createBraintreePaymentInner(create_payment_json, reply);
reply(error, message);
});
}
else if(cc_type === "amex" ) {
process.nextTick( function() {
exports.createBraintreePaymentInner(create_payment_json, reply);
});
else {
var cc_type = create_payment_json.payer.funding_instruments[0].credit_card.type;
if(cc_type === "visa" ) {
process.nextTick( function() {
braintreePayment.createBraintreePaymentInner(create_payment_json, reply);
});
}
else if(cc_type === "amex" ) {
process.nextTick( function() {
braintreePayment.createBraintreePaymentInner(create_payment_json, reply);
});
}
//response = paypal.payment.create(createPamentJson,
// function(error, payment){}
//);
}
//response = paypal.payment.create(createPamentJson,
// function(error, payment){}
//);
}
});
});
}
};

exports.braintreePayment = braintreePayment;


exports.createPaypalPaymentInner = function(create_payment_json, reply) {
var paypal = require('paypal-rest-sdk');
// TODO: remove this dummy reference to shut-up warning.
Expand All @@ -65,18 +74,19 @@ exports.createPaypalPaymentInner = function(create_payment_json, reply) {
// console.log("Create Payment Response");
// console.log(payment);
var cc_type = create_payment_json.payer.funding_instruments[0].credit_card.type;
reply( cc_type + " payment succeeded with paypal.");
var error = null;
reply( error, cc_type + " payment succeeded with paypal.");
// }
//});
};

// TODO: Enable 'create' from paypal api
exports.createPaypalPayment = function(create_payment_json, reply) {
exports.validateCreatePaymentJson(create_payment_json,
function(error) {
paymentValidator.validateCreatePaymentJson(create_payment_json,
function(error, message) {
if(error) {
process.nextTick( function() {
reply("Payment failed.");
reply(error, message);
});
}
else {
Expand All @@ -99,34 +109,31 @@ exports.createPaypalPayment = function(create_payment_json, reply) {
};

// TODO: Enable 'create' from paypal api
exports.processPaymentRequest = function(createPaymentJson, reply) {
exports.processPaymentRequest = function(create_payment_json, reply) {
// TODO: handle malformed data
// TODO: this logic is confusing and error prone, cleanup
var currency = createPaymentJson.transactions[0].amount.currency;
if(createPaymentJson.payer.funding_instruments[0].credit_card.type === "amex" ) {
var currency = create_payment_json.transactions[0].amount.currency;
if(create_payment_json.payer.funding_instruments[0].credit_card.type === "amex" ) {
if( currency === "USD" ) {
exports.createPaypalPayment(createPaymentJson, reply);
exports.createPaypalPayment(create_payment_json, reply);
}
else {
process.nextTick( function() {
reply("American Express must be used with US Dollars only.");
var error = new Error("American Express must be used with US Dollars only.");
reply(error,"American Express must be used with US Dollars only.");
});
}
}
else {
if( currency === "USD" || currency === "EUR" || currency === "AUD" ) {
exports.createPaypalPayment(createPaymentJson, reply);
exports.createPaypalPayment(create_payment_json, reply);
}
else {
exports.createBraintreePayment(createPaymentJson, reply);
braintreePayment.createBraintreePayment(create_payment_json, reply);
}
}
};

exports.braintree = function() {
throw new Error("Not Implemented.");
};

exports.create_listener = function(basePath) {
var Hapi = require('hapi');

Expand Down
123 changes: 69 additions & 54 deletions test/js-Round1_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var create_payment_json_amex_thb = {
}]
};

var create_payment_json_amex = {
var create_payment_json_amex_usd = {
"intent": "sale",
"payer": {
"payment_method": "credit_card",
Expand Down Expand Up @@ -362,105 +362,118 @@ exports['processPaymentRequest'] = {
function() {
js_Round1.processPaymentRequest(
create_payment_json_visa_usd,
function(){}
function(error){
test.ifError(error);
}
);},
Error,
'Create payment should not fail.');
test.done();
},
'visa pay usd': function(test) {
test.expect(1);
test.expect(2);
// tests here
js_Round1.processPaymentRequest(
create_payment_json_visa_usd,
function(answer){
test.equal(answer,
'Visa payment succeeded with paypal.',
'createPaypalPayment should succeed.');
function(error, message){
test.ifError(error);
test.equal(message,
'visa payment succeeded with paypal.',
'createPaypalPayment usd should succeed.');
test.done();
});
},
'visa pay eur': function(test) {
test.expect(1);
test.expect(2);
// tests here
js_Round1.processPaymentRequest(
create_payment_json_visa_eur,
function(answer){
test.equal(answer,
'Visa payment succeeded with paypal.',
'createPaypalPayment should succeed.');
function(error, message){
test.ifError(error);
test.equal(message,
'visa payment succeeded with paypal.',
'createPaypalPayment eur should succeed.');
test.done();
});
},
'visa pay aud': function(test) {
test.expect(1);
test.expect(2);
// tests here
js_Round1.processPaymentRequest(
create_payment_json_visa_aud,
function(answer){
test.equal(answer,
'Visa payment succeeded with paypal.',
'createPaypalPayment should succeed.');
function(error, message){
test.ifError(error);
test.equal(message,
'visa payment succeeded with paypal.',
'createPaypalPayment aud should succeed.');
test.done();
});
},
'visa pay thb': function(test) {
test.expect(1);
test.expect(2);
// tests here
js_Round1.processPaymentRequest(
create_payment_json_visa_thb,
function(answer){
test.equal(answer,
'Visa payment succeeded with braintree.',
'createPaypalPayment should succeed.');
function(error, message){
test.ifError(error);
test.equal(message,
'visa payment succeeded with braintree.',
'createPaypalPayment thb should succeed.');
test.done();
});
},
'visa pay hkd': function(test) {
test.expect(1);
test.expect(2);
// tests here
js_Round1.processPaymentRequest(
create_payment_json_visa_hkd,
function(answer){
test.equal(answer,
'Visa payment succeeded with braintree.',
'createPaypalPayment should succeed.');
function(error,message){
test.ifError(error);
test.equal(message,
'visa payment succeeded with braintree.',
'createPaypalPayment hkd should succeed.');
test.done();
});
},
'visa pay sgd': function(test) {
test.expect(1);
test.expect(2);
// tests here
js_Round1.processPaymentRequest(
create_payment_json_visa_sgd,
function(answer){
test.equal(answer,
'Visa payment succeeded with braintree.',
'createPaypalPayment should succeed.');
function(error, message){
test.ifError(error);
test.equal(message,
'visa payment succeeded with braintree.',
'createPaypalPayment sgd should succeed.');
test.done();
});
},
'amex pay': function(test) {
test.expect(1);
'amex pay usd': function(test) {
test.expect(2);
// tests here
js_Round1.processPaymentRequest(
create_payment_json_amex,
function(answer){
test.equal(answer,
'American Express payment succeeded with paypal.',
'createPaypalPayment should succeed.');
create_payment_json_amex_usd,
function(error, message){
test.ifError(error);
test.equal(message,
'amex payment succeeded with paypal.',
'createPaypalPayment amex usd should succeed.');
test.done();
});
},
'amex pay thb': function(test) {
test.expect(1);
test.expect(2);
// tests here
js_Round1.processPaymentRequest(
create_payment_json_amex_thb,
function(answer){
test.equal(answer,
function(error,message){
test.notEqual(error,
null,
//new Error('American Express must be used with US Dollars only.'),
'createPaypalPayment amex thb should fail.');
test.equal(message,
'American Express must be used with US Dollars only.',
'createPaypalPayment should succeed.');
'createPaypalPayment amex thb should fail.');
test.done();
});
},
Expand All @@ -476,7 +489,7 @@ exports['createBraintreePayment'] = {
// tests here
test.doesNotThrow(
function() {
js_Round1.createBraintreePayment(
js_Round1.braintreePayment.createBraintreePayment(
create_payment_json_visa_usd,
function(){}
);},
Expand All @@ -485,13 +498,14 @@ exports['createBraintreePayment'] = {
test.done();
},
'valid args': function(test) {
test.expect(1);
test.expect(2);
// tests here
js_Round1.createBraintreePayment(
js_Round1.braintreePayment.createBraintreePayment(
create_payment_json_visa_usd,
function(answer){
test.equal(answer,
'Visa payment succeeded with braintree.',
function(error, message){
test.ifError(error);
test.equal(message,
'visa payment succeeded with braintree.',
'createBraintreePayment should succeed.');
test.done();
});
Expand All @@ -517,14 +531,15 @@ exports['createPaypalPayment'] = {
test.done();
},
'valid args': function(test) {
test.expect(1);
test.expect(2);
// tests here
js_Round1.createPaypalPayment(
create_payment_json_visa_usd,
function(answer){
test.equal(answer,
'Visa payment succeeded with paypal.',
'createPaypalPayment should succeed.');
function(error, message){
test.ifError(error);
test.equal(message,
'visa payment succeeded with paypal.',
'createPaypalPayment visa usd should succeed.');
test.done();
});
},
Expand Down