Changeset View
Changeset View
Standalone View
Standalone View
src/app/Jobs/WalletCharge.php
- This file was moved from src/app/Jobs/WalletPayment.php.
<?php | <?php | ||||
namespace App\Jobs; | namespace App\Jobs; | ||||
use App\Wallet; | use App\Wallet; | ||||
use App\Http\Controllers\API\V4\PaymentsController; | use App\Http\Controllers\API\V4\PaymentsController; | ||||
use Illuminate\Bus\Queueable; | use Illuminate\Bus\Queueable; | ||||
use Illuminate\Contracts\Queue\ShouldQueue; | use Illuminate\Contracts\Queue\ShouldQueue; | ||||
use Illuminate\Foundation\Bus\Dispatchable; | use Illuminate\Foundation\Bus\Dispatchable; | ||||
use Illuminate\Queue\InteractsWithQueue; | use Illuminate\Queue\InteractsWithQueue; | ||||
use Illuminate\Queue\SerializesModels; | use Illuminate\Queue\SerializesModels; | ||||
class WalletPayment implements ShouldQueue | class WalletCharge implements ShouldQueue | ||||
{ | { | ||||
use Dispatchable; | use Dispatchable; | ||||
use InteractsWithQueue; | use InteractsWithQueue; | ||||
use Queueable; | use Queueable; | ||||
use SerializesModels; | use SerializesModels; | ||||
/** @var \App\Wallet A wallet object */ | |||||
protected $wallet; | protected $wallet; | ||||
/** @var int The number of seconds to wait before retrying the job. */ | |||||
public $retryAfter = 10; | |||||
/** @var int How many times retry the job if it fails. */ | |||||
public $tries = 5; | public $tries = 5; | ||||
/** @var bool Delete the job if its models no longer exist. */ | /** @var bool Delete the job if the wallet no longer exist. */ | ||||
public $deleteWhenMissingModels = true; | public $deleteWhenMissingModels = true; | ||||
/** | /** | ||||
* Create a new job instance. | * Create a new job instance. | ||||
* | * | ||||
* @param \App\Wallet $wallet The wallet to charge. | * @param \App\Wallet $wallet The wallet that has been charged. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function __construct(Wallet $wallet) | public function __construct(Wallet $wallet) | ||||
{ | { | ||||
$this->wallet = $wallet; | $this->wallet = $wallet; | ||||
} | } | ||||
/** | /** | ||||
* Execute the job. | * Execute the job. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
if ($this->wallet->balance < 0) { | PaymentsController::topUpWallet($this->wallet); | ||||
PaymentsController::directCharge($this->wallet, $this->wallet->balance * -1); | |||||
} | |||||
} | } | ||||
} | } |