9c8908f9ea
- Modify condition when selecting table more simplera, remove checking filter argument - Add method in BillplzService to query for transaction for 1 particular bill id - Modify and refactor updateUnsuccess command to use the newly created method in BillplzService
61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\BillplzService;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Console\Command;
|
|
|
|
class UpdateUnsuccess extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'update:unsuccess';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command description';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle(BillplzService $billplzService)
|
|
{
|
|
|
|
$getFailedOnlineTransaction = fn() => Http::arrahn()->get('/api/transaction/online/unsuccessful')->json();
|
|
|
|
$FailedBillplzID = array_map(fn($x) => $x['billplz_id'], $getFailedOnlineTransaction());
|
|
|
|
if(sizeof($FailedBillplzID) < 0){
|
|
return;
|
|
}
|
|
|
|
$billplzUpdatedTransactionStatus = array_map(fn($x) => $billplzService->getTransactionByBillId($x), $FailedBillplzID);
|
|
|
|
$getCompletedBillplzTransaction = function() use($billplzUpdatedTransactionStatus){
|
|
|
|
$dataNotNull = array_filter($billplzUpdatedTransactionStatus, fn($x) => $x !== null);
|
|
|
|
$dataHaveTransaction = array_filter($dataNotNull, fn($x) => sizeof($x['transactions']) > 0);
|
|
|
|
return array_filter($dataHaveTransaction, fn($x) => $x['transactions'][0]['status'] == 'completed');
|
|
};
|
|
|
|
foreach($getCompletedBillplzTransaction() as $transaction){
|
|
Http::arrahn()->put('/api/transaction/online/unsuccesfull/update',[
|
|
'billplz_id' => $transaction['bill_id'],
|
|
'status' => 'PAID',
|
|
'paid_at' => $transaction['transactions'][0]['completed_at']
|
|
]);
|
|
}
|
|
}
|
|
}
|