diff --git a/composer.json b/composer.json index e88613a..e852b47 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Beanstream PHP API", "type": "library", "license": "MIT", - "version": "1.0.1", + "version": "1.0.2", "authors": [ { "name": "Pavel Kulbakin", @@ -14,7 +14,7 @@ } ], "require": { - "php": ">=5.3.0" + "php": ">=7.4.0" }, "autoload": { "psr-0": {"Beanstream": "src/"} diff --git a/src/Beanstream/api/Profiles.php b/src/Beanstream/api/Profiles.php index 0853777..80d366e 100644 --- a/src/Beanstream/api/Profiles.php +++ b/src/Beanstream/api/Profiles.php @@ -138,6 +138,25 @@ public function getCards($profile_id) { return $result; } + /** + * getCard() function - Retrieve a particular card in a profile + * + * @param string $profile_id Profile Id + * @param string $card_id Card Id + * @return array ProfileCardResponse result + */ + public function getCard($profile_id, $card_id) { + + //get this profile's cards endpoint + $endpoint = $this->_endpoint->getCardURI($profile_id, $card_id); + + //process as is + $result = $this->_connector->processTransaction('GET', $endpoint, NULL); + + //return cards + return $result; + } + /** * addCard() function - Add a card to a profile * @link http://developer.beanstream.com/documentation/tokenize-payments/add-card-profile/ diff --git a/src/Beanstream/communications/Endpoints.php b/src/Beanstream/communications/Endpoints.php index 8c84e1a..dec65b4 100755 --- a/src/Beanstream/communications/Endpoints.php +++ b/src/Beanstream/communications/Endpoints.php @@ -40,6 +40,7 @@ class Endpoints { protected $voidsURL; protected $profileURI; protected $cardsURI; + protected $cardURI; protected $reportsURL; protected $continuationsURL; protected $tokenizationURL; diff --git a/src/Beanstream/communications/HttpConnector.php b/src/Beanstream/communications/HttpConnector.php index f0d0989..9a95b30 100644 --- a/src/Beanstream/communications/HttpConnector.php +++ b/src/Beanstream/communications/HttpConnector.php @@ -114,8 +114,18 @@ private function request($http_method = NULL, $url, $data = NULL) } //check for return errors from the API - if (isset($res['code']) && 1 < $res['code'] && !($req['http_code'] >= 200 && $req['http_code'] < 300)) { - throw new ApiException($res['message'], $res['code']); + $httpCode = curl_getinfo($req, CURLINFO_HTTP_CODE); + if (isset($res['code']) && 1 < $res['code'] && !($httpCode >= 200 && $httpCode < 300)) { + $message = $res['message']; + if (!empty($res['details'])) { + $details = array(); + //build out details from error response to return in API Exception message + foreach ($res['details'] as $detail) { + $details[] = $detail['message']; + } + $message .= ' ('.implode('; ', $details).'.)'; + } + throw new ApiException($message, $res['code']); } return $res; diff --git a/src/Beanstream/examples.php b/src/Beanstream/examples.php index 21fa19a..6fc5329 100644 --- a/src/Beanstream/examples.php +++ b/src/Beanstream/examples.php @@ -12,7 +12,7 @@ //generate a random order number, and set a default $amount (only used for example functions) -$order_number = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)); +$order_number = bin2hex(random_bytes(22)); $amount = 1.00; @@ -32,7 +32,7 @@ 'name' => 'Mr. Card Testerson', 'number' => '4030000010001234', 'expiry_month' => '07', - 'expiry_year' => '22', + 'expiry_year' => '32', 'cvd' => '123' ), 'billing' => array( @@ -82,7 +82,7 @@ 'name' => 'Test Testerson', 'number' => '4030000010001234', 'expiry_month' => '07', - 'expiry_year' => '22', + 'expiry_year' => '32', 'cvd' => '123' ) ); @@ -96,7 +96,7 @@ 'name' => 'Mr. Refund Testerson', 'number' => '4030000010001234', 'expiry_month' => '07', - 'expiry_year' => '22', + 'expiry_year' => '32', 'cvd' => '123' ) ); @@ -112,7 +112,7 @@ $legato_token_data = array( 'number' => '4030000010001234', 'expiry_month' => '07', - 'expiry_year' => '22', + 'expiry_year' => '32', 'cvd' => '123' ); @@ -212,6 +212,9 @@ //get all cards in profile //$result = $beanstream->profiles()->getCards($profile_id); + //get a card based on a profile cust code and card id + //$result = $beanstream->profiles()->getCard($profile_id, $card_id); + //update a specfic card in a profile //$result = $beanstream->profiles()->updateCard($profile_id, $card_id, $card_data);