mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Ensure gateway fees are not cleared inappropriately
This commit is contained in:
parent
df8f7e1c7c
commit
605ddd7d3e
@ -11,35 +11,36 @@
|
|||||||
|
|
||||||
namespace App\PaymentDrivers;
|
namespace App\PaymentDrivers;
|
||||||
|
|
||||||
use App\Events\Invoice\InvoiceWasPaid;
|
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
|
||||||
use App\Exceptions\PaymentFailed;
|
|
||||||
use App\Factory\PaymentFactory;
|
|
||||||
use App\Jobs\Mail\NinjaMailer;
|
|
||||||
use App\Jobs\Mail\NinjaMailerJob;
|
|
||||||
use App\Jobs\Mail\NinjaMailerObject;
|
|
||||||
use App\Jobs\Mail\PaymentFailedMailer;
|
|
||||||
use App\Jobs\Util\SystemLogger;
|
|
||||||
use App\Mail\Admin\ClientPaymentFailureObject;
|
|
||||||
use App\Models\Client;
|
|
||||||
use App\Models\ClientContact;
|
|
||||||
use App\Models\ClientGatewayToken;
|
|
||||||
use App\Models\CompanyGateway;
|
|
||||||
use App\Models\GatewayType;
|
|
||||||
use App\Models\Invoice;
|
|
||||||
use App\Models\Payment;
|
|
||||||
use App\Models\PaymentHash;
|
|
||||||
use App\Models\SystemLog;
|
|
||||||
use App\Services\Subscription\SubscriptionService;
|
|
||||||
use App\Utils\Helpers;
|
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Number;
|
use App\Utils\Number;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Models\Client;
|
||||||
use App\Utils\Traits\SystemLogTrait;
|
use App\Utils\Helpers;
|
||||||
use Illuminate\Http\Request;
|
use App\Models\Invoice;
|
||||||
use Illuminate\Support\Carbon;
|
use App\Models\Payment;
|
||||||
use Illuminate\Support\Facades\App;
|
use App\Models\SystemLog;
|
||||||
|
use App\Models\GatewayType;
|
||||||
|
use App\Models\PaymentHash;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\ClientContact;
|
||||||
|
use App\Jobs\Mail\NinjaMailer;
|
||||||
|
use App\Models\CompanyGateway;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use App\DataMapper\InvoiceItem;
|
||||||
|
use App\Factory\PaymentFactory;
|
||||||
|
use App\Jobs\Util\SystemLogger;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Exceptions\PaymentFailed;
|
||||||
|
use App\Jobs\Mail\NinjaMailerJob;
|
||||||
|
use App\Models\ClientGatewayToken;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
use App\Jobs\Mail\NinjaMailerObject;
|
||||||
|
use App\Utils\Traits\SystemLogTrait;
|
||||||
|
use App\Events\Invoice\InvoiceWasPaid;
|
||||||
|
use App\Jobs\Mail\PaymentFailedMailer;
|
||||||
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
|
use App\Mail\Admin\ClientPaymentFailureObject;
|
||||||
|
use App\Services\Subscription\SubscriptionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BaseDriver.
|
* Class BaseDriver.
|
||||||
@ -394,14 +395,71 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
/*Fee charged at gateway*/
|
/*Fee charged at gateway*/
|
||||||
$fee_total = $this->payment_hash->fee_total;
|
$fee_total = $this->payment_hash->fee_total;
|
||||||
|
|
||||||
/*Hydrate invoices*/
|
if(!$fee_total || $fee_total == 0)
|
||||||
$invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get();
|
return;
|
||||||
|
|
||||||
$invoices->each(function ($invoice) {
|
$invoices = Invoice::query()
|
||||||
if (collect($invoice->line_items)->contains('type_id', '3')) {
|
->whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))
|
||||||
$invoice->service()->toggleFeesPaid()->save();
|
->whereJsonContains('line_items', ['type_id' => '3'])
|
||||||
|
->withTrashed();
|
||||||
|
|
||||||
|
if($invoices->count() == 0){
|
||||||
|
|
||||||
|
$invoice = Invoice::query()
|
||||||
|
->whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))
|
||||||
|
->orderBy('id','desc')
|
||||||
|
->withTrashed()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if(!$invoice)
|
||||||
|
return;
|
||||||
|
|
||||||
|
$balance = $invoice->balance;
|
||||||
|
|
||||||
|
App::forgetInstance('translator');
|
||||||
|
$t = app('translator');
|
||||||
|
$t->replace(Ninja::transformTranslations($invoice->company->settings));
|
||||||
|
App::setLocale($invoice->client->locale());
|
||||||
|
|
||||||
|
$invoice_item = new InvoiceItem();
|
||||||
|
$invoice_item->type_id = '4';
|
||||||
|
$invoice_item->product_key = ctrans('texts.surcharge');
|
||||||
|
$invoice_item->notes = ctrans('texts.online_payment_surcharge');
|
||||||
|
$invoice_item->quantity = 1;
|
||||||
|
$invoice_item->cost = $fee_total;
|
||||||
|
|
||||||
|
$invoice_items = (array) $invoice->line_items;
|
||||||
|
$invoice_items[] = $invoice_item;
|
||||||
|
|
||||||
|
$invoice->line_items = $invoice_items;
|
||||||
|
|
||||||
|
/**Refresh Invoice values*/
|
||||||
|
$invoice = $invoice->calc()->getInvoice();
|
||||||
|
|
||||||
|
$new_balance = $invoice->balance;
|
||||||
|
|
||||||
|
if (floatval($new_balance) - floatval($balance) != 0) {
|
||||||
|
$adjustment = $new_balance - $balance;
|
||||||
|
|
||||||
|
$invoice
|
||||||
|
->ledger()
|
||||||
|
->updateInvoiceBalance($adjustment, 'Adjustment for adding gateway fee');
|
||||||
|
|
||||||
|
$invoice->client->service()->calculateBalance();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
$invoices
|
||||||
|
->cursor()
|
||||||
|
->each(function ($i){
|
||||||
|
$i->service()->toggleFeesPaid()->save();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -383,7 +383,6 @@ class InvoiceService
|
|||||||
return $item;
|
return $item;
|
||||||
})->toArray();
|
})->toArray();
|
||||||
|
|
||||||
// $this->deletePdf();
|
|
||||||
$this->deleteEInvoice();
|
$this->deleteEInvoice();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user