diff --git a/app/Http/Controllers/Pargar/PargarInboundController.php b/app/Http/Controllers/Pargar/PargarInboundController.php index 41a7fc6..e00b370 100644 --- a/app/Http/Controllers/Pargar/PargarInboundController.php +++ b/app/Http/Controllers/Pargar/PargarInboundController.php @@ -234,43 +234,34 @@ class PargarInboundController extends Controller { $data = $this->pargarPayload($request); $accountId = trim((string) ($data['accountId'] ?? '')); + $summary = $this->sync()->summarizeInboundDocument($data); $customer = $accountId !== '' ? Customer::where('pargar_account_id', $accountId)->first() : null; - if ($customer) { - $applyResult = $this->inboundWallet()->applyDocuments($customer, $data); - - return response()->json([ - 'success' => true, - 'message' => sprintf( - 'اسناد مشتری دریافت شد — اعمال: %d، رد شده: %d', - $applyResult['applied'], - $applyResult['skipped'] - ), - 'data' => $applyResult, - ]); - } - - // مشتری ناشناس — فقط لاگ برای بررسی ادمین - $summary = $this->sync()->summarizeInboundDocument($data); + // فقط لاگ — اعمال خودکار روی کیف خاموش است (جلوگیری از شارژ چندباره وقتی پرگار مکرر می‌فرستد) PargarSyncLog::create([ - 'customer_id' => null, + 'customer_id' => $customer?->id, 'amount' => $summary['amount'], - 'desc' => 'دریافت اسناد از پرگار — مشتری یافت نشد', + 'desc' => $customer + ? ($summary['desc'] !== '' ? $summary['desc'] : 'دریافت اسناد از پرگار') + : 'دریافت اسناد از پرگار — مشتری یافت نشد', 'type' => PargarSyncService::TYPE_DOCUMENT, 'sync_status' => PargarSyncService::STATUS_SUCCESS, 'pargar_ref' => $accountId !== '' ? $accountId : null, 'data' => json_encode(array_merge($data, [ '_summary' => $summary, 'wallet_applied' => false, + 'auto_apply_disabled' => true, ]), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT), ]); return response()->json([ 'success' => true, - 'message' => 'اسناد دریافت شد ولی مشتری با این کد حساب یافت نشد', + 'message' => $customer + ? 'اسناد مشتری دریافت و ثبت شد (بدون تغییر کیف)' + : 'اسناد دریافت شد ولی مشتری با این کد حساب یافت نشد', 'data' => null, ]); }