mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Refactor calcGatewayFee:
- Remove default GatewayType::CREDIT_CARD - Swapped spaces for taxes & gateway type
This commit is contained in:
parent
66d6595a90
commit
5833df9850
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user