[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: Requestor.php
<?php namespace FedaPay; /** * Class Requestor * * @package FedaPay */ class Requestor { const SANDBOX_BASE = 'https://sandbox-api.fedapay.com'; const PRODUCTION_BASE = 'https://api.fedapay.com'; const DEVELOPMENT_BASE = 'https://dev-api.fedapay.com'; /** * Http Client * @var GuzzleHttp\ClientInterface */ protected static $httpClient; /** * @static * * @param HttpClient\ClientInterface $client */ public static function setHttpClient($client) { self::$httpClient = $client; } /** * @return HttpClient\ClientInterface */ private function httpClient() { if (!self::$httpClient) { $options = []; if (FedaPay::getVerifySslCerts()) { $options['verify'] = FedaPay::getCaBundlePath(); } self::$httpClient = HttpClient\CurlClient::instance(); } return self::$httpClient; } /** * @param string $method * @param string $url * @param array|null $params * @param array|null $headers * * @return array An API response. */ public function request($method, $path, $params = null, $headers = null) { $params = $params ?: []; $headers = $headers ?: []; $params = array_merge($this->defaultParams(), $params); $headers = array_merge($this->defaultHeaders(), $headers); $url = $this->url($path); $rawHeaders = []; foreach ($headers as $h => $v) { $rawHeaders[] = $h . ': ' . $v; } list($rbody, $rcode, $rheaders) = $this->httpClient()->request($method, $url, $params, $rawHeaders); $json = $this->_interpretResponse($rbody, $rcode, $rheaders); return $json; } /** * Format http request error * @param GuzzleHttp\Exception\RequestException $e * @throws Error\ApiConnection * @return void */ protected function handleRequestException($e) { $message = 'Request error: '. $e->getMessage(); $httpStatusCode = $e->hasResponse() ? $e->getResponse()->getStatusCode() : null; $httpRequest = $e->getRequest(); $httpResponse = $e->getResponse(); throw new Error\ApiConnection( $message, $httpStatusCode, $httpRequest, $httpResponse ); } /** * Return the default request params * @return array */ protected function defaultParams() { $params = []; if (FedaPay::getLocale()) { $params['locale'] = FedaPay::getLocale(); } return $params; } /** * Return the default request headers * @return array */ protected function defaultHeaders() { $auth = FedaPay::getApiKey() ?: FedaPay::getToken(); $apiVersion = FedaPay::getApiVersion(); $accountId = FedaPay::getAccountId(); $default = [ 'X-Version' => FedaPay::VERSION, 'X-Api-Version' => $apiVersion, 'X-Source' => 'FedaPay PhpLib', 'Authorization' => "Bearer $auth" ]; if ($accountId) { $default['FedaPay-Account'] = $accountId; } return $default; } /** * Return the base url of the requests * @return string */ protected function baseUrl() { $apiBase = FedaPay::getApiBase(); $environment = FedaPay::getEnvironment(); if ($apiBase) { return $apiBase; } switch ($environment) { case 'development': case 'dev': return self::DEVELOPMENT_BASE; case 'sandbox': case 'test': case null: return self::SANDBOX_BASE; case 'production': case 'live': return self::PRODUCTION_BASE; } } /** * Return the request url * @return string */ protected function url($path) { return $this->baseUrl() . '/' . FedaPay::getApiVersion() . $path; } /** * @param string $rbody * @param int $rcode * @param array $rheaders * * @return mixed */ private function _interpretResponse($rbody, $rcode, $rheaders) { $resp = json_decode($rbody, true); $jsonError = json_last_error(); if ($resp === null && $jsonError !== JSON_ERROR_NONE) { $msg = "Invalid response body from API: $rbody " . "(HTTP response code was $rcode, json_last_error() was $jsonError)"; throw new Error\ApiConnection($msg, $rcode, $rbody); } if ($rcode < 200 || $rcode >= 300) { $this->handleErrorResponse($rbody, $rcode, $rheaders, $resp); } return $resp; } /** * @param string $rbody A JSON string. * @param int $rcode * @param array $rheaders * @param array $resp * * @throws Error\InvalidRequest if the error is caused by the user. */ public function handleErrorResponse($rbody, $rcode, $rheaders, $resp) { $msg = isset($resp['message']) ? $resp['message'] : 'ApiConnection Error' ; throw new Error\ApiConnection($msg, $rcode, $rbody, $resp, $rheaders); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.72 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002