mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 08:54:34 -04:00
Working on tests for fees and limits
This commit is contained in:
parent
713d967e8e
commit
d6e169a891
@ -97,7 +97,6 @@ class InvoiceController extends Controller
|
|||||||
|
|
||||||
$invoices->map(function ($invoice) {
|
$invoices->map(function ($invoice) {
|
||||||
$invoice->balance = Number::formatMoney($invoice->balance, $invoice->client);
|
$invoice->balance = Number::formatMoney($invoice->balance, $invoice->client);
|
||||||
//$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format());
|
|
||||||
return $invoice;
|
return $invoice;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -236,26 +236,40 @@ class CompanyGateway extends BaseModel
|
|||||||
|
|
||||||
public function calcGatewayFee($amount)
|
public function calcGatewayFee($amount)
|
||||||
{
|
{
|
||||||
|
$fees_and_limits = new \stdClass;
|
||||||
|
|
||||||
|
foreach($this->fees_and_limits as $key => $value)
|
||||||
|
$fees_and_limits = $this->fees_and_limits->{$key};
|
||||||
|
|
||||||
$fee = 0;
|
$fee = 0;
|
||||||
|
|
||||||
if ($this->fee_amount) {
|
if ($fees_and_limits->fee_amount) {
|
||||||
$fee += $this->fee_amount;
|
$fee += $fees_and_limits->fee_amount;
|
||||||
|
info("fee after adding fee amount = {$fee}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->fee_percent) {
|
if ($fees_and_limits->fee_percent) {
|
||||||
$fee += $amount * $this->fee_percent / 100;
|
$fee += $amount * $fees_and_limits->fee_percent / 100;
|
||||||
|
info("fee after adding fee percent = {$fee}");
|
||||||
}
|
}
|
||||||
|
|
||||||
$pre_tax_fee = $fee;
|
$pre_tax_fee = $fee;
|
||||||
|
|
||||||
if ($this->fee_tax_rate1) {
|
if ($fees_and_limits->fee_tax_rate1) {
|
||||||
$fee += $pre_tax_fee * $this->fee_tax_rate1 / 100;
|
$fee += $pre_tax_fee * $fees_and_limits->fee_tax_rate1 / 100;
|
||||||
|
info("fee after adding fee tax 1 = {$fee}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->fee_tax_rate2) {
|
if ($fees_and_limits->fee_tax_rate2) {
|
||||||
$fee += $pre_tax_fee * $this->fee_tax_rate2 / 100;
|
$fee += $pre_tax_fee * $fees_and_limits->fee_tax_rate2 / 100;
|
||||||
|
info("fee after adding fee tax 2 = {$fee}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($fees_and_limits->fee_tax_rate3) {
|
||||||
|
$fee += $pre_tax_fee * $fees_and_limits->fee_tax_rate3 / 100;
|
||||||
|
info("fee after adding fee tax 3 = {$fee}");
|
||||||
|
}
|
||||||
|
|
||||||
return $fee;
|
return $fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ use App\Models\Account;
|
|||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\CompanyGateway;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver;
|
use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
@ -19,9 +20,9 @@ use Illuminate\Foundation\Testing\WithFaker;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
|
use PaymentLibrariesSeeder;
|
||||||
use Tests\MockAccountData;
|
use Tests\MockAccountData;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use PaymentLibrariesSeeder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
@ -178,4 +179,38 @@ class CompanyGatewayApiTest extends TestCase
|
|||||||
$this->assertEquals($arr['min_limit'], $new_arr['min_limit']);
|
$this->assertEquals($arr['min_limit'], $new_arr['min_limit']);
|
||||||
$this->assertTrue(array_key_exists('fee_amount', $new_arr));
|
$this->assertTrue(array_key_exists('fee_amount', $new_arr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFeesAndLimitsFeeAmountCalcuation()
|
||||||
|
{
|
||||||
|
//{"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 = 10;
|
||||||
|
// $fee->fee_percent = 2;
|
||||||
|
// $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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user