Skip to content

Commit

Permalink
Updated to use FraudLabs Pro v2 API
Browse files Browse the repository at this point in the history
  • Loading branch information
fraudlabspro committed Jan 15, 2024
1 parent 56ebd59 commit fbf337a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 60 deletions.
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
{
"name": "fraudlabspro-nodejs",
"version": "2.2.0",
"version": "3.0.0",
"description": "FraudLabs Pro Node.js module enables users to easily implement fraud detection feature using the FraudLabs Pro API.",
"keywords": ["fraud prevention", "fraud detection", "fraud checker", "fraudlabs pro", "fraudlabspro", "fraud protection"],
"keywords": [
"fraud prevention",
"fraud detection",
"fraud checker",
"fraudlabs pro",
"fraudlabspro",
"fraud protection"
],
"homepage": "https://github.com/fraudlabspro/fraudlabspro-nodejs",
"author": {
"name": "FraudLabsPro.com",
"email": "sales@fraudlabspro.com",
"url": "https://www.fraudlabspro.com/"
},
"files": ["src/fraudlabspro.js","src/test.js","./README.md"],
"files": [
"src/fraudlabspro.js",
"src/test.js",
"./README.md"
],
"main": "src/fraudlabspro.js",
"license" : "MIT",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/fraudlabspro/fraudlabspro-nodejs.git"
"url": "git+https://github.com/fraudlabspro/fraudlabspro-nodejs.git"
}
}
106 changes: 51 additions & 55 deletions src/fraudlabspro.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var https = require('https');
var crypto = require('crypto');
var VERSION = '2.2.0';
var VERSION = '3.0.0';
var SOURCE = 'sdk-nodejs';
var FORMAT = 'json';

Expand Down Expand Up @@ -29,41 +29,50 @@ class FraudValidation {
ip: 'ip' in params ? params['ip'] : '',
username: 'username' in params ? params['username'] : '',
flp_checksum: 'flp_checksum' in params ? params['flp_checksum'] : '',

// Billing information
last_name: (typeof(params['billing']['last_name']) !== 'undefined') ? params['billing']['last_name'] : '',
first_name: (typeof(params['billing']['first_name']) !== 'undefined') ? params['billing']['first_name'] : '',
bill_addr: (typeof(params['billing']['address']) !== 'undefined') ? params['billing']['address'] : '',
bill_city: (typeof(params['billing']['city']) !== 'undefined') ? params['billing']['city'] : '',
bill_state: (typeof(params['billing']['state']) !== 'undefined') ? params['billing']['state'] : '',
bill_country: (typeof(params['billing']['country']) !== 'undefined') ? params['billing']['country'] : '',
bill_zip_code: (typeof(params['billing']['zip_code']) !== 'undefined') ? params['billing']['zip_code'] : '',
user_phone: (typeof(params['billing']['phone']) !== 'undefined') ? params['billing']['phone'] : '',
email: (typeof(params['billing']['email']) !== 'undefined') ? params['billing']['email'] : '',

// Shipping information
ship_last_name: (typeof(params['shipping']['last_name']) !== 'undefined') ? params['shipping']['last_name'] : '',
ship_first_name: (typeof(params['shipping']['first_name']) !== 'undefined') ? params['shipping']['first_name'] : '',
ship_addr: (typeof(params['shipping']['address']) !== 'undefined') ? params['shipping']['address'] : '',
ship_city: (typeof(params['shipping']['city']) !== 'undefined') ? params['shipping']['city'] : '',
ship_state: (typeof(params['shipping']['state']) !== 'undefined') ? params['shipping']['state'] : '',
ship_country: (typeof(params['shipping']['country']) !== 'undefined') ? params['shipping']['country'] : '',
ship_zip_code: (typeof(params['shipping']['zip_code']) !== 'undefined') ? params['shipping']['zip_code'] : '',

// Order information
user_order_id: (typeof(params['order']['order_id']) !== 'undefined') ? params['order']['order_id'] : '',
currency: (typeof(params['order']['currency']) !== 'undefined') ? params['order']['currency'] : 'USD',
amount: (typeof(params['order']['amount']) !== 'undefined') ? params['order']['amount'] : 0,
quantity: (typeof(params['order']['quantity']) !== 'undefined') ? params['order']['quantity'] : 0,
user_order_memo: (typeof(params['order']['order_memo']) !== 'undefined') ? params['order']['order_memo'] : '',
department: (typeof(params['order']['department']) !== 'undefined') ? params['order']['department'] : '',
payment_gateway: (typeof(params['order']['payment_gateway']) !== 'undefined') ? params['order']['payment_gateway'] : '',
payment_mode: (typeof(params['order']['payment_mode']) !== 'undefined') ? params['order']['payment_mode'] : '',
bin_no: (typeof(params['order']['bin_no']) !== 'undefined') ? params['order']['bin_no'] : '',
avs_result: (typeof(params['order']['avs_result']) !== 'undefined') ? params['order']['avs_result'] : '',
cvv_result: (typeof(params['order']['cvv_result']) !== 'undefined') ? params['order']['cvv_result'] : '',
};

// Billing information
if (typeof(params['billing']) === 'undefined') {
params['billing'] = {};
}
data.last_name = (typeof(params['billing']['last_name']) !== 'undefined') ? params['billing']['last_name'] : '';
data.first_name = (typeof(params['billing']['first_name']) !== 'undefined') ? params['billing']['first_name'] : '';
data.bill_addr = (typeof(params['billing']['address']) !== 'undefined') ? params['billing']['address'] : '';
data.bill_city = (typeof(params['billing']['city']) !== 'undefined') ? params['billing']['city'] : '';
data.bill_state = (typeof(params['billing']['state']) !== 'undefined') ? params['billing']['state'] : '';
data.bill_country = (typeof(params['billing']['country']) !== 'undefined') ? params['billing']['country'] : '';
data.bill_zip_code = (typeof(params['billing']['zip_code']) !== 'undefined') ? params['billing']['zip_code'] : '';
data.user_phone = (typeof(params['billing']['phone']) !== 'undefined') ? params['billing']['phone'] : '';
data.email = (typeof(params['billing']['email']) !== 'undefined') ? params['billing']['email'] : '';

// Shipping information
if (typeof(params['shipping']) === 'undefined') {
params['shipping'] = {};
}
data.ship_last_name = (typeof(params['shipping']['last_name']) !== 'undefined') ? params['shipping']['last_name'] : '';
data.ship_first_name = (typeof(params['shipping']['first_name']) !== 'undefined') ? params['shipping']['first_name'] : '';
data.ship_addr = (typeof(params['shipping']['address']) !== 'undefined') ? params['shipping']['address'] : '';
data.ship_city = (typeof(params['shipping']['city']) !== 'undefined') ? params['shipping']['city'] : '';
data.ship_state = (typeof(params['shipping']['state']) !== 'undefined') ? params['shipping']['state'] : '';
data.ship_country = (typeof(params['shipping']['country']) !== 'undefined') ? params['shipping']['country'] : '';
data.ship_zip_code = (typeof(params['shipping']['zip_code']) !== 'undefined') ? params['shipping']['zip_code'] : '';

// Order information
if (typeof(params['order']) === 'undefined') {
params['order'] = {};
}
data.user_order_id = (typeof(params['order']['order_id']) !== 'undefined') ? params['order']['order_id'] : '';
data.currency = (typeof(params['order']['currency']) !== 'undefined') ? params['order']['currency'] : 'USD';
data.amount = (typeof(params['order']['amount']) !== 'undefined') ? params['order']['amount'] : 0;
data.quantity = (typeof(params['order']['quantity']) !== 'undefined') ? params['order']['quantity'] : 0;
data.user_order_memo = (typeof(params['order']['order_memo']) !== 'undefined') ? params['order']['order_memo'] : '';
data.department = (typeof(params['order']['department']) !== 'undefined') ? params['order']['department'] : '';
data.payment_gateway = (typeof(params['order']['payment_gateway']) !== 'undefined') ? params['order']['payment_gateway'] : '';
data.payment_mode = (typeof(params['order']['payment_mode']) !== 'undefined') ? params['order']['payment_mode'] : '';
data.bin_no = (typeof(params['order']['bin_no']) !== 'undefined') ? params['order']['bin_no'] : '';
data.avs_result = (typeof(params['order']['avs_result']) !== 'undefined') ? params['order']['avs_result'] : '';
data.cvv_result = (typeof(params['order']['cvv_result']) !== 'undefined') ? params['order']['cvv_result'] : '';

// Item information
if (typeof(params['items']) !== 'undefined') {
data['items'] = '';
Expand Down Expand Up @@ -111,7 +120,7 @@ class FraudValidation {
let options = {
hostname: 'api.fraudlabspro.com',
port: 443,
path: '/v1/order/screen',
path: '/v2/order/screen',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Expand Down Expand Up @@ -159,7 +168,7 @@ class FraudValidation {
let options = {
hostname: 'api.fraudlabspro.com',
port: 443,
path: '/v1/order/feedback',
path: '/v2/order/feedback',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Expand Down Expand Up @@ -193,7 +202,7 @@ class FraudValidation {
id_type: 'id_type' in params ? params['id_type'] : '',
};

let urlStr = 'https://api.fraudlabspro.com/v1/order/result?';
let urlStr = 'https://api.fraudlabspro.com/v2/order/result?';

Object.keys(data).forEach(function (key, index) {
if (this[key] != '') {
Expand Down Expand Up @@ -250,7 +259,7 @@ class SMSVerification {
let options = {
hostname: 'api.fraudlabspro.com',
port: 443,
path: '/v1/verification/send',
path: '/v2/verification/send',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Expand Down Expand Up @@ -284,37 +293,24 @@ class SMSVerification {
otp: 'otp' in params ? params['otp'] : '',
};

let dataStr = '';
let urlStr = 'https://api.fraudlabspro.com/v2/verification/result?';

Object.keys(data).forEach(function (key, index) {
if (this[key] != '') {
dataStr += key + '=' + encodeURIComponent(this[key]) + '&';
urlStr += key + '=' + encodeURIComponent(this[key]) + '&';
}
}, data);

dataStr = dataStr.substring(0, dataStr.length - 1);

let options = {
hostname: 'api.fraudlabspro.com',
port: 443,
path: '/v1/verification/result',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(dataStr),
},
};
urlStr = urlStr.substring(0, urlStr.length - 1);

let d = '';
let req = https.request(options, function (res) {
let req = https.get(urlStr, function (res) {
res.on('data', (chunk) => (d = d + chunk));
res.on('end', function () {
callback(null, JSON.parse(d));
});
});

req.write(dataStr);
req.end();
req.on('error', function (e) {
callback(e);
});
Expand Down

0 comments on commit fbf337a

Please sign in to comment.