1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Services/Payment/ApplyNumber.php

60 lines
1.3 KiB
PHP
Raw Normal View History

<?php
/**
* Payment Ninja (https://paymentninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Payment Ninja LLC (https://paymentninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Payment;
use App\Models\Payment;
use App\Services\AbstractService;
use App\Utils\Traits\GeneratesCounter;
use Illuminate\Database\QueryException;
class ApplyNumber extends AbstractService
{
use GeneratesCounter;
private bool $completed = true;
public function __construct(private Payment $payment)
{
}
public function run()
{
if ($this->payment->number != '') {
return $this->payment;
}
$this->trySaving();
return $this->payment;
}
private function trySaving()
{
$x = 1;
do {
try {
$this->payment->number = $this->getNextPaymentNumber($this->payment->client, $this->payment);
$this->payment->saveQuietly();
$this->completed = false;
} catch (QueryException $e) {
$x++;
2022-09-07 06:15:27 +02:00
if ($x > 50) {
$this->completed = false;
}
}
} while ($this->completed);
}
}