Update codebase

- 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
This commit is contained in:
Afiq Hamzah
2024-07-16 10:38:29 +08:00
parent 694e1af651
commit 9c8908f9ea
3 changed files with 41 additions and 64 deletions
+29 -62
View File
@@ -2,22 +2,11 @@
namespace App\Console\Commands;
use Illuminate\Http\Request;
use App\Services\BillplzService;
use Illuminate\Support\Facades\Http;
use Session;
use Illuminate\Support\Facades\Auth;
use Billplz\Client;
use Http\Client\Common\HttpMethodsClient;
use Http\Adapter\Guzzle6\Client as GuzzleHttpClient;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use Money\Money;
use Carbon\Carbon;
use Illuminate\Console\Command;
class updateUnsuccess extends Command
class UpdateUnsuccess extends Command
{
/**
* The name and signature of the console command.
@@ -33,61 +22,39 @@ class updateUnsuccess extends Command
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
if(config('app.env') != 'production'){
$this->api_key = 'abecfd0c-98d8-4635-abc2-2fcba8c60c11';
$this->XSignature_Key = 'S-GWr7z03XjAhqPsFfu_H5nQ';
$this->collection_id = 'z0r4kjhi';
}else{
$this->api_key = 'f3e82fe1-a422-4660-97f0-65cc59ff6c47';
$this->XSignature_Key = 'S-alZUbzmD2_TF3vmrRqgehQ';
}
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
public function handle(BillplzService $billplzService)
{
$http = new HttpMethodsClient(
new GuzzleHttpClient(),
new GuzzleMessageFactory()
);
$billplz = new Client($http, $this->api_key);
if(config('app.env') != 'production'){
$billplz->useSandbox();
}
$billplz->useVersion('v4');
$transaction = $billplz->bill();
$list_transaction = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/transaction/online/unsuccessful')->json();
if($list_transaction){
foreach($list_transaction as $index=>$list){
$show_transaction = $transaction->transaction($list['billplz_id']);
$data = $show_transaction->toArray();
if(!empty($data['transactions'])){
if($data['transactions'][0]['status'] == 'completed'){
Http::withOptions(['verify' => config('app.api_verify')])->put(config('api.url') . '/api/transaction/online/unsuccesfull/update',[
'billplz_id' => $data['bill_id'],
'status' => 'PAID',
'paid_at' => $data['transactions'][0]['completed_at']
]);
}
}
}
$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']
]);
}
}
}
+10
View File
@@ -119,4 +119,14 @@ class BillplzService
return $summarizedBillplzTransactions;
}
public function getTransactionByBillId($billId)
{
try {
return $this->client->bill()->transaction($billId)->toArray();
} catch (\Throwable $th) {
logger()->error('Error when querying billplz id : ' . $billId);
logger()->error($th->getMessage());
}
}
}
+2 -2
View File
@@ -83,7 +83,7 @@
@endif
<br>
@if (request()->has('filter') && request()->get('filter') == 'pembiayaan-akan-dilelong')
@if (request()->get('filter') == 'pembiayaan-akan-dilelong')
<x-dashboard-notification>
<x-dashboard-notification.item content="1. Sekiranya Lelongan Anda Dalam Tempoh Kontrak Lanjutan (Mencapai 12 Bulan), Urusan Penebusan Hanya Dibenarkan Di Kaunter Cawangan Selewatnya-lewatnya 3 Hari Sebelum Tarikh Lelong." />
<x-dashboard-notification.item content="2. Transaksi Pembayaran Hanya Dibenarkan Selewat-lewatnya 3 Hari Sebelum Lelongan." />
@@ -100,7 +100,7 @@
<div class="card shadow">
<div class="card-body">
@if (request()->has('filter') && request()->get('filter') == 'pembiayaan-akan-dilelong')
@if (request()->get('filter') == 'pembiayaan-akan-dilelong')
@include('includes.partials.table-pembiayaan-akan-dilelong')
@else
@include('includes.partials.table-pembiayaan')