/**
  * Get a list of supported gateways which may be available
  *
  * @return array
  */
 public function getSupportedGateways()
 {
     $composer = Json::decode(file_get_contents(__DIR__ . '/../composer.json'));
     return $composer['extra']['gateways'];
 }
Пример #2
0
 /**
  * @param string $url
  * @param string $method
  * @param array $params
  * @param array $options
  *
  * @return array
  */
 protected function request($url, $method = self::GET, $params = array(), $options = array())
 {
     if (in_array($method, array(self::GET, self::DELETE)) && count($params)) {
         $url .= (stripos($url, '?') ? '&' : '?') . http_build_query($params);
         $params = array();
     }
     curl_setopt($this->curl, CURLOPT_HEADER, true);
     curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $method);
     curl_setopt($this->curl, CURLOPT_URL, $url);
     curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 5);
     curl_setopt($this->curl, CURLOPT_TIMEOUT, 30);
     // File Upload
     if (isset($options['files']) && count($options['files']) > 0) {
         foreach ($options['files'] as $index => $file) {
             $params[$index] = $this->createCurlFile($file);
         }
         version_compare(PHP_VERSION, '5.5', '<') || curl_setopt($this->curl, CURLOPT_SAFE_UPLOAD, false);
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
     } elseif (isset($options['xml'])) {
         $options['headers'][] = 'content-type:text/xml';
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params['xml']);
     } elseif (isset($options['json'])) {
         $options['headers'][] = 'content-type:application/json';
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, Json::encode($params));
     } elseif (in_array($method, array(self::POST))) {
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($params));
     } else {
     }
     // Check for custom headers
     if (isset($options['headers']) && count($options['headers'])) {
         curl_setopt($this->curl, CURLOPT_HTTPHEADER, $options['headers']);
     }
     // Check for basic auth
     if (isset($options['auth']['type']) && 'basic' === $options['auth']['type']) {
         curl_setopt($this->curl, CURLOPT_USERPWD, $options['auth']['username'] . ':' . $options['auth']['password']);
     }
     $response = $this->doCurl();
     // Separate headers and body
     $headerSize = $response['curl_info']['header_size'];
     $header = substr($response['response'], 0, $headerSize);
     $body = substr($response['response'], $headerSize);
     $results = array('curl_info' => $response['curl_info'], 'content_type' => $response['curl_info']['content_type'], 'status' => $response['curl_info']['http_code'], 'headers' => $this->splitHeaders($header), 'data' => $body);
     if ($response['response'] === false) {
         $results['curl_error'] = curl_error($this->curl);
     }
     return $results;
 }