1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Merge pull request #4624 from beganovich/v5-refactor-calcGatewayFee

(v5) Refactor calcGatewayFee
This commit is contained in:
David Bomba 2021-01-07 07:29:10 +11:00 committed by GitHub
commit 3d9755b906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 14 deletions

View File

@ -268,7 +268,7 @@ class CompanyGateway extends BaseModel
return $label;
}
public function calcGatewayFee($amount, $include_taxes = false, $gateway_type_id = GatewayType::CREDIT_CARD)
public function calcGatewayFee($amount, $gateway_type_id, $include_taxes = false)
{
$fees_and_limits = $this->getFeesAndLimits($gateway_type_id);

View File

@ -41,7 +41,7 @@ class AddGatewayFee extends AbstractService
public function run()
{
$gateway_fee = round($this->company_gateway->calcGatewayFee($this->amount, $this->invoice->uses_inclusive_taxes, $this->gateway_type_id), $this->invoice->client->currency()->precision);
$gateway_fee = round($this->company_gateway->calcGatewayFee($this->amount, $this->gateway_type_id, $this->invoice->uses_inclusive_taxes), $this->invoice->client->currency()->precision);
if ((int)$gateway_fee == 0) {
return $this->invoice;

View File

@ -14,7 +14,6 @@ namespace App\Services\Invoice;
use App\DataMapper\InvoiceItem;
use App\Events\Payment\PaymentWasCreated;
use App\Factory\PaymentFactory;
use App\Models\Client;
use App\Models\Credit;
use App\Models\Invoice;
use App\Models\Payment;
@ -82,7 +81,7 @@ class AutoBillInvoice extends AbstractService
}
/* $gateway fee */
$fee = $gateway_token->gateway->calcGatewayFee($amount, $this->invoice->uses_inclusive_taxes);
$fee = $gateway_token->gateway->calcGatewayFee($amount, $gateway_token->gateway_type_id, $this->invoice->uses_inclusive_taxes);
//todo determine exact fee as per PaymentController

View File

@ -12,6 +12,7 @@ namespace Tests\Feature;
use App\DataMapper\FeesAndLimits;
use App\Models\CompanyGateway;
use App\Models\GatewayType;
use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
@ -197,7 +198,7 @@ class CompanyGatewayApiTest extends TestCase
$company_gateway = CompanyGateway::find($id);
$this->assertEquals(10, $company_gateway->calcGatewayFee(10));
$this->assertEquals(10, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
}
public function testFeesAndLimitsFeePercentCalcuation()
@ -230,7 +231,7 @@ class CompanyGatewayApiTest extends TestCase
$company_gateway = CompanyGateway::find($id);
$this->assertEquals(0.2, $company_gateway->calcGatewayFee(10));
$this->assertEquals(0.2, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
}
public function testFeesAndLimitsFeePercentAndAmountCalcuation()
@ -263,7 +264,7 @@ class CompanyGatewayApiTest extends TestCase
$company_gateway = CompanyGateway::find($id);
$this->assertEquals(10.2, $company_gateway->calcGatewayFee(10));
$this->assertEquals(10.2, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
}
public function testFeesAndLimitsFeePercentAndAmountAndTaxCalcuation()
@ -296,7 +297,7 @@ class CompanyGatewayApiTest extends TestCase
$company_gateway = CompanyGateway::find($id);
$this->assertEquals(11, $company_gateway->calcGatewayFee(10, true));
$this->assertEquals(11, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD, true));
}
public function testFeesAndLimitsFeePercentAndAmountAndTaxCalcuationInclusiveTaxes()
@ -329,7 +330,7 @@ class CompanyGatewayApiTest extends TestCase
$company_gateway = CompanyGateway::find($id);
$this->assertEquals(10, $company_gateway->calcGatewayFee(10));
$this->assertEquals(10, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
}
public function testFeesAndLimitsFeePercentAndAmountAndDoubleTaxCalcuation()
@ -364,7 +365,7 @@ class CompanyGatewayApiTest extends TestCase
$company_gateway = CompanyGateway::find($id);
$this->assertEquals(12, $company_gateway->calcGatewayFee(10, true));
$this->assertEquals(12, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD, true));
}
public function testFeesAndLimitsFeePercentAndAmountAndDoubleTaxCalcuationWithFeeCap()
@ -400,6 +401,6 @@ class CompanyGatewayApiTest extends TestCase
$company_gateway = CompanyGateway::find($id);
$this->assertEquals(1.2, $company_gateway->calcGatewayFee(10, true));
$this->assertEquals(1.2, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD, true));
}
}

View File

@ -102,9 +102,9 @@ class CompanyGatewayResolutionTest extends TestCase
*/
public function testGatewayResolution()
{
$fee = $this->cg->calcGatewayFee(10, false, GatewayType::CREDIT_CARD);
$fee = $this->cg->calcGatewayFee(10, GatewayType::CREDIT_CARD, false);
$this->assertEquals(0.2, $fee);
$fee = $this->cg->calcGatewayFee(10, false, GatewayType::BANK_TRANSFER);
$fee = $this->cg->calcGatewayFee(10, GatewayType::CREDIT_CARD, false);
$this->assertEquals(0.1, $fee);
}

View File

@ -181,7 +181,7 @@ class CompanyGatewayTest extends TestCase
$total = 10.93;
$total_invoice_count = 5;
$total_gateway_fee = round($cg->calcGatewayFee($total, true, GatewayType::CREDIT_CARD), 2);
$total_gateway_fee = round($cg->calcGatewayFee($total, GatewayType::CREDIT_CARD, true), 2);
$this->assertEquals(1.58, $total_gateway_fee);