billplzService = $billplzService; } public function handle() { $date = $this->option('date') ?? now()->toDateString(); $preview = $this->option('preview'); // Validate date try { $dateObj = Carbon::createFromFormat('Y-m-d', $date); } catch (\Exception $e) { $this->error("Invalid date format. Use YYYY-MM-DD."); return 1; } $this->info("Retrying Billplz check for date: {$dateObj->toDateString()}"); $date = $dateObj->toDateString(); $pendingResits = DB::table('resit as r') ->join('payment as p', 'p.resit_id', '=', 'r.id') ->join(DB::raw('( SELECT user_id, total_payment, MIN(id) AS min_id FROM payment GROUP BY user_id, total_payment ) as unique_payment'), 'p.id', '=', 'unique_payment.min_id') ->whereNull('r.status') ->where('p.status', 0) ->whereNotNull('r.billplz_id') ->whereDate('r.created_at', $date) ->where('r.billplz_id', 'NOT LIKE', '%CDM%') ->select('r.*', 'p.id as payment_id', 'p.total_payment') ->distinct() ->get(); if ($pendingResits->isEmpty()) { $this->info('Tiada Resit belum dibayar ditemui.'); return 0; } if ($preview) { $this->info("Preview mode aktif. Senarai Resit:"); foreach ($pendingResits as $resit) { $this->line("Resit ID: {$resit->id} | Billplz ID: {$resit->billplz_id} | Jumlah: RM{$resit->total_payment}"); } return 0; } foreach ($pendingResits as $resit) { $this->info("Semak Resit ID: {$resit->id}"); $billData = $this->billplzService->testGetBill($resit->billplz_id); if (isset($billData['error'])) { $this->error("❌ Gagal semak Billplz untuk Resit {$resit->id}: {$billData['details']}"); continue; } if (isset($billData['paid']) && $billData['paid'] === true) { // Simulate Request object $data = [ 'billplz' => [ 'id' => $resit->billplz_id, 'paid' => 'true', 'paid_at' => $billData['paid_at'] ?? now()->toDateTimeString(), ] ]; // dd($data); $apiController = App::make(ApiController::class); $apiController->processPaidResit($data); // dd($fakeRequest); $this->info("✅ Resit ID {$resit->id} handled via processPaidResit."); }else { $this->info("â„šī¸ Resit ID {$resit->id} masih belum dibayar."); } } $this->info('Semakan semula Billplz selesai.'); } }