mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Handle 100% gateway fees
This commit is contained in:
parent
959d45f081
commit
92b490043c
@ -1 +1 @@
|
||||
5.3.41
|
||||
5.3.42
|
@ -343,7 +343,10 @@ class CompanyGateway extends BaseModel
|
||||
}
|
||||
|
||||
if ($fees_and_limits->fee_percent) {
|
||||
if ($fees_and_limits->adjust_fee_percent) {
|
||||
if($fees_and_limits->fee_percent == 100){ //unusual edge case if the user wishes to charge a fee of 100% 09/01/2022
|
||||
$fee += $amount;
|
||||
}
|
||||
elseif ($fees_and_limits->adjust_fee_percent) {
|
||||
$fee += round(($amount / (1 - $fees_and_limits->fee_percent / 100) - $amount), 2);
|
||||
} else {
|
||||
$fee += round(($amount * $fees_and_limits->fee_percent / 100), 2);
|
||||
@ -383,42 +386,6 @@ class CompanyGateway extends BaseModel
|
||||
return route('payment_webhook', ['company_key' => $this->company->company_key, 'company_gateway_id' => $this->hashed_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* we need to average out the gateway fees across all the invoices
|
||||
* so lets iterate.
|
||||
*
|
||||
* we MAY need to adjust the final fee to ensure our rounding makes sense!
|
||||
* @param $amount
|
||||
* @param $invoice_count
|
||||
* @return stdClass
|
||||
*/
|
||||
// public function calcGatewayFeeObject($amount, $invoice_count)
|
||||
// {
|
||||
// $total_gateway_fee = $this->calcGatewayFee($amount);
|
||||
|
||||
// $fee_object = new stdClass;
|
||||
|
||||
// $fees_and_limits = $this->getFeesAndLimits();
|
||||
|
||||
// if (! $fees_and_limits) {
|
||||
// return $fee_object;
|
||||
// }
|
||||
|
||||
// $fee_component_amount = $fees_and_limits->fee_amount ?: 0;
|
||||
// $fee_component_percent = $fees_and_limits->fee_percent ? ($amount * $fees_and_limits->fee_percent / 100) : 0;
|
||||
|
||||
// $combined_fee_component = $fee_component_amount + $fee_component_percent;
|
||||
|
||||
// $fee_component_tax_name1 = $fees_and_limits->fee_tax_name1 ?: '';
|
||||
// $fee_component_tax_rate1 = $fees_and_limits->fee_tax_rate1 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate1 / 100) : 0;
|
||||
|
||||
// $fee_component_tax_name2 = $fees_and_limits->fee_tax_name2 ?: '';
|
||||
// $fee_component_tax_rate2 = $fees_and_limits->fee_tax_rate2 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate2 / 100) : 0;
|
||||
|
||||
// $fee_component_tax_name3 = $fees_and_limits->fee_tax_name3 ?: '';
|
||||
// $fee_component_tax_rate3 = $fees_and_limits->fee_tax_rate3 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate3 / 100) : 0;
|
||||
// }
|
||||
|
||||
public function resolveRouteBinding($value, $field = null)
|
||||
{
|
||||
return $this
|
||||
|
@ -14,8 +14,8 @@ return [
|
||||
'require_https' => env('REQUIRE_HTTPS', true),
|
||||
'app_url' => rtrim(env('APP_URL', ''), '/'),
|
||||
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
|
||||
'app_version' => '5.3.41',
|
||||
'app_tag' => '5.3.41',
|
||||
'app_version' => '5.3.42',
|
||||
'app_tag' => '5.3.42',
|
||||
'minimum_client_version' => '5.0.16',
|
||||
'terms_version' => '1.0.1',
|
||||
'api_secret' => env('API_SECRET', ''),
|
||||
|
@ -319,6 +319,71 @@ class CompanyGatewayApiTest extends TestCase
|
||||
$this->assertEquals(10.2, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
|
||||
}
|
||||
|
||||
|
||||
public function testFeesAndLimitsFeePercentAndAmountCalcuationOneHundredPercent()
|
||||
{
|
||||
//{"1":{"min_limit":1,"max_limit":1000000,"fee_amount":10,"fee_percent":2,"fee_tax_name1":"","fee_tax_name2":"","fee_tax_name3":"","fee_tax_rate1":0,"fee_tax_rate2":0,"fee_tax_rate3":0,"fee_cap":10,"adjust_fee_percent":true}}
|
||||
$fee = new FeesAndLimits;
|
||||
$fee->fee_amount = 0;
|
||||
$fee->fee_percent = 100;
|
||||
// $fee->fee_tax_name1 = 'GST';
|
||||
// $fee->fee_tax_rate1 = '10.0';
|
||||
|
||||
$fee_arr[1] = (array) $fee;
|
||||
|
||||
$data = [
|
||||
'config' => 'random config',
|
||||
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
||||
'fees_and_limits' => $fee_arr,
|
||||
];
|
||||
|
||||
/* POST */
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/company_gateways', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
$id = $this->decodePrimaryKey($arr['data']['id']);
|
||||
|
||||
$company_gateway = CompanyGateway::find($id);
|
||||
|
||||
$this->assertEquals(10, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
|
||||
}
|
||||
|
||||
public function testFeesAndLimitsFeePercentAndAmountCalcuationOneHundredPercentVariationOne()
|
||||
{
|
||||
$fee = new FeesAndLimits;
|
||||
$fee->fee_amount = 0;
|
||||
$fee->fee_percent = 10;
|
||||
|
||||
$fee_arr[1] = (array) $fee;
|
||||
|
||||
$data = [
|
||||
'config' => 'random config',
|
||||
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
||||
'fees_and_limits' => $fee_arr,
|
||||
];
|
||||
|
||||
/* POST */
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/company_gateways', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
$id = $this->decodePrimaryKey($arr['data']['id']);
|
||||
|
||||
$company_gateway = CompanyGateway::find($id);
|
||||
|
||||
$this->assertEquals(1, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
|
||||
}
|
||||
|
||||
|
||||
public function testFeesAndLimitsFeePercentAndAmountAndTaxCalcuation()
|
||||
{
|
||||
//{"1":{"min_limit":1,"max_limit":1000000,"fee_amount":10,"fee_percent":2,"fee_tax_name1":"","fee_tax_name2":"","fee_tax_name3":"","fee_tax_rate1":0,"fee_tax_rate2":0,"fee_tax_rate3":0,"fee_cap":10,"adjust_fee_percent":true}}
|
||||
|
Loading…
Reference in New Issue
Block a user