Files
shipping-portal/app/Console/Commands/V2/FixBillplzFailedCallbackPaymentV2Command.php
T

75 lines
2.1 KiB
PHP

<?php
namespace App\Console\Commands\V2;
use App\Classes\Jobs\Commands\V2\FixBillplzFailedCallbackPaymentV2CommandJob;
use Illuminate\Console\Command;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Transaction;
use Illuminate\Support\Facades\Log;
class FixBillplzFailedCallbackPaymentV2Command extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'billplz-failed-callback-fix-command';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fix all failled callback from billplz';
protected $output = null;
protected $outputArray = [];
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$jobsWithDelay1 = $this->fixBillplzFailedCallbackPaymentV2CommandJobs();
foreach ($jobsWithDelay1 as $index => $job) {
dispatch($job)->delay(now()->addSeconds($index * 1));
}
}
private function fixBillplzFailedCallbackPaymentV2CommandJobs(){
$jobs = [];
$transactions = Transaction::whereIn('type', [TransactionType::PAYMENT, TransactionType::TOP_UP, TransactionType::GROUP_PAYMENT])->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->whereNotIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get();
$count = 0;
foreach ($transactions as $transaction){
Log::info('Billplz Failled: '.config('billplz.base_url').'/api/v3/bills/'.$transaction->payment_reference);
$jobs[] = new FixBillplzFailedCallbackPaymentV2CommandJob($transaction->id);
$count++;
}
Log::info('Total FixBillplzFailedCallbackPaymentV2CommandJob dispatched: ' . $count);
return $jobs;
}
}