diff --git a/src/app/Console/Commands/Wallet/ChargeCommand.php b/src/app/Console/Commands/Wallet/ChargeCommand.php --- a/src/app/Console/Commands/Wallet/ChargeCommand.php +++ b/src/app/Console/Commands/Wallet/ChargeCommand.php @@ -52,30 +52,7 @@ } foreach ($wallets as $wallet) { - // This is a long-running process. Because another process might have modified - // the wallet balance in meantime we have to refresh it. - // Note: This is needed despite the use of cursor() above. - $wallet->refresh(); - - // Sanity check after refresh (owner deleted in meantime) - if (!$wallet->owner) { - continue; - } - - $charge = $wallet->chargeEntitlements(); - - if ($charge > 0) { - $this->info("Charged wallet {$wallet->id} for user {$wallet->owner->email} with {$charge}"); - - // Top-up the wallet if auto-payment enabled for the wallet - \App\Jobs\WalletCharge::dispatch($wallet); - } - - if ($wallet->balance < 0) { - // Check the account balance, send notifications, (suspend, delete,) degrade - // Also sends reminders to the degraded account owners - \App\Jobs\WalletCheck::dispatch($wallet); - } + \App\Jobs\WalletCharge::dispatch($wallet); } } } diff --git a/src/app/Jobs/WalletCheck.php b/src/app/Jobs/WalletCheck.php --- a/src/app/Jobs/WalletCheck.php +++ b/src/app/Jobs/WalletCheck.php @@ -57,6 +57,18 @@ */ public function handle() { + + $wallet->refresh(); + + // Sanity check after refresh (owner deleted in meantime) + if (!$wallet->owner) { + continue; + } + + if ($wallet->chargeEntitlements() > 0) { + $this->topUpWallet(); + } + if ($this->wallet->balance >= 0) { return null; }