/** * Успешный запрос статуса счёта * * @return void */ public function testCheckStatusSuccess() { $this->call('GET', Config::get('ff-qiwi-gate::app.url') . '/qiwi/gate/api/v2/prv/1/bills/1q2w3e/refund/456'); $oResponse = $this->response()->getData(); $this->assertEquals(0, $oResponse->response->result_code); $this->assertEquals('processing', $oResponse->response->refund->status); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); Refund::truncate(); }
/** * Проводит возварт по прошествии минуты * Отдаёт новый счётё * * @return Refund */ public function doSuccess() { $date = date('Y-m-d H:i:s', time() - 60); $dateRefund = $this->updated_at; //даём минуту для прохождения оплаты if ($date > $dateRefund) { Refund::find($this->id)->whereStatus(self::C_STATUS_PROCESSING)->update(array('status' => self::C_STATUS_SUCCESS)); } return Refund::find($this->id); }
/** * Если сумма возврата больше возможного, то сумма возарвта равна возможной * * @param Bill $bill * @param string $amountQuery * * @return string */ public static function calculateAmount($bill, $amountQuery) { //Берём общую сумму счёта $amountBill = $bill->amount; //Берём суммы прошлых возвратов $refundsBefore = Refund::whereBillId($bill->bill_id)->get(); $amount_refund = 0; foreach ($refundsBefore as $one) { $amount_refund += $one->amount; } //Вычисляем возможную сумму возвтрата и отдаём её $rest = $amountBill - $amount_refund; $amount = $amountQuery > $rest ? $rest : $amountQuery; return $amount; }
/** * Проверка статуса возврата * * @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); }
/** * Если есть, отдаёт таблицу с возвратами * * @param $bill_id * * @return \Illuminate\View\View|string */ public function GetRefundTable($bill_id) { $provider_id = Config::get('ff-qiwi-gate::user_id'); $bill = Bill::getBill($bill_id, $provider_id); if (!$bill) { return 'Нет такого счёта'; } $refunds = Refund::whereBillId($bill_id)->get(); if (count($refunds) == 0) { return 'Возвратов нет'; } return $this->make('refundsTable', array('refunds' => $refunds)); }
/** * @return Illuminate\Http\JsonResponse */ public function testRefundBillFailIdExist() { // создаём возврат оплаты по счёту Refund::truncate(); $refund = new Refund(); $refund->create(array('bill_id' => '1q2w3e', 'refund_id' => '456', 'amount' => 123.45, 'status' => 'processing')); $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(215, $oResponse->response->result_code); $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); }