successResponse(HarimState::query()->get(['id', 'name'])); } /** * @throws Throwable */ public function histories(Harim $harim): JsonResponse { throw_if($harim->province_id != auth()->user()->province_id, new ProhibitedAction("شما دسترسی لازم جهت مشاهده ی این صفحه را ندارید")); return $this->successResponse($harim->histories() ->orderBy('id', 'desc') ->get(['id', 'expert_description', 'action_name', 'previous_state_name'])); } /** * @throws Throwable * @throws ProhibitedAction */ public function submitInvoice(Harim $harim, HarimPaymentService $harimpaymentService, HarimSubmitInvoiceRequest $request): JsonResponse { $lock = Cache::lock("harimPayment-{$harim->id}", 10); throw_if(! $lock->get(), new ProhibitedAction('امکان درخواست مجدد تا 10 ثانیه دیگر وجود ندارد')); $payment_amount = $harim->payment_amount; $bill_code = $harimpaymentService->invoiceBillApi($harim->national_id, $payment_amount); DB::transaction(function () use ($bill_code, $harim) { $harim->histories()->update([ // 'bill_code' => $bill_code, 'status' => HarimStates::SODOR_FACTOR->value, 'status_fa' => HarimStates::SODOR_FACTOR->label(), ]); }); $msg = "فاکتور با شناسه پرداخت \n" . explode("/", $harim->bill_code)[0]. "\n برای پرداخت از لینک زیر اقدام نمایید.\n\n" . config('harim_web_services.Harim_Payment.LINK')."/#/pay/".explode("/", $harim->bill_code)[0]."/$payment_amount"; Sms::sendSms($harim->phone_number, $msg); $lock->release(); return $this->successResponse(); } /** * @throws Throwable */ public function checkPaymentStatus(Harim $harim, HarimPaymentService $harimpaymentService): JsonResponse { DB::transaction(function () use ($harim, $harimpaymentService) { $response = json_decode($harimpaymentService->callPaymentStatusBillApi(explode('/', $harim->bill_code)[0])); throw_if(! $response->isPayed, new ProhibitedAction('پرداخت انجام نشده است')); $harim->histories()->update([ 'status' => HarimStates::PARDAKHT_FACTOR->value, 'status_fa' => HarimStates::PARDAKHT_FACTOR->label(), ]); }); return $this->successResponse($harim); } }