mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
95 lines
2.6 KiB
PHP
95 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Classes\Modules\Billplzs\Processors\CallbackBillplzProcessor;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Models\Group;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class FixApprovedPaymentFailedGroup extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'fix-approved-payment-failed-group';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Fix all payment is approved or completed but group failed to be updated';
|
|
|
|
protected $output = null;
|
|
|
|
protected $outputArray = [];
|
|
|
|
/** @var CallbackBillplzProcessor */
|
|
private $callbackBillplzProcessor;
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(CallbackBillplzProcessor $callbackBillplzProcessor)
|
|
{
|
|
parent::__construct();
|
|
$this->callbackBillplzProcessor = $callbackBillplzProcessor;
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
ini_set('memory_limit', '-1');
|
|
|
|
$this->outputArray = [];
|
|
$start = new Carbon();
|
|
|
|
$groups = Group::whereNotIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
|
->whereHas('payment', function ($query) {
|
|
$query->whereIn('status', [2, 3]);
|
|
})->get();
|
|
|
|
foreach ($groups as $group) {
|
|
$transaction = $group->payment;
|
|
|
|
$response = Http::withBasicAuth(config('billplz.api_key') . ':', '')->get(config('billplz.base_url') . '/api/v3/bills/' . $transaction->payment_reference);
|
|
|
|
dump($transaction->payment_reference);
|
|
|
|
if ($response->successful()) {
|
|
$data = $response->json();
|
|
if ($data['paid']) {
|
|
$status = ApprovalStatus::PENDING_VERIFICATION;
|
|
|
|
if ($data['state'] === 'paid') {
|
|
$status = ApprovalStatus::APPROVED;
|
|
}
|
|
|
|
$this->info(Carbon::now() . ' : Fixing ' . $transaction->payment_reference);
|
|
$this->callbackBillplzProcessor->execute($transaction, $status);
|
|
}
|
|
} else {
|
|
$this->info("billplz error</br>");
|
|
}
|
|
}
|
|
|
|
$end = new Carbon();
|
|
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
|
|
|
if ($groups) {
|
|
$this->info(Carbon::now() . ' : Done . ElapsedTime: ' . $elapsedTime);
|
|
}
|
|
}
|
|
}
|