From 05d7bf6cebcbb73673b1fefbe8f7bf28595e29c8 Mon Sep 17 00:00:00 2001 From: Michael Valushko Date: Fri, 1 Feb 2019 12:33:42 +0300 Subject: [PATCH] GET methods added 'echo' removed, library shouldn't echo anything --- payeezy_php/example/src/Payeezy.php | 111 +++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 2 deletions(-) diff --git a/payeezy_php/example/src/Payeezy.php b/payeezy_php/example/src/Payeezy.php index d7a3d6e..29f54f9 100755 --- a/payeezy_php/example/src/Payeezy.php +++ b/payeezy_php/example/src/Payeezy.php @@ -675,8 +675,12 @@ public function postTransaction($payload, $headers) $response = curl_exec($request); - if (FALSE === $response) - echo curl_error($request); + if (FALSE === $response) { + $response = json_encode([ + 'request_error' => curl_error($request) + ]); + //echo curl_error($request); + } //$httpcode = curl_getinfo($request, CURLINFO_HTTP_CODE); curl_close($request); @@ -687,6 +691,51 @@ public function postTransaction($payload, $headers) /** * Payeezy * + * Get Transaction + * @param array $headers + * @return mixed + */ + + public function getTransaction($headers) + { + $request = curl_init(); + curl_setopt($request, CURLOPT_URL, self::$url); + curl_setopt($request, CURLOPT_RETURNTRANSFER, true); + curl_setopt($request, CURLOPT_HEADER, false); + curl_setopt($request, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'apikey:'.strval(self::$apiKey), + 'token:'.strval(self::$merchantToken), + 'Authorization:'.$headers['authorization'], + 'nonce:'.$headers['nonce'], + 'timestamp:'.$headers['timestamp'], + )); + + $response = curl_exec($request); + + if (FALSE === $response){ + $response = json_encode([ + 'request_error' => curl_error($request) + ]); + //echo "
Request error: ".curl_error($request)."
"; + } + + $httpcode = curl_getinfo($request, CURLINFO_HTTP_CODE); + if($httpcode != 200){ + if($result = json_decode($response, true)){ + $result['http_response_code'] = $httpcode; + $response = json_encode($result); + } + //echo "
Response code: ".$httpcode."
"; + } + curl_close($request); + + return $response; + } + + /** + * Payeezy + * * Authorize Transaction */ @@ -1012,4 +1061,62 @@ public function valuelink_balance_inquiry($args = array()) return $this->postTransaction($payload, $headerArray); } + /** + * Requests report + * @param string $from + * @param string $to + * @param string $page + * @param string $limit + * @return mixed + * @see https://developer.payeezy.com/payeezy-api/apis/get/transactions + */ + public function report($from, $to, $page, $limit){ + $data = array( + 'start_date' => $from, + 'end_date' => $to, + 'offset' => $page, + 'limit' => $limit + ); + $query_string = http_build_query($data); + self::$url = self::$baseURL."?".$query_string; + $headerArray = $this->hmacAuthorizationToken(''); + return $this->getTransaction($headerArray); + } + + /** + * Search for events + * @param string $from format is yyyy-MM-dd + * @param string $to format is yyyy-MM-dd + * @param int $offset + * @param int $limit + * @param string $eventType + * @return mixed + * @see https://developer.payeezy.com/payeezy-api/apis/get/events + */ + public function search_event($from, $to, $offset, $limit, $eventType = 'TRANSACTION_STATUS'){ + $data = array( + 'eventType' => $eventType, + 'from' => $from, + 'to' => $to, + 'offset' => $offset, + 'limit' => $limit + ); + $query_string = http_build_query($data); + self::$url = str_replace('transactions', 'events', self::$baseURL)."?".$query_string; + $headerArray = $this->hmacAuthorizationToken(''); + return $this->getTransaction($headerArray); + } + + /** + * Get event info data + * @param string $id Event ID + * @return mixed + * @see https://developer.payeezy.com/payeezy-api/apis/get/events/%7Bid%7D + */ + public function get_event_by_id($id){ + self::$url = str_replace('transactions', 'events', self::$baseURL)."/".$id; + $headerArray = $this->hmacAuthorizationToken(''); + return $this->getTransaction($headerArray); + } + }//end of class