src
5 years ago
tests
5 years ago
LICENSE
5 years ago
README.md
5 years ago
composer.json
5 years ago
example.php
5 years ago
phpunit.xml
5 years ago
example.php
91 lines
| 1 | <?php |
| 2 | // Preset PHP settings |
| 3 | error_reporting(E_ALL); |
| 4 | ini_set('display_errors', 1); |
| 5 | |
| 6 | require_once __DIR__.'/vendor/autoload.php'; |
| 7 | |
| 8 | // Configures FraudLabs Pro API key |
| 9 | $config = new FraudLabsPro\Configuration('YOUR_API_KEY'); |
| 10 | |
| 11 | // Order details |
| 12 | $orderDetails = [ |
| 13 | // IP parameter is optional, this library can detects IP address automatically |
| 14 | 'ip' => '146.112.62.105', |
| 15 | |
| 16 | 'order' => [ |
| 17 | 'orderId' => '67398', |
| 18 | 'note' => 'Online shop', |
| 19 | 'currency' => 'USD', |
| 20 | 'amount' => '79.89', |
| 21 | 'quantity' => 1, |
| 22 | 'paymentMethod' => FraudLabsPro\FraudValidation::CREDIT_CARD, |
| 23 | ], |
| 24 | |
| 25 | 'card' => [ |
| 26 | 'number' => '4556553172971283', |
| 27 | ], |
| 28 | |
| 29 | 'billing' => [ |
| 30 | 'firstName' => 'Hector', |
| 31 | 'lastName' => 'Henderson', |
| 32 | 'email' => 'hh5566@gmail.com', |
| 33 | 'phone' => '561-628-8674', |
| 34 | |
| 35 | 'address' => '1766 Powder House Road', |
| 36 | 'city' => 'West Palm Beach', |
| 37 | 'state' => 'FL', |
| 38 | 'postcode' => '33401', |
| 39 | 'country' => 'US', |
| 40 | ], |
| 41 | |
| 42 | 'shipping' => [ |
| 43 | 'address' => '4469 Chestnut Street', |
| 44 | 'city' => 'Tampa', |
| 45 | 'state' => 'FL', |
| 46 | 'postcode' => '33602', |
| 47 | 'country' => 'US', |
| 48 | ], |
| 49 | ]; |
| 50 | |
| 51 | // Sends the order details to FraudLabs Pro |
| 52 | $fraudlabspro = new FraudLabsPro\FraudValidation($config); |
| 53 | $result = $fraudlabspro->validate($orderDetails); |
| 54 | |
| 55 | if ($result) { |
| 56 | // Prints fraud result |
| 57 | echo '<h2>FraudLabs Pro Result</h2>'; |
| 58 | |
| 59 | echo '<pre>'; |
| 60 | |
| 61 | foreach ($result as $key => $value) { |
| 62 | echo '<strong>' . str_pad($key, 40) . '</strong>'; |
| 63 | echo $value . "\n"; |
| 64 | } |
| 65 | |
| 66 | echo '</pre>'; |
| 67 | |
| 68 | if ($result->fraudlabspro_status != 'APPROVE') { |
| 69 | // Cancel the order |
| 70 | } |
| 71 | |
| 72 | if ($result->fraudlabspro_score > 80) { |
| 73 | // High risk, better cancel the order |
| 74 | } |
| 75 | |
| 76 | if ($result->is_proxy_ip_address == 'Y') { |
| 77 | // User cannot made purchase through proxy server, do something |
| 78 | } |
| 79 | |
| 80 | if ($result->fraudlabspro_status == 'REVIEW') { |
| 81 | // Orders from US are trusted, approve and feedback to FarudLabs Pro |
| 82 | if ($result->ip_country == 'US' && $result->is_proxy_ip_address == 'N') { |
| 83 | $fraudlabspro->feedback([ |
| 84 | 'id' => $result->fraudlabspro_id, |
| 85 | 'status' => FraudLabsPro\FraudValidation::APPROVE, |
| 86 | 'note' => 'We trust orders from US.', |
| 87 | ]); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 |