diff --git a/app/Http/Controllers/Customer/WalletController.php b/app/Http/Controllers/Customer/WalletController.php index 0e89ac0..58ac749 100644 --- a/app/Http/Controllers/Customer/WalletController.php +++ b/app/Http/Controllers/Customer/WalletController.php @@ -179,21 +179,11 @@ class WalletController extends Controller } $wallet_interface_fund = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type); - $wallet = $wallet_interface_fund->wallet; if ($data['value'] < 0) { throw new UnprocessableEntityHttpException('مقدار برداشت باید مثبت باشد'); } - if ($data['value'] > $wallet->cash) { - throw new UnprocessableEntityHttpException('مقدار برداشت بیشتر از موجودی است'); - } - $min_withdraw = Setting::where('is_active', 1) - ->where('key', 'min_withdraw') - ->first(); - - if ($min_withdraw && (int) $min_withdraw->value > $data['value']) { - throw new UnprocessableEntityHttpException('حداقل مقدار برداشت ' . number_format((int) $min_withdraw->value) . ' ریال است'); - } + $this->validateWithdrawAmount((int) $data['value']); $Withdraw = Withdraw::create([ 'customer_id' => auth('customer')->id(), @@ -324,6 +314,16 @@ class WalletController extends Controller public function withdrawOtp(Request $request) { + $data = $request->all(); + if (!isset($data['value'])) { + return response()->json(['message' => 'مبلغ برداشت مشخص نشده است'], 422); + } + if ($data['value'] < 0) { + throw new UnprocessableEntityHttpException('مقدار برداشت باید مثبت باشد'); + } + + $this->validateWithdrawAmount((int) $data['value']); + $customer = auth('customer')->user(); $otp = rand(1000, 9999); $customer->token_sms = $otp; @@ -335,6 +335,24 @@ class WalletController extends Controller return response()->json(true); } + private function validateWithdrawAmount(int $value): void + { + $wallet_interface_fund = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type); + $wallet = $wallet_interface_fund->wallet; + + if ($value > $wallet->cash) { + throw new UnprocessableEntityHttpException('مقدار برداشت بیشتر از موجودی است'); + } + + $min_withdraw = Setting::where('is_active', 1) + ->where('key', 'min_withdraw') + ->first(); + + if ($min_withdraw && (int) $min_withdraw->value > $value) { + throw new UnprocessableEntityHttpException('حداقل مقدار برداشت ' . number_format((int) $min_withdraw->value) . ' ریال است'); + } + } + private function applyMetalTypeTransactionTitle($record): void { if (!empty($record->product_id)) {