mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-30 01:44:05 +00:00
64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Jobs\Commands\V2;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Models\Transaction;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CheckDeletedInvoiceButPaidV2CommandJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
public function handle()
|
|
{
|
|
Log::info(Carbon::now() . ': Start job - Check all deleted invoice but has completed payment.');
|
|
$start = new Carbon();
|
|
|
|
// ini_set('memory_limit', '-1');
|
|
|
|
$totalAmount = 0;
|
|
|
|
$softDeletedTransactions = Transaction::onlyTrashed()->where('type', TransactionType::SHIPPING_INVOICE)->whereHas('transactions', function (Builder $query) {
|
|
$query->where('type', TransactionType::PAYMENT)->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY);
|
|
})->get();
|
|
|
|
foreach ($softDeletedTransactions as $invoice) {
|
|
$invoice_payments = $invoice->transactions()->payments()->get();
|
|
|
|
foreach($invoice_payments as $invoice_payment) {
|
|
|
|
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$invoice_payment->payment_reference);
|
|
|
|
if($response->successful()){
|
|
$data = $response->json();
|
|
|
|
$orderReference = $invoice->owner->owner->reference ?? null;
|
|
|
|
if($data['paid']){
|
|
Log::info('Invoice id: ' . $invoice->id. '. Payment id: ' . $invoice_payment->id . '. Order: ' . $orderReference);
|
|
} else {
|
|
|
|
}
|
|
}else{
|
|
Log::info("billplz error</br>");
|
|
}
|
|
}
|
|
}
|
|
|
|
$end = new Carbon();
|
|
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
|
Log::info(Carbon::now() . ': End job - Check all deleted invoice but has completed payment. ElapsedTime: ' . $elapsedTime . '. Total: ' . $totalAmount);
|
|
}
|
|
}
|