diff --git a/composer.json b/composer.json index ee17bc6..5204342 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,11 @@ { "name": "white/white", "description": "White makes accepting online payments in the Middle East a piece of cake", - "require": { - "guzzlehttp/guzzle": "~4.0" - }, + "require": {}, "require-dev": { "phpunit/phpunit": "4.2.*" }, + "lib-curl": "*", "autoload": { "psr-0": { "White": "src/", diff --git a/composer.lock b/composer.lock index e522f0d..bfbd1a0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,126 +4,9 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "d5ce04c0819f0657f7f3bd705aae7937", + "hash": "99e6c9ed97abfb9093a26fa2db754775", "packages": [ - { - "name": "guzzlehttp/guzzle", - "version": "4.2.2", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "9c4fbbf6457768f5036fbd88f1229f3fca812a5d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/9c4fbbf6457768f5036fbd88f1229f3fca812a5d", - "reference": "9c4fbbf6457768f5036fbd88f1229f3fca812a5d", - "shasum": "" - }, - "require": { - "ext-json": "*", - "guzzlehttp/streams": "~2.1", - "php": ">=5.4.0" - }, - "require-dev": { - "ext-curl": "*", - "phpunit/phpunit": "~4.0", - "psr/log": "~1.0" - }, - "suggest": { - "ext-curl": "Guzzle will use specific adapters if cURL is present" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\": "src/" - }, - "files": [ - "src/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "rest", - "web service" - ], - "time": "2014-09-08 22:11:58" - }, - { - "name": "guzzlehttp/streams", - "version": "2.1.0", - "source": { - "type": "git", - "url": "https://github.com/guzzle/streams.git", - "reference": "f91b721d73f0e561410903b3b3c90a5d0e40b534" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/streams/zipball/f91b721d73f0e561410903b3b3c90a5d0e40b534", - "reference": "f91b721d73f0e561410903b3b3c90a5d0e40b534", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Stream\\": "src/" - }, - "files": [ - "src/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Provides a simple abstraction over streams of data (Guzzle 4+)", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "Guzzle", - "stream" - ], - "time": "2014-08-17 21:15:53" - } + ], "packages-dev": [ { diff --git a/src/White.php b/src/White.php index 119a074..a17232c 100644 --- a/src/White.php +++ b/src/White.php @@ -72,11 +72,8 @@ public static function getEndPoint($name) return self::$baseURL . self::$endpoints[$name]; } - public static function handleErrors(\Exception $e) - { - $code = $e->getResponse()->getStatusCode(); - $result = $e->getResponse()->json(); - + public static function handleErrors($result, $code) + { if($code == White_Error_Card::$CODE && $result['error']['type'] == White_Error_Card::$TYPE) { throw new White_Error_Card($result['error']['message'], $result['error']['code']); } diff --git a/src/White/Charge.php b/src/White/Charge.php index 402894b..719192d 100644 --- a/src/White/Charge.php +++ b/src/White/Charge.php @@ -24,18 +24,25 @@ public static function create(array $data) { $url = White::getEndPoint('charge'); - $client = new GuzzleHttp\Client(); - try { - $response = $client->post($url, array( - 'auth' => array(White::getApiKey(), ''), - 'body' => $data, - )); - $result = $response->json(); - } catch (\GuzzleHttp\Exception\TransferException $e) { //catch all Guzzle exceptions - White::handleErrors($e); - } catch(\Exception $e) { //Rethrow any other errors - throw $e; + $ch = curl_init(); + curl_setopt($ch,CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_USERPWD, White::getApiKey() . ':'); + curl_setopt($ch,CURLOPT_POST, true); + curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($data)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $result = json_decode(curl_exec($ch), true); + + // Check for errors and such. + $info = curl_getinfo($ch); + $errno = curl_errno($ch); + if( $result === false || $errno != 0 ) { + // Do error checking + throw new Exception(curl_error($ch)); + } else if($info['http_code'] != 200) { + // Got a non-200 error code. + White::handleErrors($result, $info['http_code']); } + curl_close($ch); return $result; } @@ -53,17 +60,23 @@ public static function all() { $url = White::getEndPoint('charge_list'); - $client = new GuzzleHttp\Client(); - try { - $response = $client->get($url, array( - 'auth' => array(White::getApiKey(), '') - )); - $result = $response->json(); - } catch (\GuzzleHttp\Exception\TransferException $e) { //catch all Guzzle exceptions - White::handleErrors($e); - } catch(\Exception $e) { //Rethrow any other errors - throw $e; + $ch = curl_init(); + curl_setopt($ch,CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_USERPWD, White::getApiKey() . ':'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $result = json_decode(curl_exec($ch), true); + + // Check for errors and such. + $info = curl_getinfo($ch); + $errno = curl_errno($ch); + if( $result === false || $errno != 0 ) { + // Do error checking + throw new Exception(curl_error($ch)); + } else if($info['http_code'] != 200) { + // Got a non-200 error code. + White::handleErrors($result, $info['http_code']); } + curl_close($ch); return $result; }