option('dry-run'); if ($isDryRun) { $this->info(' DRY RUN MODE - No changes will be made'); $this->newLine(); } $this->info('🔎 Searching for payment links with incorrect status...'); $this->newLine(); // Find all ShoppingPayments with identifier that are paid $paidPayments = ShoppingPayment::whereNotNull('identifier') ->whereHas('shopping_order', function ($query) { $query->where('paid', 1) ->where('txaction', 'paid'); }) ->with(['shopping_order']) ->get(); $this->info("Found {$paidPayments->count()} paid payments with identifiers"); $this->newLine(); $fixed = 0; $skipped = 0; $errors = 0; foreach ($paidPayments as $payment) { $identifier = $payment->identifier; // Find the corresponding ShoppingInstance $instance = ShoppingInstance::where('identifier', $identifier)->first(); if (! $instance) { $this->warn("⚠️ ShoppingInstance not found for identifier: {$identifier}"); $errors++; continue; } // Check if status needs to be updated if ($instance->status < 10) { $oldStatus = $instance->status; $oldStatusName = $instance->getStatus(); if (! $isDryRun) { $instance->status = 10; // link_paid $instance->save(); } $this->line(sprintf( '%s Payment #%d: %s → %s (Order #%d, Amount: %s)', $isDryRun ? '📋' : '✅', $payment->id, $oldStatusName." ($oldStatus)", 'link_paid (10)', $payment->shopping_order_id, $payment->getPaymentAmount() )); $fixed++; } else { $skipped++; } } $this->newLine(); $this->info('📊 Summary:'); $this->table( ['Status', 'Count'], [ ['Fixed/Would fix', $fixed], ['Already correct', $skipped], ['Errors', $errors], ['Total processed', $paidPayments->count()], ] ); if ($isDryRun && $fixed > 0) { $this->newLine(); $this->warn('⚠️ This was a DRY RUN. Run without --dry-run to apply changes.'); } if (! $isDryRun && $fixed > 0) { $this->newLine(); $this->info("✨ Successfully updated {$fixed} payment link(s)!"); } return 0; } }