/** * @param array $fields * * @return string */ public function notifyValidate(array $fields) { $fields['cmd'] = self::CMD_NOTIFY_VALIDATE; $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); $request = $this->messageFactory->createRequest('POST', $this->getIpnEndpoint(), $headers, http_build_query($fields)); $response = $this->client->send($request); if (false == ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300)) { throw HttpException::factory($request, $response); } $result = $response->getBody()->getContents(); return self::NOTIFY_VERIFIED === $result ? self::NOTIFY_VERIFIED : self::NOTIFY_INVALID; }
/** * @param array $fields * * @throws HttpException * * @return array */ protected function doRequest(array $fields) { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); $request = $this->messageFactory->createRequest('POST', $this->getApiEndpoint(), $headers, http_build_query($fields)); $response = $this->client->send($request); if (false == ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300)) { throw HttpException::factory($request, $response); } $result = []; parse_str($response->getBody()->getContents(), $result); foreach ($result as &$value) { $value = urldecode($value); } return $result; }
public function __construct(Request $request, Response $response, $message = "", $code = 0, \Exception $previous = null) { if (false == $message) { $message = sprintf("The response is not success.\n Response: %s", print_r($response->toArray(), true)); } parent::__construct($request, $response, $message, $code, $previous); }
/** * @param array $fields * * @return array */ protected function doRequest($method, array $fields) { $headers = []; $request = $this->messageFactory->createRequest($method, $this->getApiEndpoint(), $headers, http_build_query($fields)); $response = $this->client->send($request); if (false == ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300)) { throw HttpException::factory($request, $response); } return $response; }
/** * @test */ public function shouldAllowCreateHttpExceptionFromRequestAndResponse() { $request = new Request('GET', 'http://example.com/foobar'); $response = new Response(404); $httpException = HttpException::factory($request, $response); $this->assertInstanceOf('Payum\\Core\\Exception\\Http\\HttpException', $httpException); $this->assertSame($request, $httpException->getRequest()); $this->assertSame($response, $httpException->getResponse()); $this->assertEquals("Client error response\n[status code] 404\n[reason phrase] Not Found\n[url] http://example.com/foobar", $httpException->getMessage()); $this->assertEquals(404, $httpException->getCode()); }
/** * @test */ public function shouldAllowFactoryHttpExceptionFromRequestAndResponse() { $request = new Request(); $request->setHost('http://example.com'); $request->setResource('/foobar'); $response = new Response(); $response->setHeaders(array('HTTP/1.1 404 Not Found')); $httpException = HttpException::factory($request, $response); $this->assertInstanceOf('Payum\\Core\\Exception\\Http\\HttpException', $httpException); $this->assertSame($request, $httpException->getRequest()); $this->assertSame($response, $httpException->getResponse()); $this->assertEquals("Client error response\n[status code] 404\n[reason phrase] Not Found\n[url] http://example.com/foobar", $httpException->getMessage()); $this->assertEquals(404, $httpException->getCode()); }
/** * @param array $notification * * @return string */ public function notifyValidate(array $notification) { $request = new FormRequest(); $request->setField('cmd', self::CMD_NOTIFY_VALIDATE); $request->addFields($notification); $request->setMethod('POST'); $request->fromUrl($this->getIpnEndpoint()); $response = new Response(); $this->client->send($request, $response); if (false == $response->isSuccessful()) { throw HttpException::factory($request, $response); } if (self::NOTIFY_VERIFIED === $response->getContent()) { return self::NOTIFY_VERIFIED; } return self::NOTIFY_INVALID; }
/** * @param FormRequest $request * * @throws HttpException * * @return array */ protected function doRequest(FormRequest $request) { $request->setMethod('POST'); $request->fromUrl($this->getApiEndpoint()); $this->client->send($request, $response = new Response()); if (false == $response->isSuccessful()) { throw HttpException::factory($request, $response); } $result = array(); parse_str($response->getContent(), $result); foreach ($result as &$value) { $value = urldecode($value); } return $result; }
/** * @param \Buzz\Message\Form\FormRequest $request * * @throws \Payum\Core\Exception\Http\HttpException * * @return \Payum\Core\Bridge\Buzz\JsonResponse */ protected function doRequest(FormRequest $request) { $request->setMethod('POST'); $request->fromUrl($this->getApiEndpoint()); $this->client->send($request, $response = new JsonResponse()); if (false == $response->isSuccessful()) { throw HttpException::factory($request, $response); } return $response; }
/** * @param array $fields * * @return \Psr\Http\Message\ResponseInterface * @throws \Payum\Core\Exception\Http\HttpException */ protected function doRequest(array $fields) { $headers = ['Content-Type' => 'application/x-www-form-urlencoded']; $request = new Request('POST', $this->getApiEndpoint(), $headers, http_build_query($fields)); $response = $this->client->send($request); if (false == ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300)) { throw HttpException::factory($request, $response); } // Check response $result = $response->getBody()->getContents(); return $result; }
/** * @param array $fields * * @return array */ protected function doRequest(array $fields) { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); $request = new Request('POST', $this->getApiEndpoint(), $headers, http_build_query($fields)); $response = $this->client->send($request); if (false == ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300)) { throw HttpException::factory($request, $response); } $result = json_decode($response->getBody()->getContents()); if (null === $result) { throw new LogicException("Response content is not valid json: \n\n{$response->getBody()->getContents()}"); } return $result; }