コード例 #1
0
ファイル: GatewayTest.php プロジェクト: fintech-fab/qiwi-sdk
 public function testCreateBillFailFormat()
 {
     $connector = new Gateway($this->mock);
     $bill = array('user' => 'tel:+', 'amount' => 123.45, 'ccy' => 'RUB', 'comment' => null, 'lifetime' => null, 'prv_name' => Gateway::getConfig('provider.name'));
     $args = array(123, 'PUT', $bill);
     $this->mock->shouldReceive('request')->withArgs($args)->andReturn((object) array('response' => (object) array('result_code' => 5)));
     $isSuccess = $connector->createBill(123, '+', 123.45);
     $this->assertFalse($isSuccess);
     $this->assertEquals('Неверный формат параметров запроса', $connector->getError());
 }
コード例 #2
0
 /**
  * Получить новый счёт
  *
  * @return void
  */
 public function testGetBillSuccess()
 {
     App::bind('FintechFab\\QiwiSdk\\Curl', function () {
         $bill = array('user' => 'tel:+7123', 'amount' => 543.21, 'ccy' => 'RUB', 'comment' => 'without', 'lifetime' => date('Y-m-d\\TH:i:s', time() + 3600 * 24 * 3), 'prv_name' => Gateway::getConfig('provider.name'));
         $args = array(1, 'PUT', $bill);
         $this->mock->shouldReceive('request')->withArgs($args)->andReturn((object) array('response' => (object) array('result_code' => 0, 'bill' => (object) array('bill_id' => 123))));
         return $this->mock;
     });
     $order = new Order();
     $order->create(array('user_id' => 1, 'item' => 'New Lamp2', 'sum' => 543.21, 'tel' => '+7123', 'comment' => 'without', 'status' => 'new', 'lifetime' => date('Y-m-d H:i:s', time() + 3600 * 24 * 3)));
     $resp = $this->call('POST', Config::get('ff-qiwi-shop::testConfig.testUrl') . '/action/createBill', array('order_id' => '1'));
     $this->assertContains('Счёт выставлен', $resp->original['message']);
 }
コード例 #3
0
ファイル: Curl.php プロジェクト: fintech-fab/qiwi-sdk
 /**
  * Получает параметры для запроса и возвращает объект с ответом от сервера
  * или с ошибками curl
  *
  * @param int    $order_id
  * @param string $method
  * @param null   $query
  * @param null   $payReturnId
  *
  * @return stdClass
  */
 public function request($order_id, $method = 'GET', $query = null, $payReturnId = null)
 {
     $this->setUrl($order_id, $payReturnId);
     $headers = array("Accept: text/json", "Content-Type: application/x-www-form-urlencoded; charset=utf-8");
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->url);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_USERPWD, Gateway::getConfig('provider.id') . ':' . Gateway::getConfig('provider.password'));
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
     if ($query != null) {
         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($query));
     }
     $httpResponse = curl_exec($ch);
     $httpError = curl_error($ch);
     $info = curl_getinfo($ch);
     $response = @json_decode($httpResponse);
     if (!$response || !$httpResponse || $httpError) {
         $this->curlError = (object) array('code' => $info['http_code'], 'error' => $httpError, 'response' => $httpResponse);
         return $this->curlError;
     }
     return $response;
 }