91 lines
3.1 KiB
PHP
91 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\CompanyStatus;
|
|
use App\Models\TransactionOnlineStatus;
|
|
use App\Services\BillplzService;
|
|
use App\Services\OnlineTransactionLoggerService;
|
|
use Billplz\Base\Bill;
|
|
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()
|
|
{
|
|
$getFailedOnlineTransaction = fn() => Http::arrahn()->get('/api/transaction/online/unsuccessful')->json();
|
|
$getFailedOnlineTransaction_Koop = fn() => Http::arrahn_koop()->get('/api/transaction/online/unsuccessful')->json();
|
|
|
|
$FailedBillplzID = array_map(fn($x) => $x['billplz_id'], $getFailedOnlineTransaction());
|
|
$FailedBillplzID_Koop = array_map(fn($x) => $x['billplz_id'], $getFailedOnlineTransaction_Koop());
|
|
|
|
$this->resolve_payment($FailedBillplzID,CompanyStatus::COM_PKB);
|
|
$this->resolve_payment($FailedBillplzID_Koop,CompanyStatus::COM_KOOPPKB);
|
|
|
|
}
|
|
public function resolve_payment($FailedBillplzID,$company)
|
|
{
|
|
$billplzService = new BillplzService($company);
|
|
|
|
if(sizeof($FailedBillplzID) < 0){
|
|
return;
|
|
}
|
|
|
|
$billplzUpdatedTransactionStatus = array_map(fn($x) => $billplzService->getTransactionByBillId($x,$company), $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){
|
|
$transactionData = [
|
|
'billplz_id' => $transaction['bill_id'],
|
|
'status' => 'PAID',
|
|
'paid_at' => $transaction['transactions'][0]['completed_at']
|
|
];
|
|
|
|
try {
|
|
|
|
$CallableHttp = $company == CompanyStatus::COM_PKB
|
|
? Http::arrahn()
|
|
: Http::arrahn_koop();
|
|
|
|
$response = $CallableHttp->put('/api/transaction/online/unsuccesfull/update', $transactionData);
|
|
|
|
OnlineTransactionLoggerService::logs($transaction['bill_id'], $transactionData, $response, TransactionOnlineStatus::UPDATE_UNSUCCESSFUL_TRANSACTION );
|
|
|
|
} catch (\Exception $e) {
|
|
OnlineTransactionLoggerService::logs($transaction['bill_id'], $transactionData, $e->getMessage(), TransactionOnlineStatus::UPDATE_UNSUCCESSFUL_TRANSACTION );
|
|
|
|
throw $e;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|