Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #14 from Xavi-/remove-require-paths
Browse files Browse the repository at this point in the history
Help make paynode compatible with node 0.6.x
  • Loading branch information
tcurdt committed Jan 17, 2012
2 parents 0fccaa1 + 4e2e1a5 commit dcbc441
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 144 deletions.
4 changes: 2 additions & 2 deletions docs/PayflowPro.md
Expand Up @@ -95,8 +95,8 @@ Get the balances of your account
}) })
client.getBalance().on('success', function(result){ client.getBalance().on('success', function(result){
result.balances.forEach(function(balance){ result.balances.forEach(function(balance){
sys.puts(balance.amt) console.log(balance.amt)
sys.puts(balance.currencycode) console.log(balance.currencycode)
}) })
}) })


Expand Down
6 changes: 2 additions & 4 deletions lib/authorizenet/client.js
@@ -1,8 +1,6 @@
require.paths.unshift(__dirname)

var EventEmitter = require('events').EventEmitter, var EventEmitter = require('events').EventEmitter,
GatewayClient = require('../gateway-client').GatewayClient, GatewayClient = require('../gateway-client').GatewayClient,
response = require('response-parser') response = require('./response-parser')


exports.createClient = function(options, netClient){ exports.createClient = function(options, netClient){
var conn = netClient || new GatewayClient({ var conn = netClient || new GatewayClient({
Expand All @@ -14,7 +12,7 @@ exports.createClient = function(options, netClient){
return new Client(options, conn) return new Client(options, conn)
} }


exports.levels = require('levels').levels exports.levels = require('./levels').levels


function Client(options, netClient){ function Client(options, netClient){
var addOptionAttributes = function(req){ var addOptionAttributes = function(req){
Expand Down
2 changes: 0 additions & 2 deletions lib/chargify/client.js
@@ -1,5 +1,3 @@
require.paths.unshift(__dirname+'/../');

var https = require ('https'), var https = require ('https'),
events = require ('events'), events = require ('events'),
querystring = require ('querystring'); querystring = require ('querystring');
Expand Down
3 changes: 1 addition & 2 deletions lib/gateway-client.js
@@ -1,5 +1,4 @@
var qs = require('querystring'), var qs = require('querystring'),
sys = require('sys'),
https = require('https'); https = require('https');


function GatewayClient(opts, authInfo){ function GatewayClient(opts, authInfo){
Expand Down Expand Up @@ -30,7 +29,7 @@ function GatewayClient(opts, authInfo){
req.on('response', function(res){ req.on('response', function(res){
res.on('data', function(data){ res.on('data', function(data){
// TODO add error handling // TODO add error handling
callback(opts.responseParser.parseResponse(opts.responseOptions, request, data.toString())) callback(opts.responseParser.parseResponse(requestString, data.toString(), opts.responseOptions))
}) })
}) })
} }
Expand Down
10 changes: 4 additions & 6 deletions lib/payflowpro/client.js
@@ -1,8 +1,6 @@
require.paths.unshift(__dirname)

var EventEmitter = require('events').EventEmitter, var EventEmitter = require('events').EventEmitter,
PaypalNetworkClient = require('paypal-network-client').PaypalNetworkClient, PaypalNetworkClient = require('./paypal-network-client').PaypalNetworkClient,
requestBuilder = require("request-builder"); requestBuilder = require("./request-builder");


var SUPPORTED_API_METHODS = [ var SUPPORTED_API_METHODS = [
'transactionSearch', 'transactionSearch',
Expand Down Expand Up @@ -31,7 +29,7 @@ var SUPPORTED_API_METHODS = [
'doExpressCheckoutPayment' 'doExpressCheckoutPayment'
]; ];


exports.levels = require('levels'); exports.levels = require('./levels');


exports.createClient = function(options){ exports.createClient = function(options){
options.version = '64.0'; options.version = '64.0';
Expand Down Expand Up @@ -59,7 +57,7 @@ function Client(options, paypal){
var emitter = new EventEmitter(); var emitter = new EventEmitter();


paypal.request(req, function(data){ paypal.request(req, function(data){
emitter.emit((data.ack ? data.ack.toLowerCase() : 'fail'), data); emitter.emit((data.ack ? data.ack.toLowerCase() : 'failure'), data);
}); });


return emitter; return emitter;
Expand Down
2 changes: 1 addition & 1 deletion lib/payflowpro/paypal-network-client.js
@@ -1,5 +1,5 @@
var GatewayClient = require('../gateway-client').GatewayClient, var GatewayClient = require('../gateway-client').GatewayClient,
paypalResponse = require('response-parser'); paypalResponse = require('./response-parser');


function PaypalNetworkClient(level, authInfo){ function PaypalNetworkClient(level, authInfo){


Expand Down
5 changes: 2 additions & 3 deletions lib/payflowpro/response-parser.js
@@ -1,6 +1,5 @@
var qs = require('querystring') var qs = require('querystring')
var s = require('sys') var val = require('../value-matcher').val
var val = require('value-matcher').val


var errorField = [ 'errorcode', 'shortmessage', 'longmessage', 'severitycode' ] var errorField = [ 'errorcode', 'shortmessage', 'longmessage', 'severitycode' ]
var balanceField = [ 'amt', 'currencycode' ] var balanceField = [ 'amt', 'currencycode' ]
Expand All @@ -20,7 +19,7 @@ var isSpecialNestedField = function(s){
return s.search(/_\d_/) > -1 return s.search(/_\d_/) > -1
} }


function buildResponse(responseOptions, request, data){ function buildResponse(request, data, responseOptions){
var lowercaseKeys = function(data){ var lowercaseKeys = function(data){
var result = {} var result = {}
Object.keys(data).forEach(function(k){ Object.keys(data).forEach(function(k){
Expand Down
2 changes: 0 additions & 2 deletions lib/paynode.js
@@ -1,5 +1,3 @@
require.paths.unshift(__dirname);

exports.use = function(name){ exports.use = function(name){
return require(__dirname + '/'+name+'/client') return require(__dirname + '/'+name+'/client')
} }
4 changes: 1 addition & 3 deletions spec/helpers/prenuptials.js
@@ -1,9 +1,7 @@
var sys = require('sys')

exports.one = function(fn){ exports.one = function(fn){
return function(err, result) { fn(err) } return function(err, result) { fn(err) }
} }


exports.failWithDump = function(){ exports.failWithDump = function(){
sys.puts(sys.inspect(arguments)) console.dir(arguments)
} }
2 changes: 1 addition & 1 deletion spec/helpers/transactions.js
Expand Up @@ -4,7 +4,7 @@ exports.valid={amt:'99.06'
,ipaddress:'1.1.1.1' ,ipaddress:'1.1.1.1'
,creditcardtype:'Visa' ,creditcardtype:'Visa'
,acct:'4834907016040081' ,acct:'4834907016040081'
,expdate:'032011' ,expdate:'032015'
,cvv2:'000' ,cvv2:'000'
,firstname:'John' ,firstname:'John'
,lastname:'Doe' ,lastname:'Doe'
Expand Down
56 changes: 26 additions & 30 deletions spec/integration/authorizenet/performAimTransaction.spec.js
@@ -1,11 +1,7 @@
require.paths.unshift(__dirname+'/../../helpers/')
require.paths.unshift(__dirname+'/../../../lib/')

var vows = require('vows'), var vows = require('vows'),
assert = require('assert'), assert = require('assert'),
clients = require('clients'), clients = require('../../helpers/clients'),
authorizenet = require('paynode').use('authorizenet'), authorizenet = require('../../../lib/paynode').use('authorizenet')
sys = require('sys')


var client = authorizenet.createClient({ var client = authorizenet.createClient({
level:authorizenet.levels.sandbox level:authorizenet.levels.sandbox
Expand All @@ -20,18 +16,18 @@ var invalidAuthClient = authorizenet.createClient({
}) })


var goodTransaction = { var goodTransaction = {
"x_type": "AUTH_CAPTURE", "x_type": "AUTH_CAPTURE",
"x_method": "CC", "x_method": "CC",
"x_card_num": "4111111111111111", "x_card_num": "4111111111111111",
"x_exp_date": "0115", "x_exp_date": "0115",

"x_amount": "19.99", "x_amount": "19.99",
"x_description": "Sample Transaction", "x_description": "Sample Transaction",


"x_first_name": "John", "x_first_name": "John",
"x_last_name": "Doe", "x_last_name": "Doe",
"x_address": "1234 Street", "x_address": "1234 Street",
"x_state": "WA", "x_state": "WA",
"x_zip": "98004"} "x_zip": "98004"}




Expand Down Expand Up @@ -60,18 +56,18 @@ vows.describe('AIM Transaction').addBatch({
'a failed transaction due to invalid card':{ 'a failed transaction due to invalid card':{
topic:function(){ topic:function(){
client.performAimTransaction({ client.performAimTransaction({
"x_type": "AUTH_CAPTURE", "x_type": "AUTH_CAPTURE",
"x_method": "CC", "x_method": "CC",
"x_card_num": "4111111111111111", "x_card_num": "4111111111111111",
"x_exp_date": "0105", "x_exp_date": "0105",

"x_amount": "19.99", "x_amount": "19.99",
"x_description": "Sample Transaction", "x_description": "Sample Transaction",


"x_first_name": "John", "x_first_name": "John",
"x_last_name": "Doe", "x_last_name": "Doe",
"x_address": "1234 Street", "x_address": "1234 Street",
"x_state": "WA", "x_state": "WA",
"x_zip": "98004" "x_zip": "98004"
}).on('failure', this.callback) }).on('failure', this.callback)
}, },
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/chargify/customers.spec.js
@@ -1,7 +1,6 @@
require.paths.unshift(__dirname+'/../../../lib/');
var vows = require('vows'); var vows = require('vows');
var assert = require('assert'); var assert = require('assert');
var paynode = require('paynode').use('chargify'); var paynode = require('../../../lib/paynode').use('chargify');




var client = paynode.createClient({ var client = paynode.createClient({
Expand All @@ -20,13 +19,14 @@ vows.describe('module').addBatch({
}, },
'Given I have customer data': { 'Given I have customer data': {
topic: function() { topic: function() {
var callback = this.callback;
client.customers.create({ client.customers.create({
customer:{ customer:{
first_name:'Joe', first_name:'Joe',
last_name:'Blow', last_name:'Blow',
email:'joe.blow@example.com' email:'joe.blow@example.com'
} }
}).on('success', this.callback); }).on('success', function(response) { callback(null, response) })
}, },
'should get response with same details sent': function(response) { 'should get response with same details sent': function(response) {
assert.equal(response.customer.first_name, 'Joe') assert.equal(response.customer.first_name, 'Joe')
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/chargify/subscriptions.spec.js
@@ -1,6 +1,6 @@
var vows = require('vows'); var vows = require('vows');
var assert = require('assert'); var assert = require('assert');
var paynode = require('paynode').use('chargify'); var paynode = require('../../../lib/paynode').use('chargify');




vows.describe('subscriptions').addBatch({ vows.describe('subscriptions').addBatch({
Expand Down
12 changes: 4 additions & 8 deletions spec/integration/payflowpro/SetExpressCheckout.spec.js
@@ -1,13 +1,9 @@
require.paths.unshift(__dirname+'/../../helpers/')
require.paths.unshift(__dirname+'/../../../lib/')

var vows = require('vows'), var vows = require('vows'),
one = require('prenuptials').one, one = require('../../helpers/prenuptials').one,
assert = require('assert'), assert = require('assert'),
transactions = require("transactions"), transactions = require("../../helpers/transactions"),
clients = require('clients'), clients = require('../../helpers/clients'),
payflow = require('paynode').use('payflowpro'), payflow = require('../../../lib/paynode').use('payflowpro')
sys = require('sys')


vows.describe('SetExpressCheckout').addBatch({ vows.describe('SetExpressCheckout').addBatch({
'successful transaction':{ 'successful transaction':{
Expand Down
8 changes: 3 additions & 5 deletions spec/integration/payflowpro/TransactionRelated.spec.js
@@ -1,11 +1,9 @@
require.paths.unshift(__dirname+'../../../lib/')
require.paths.unshift(__dirname+'/../../helpers/')
var vows = require('vows'); var vows = require('vows');
var assert = require('assert'); var assert = require('assert');
var clients = require('clients'); var clients = require('../../helpers/clients');
var transactions = require ('transactions'); var transactions = require ('../../helpers/transactions');


var client = clients.signatureAuth(require('paynode').use('payflowpro')); var client = clients.signatureAuth(require('../../../lib/paynode').use('payflowpro'));


// promise for transaction execution // promise for transaction execution
function executeTransaction () { function executeTransaction () {
Expand Down
18 changes: 7 additions & 11 deletions spec/integration/payflowpro/doDirectPayment.spec.js
@@ -1,21 +1,17 @@
require.paths.unshift(__dirname+'/../../helpers/')
require.paths.unshift(__dirname+'/../../../lib/')

var vows = require('vows'), var vows = require('vows'),
one = require('prenuptials').one, one = require('../../helpers/prenuptials').one,
assert = require('assert'), assert = require('assert'),
transactions = require("transactions"), transactions = require("../../helpers/transactions"),
payflow = require('paynode').use('payflowpro'), payflow = require('../../../lib/paynode').use('payflowpro'),
clients = require('clients'), clients = require('../../helpers/clients')
sys = require('sys')


function examplesUsing(client){ function examplesUsing(client){
return { return {
'Successful Transaction':{ 'Successful Transaction':{
topic: function () { topic: function () {
client.doDirectPayment(transactions.valid) client.doDirectPayment(transactions.valid)
.on('success', this.callback) .on('success', this.callback)
.on('failure', function(res){ console.log(sys.inspect(res)) }) .on('failure', function(res){ console.dir(res) })
}, },
'emits a successful result': function (result, ignore){ 'emits a successful result': function (result, ignore){
assert.equal('Success', result.ack) assert.equal('Success', result.ack)
Expand Down Expand Up @@ -58,5 +54,5 @@ function examplesUsing(client){


vows.describe('doDirectPayment') vows.describe('doDirectPayment')
.addBatch(examplesUsing(clients.signatureAuth(payflow))) .addBatch(examplesUsing(clients.signatureAuth(payflow)))
.addBatch(examplesUsing(clients.certAuth(payflow))) //.addBatch(examplesUsing(clients.certAuth(payflow)))
.export(module); .export(module);
11 changes: 4 additions & 7 deletions spec/integration/payflowpro/getBalance.spec.js
@@ -1,13 +1,10 @@
require.paths.unshift(__dirname+'/../../helpers/')
require.paths.unshift(__dirname+'/../../../lib/')

var vows = require('vows'), var vows = require('vows'),
one = require('prenuptials').one, one = require('../../helpers/prenuptials').one,
assert = require('assert'), assert = require('assert'),
transactions = require("transactions"), transactions = require("../../helpers/transactions"),
clients = require('clients') clients = require('../../helpers/clients')


var client = clients.signatureAuth(require('paynode').use('payflowpro')); var client = clients.signatureAuth(require('../../../lib/paynode').use('payflowpro'));


vows.describe('getBalance').addBatch({ vows.describe('getBalance').addBatch({
'get single balances': { 'get single balances': {
Expand Down
13 changes: 5 additions & 8 deletions spec/integration/payflowpro/getTransactionDetails.spec.js
@@ -1,13 +1,10 @@
require.paths.unshift(__dirname+'/../../helpers/')
require.paths.unshift(__dirname+'/../../../lib/')

var vows = require('vows'), var vows = require('vows'),
one = require('prenuptials').one, one = require('../../helpers/prenuptials').one,
fail = require('prenuptials').failWithDump, fail = require('../../helpers/prenuptials').failWithDump,
assert = require('assert'), assert = require('assert'),
transactions = require("transactions"), transactions = require("../../helpers/transactions"),
clients = require('clients'), clients = require('../../helpers/clients'),
payflow = require('paynode').use('payflowpro') payflow = require('../../../lib/paynode').use('payflowpro')




var client = clients.signatureAuth(payflow); var client = clients.signatureAuth(payflow);
Expand Down
19 changes: 8 additions & 11 deletions spec/integration/payflowpro/paypal-network-client.spec.js
@@ -1,19 +1,16 @@
require.paths.unshift(__dirname+'/../../helpers/')
require.paths.unshift(__dirname+'/../../../lib/')
require.paths.unshift(__dirname+'/../../../lib/payflowpro')

var vows = require('vows'), var vows = require('vows'),
one = require('prenuptials').one, one = require('../../helpers/prenuptials').one,
fail = require('prenuptials').failWithDump, fail = require('../../helpers/prenuptials').failWithDump,
assert = require('assert'), assert = require('assert'),
transactions = require("transactions"), transactions = require("../../helpers/transactions"),
certuser = require('clients').certuser certuser = require('../../helpers/clients').certuser,
levels = require('../../../lib/payflowpro/levels')


var PaypalNetworkClient = require('paypal-network-client').PaypalNetworkClient; var PaypalNetworkClient = require('../../../lib/payflowpro/paypal-network-client').PaypalNetworkClient;


(function(){ (function(){
var client = new PaypalNetworkClient('api-3t.sandbox.paypal.com') var client = new PaypalNetworkClient(levels.sandbox({}))
,certClient = new PaypalNetworkClient('api.sandbox.paypal.com', {cert:certuser.cert, key:certuser.key}) ,certClient = new PaypalNetworkClient(levels.sandbox({ cert: true }), {cert:certuser.cert, key:certuser.key})
vows.describe('PaypalNetworkClient').addBatch({ vows.describe('PaypalNetworkClient').addBatch({
'signature auth': { 'signature auth': {
topic:function(){ topic:function(){
Expand Down
5 changes: 1 addition & 4 deletions spec/unit/authorizenet/aim-response-parser.spec.js
@@ -1,9 +1,6 @@
require.paths.unshift(__dirname+'/../helpers/')
require.paths.unshift(__dirname+'/../../../lib/')

var vows = require('vows'), var vows = require('vows'),
assert = require('assert'), assert = require('assert'),
response = require('authorizenet/response-parser') response = require('../../../lib/authorizenet/response-parser')




vows.describe('Authorize.net Response Parser').addBatch({ vows.describe('Authorize.net Response Parser').addBatch({
Expand Down
3 changes: 1 addition & 2 deletions spec/unit/chargify-client.spec.js
@@ -1,7 +1,6 @@
require.paths.unshift(__dirname+'/../../lib/');
var vows = require('vows'); var vows = require('vows');
var assert = require('assert'); var assert = require('assert');
var Client = require('paynode').use('chargify')._Client; var Client = require('../../lib/paynode').use('chargify')._Client;


/// -- example data /// -- example data
var exampleSubscription = {"subscription":{ var exampleSubscription = {"subscription":{
Expand Down

0 comments on commit dcbc441

Please sign in to comment.