diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 90247f1f87..5284485a0e 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -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); diff --git a/app/Services/Invoice/AddGatewayFee.php b/app/Services/Invoice/AddGatewayFee.php index 8470e72d05..834dc4fc2b 100644 --- a/app/Services/Invoice/AddGatewayFee.php +++ b/app/Services/Invoice/AddGatewayFee.php @@ -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; diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 43a482bbf1..3f92130af0 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -16,6 +16,7 @@ use App\Events\Payment\PaymentWasCreated; use App\Factory\PaymentFactory; use App\Models\Client; use App\Models\Credit; +use App\Models\GatewayType; use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentHash; @@ -82,7 +83,7 @@ class AutoBillInvoice extends AbstractService } /* $gateway fee */ - $fee = $gateway_token->gateway->calcGatewayFee($amount, $this->invoice->uses_inclusive_taxes); + $fee = $gateway_token->gateway->calcGatewayFee($amount, GatewayType::CREDIT_CARD, $this->invoice->uses_inclusive_taxes); //todo determine exact fee as per PaymentController diff --git a/tests/Feature/CompanyGatewayApiTest.php b/tests/Feature/CompanyGatewayApiTest.php index 8ce7c5f812..33f7bd55e4 100644 --- a/tests/Feature/CompanyGatewayApiTest.php +++ b/tests/Feature/CompanyGatewayApiTest.php @@ -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)); } } diff --git a/tests/Feature/CompanyGatewayResolutionTest.php b/tests/Feature/CompanyGatewayResolutionTest.php index 6073df3332..2860b57961 100644 --- a/tests/Feature/CompanyGatewayResolutionTest.php +++ b/tests/Feature/CompanyGatewayResolutionTest.php @@ -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); } diff --git a/tests/Feature/CompanyGatewayTest.php b/tests/Feature/CompanyGatewayTest.php index 0bcf9d02e2..21e78bfbe3 100644 --- a/tests/Feature/CompanyGatewayTest.php +++ b/tests/Feature/CompanyGatewayTest.php @@ -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);