Esempio n. 1
0
 /**
  * @dataProvider cbProvider
  */
 public function testResponse($expectedStatusCode, $expectedResponseContent, $request, $testCase, $testHeaders)
 {
     $process = new Process('php -S [::1]:8999', __DIR__ . '/../../resources');
     $process->start();
     sleep(1);
     $signature = sha1($request . ServerMock::PROJECT_SECRET_KEY);
     $headers = null;
     if ($testHeaders) {
         $headers = $testHeaders;
     } else {
         $headers = array('Authorization' => 'Signature ' . $signature);
     }
     $request = $this->guzzleClient->post('/webhook_server.php?test_case=' . $testCase, $headers, $request);
     try {
         $response = $request->send();
     } catch (BadResponseException $e) {
         $process->stop();
         $response = $e->getResponse();
     }
     static::assertSame($expectedResponseContent, $response->getBody(true));
     static::assertSame($expectedStatusCode, $response->getStatusCode());
     static::assertArrayHasKey('x-xsolla-sdk', $response->getHeaders());
     static::assertSame(Version::getVersion(), (string) $response->getHeader('x-xsolla-sdk'));
     static::assertArrayHasKey('content-type', $response->getHeaders());
     if (204 === $response->getStatusCode()) {
         static::assertStringStartsWith('text/plain', (string) $response->getHeader('content-type'));
     } else {
         static::assertStringStartsWith('application/json', (string) $response->getHeader('content-type'));
     }
 }
Esempio n. 2
0
 /**
  * @dataProvider cbProvider
  */
 public function testResponse($expectedStatusCode, $expectedResponseContent, $request, $testCase, $testHeaders)
 {
     $signature = sha1($request . self::PROJECT_SECRET_KEY);
     if ($testHeaders) {
         $headers = $testHeaders;
     } else {
         $headers = array('Authorization' => 'Signature ' . $signature);
     }
     $request = self::$httpClient->post('/webhook_server.php?test_case=' . $testCase, $headers, $request);
     try {
         $response = $request->send();
     } catch (BadResponseException $e) {
         $response = $e->getResponse();
     }
     static::assertSame($expectedResponseContent, $response->getBody(true));
     static::assertSame($expectedStatusCode, $response->getStatusCode());
     static::assertArrayHasKey('x-xsolla-sdk', $response->getHeaders());
     static::assertSame(Version::getVersion(), (string) $response->getHeader('x-xsolla-sdk'));
     static::assertArrayHasKey('content-type', $response->getHeaders());
     if (Response::HTTP_NO_CONTENT === $response->getStatusCode()) {
         static::assertStringStartsWith('text/plain', (string) $response->getHeader('content-type'));
     } else {
         static::assertStringStartsWith('application/json', (string) $response->getHeader('content-type'));
     }
 }
Esempio n. 3
0
 /**
  * @param int    $httpStatusCode
  * @param string $body
  */
 public function __construct($httpStatusCode = 204, $body = null)
 {
     $this->symfonyResponse = new Response($body, $httpStatusCode);
     $this->symfonyResponse->headers->set('x-xsolla-sdk', Version::getVersion());
     if ($body) {
         $contentType = 'application/json';
     } else {
         $contentType = 'text/plain';
     }
     $this->symfonyResponse->headers->set('content-type', $contentType);
 }
 /**
  * @param  array  $config
  * @return static
  */
 public static function factory($config = array())
 {
     $default = array('ssl.certificate_authority' => 'system');
     $required = array('merchant_id', 'api_key');
     $config = Collection::fromConfig($config, $default, $required);
     $client = new static(isset($config['base_url']) ? $config['base_url'] : null, $config);
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/xsolla-2015-07-23.php'));
     $client->setDefaultOption('auth', array($config['merchant_id'], $config['api_key'], 'Basic'));
     $client->setDefaultOption('headers', array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
     $client->setDefaultOption('command.params', array('merchant_id' => $config['merchant_id']));
     $client->setUserAgent(Version::getVersion());
     $exceptionCb = function (Event $event) {
         $previous = $event['exception'];
         if ($previous instanceof BadResponseException) {
             $e = XsollaAPIException::fromBadResponse($previous);
         } else {
             $e = new XsollaAPIException('XsollaClient Exception: ' . $previous->getMessage(), 0, $previous);
         }
         throw $e;
     };
     $client->getEventDispatcher()->addListener('request.exception', $exceptionCb);
     return $client;
 }