handle katod error

This commit is contained in:
2026-06-03 19:53:14 +03:30
parent 10f270bf62
commit 4dc6b80ba4
@@ -32,7 +32,8 @@ class SingleOrderController extends Controller
public function store(Request $request) public function store(Request $request)
{ {
$data = $request->all(); $data = $request->all();
if (($data['method'] ?? null) === 'katod') { $data['is_katod'] = ($data['method'] ?? null) === 'katod';
if ($data['is_katod']) {
$data['method'] = 'gold'; $data['method'] = 'gold';
} }
$config = app(ConfigService::class); $config = app(ConfigService::class);
@@ -271,7 +272,7 @@ class SingleOrderController extends Controller
$data['service_charge_price'] = $data['service_charge'] * $data['price_original']; $data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
$data['wallet'] = $wallet; $data['wallet'] = $wallet;
if ($wallet->gold < $data['total_amount']) { if ($wallet->gold < $data['total_amount']) {
throw new UnprocessableEntityHttpException('موجودی طلایی شما کمتر از میزان سفارش است'); throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data));
} }
if (!$data['product']['open_buy']) { if (!$data['product']['open_buy']) {
throw new UnprocessableEntityHttpException('خرید این محصول در این لحظه مقدور نمیباشد'); throw new UnprocessableEntityHttpException('خرید این محصول در این لحظه مقدور نمیباشد');
@@ -310,7 +311,7 @@ class SingleOrderController extends Controller
$data['payment_amount'] = $data['total_price']; $data['payment_amount'] = $data['total_price'];
$data['payment_amount'] -= $data['service_charge_price']; $data['payment_amount'] -= $data['service_charge_price'];
if ($wallet->gold < $data['amount']) { if ($wallet->gold < $data['amount']) {
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است'); throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data));
} }
$data['order'] = $order = Order::create($data); $data['order'] = $order = Order::create($data);
new TransactionInterface($wallet_interface, [ new TransactionInterface($wallet_interface, [
@@ -488,7 +489,7 @@ class SingleOrderController extends Controller
// $pricePerGram = $totalPrice / $amount; // $pricePerGram = $totalPrice / $amount;
$customerMessage = "$companyName\n$transactionType آبشده\nگرم: {$amount}\n" . $customerMessage = "$companyName\n$transactionType آبشده\nگرم: {$amount}\n" .
"مبلغ کل: " . number_format($totalPrice) . "\n\n" . "مبلغ کل: " . number_format($totalPrice) . "\n\n" .
"موجودی طلایی: {$wallet->gold}\n" . "موجودی {$this->goldBalanceLabel($data)}: {$wallet->gold}\n" .
"مانده ریالی: " . number_format($wallet->cash) . "\n" . "مانده ریالی: " . number_format($wallet->cash) . "\n" .
$this->Config('app_url'); $this->Config('app_url');
@@ -669,4 +670,19 @@ class SingleOrderController extends Controller
->where('payment_sts', 4) ->where('payment_sts', 4)
->count() < (int)$count; ->count() < (int)$count;
} }
private function isKatodPayment(array $data): bool
{
return ($data['is_katod'] ?? false) === true;
}
private function goldBalanceLabel(array $data): string
{
return $this->isKatodPayment($data) ? 'کاتد' : 'طلایی';
}
private function insufficientGoldBalanceMessage(array $data): string
{
return 'موجودی ' . $this->goldBalanceLabel($data) . ' شما کمتر از میزان سفارش است';
}
} }