Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/WalletCharge.php
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands; | ||||
use App\Domain; | |||||
use App\User; | |||||
use Carbon\Carbon; | |||||
use Illuminate\Console\Command; | use Illuminate\Console\Command; | ||||
use Illuminate\Support\Facades\DB; | |||||
class WalletCharge extends Command | class WalletCharge extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
Show All 21 Lines | class WalletCharge extends Command | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$wallets = \App\Wallet::all(); | $wallets = \App\Wallet::all(); | ||||
foreach ($wallets as $wallet) { | foreach ($wallets as $wallet) { | ||||
$charge = $wallet->expectedCharges(); | $charge = $wallet->chargeEntitlements(); | ||||
if ($charge > 0) { | if ($charge > 0) { | ||||
$this->info( | $this->info( | ||||
"charging wallet {$wallet->id} for user {$wallet->owner->email} with {$charge}" | "Charged wallet {$wallet->id} for user {$wallet->owner->email} with {$charge}" | ||||
); | ); | ||||
$wallet->chargeEntitlements(); | // Top-up the wallet if auto-payment enabled for the wallet | ||||
\App\Jobs\WalletCharge::dispatch($wallet); | |||||
if ($wallet->balance < 0) { | |||||
// Disabled for now | |||||
// \App\Jobs\WalletPayment::dispatch($wallet); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |