Configuration.php
5 years ago
FraudValidation.php
5 years ago
Http.php
5 years ago
SmsVerification.php
5 years ago
Http.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FraudLabsPro; |
| 4 | |
| 5 | /** |
| 6 | * FraudLabsPro HTTP Client |
| 7 | * Sends Http requests using curl. |
| 8 | * |
| 9 | * @copyright 2020 FraudLabsPro.com |
| 10 | */ |
| 11 | class Http |
| 12 | { |
| 13 | public function __construct() |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | public function get($url) |
| 18 | { |
| 19 | $ch = curl_init(); |
| 20 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 21 | curl_setopt($ch, CURLOPT_URL, $url); |
| 22 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
| 23 | curl_setopt($ch, CURLOPT_TIMEOUT, 60); |
| 24 | curl_setopt($ch, CURLOPT_USERAGENT, 'FraudLabsPro PHP SDK ' . Configuration::VERSION); |
| 25 | |
| 26 | $response = curl_exec($ch); |
| 27 | |
| 28 | if (empty($response) || curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) { |
| 29 | curl_close($ch); |
| 30 | |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | curl_close($ch); |
| 35 | |
| 36 | return $response; |
| 37 | } |
| 38 | |
| 39 | public function post($url, $fields = []) |
| 40 | { |
| 41 | $ch = curl_init(); |
| 42 | curl_setopt($ch, CURLOPT_POST, 1); |
| 43 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 44 | curl_setopt($ch, CURLOPT_URL, $url); |
| 45 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
| 46 | curl_setopt($ch, CURLOPT_TIMEOUT, 60); |
| 47 | curl_setopt($ch, CURLOPT_USERAGENT, 'FraudLabsPro PHP SDK ' . Configuration::VERSION); |
| 48 | |
| 49 | $queries = (!empty($fields)) ? http_build_query($fields) : ''; |
| 50 | |
| 51 | if ($queries) { |
| 52 | curl_setopt($ch, CURLOPT_POSTFIELDS, $queries); |
| 53 | } |
| 54 | |
| 55 | $response = curl_exec($ch); |
| 56 | |
| 57 | if (empty($response) || curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) { |
| 58 | curl_close($ch); |
| 59 | |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | curl_close($ch); |
| 64 | |
| 65 | return $response; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | class_alias('FraudLabsPro\Http', 'FraudLabsPro_Http'); |
| 70 |