Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pass through env information and add token_url to setExpressCheckout …

…response
  • Loading branch information...
commit 93c4306fc57e80e6ec162439c1707fd7e5449d1a 1 parent 49a41cc
@tcurdt tcurdt authored
View
2  lib/gateway-client.js
@@ -30,7 +30,7 @@ function GatewayClient(opts, authInfo){
req.on('response', function(res){
res.on('data', function(data){
// TODO add error handling
- callback(opts.responseParser.parseResponse(request, data.toString()))
+ callback(opts.responseParser.parseResponse(opts.responseOptions, request, data.toString()))
})
})
}
View
14 lib/payflowpro/levels.js
@@ -1,2 +1,12 @@
-exports.sandbox = function(opts){ return (opts.cert) ? 'api.sandbox.paypal.com' : 'api-3t.sandbox.paypal.com' }
-exports.live = function(opts){ return (opts.cert) ? 'api.paypal.com' : 'api-3t.paypal.com' }
+exports.sandbox = function(opts){
+ return {
+ api: (opts.cert) ? 'api.sandbox.paypal.com' : 'api-3t.sandbox.paypal.com',
+ site: 'www.sandbox.paypal.com'
+ }
+}
+exports.live = function(opts){
+ return {
+ api: (opts.cert) ? 'api.paypal.com' : 'api-3t.paypal.com',
+ site: 'www.paypal.com'
+ }
+}
View
7 lib/payflowpro/paypal-network-client.js
@@ -1,13 +1,14 @@
var GatewayClient = require('../gateway-client').GatewayClient,
paypalResponse = require('response-parser');
-function PaypalNetworkClient(host, authInfo){
+function PaypalNetworkClient(level, authInfo){
var client = new GatewayClient({
- host: host,
+ host: level.api,
contentType: 'text/namevalue',
path: '/nvp',
- responseParser: paypalResponse
+ responseParser: paypalResponse,
+ responseOptions: level
}, authInfo);
this.request = client.request;
View
15 lib/payflowpro/response-parser.js
@@ -1,6 +1,6 @@
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 balanceField = [ 'amt', 'currencycode' ]
@@ -20,7 +20,7 @@ var isSpecialNestedField = function(s){
return s.search(/_\d_/) > -1
}
-function buildResponse(request, data){
+function buildResponse(responseOptions, request, data){
var lowercaseKeys = function(data){
var result = {}
Object.keys(data).forEach(function(k){
@@ -34,7 +34,7 @@ function buildResponse(request, data){
newData.errors = buildFrom(errorField, newData)
}
- parsers.forMethod(request.method)(newData);
+ parsers.forMethod(request.method)(responseOptions, newData);
return buildAdditionalNestedFields(newData)
}
@@ -69,14 +69,17 @@ var addNestedFields = function(nestedFields, data){
}
var parsers = {
- 'getBalance': function(newData){
+ 'getBalance': function(responseOptions, newData){
newData.balances = buildFrom(balanceField, newData)
},
- 'transactionSearch': function(newData){
+ 'transactionSearch': function(responseOptions, newData){
newData.results = build(newData);
},
+ 'setExpressCheckout': function(responseOptions, newData){
+ newData.token_url = 'https://' + responseOptions.site + '/cgi-bin/webscr?cmd=_express-checkout&token=' + newData.token;
+ },
forMethod: function(method){
- return this[method] ? this[method] : (function(a){ return a });
+ return this[method] ? this[method] : (function(responseOptions, a){ return a });
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.