public function setUp()
 {
     parent::setUp();
     // создаём счёт
     Bill::truncate();
     $bill = new Bill();
     $bill->create(array('merchant_id' => 1, 'bill_id' => '1q2w3e', 'user' => 'tel:+7123', 'amount' => 123.45, 'ccy' => 'RUB', 'comment' => 'test', 'status' => 'waiting'));
 }
 /**
  * Омена невозможна, текущий статус счёта не waiting
  *
  * @return void
  */
 public function testRefundBillFailStatus()
 {
     // создаём счёт со статусом paid
     Bill::truncate();
     $bill = new Bill();
     $bill->create(array('merchant_id' => 1, 'bill_id' => '1q2w3e', 'user' => 'tel:+7123', 'amount' => 123.45, 'ccy' => 'RUB', 'comment' => 'test', 'status' => 'waiting'));
     $this->call('PUT', Config::get('ff-qiwi-gate::app.url') . '/qiwi/gate/api/v2/prv/1/bills/1q2w3e/refund/456', array('amount' => 50));
     $oResponse = $this->response()->getData();
     $this->assertEquals(210, $oResponse->response->result_code);
     $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
 }
 public function setUp()
 {
     parent::setUp();
     // создаём счёт
     Bill::truncate();
     $bill = new Bill();
     $bill->create(array('merchant_id' => 1, 'bill_id' => '1q2w3e', 'user' => 'tel:+7123', 'amount' => 123.45, 'ccy' => 'RUB', 'comment' => 'test', 'status' => 'paid'));
     // создаём возврат оплаты по счёту
     Refund::truncate();
     $refund = new Refund();
     $refund->create(array('bill_id' => 1, 'refund_id' => '456', 'amount' => 123.45, 'status' => 'processing'));
 }
Esempio n. 4
0
 public function postPay()
 {
     $bill_id = Input::get('transaction');
     $provider_id = Input::get('shop');
     $bill = Bill::getBill($bill_id, $provider_id);
     //Предполагаем ошибку статуса
     $error = 'Ошибка оплаты, проверьте статус.';
     if ($bill) {
         try {
             $result = DB::connection('ff-qiwi-gate')->transaction(function () use($bill_id) {
                 if (Bill::doPay($bill_id)) {
                     SendCallback::jobBillToQueue($bill_id);
                     SendEmail::emailToQueue($bill_id);
                     return array('message' => 'Счёт успешно оплачен.');
                 }
                 return null;
             });
             if ($result) {
                 return $result;
             }
         } catch (Exception $e) {
         }
     } else {
         //Меняем ошибку на Счёт не найден
         $error = 'Счет не найден.';
     }
     return array('error' => true, 'message' => $error);
 }
Esempio n. 5
0
 /**
  * @return void
  */
 public function testCreateBillSuccess()
 {
     Bill::truncate();
     // запрос на создание счета, проверяем авторизацию с этим логином и паролем
     $this->client->request('PUT', Config::get('ff-qiwi-gate::app.url') . '/qiwi/gate/api/v2/prv/1/bills/4a5s6d', array('user' => 'tel:+79161234567', 'amount' => '123.34', 'ccy' => 'RUB'), array(), array('HTTP_Authorization' => 'Basic ' . base64_encode('1:password')));
     $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
 }
Esempio n. 6
0
 /**
  * @param $data
  *
  * @return Bill
  */
 public static function NewBill($data)
 {
     $bill = new Bill();
     $merchantData = Headers::GetMerchant();
     $bill->merchant_id = $merchantData['login'];
     $bill->bill_id = $data['bill_id'];
     $bill->user = $data['user'];
     $bill->amount = $data['amount'];
     $bill->ccy = $data['ccy'];
     $bill->comment = isset($data['comment']) ? $data['comment'] : null;
     $bill->lifetime = isset($data['lifetime']) ? $data['lifetime'] : 0;
     $bill->pay_source = isset($data['pay_source']) ? $data['pay_source'] : null;
     $bill->prv_name = isset($data['prv_name']) ? $data['prv_name'] : null;
     $bill->status = Bill::C_STATUS_WAITING;
     $bill->save();
     return $bill;
 }
 /**
  *
  * @return void
  */
 public function testCreateBillSuccess()
 {
     Route::enableFilters();
     Bill::truncate();
     $this->call('PUT', Config::get('ff-qiwi-gate::app.url') . '/qiwi/gate/api/v2/prv/1/bills/4a5s6d', array('user' => 'tel:+79161234567', 'amount' => '123.34', 'ccy' => 'RUB', 'comment' => 'Test!'), array(), array('HTTP_Authorization' => 'Basic ' . base64_encode('1:password')));
     $oResponse = $this->response()->getData();
     $this->assertEquals('4a5s6d', $oResponse->response->bill->bill_id);
     $this->assertEquals('Test!', $oResponse->response->bill->comment);
     $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
 }
Esempio n. 8
0
 /**
  * Принимает id счёта и отправляет задачу в очередь
  *
  * @param integer $bill_id
  */
 public static function jobBillToQueue($bill_id)
 {
     $bill = Bill::whereBillId($bill_id)->first();
     $merchant = $bill->merchant;
     $command = 'bill';
     $error = 0;
     $key = $merchant->key;
     $sign = '';
     if ('' != $key) {
         $signData = $bill->amount . '|' . $bill->bill_id . '|' . $bill->ccy . '|' . $command . '|' . $bill->comment . '|' . $error . '|' . $bill->prv_name . '|' . $bill->status . '|' . $bill->user;
         $sign = base64_encode(hash_hmac('sha1', $signData, $key));
     }
     Queue::connection('ff-qiwi-gate')->push('FintechFab\\QiwiGate\\Queue\\SendCallback', array('url' => $merchant->callback_url, 'merchant_id' => $merchant->id, 'merchant_pass' => $merchant->password, 'bill_id' => $bill->bill_id, 'status' => $bill->status, 'error' => $error, 'amount' => $bill->amount, 'user' => $bill->user, 'prv_name' => $bill->prv_name, 'ccy' => $bill->ccy, 'comment' => $bill->comment, 'command' => $command, 'sign' => $sign));
 }
 /**
  * Проверка статуса возврата
  *
  * @param int    $provider_id
  * @param string $bill_id
  * @param int    $refund_id
  *
  * @internal param int $id
  *
  * @return Response
  */
 public function show($provider_id, $bill_id, $refund_id)
 {
     if (!($bill = Bill::getBill($bill_id, $provider_id))) {
         $data['error'] = Catalog::C_BILL_NOT_FOUND;
         return $this->responseFromGate($data);
     }
     $refund = Refund::whereBillId($bill_id)->whereRefundId($refund_id)->first();
     if ($refund == null) {
         $data['error'] = Catalog::C_BILL_NOT_FOUND;
         return $this->responseFromGate($data);
     }
     //Проводим возврат по прошествии минуты
     if ($refund->isProcessing()) {
         $refund = $refund->doSuccess();
     }
     $data = $this->dataFromObj($refund);
     $data['user'] = $bill->user;
     $data['error'] = 0;
     return $this->responseFromGate($data);
 }
Esempio n. 10
0
 public function postExpireBill()
 {
     $bill_id = Input::get('transaction');
     $provider_id = Input::get('shop');
     $bill = Bill::getBill($bill_id, $provider_id);
     //предполагаем ошибку
     $error = 'Счёт не найден';
     if ($bill) {
         //Если счёт просрочен, то кидаем callback и отдаём успех
         if ($bill->doExpire($bill_id)) {
             $this->sendCallback($bill_id);
             return array('message' => 'Счёт просрочен');
         }
         $error = 'Счёт не просрочен. Проверьте статус.';
     }
     //Отдаём ошибку
     return array('error' => true, 'message' => $error);
 }
Esempio n. 11
0
 /**
  * Делаает просроченным найденный счёт
  *
  * @param $bill_id
  *
  * @return Bill
  */
 public static function doExpire($bill_id)
 {
     $isUpdate = Bill::whereBillId($bill_id)->whereStatus(self::C_STATUS_WAITING)->update(array('status' => self::C_STATUS_EXPIRED));
     if ($isUpdate) {
         return true;
     }
     return false;
 }
Esempio n. 12
0
 /**
  * Принимает id счёта и отправляет задачу в очередь
  *
  * @param integer $bill_id
  */
 public static function emailToQueue($bill_id)
 {
     $bill = Bill::whereBillId($bill_id)->first();
     $merchant = $bill->merchant;
     Queue::connection('ff-qiwi-gate')->push('FintechFab\\QiwiGate\\Queue\\SendEmail', array('email' => $merchant->email, 'merchant_id' => $merchant->id, 'bill_id' => $bill->bill_id, 'status' => $bill->status, 'amount' => $bill->amount, 'user' => $bill->user, 'prv_name' => $bill->prv_name, 'ccy' => $bill->ccy, 'comment' => $bill->comment));
 }
Esempio n. 13
0
 /**
  * Отмена счёта (или отправить на создание счёта)
  *
  * @param  int    $provider_id
  * @param  string $bill_id
  *
  * @return Response
  */
 public function update($provider_id, $bill_id)
 {
     //Если это создание - счёта отправляем на создание
     if ($this->isCreateBill()) {
         return $this->store($provider_id, $bill_id);
     }
     if ($this->isCancelBill()) {
         //Находим счёт
         $bill = Bill::getBill($bill_id, $provider_id);
         //Если не нашли - ошибка "Счёт не найден"
         if ($bill == null) {
             $data['error'] = Catalog::C_BILL_NOT_FOUND;
             return $this->responseFromGate($data);
         }
         //Если статус waiting - отменяем счёт, кидаем callback и отдаём счёт в ответе
         if ($bill->isWaiting() && $bill->doCancel($bill_id)) {
             $this->sendCallback($bill_id);
             $canceledBill = Bill::whereBillId($bill_id)->first();
             $data = $this->dataFromObj($canceledBill);
             $data['error'] = 0;
             return $this->responseFromGate($data);
         }
         $data['error'] = Catalog::C_BILL_NOT_FOUND;
         return $this->responseFromGate($data);
     }
     return null;
 }