1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Services/Invoice/AutoBillInvoice.php

75 lines
1.8 KiB
PHP
Raw Normal View History

2020-07-07 14:33:11 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Invoice;
use App\Events\Payment\PaymentWasCreated;
use App\Factory\PaymentFactory;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\Payment;
use App\Services\AbstractService;
use App\Services\Client\ClientService;
use App\Services\Payment\PaymentService;
use App\Utils\Traits\GeneratesCounter;
class AutoBillInvoice extends AbstractService
{
private $invoice;
private $client;
public function __construct(Invoice $invoice)
{
$this->invoice = $invoice;
$this->client = $invoice->client;
}
public function run()
{
if(!$invoice->isPayable())
return $invoice;
}
private function getGateway($amount)
{
$gateway_tokens = $this->client->gateway_tokens->orderBy('is_default', 'DESC');
2020-07-07 16:50:51 +02:00
$billing_gateway_token = null;
$gateway_tokens->filter(function ($token) use ($amount){
if(isset($token->gateway->fees_and_limits))
$fees_and_limits = $token->gateway->fees_and_limits->{"1"};
else
return true;
2020-07-07 14:33:11 +02:00
2020-07-07 16:50:51 +02:00
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit)
return false;
if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->min_limit)
2020-07-07 14:33:11 +02:00
return false;
2020-07-07 16:50:51 +02:00
return true;
})->all()->first();
2020-07-07 14:33:11 +02:00
}
2020-07-07 16:50:51 +02:00
2020-07-07 14:33:11 +02:00
}