1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Jobs/Invoice/CheckGatewayFee.php

66 lines
1.4 KiB
PHP
Raw Normal View History

2023-01-11 05:43:54 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2023-01-11 05:43:54 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Invoice;
2023-05-18 00:31:21 +02:00
use App\Libraries\MultiDB;
2023-10-26 04:57:44 +02:00
use App\Models\Invoice;
2023-01-11 05:43:54 +01:00
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
2023-10-26 04:57:44 +02:00
use Illuminate\Queue\InteractsWithQueue;
2023-05-18 00:31:21 +02:00
use Illuminate\Queue\Middleware\WithoutOverlapping;
2023-10-26 04:57:44 +02:00
use Illuminate\Queue\SerializesModels;
2023-01-11 05:43:54 +01:00
class CheckGatewayFee implements ShouldQueue
{
2024-01-14 05:05:00 +01:00
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
2023-01-11 05:43:54 +01:00
public $tries = 1;
/**
* @param $invoice_id
* @param string $db
*/
2023-02-16 02:36:09 +01:00
public function __construct(public int $invoice_id, public string $db)
{
}
2023-01-11 05:43:54 +01:00
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
2024-01-14 05:05:00 +01:00
2023-01-11 05:43:54 +01:00
MultiDB::setDb($this->db);
$i = Invoice::withTrashed()->find($this->invoice_id);
2023-02-16 02:36:09 +01:00
if (!$i) {
2023-01-11 05:43:54 +01:00
return;
2023-02-16 02:36:09 +01:00
}
2023-01-11 05:43:54 +01:00
2023-02-16 02:36:09 +01:00
if ($i->status_id == Invoice::STATUS_SENT) {
2023-01-11 05:43:54 +01:00
$i->service()->removeUnpaidGatewayFees();
}
}
2023-05-18 00:31:21 +02:00
public function middleware()
{
return [(new WithoutOverlapping($this->invoice_id.$this->db))];
}
2023-01-11 05:43:54 +01:00
}