Пример #1
0
 public function send(Swish_HTTP_Request $request)
 {
     $curl = $this->curl->handle();
     if ($curl === false) {
         throw new RuntimeException('Failed to init curl handle');
     }
     $url = $request->getUrl();
     $curl->setOption(CURLOPT_URL, $url);
     $method = $request->getMethod();
     if ($method == 'POST') {
         $curl->setOption(CURLOPT_POST, true);
         $curl->setOption(CURLOPT_POSTFIELDS, $request->getData());
     }
     $requestHeaders = array();
     foreach ($request->getHeaders() as $option => $value) {
         $requestHeaders[] = $option . ": " . $value;
     }
     $curl->setOption(CURLOPT_HTTPHEADER, $requestHeaders);
     $curl->setOption(CURLOPT_RETURNTRANSFER, true);
     $curl->setOption(CURLOPT_TIMEOUT, $this->timeout);
     $curl->setOption(CURLOPT_CONNECTTIMEOUT, $this->timeout);
     $curl->setOption(CURLOPT_SSL_VERIFYPEER, true);
     foreach ($this->options as $option => $value) {
         $curl->setOption($option, $value);
     }
     $payload = $curl->execute();
     $info = $curl->getInfo();
     $error = $curl->getError();
     $curl->close();
     $response = $payload;
     return $info;
 }
Пример #2
0
 public function createPayment(array $params, $location = 'TEST')
 {
     $environment = new Swish_Environment();
     if ($location === 'TEST') {
         $environment->setEnvironment(Swish_Environment::TEST_URI);
     } else {
         $environment->setEnvironment(Swish_Environment::LIVE_URI);
     }
     $endpoint = $environment->getEnvironment() . self::RELATIVE_PATH;
     $request = new Swish_HTTP_Request($endpoint);
     $request->setHeaders('Content-Type', 'application/json');
     $request->setData($params);
     $transport = new Swish_HTTP_Transport();
     $swish_request = $transport->create();
     $response = $swish_request->send($request);
     return $response;
 }