fix(sms): keep charge deposit defaults and unlock referral bonus

Empty SuperAdmin chargeInfo was wiping sms_charge_* on header refresh.
Seed those keys only when empty, and move referral_bonus_amount to can_edit=1.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-01 21:38:19 +03:30
co-authored by Cursor
parent cae41e72b8
commit 91a2dab440
8 changed files with 368 additions and 31 deletions
@@ -36,13 +36,49 @@ class SmsPanelController extends Controller
private function depositFromChargeInfo(array $chargeInfo): array
{
return [
'card_number' => (string) ($chargeInfo['card'] ?? ''),
'sheba' => (string) ($chargeInfo['iban'] ?? ''),
'account_holder' => (string) ($chargeInfo['account_holder'] ?? ''),
'note' => (string) ($chargeInfo['instruction'] ?? ''),
'card_number' => trim((string) ($chargeInfo['card'] ?? $chargeInfo['card_number'] ?? '')),
'sheba' => trim((string) ($chargeInfo['iban'] ?? $chargeInfo['sheba'] ?? '')),
'account_holder' => trim((string) ($chargeInfo['account_holder'] ?? $chargeInfo['accountHolder'] ?? '')),
'note' => trim((string) ($chargeInfo['instruction'] ?? $chargeInfo['note'] ?? '')),
];
}
/** @param array<string, string> $deposit */
private function depositHasAny(array $deposit): bool
{
foreach (['card_number', 'sheba', 'account_holder', 'note'] as $field) {
if (trim((string) ($deposit[$field] ?? '')) !== '') {
return true;
}
}
return false;
}
/**
* اگر سوپرادمین کارت/شبا خالی بدهد، دیفالت محلی را نگه دار — وگرنه هر رفرش هدر تنظیمات را خالی می‌کند.
*
* @param array<string, mixed>|null $chargeInfo
* @return array{card_number: string, sheba: string, account_holder: string, note: string}
*/
private function resolveDeposit(?array $chargeInfo): array
{
$fromSa = is_array($chargeInfo) ? $this->depositFromChargeInfo($chargeInfo) : [
'card_number' => '',
'sheba' => '',
'account_holder' => '',
'note' => '',
];
$local = SmsWalletService::getDepositInfo();
$out = [];
foreach (['card_number', 'sheba', 'account_holder', 'note'] as $field) {
$saVal = trim((string) ($fromSa[$field] ?? ''));
$out[$field] = $saVal !== '' ? $saVal : $local[$field];
}
return $out;
}
/**
* @param array<string, mixed> $data
*/
@@ -79,10 +115,15 @@ class SmsPanelController extends Controller
app(SmsWalletService::class)->mirrorFromSuperAdmin($balance, $price, $blocked);
if (isset($data['charge_info']) && is_array($data['charge_info'])) {
SmsWalletService::setDepositInfo($this->depositFromChargeInfo($data['charge_info']));
$fromCharge = $this->depositFromChargeInfo($data['charge_info']);
if ($this->depositHasAny($fromCharge)) {
SmsWalletService::setDepositInfo($fromCharge);
}
}
if (isset($data['deposit']) && is_array($data['deposit'])) {
SmsWalletService::setDepositInfo($data['deposit']);
if ($this->depositHasAny($data['deposit'])) {
SmsWalletService::setDepositInfo($data['deposit']);
}
}
} catch (\Throwable $e) {
report($e);
@@ -98,7 +139,7 @@ class SmsPanelController extends Controller
}
$charge = is_array($data['charge_info'] ?? null) ? $data['charge_info'] : [];
$data['deposit'] = $this->depositFromChargeInfo($charge);
$data['deposit'] = $this->resolveDeposit($charge);
$this->mirrorLocalFromSa($data);
return response()->json($data);
@@ -162,12 +203,9 @@ class SmsPanelController extends Controller
$charge = $this->sa()->chargeInfo();
if ($balanceData !== null) {
$deposit = is_array($charge)
? $this->depositFromChargeInfo($charge)
: SmsWalletService::getDepositInfo();
$deposit = $this->resolveDeposit(is_array($charge) ? $charge : null);
$this->mirrorLocalFromSa(array_merge($balanceData, [
'charge_info' => is_array($charge) ? $charge : [],
'deposit' => $deposit,
]));