From d105943bf3006af69a34c0bcf5434a01e0fd9d2e Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 16 Mar 2017 19:34:14 +0200 Subject: [PATCH] Fix for gateway fees w/partial --- app/Models/Traits/ChargesFees.php | 4 ++-- app/Ninja/PaymentDrivers/BasePaymentDriver.php | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Models/Traits/ChargesFees.php b/app/Models/Traits/ChargesFees.php index f348e09d3c72..ddd1f8f156fa 100644 --- a/app/Models/Traits/ChargesFees.php +++ b/app/Models/Traits/ChargesFees.php @@ -27,12 +27,12 @@ trait ChargesFees if ($settings->fee_percent) { // prevent charging taxes twice on the surcharge - $amount = $this->getRequestedAmount(); + $amount = $this->amount; $taxField = $account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? 'custom_invoice_taxes1' : 'custom_invoice_taxes1'; if ($account->$taxField) { $taxAmount = 0; foreach ($this->getTaxes() as $key => $tax) { - $taxAmount += $tax['amount'] - $tax['paid']; + $taxAmount += $tax['amount']; } $amount -= $taxAmount; } diff --git a/app/Ninja/PaymentDrivers/BasePaymentDriver.php b/app/Ninja/PaymentDrivers/BasePaymentDriver.php index af488f98e59e..6cb72bde4906 100644 --- a/app/Ninja/PaymentDrivers/BasePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BasePaymentDriver.php @@ -132,9 +132,11 @@ class BasePaymentDriver return redirect()->to('view/' . $this->invitation->invitation_key); } - // apply gateway fees - $invoicRepo = app('App\Ninja\Repositories\InvoiceRepository'); - $invoicRepo->setGatewayFee($this->invoice(), $this->gatewayType); + if (! $this->isGatewayType(GATEWAY_TYPE_TOKEN)) { + // apply gateway fees + $invoicRepo = app('App\Ninja\Repositories\InvoiceRepository'); + $invoicRepo->setGatewayFee($this->invoice(), $this->gatewayType); + } if ($this->isGatewayType(GATEWAY_TYPE_TOKEN) || $gateway->is_offsite) { if (Session::has('error')) { @@ -267,6 +269,9 @@ class BasePaymentDriver ->firstOrFail(); } + $invoicRepo = app('App\Ninja\Repositories\InvoiceRepository'); + $invoicRepo->setGatewayFee($this->invoice(), $paymentMethod->payment_type->gateway_type_id); + if (! $this->meetsGatewayTypeLimits($paymentMethod->payment_type->gateway_type_id)) { // The customer must have hacked the URL Session::flash('error', trans('texts.limits_not_met'));