/** * Получить новый счёт * * @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']); }
/** * Получает параметры для запроса и возвращает объект с ответом от сервера * или с ошибками 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; }
/** * @dataProvider callbacks */ public function testCallback($post, $error, $xml, $message = null) { $connector = new Gateway($this->mock); $result = $connector->doParseCallback($post); if ($error) { $this->assertFalse($result, print_r($post, true)); } else { $this->assertTrue($result, print_r($post, true)); $this->assertEquals($post['bill_id'], $connector->getCallbackOrderId()); $this->assertEquals($post['amount'], $connector->getCallbackAmount()); $this->assertEquals($post['status'], $connector->getValueBillStatus()); $this->assertEquals($message, $connector->getError()); } $this->assertEquals($xml, $connector->getCallbackResponse()); }
/** * @param Setting $oSettings */ private function setConfigForGateway($oSettings) { if ($oSettings == null) { return; } $config = array('gateUrl' => $oSettings->gate_url, 'provider' => array('id' => $oSettings->gate_id, 'password' => $oSettings->gate_password, 'name' => $oSettings->name, 'key' => $oSettings->gate_key)); Gateway::setConfig($config); }