<?php
namespace Torann\GeoIP\Support;
use Illuminate\Support\Arr;
class HttpClient
{
/**
* Request configurations.
*
* @var array
**/
private $config = [
'base_uri' => '',
'headers' => [],
'query' => [],
];
/**
* Last request http status.
*
* @var int
**/
protected $http_code = 200;
/**
* Last request error string.
*
* @var string
**/
protected $errors = null;
/**
* Array containing headers from last performed request.
*
* @var array
*/
private $headers = [];
/**
* HttpClient constructor.
*
* @param array $config
*/
public function __construct(array $config = [])
{
$this->config = $config;
}
/**
* Perform a get request.
*
* @param string $url
* @param array $query
* @param array $headers
*
* @return array
*/
public function get($url, array $query = [], array $headers = [])
{
return $this->execute('GET', $this->buildGetUrl($url, $query), [], $headers);
}
/**
* Execute the curl request
*
* @param string $method
* @param string $url
* @param array $query
* @param array $headers
*
* @return array
*/
public function execute($method, $url, array $query = [], array $headers = [])
{
// Merge global and request headers
$headers = array_merge(
Arr::get($this->config, 'headers', []),
$headers
);
// Merge global and request queries
$query = array_merge(
Arr::get($this->config, 'query', []),
$query
);
$this->errors = null;
$curl = curl_init();
// Set options
curl_setopt_array($curl, [
CURLOPT_URL => $this->getUrl($url),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_CONNECTTIMEOUT => 20,
CURLOPT_TIMEOUT => 90,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_HEADER => 1,
CURLINFO_HEADER_OUT => 1,
CURLOPT_VERBOSE => 1,
]);
// Setup method specific options
switch ($method) {
case 'PUT':
case 'PATCH':
case 'POST':
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $query,
]);
break;
case 'DELETE':
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
default:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
break;
}
// Make request
curl_setopt($curl, CURLOPT_HEADER, true);
$response = curl_exec($curl);
// Set HTTP response code
$this->http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// Set errors if there are any
if (curl_errno($curl)) {
$this->errors = curl_error($curl);
}
// Parse body
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
curl_close($curl);
return [$body, $this->parseHeaders($header)];
}
/**
* Check if the curl request ended up with errors
*
* @return bool
*/
public function hasErrors()
{
return is_null($this->errors) === false;
}
/**
* Get curl errors
*
* @return string
*/
public function getErrors()
{
return $this->errors;
}
/**
* Get last curl HTTP code.
*
* @return int
*/
public function getHttpCode()
{
return $this->http_code;
}
/**
* Parse string headers into array
*
* @param string $headers
*
* @return array
*/
private function parseHeaders($headers)
{
$result = [];
foreach (preg_split("/\\r\\n|\\r|\\n/", $headers) as $row) {
$header = explode(':', $row, 2);
if (count($header) == 2) {
$result[$header[0]] = trim($header[1]);
}
else {
$result[] = $header[0];
}
}
return $result;
}
/**
* Get request URL.
*
* @param string $url
*
* @return string
*/
private function getUrl($url)
{
// Check for URL scheme
if (parse_url($url, PHP_URL_SCHEME) === null) {
$url = Arr::get($this->config, 'base_uri') . $url;
}
return $url;
}
/**
* Build a GET request string.
*
* @param string $url
* @param array $query
*
* @return string
*/
private function buildGetUrl($url, array $query = [])
{
// Merge global and request queries
$query = array_merge(
Arr::get($this->config, 'query', []),
$query
);
// Append query
if ($query = http_build_query($query)) {
$url .= strpos($url, '?') ? $query : "?{$query}";
}
return $url;
}
}
The Kueue Pay Payment Gateway is an innovative technology that facilitates seamless and secure transactions between merchants and their customers. It enables businesses to accept debit and credit card payments both online and in physical stores.
The Kueue Pay Payment Gateway acts as a bridge between a merchant’s website or point-of-sale system and the payment processing network. It securely transmits payment information, authorizes transactions, and provides real-time status updates.
The Kueue Pay Developer API empowers developers and entrepreneurs to integrate the Kueue Pay Payment Gateway directly into their websites or applications. This streamlines the payment process for customers and provides businesses with a customizable and efficient payment solution.
To access the Kueue Pay Developer API, you need to sign up for a developer account on our platform. Once registered, you’ll receive an API key that you can use to authenticate your API requests.
The Kueue Pay Developer API allows you to initiate payments, check the status of payments, and process refunds. You can create a seamless payment experience for your customers while maintaining control over transaction management.
Yes, the Kueue Pay Developer API is designed to accommodate businesses of varying sizes and industries. Whether you’re a small online store or a large enterprise, our API can be tailored to fit your specific payment needs.
The Kueue Pay Developer API is designed with simplicity and ease of use in mind. Our comprehensive documentation, code samples, and developer support resources ensure a smooth integration process for any web platform.
We offer competitive pricing plans for using the Kueue Pay Payment Gateway and Developer API. Details about fees and pricing tiers can be found on our developer portal.
Absolutely, the Kueue Pay Developer API offers customization options that allow you to tailor the payment experience to match your brand and user interface. You can create a seamless and cohesive payment journey for your customers.
We provide dedicated developer support to assist you with any issues or questions you may have during the API integration process. Reach out to our support team at developersupport@NFCPay.com for prompt assistance.
Remember, our goal is to empower your business with a robust and efficient payment solution. If you have any additional questions or concerns, feel free to explore our developer portal or contact our support team.