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 11, 2024
1 parent 63a2492 commit 65e71f8
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "library",
"description": "FraudLabs Pro PHP SDK to help merchants to detect fraud order and therefore reduce chargebacks.",
"license": "MIT",
"version": "3.0.3",
"version": "4.0.0",
"authors": [
{
"name": "FraudLabs Pro",
Expand Down
20 changes: 11 additions & 9 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@
$fraudlabspro = new FraudLabsPro\FraudValidation($config);
$result = $fraudlabspro->validate($orderDetails);

if ($result) {
if (isset($result->error->error_code)) {
echo 'Error: ' . $result->error->error_message;
} else {
// Prints fraud result
echo '<h2>FraudLabs Pro Result</h2>';

echo '<pre>';

foreach ($result as $key => $value) {
echo '<strong>' . str_pad($key, 40) . '</strong>';
echo $value . "\n";
}

echo '<strong>FraudLabs Pro ID: </strong>';
echo $result->fraudlabspro_id . "\n";
echo '<strong>FraudLabs Pro Score: </strong>';
echo $result->fraudlabspro_score . "\n";
echo '<strong>FraudLabs Pro Status: </strong>';
echo $result->fraudlabspro_status . "\n";
echo '</pre>';

if ($result->fraudlabspro_status != 'APPROVE') {
Expand All @@ -73,13 +75,13 @@
// High risk, better cancel the order
}

if ($result->is_proxy_ip_address == 'Y') {
if ($result->ip_geolocation->is_proxy) {
// User cannot made purchase through proxy server, do something
}

if ($result->fraudlabspro_status == 'REVIEW') {
// Orders from US are trusted, approve and feedback to FarudLabs Pro
if ($result->ip_country == 'US' && $result->is_proxy_ip_address == 'N') {
if ($result->ip_geolocation->country_code == 'US' && $result->ip_geolocation->is_proxy === false) {
$fraudlabspro->feedback([
'id' => $result->fraudlabspro_id,
'status' => FraudLabsPro\FraudValidation::APPROVE,
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class Configuration
{
const VERSION = '3.0.3';
const VERSION = '4.0.0';

public $apiKey = '';

Expand Down
6 changes: 3 additions & 3 deletions src/FraudValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function validate($params = [])
];

$http = new Http();
$response = $http->post('https://api.fraudlabspro.com/v1/order/screen', $queries);
$response = $http->post('https://api.fraudlabspro.com/v2/order/screen', $queries);

if (($json = json_decode($response)) === null) {
return false;
Expand Down Expand Up @@ -142,7 +142,7 @@ public function feedback($params = [])
];

$http = new Http();
$response = $http->post('https://api.fraudlabspro.com/v1/order/feedback', $queries);
$response = $http->post('https://api.fraudlabspro.com/v2/order/feedback', $queries);

if (($json = json_decode($response)) === null) {
return false;
Expand Down Expand Up @@ -173,7 +173,7 @@ public function getTransaction($id, $type = 'fraudlabspro_id')
];

$http = new Http();
$response = $http->get('https://api.fraudlabspro.com/v1/order/result?' . http_build_query($queries));
$response = $http->get('https://api.fraudlabspro.com/v2/order/result?' . http_build_query($queries));

if (($json = json_decode($response)) === null) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function get($url)

$response = curl_exec($ch);

if (empty($response) || curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
if (empty($response) || curl_error($ch)) {
curl_close($ch);

return false;
Expand Down Expand Up @@ -54,7 +54,7 @@ public function post($url, $fields = [])

$response = curl_exec($ch);

if (empty($response) || curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
if (empty($response) || curl_error($ch)) {
curl_close($ch);

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/SmsVerification.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function sendSms($params = [])
];

$http = new Http();
$response = $http->post('https://api.fraudlabspro.com/v1/verification/send', $queries);
$response = $http->post('https://api.fraudlabspro.com/v2/verification/send', $queries);

if (($json = json_decode($response)) === null) {
return false;
Expand All @@ -68,7 +68,7 @@ public function verifyOtp($params = [])
];

$http = new Http();
$response = $http->post('https://api.fraudlabspro.com/v1/verification/result', $queries);
$response = $http->get('https://api.fraudlabspro.com/v2/verification/result?' . http_build_query($queries));

if (($json = json_decode($response)) === null) {
return false;
Expand Down
10 changes: 5 additions & 5 deletions tests/FraudValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testInvalidApiKey() {

$this->assertEquals(
'INVALID API KEY',
$result->fraudlabspro_message,
$result->error->error_message,
);
}

Expand Down Expand Up @@ -55,7 +55,7 @@ public function testValidateOrder() {
} else {
$this->assertEquals(
'US',
$result->ip_country,
$result->ip_geolocation->country_code,
);
}
}
Expand All @@ -66,7 +66,7 @@ public function testGetTransaction() {
$result = $fraudlabspro->getTransaction('20170906MXFHSTRF', FraudLabsPro\FraudValidation::FLP_ID);

$this->assertEquals(
'NA',
null,
$result->fraudlabspro_id,
);
}
Expand All @@ -83,12 +83,12 @@ public function testFeedback() {
if ($GLOBALS['testApiKey'] == 'YOUR_API_KEY') {
$this->assertEquals(
'INVALID API KEY',
$result->fraudlabspro_message,
$result->error->error_message,
);
} else {
$this->assertEquals(
'INVALID TRANSACTION ID',
$result->fraudlabspro_message,
$result->error->error_message,
);
}
}
Expand Down
16 changes: 8 additions & 8 deletions tests/SmsVerificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public function testSendSms() {

if ($GLOBALS['testApiKey'] == 'YOUR_API_KEY') {
$this->assertEquals(
'API key not found.',
$result->error,
'INVALID API KEY',
$result->error->error_message,
);
} else {
$this->assertEquals(
'Invalid phone number.',
$result->error,
'INVALID PHONE NUMBER',
$result->error->error_message,
);
}
}
Expand All @@ -39,13 +39,13 @@ public function testVerifyOtp() {

if ($GLOBALS['testApiKey'] == 'YOUR_API_KEY') {
$this->assertEquals(
'API key not found.',
$result->error,
'INVALID API KEY',
$result->error->error_message,
);
} else {
$this->assertEquals(
'Invalid OTP.',
$result->error,
'INVALID OTP',
$result->error->error_message,
);
}
}
Expand Down

0 comments on commit 65e71f8

Please sign in to comment.