diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 407c346bb8fd..fe8d6adf2a1e 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -97,7 +97,6 @@ class InvoiceController extends Controller $invoices->map(function ($invoice) { $invoice->balance = Number::formatMoney($invoice->balance, $invoice->client); - //$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format()); return $invoice; }); diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 0ac92321b71d..fc576acac617 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -236,26 +236,40 @@ class CompanyGateway extends BaseModel 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; - if ($this->fee_amount) { - $fee += $this->fee_amount; + if ($fees_and_limits->fee_amount) { + $fee += $fees_and_limits->fee_amount; + info("fee after adding fee amount = {$fee}"); } - if ($this->fee_percent) { - $fee += $amount * $this->fee_percent / 100; + if ($fees_and_limits->fee_percent) { + $fee += $amount * $fees_and_limits->fee_percent / 100; + info("fee after adding fee percent = {$fee}"); } $pre_tax_fee = $fee; - if ($this->fee_tax_rate1) { - $fee += $pre_tax_fee * $this->fee_tax_rate1 / 100; + if ($fees_and_limits->fee_tax_rate1) { + $fee += $pre_tax_fee * $fees_and_limits->fee_tax_rate1 / 100; + info("fee after adding fee tax 1 = {$fee}"); } - if ($this->fee_tax_rate2) { - $fee += $pre_tax_fee * $this->fee_tax_rate2 / 100; + if ($fees_and_limits->fee_tax_rate2) { + $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; } diff --git a/tests/Feature/CompanyGatewayApiTest.php b/tests/Feature/CompanyGatewayApiTest.php index 417d9ae2c9d6..a5bd9e879994 100644 --- a/tests/Feature/CompanyGatewayApiTest.php +++ b/tests/Feature/CompanyGatewayApiTest.php @@ -8,6 +8,7 @@ use App\Models\Account; use App\Models\Client; use App\Models\ClientContact; use App\Models\Company; +use App\Models\CompanyGateway; use App\Models\User; use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver; use App\Utils\Traits\MakesHash; @@ -19,9 +20,9 @@ use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Session; +use PaymentLibrariesSeeder; use Tests\MockAccountData; use Tests\TestCase; -use PaymentLibrariesSeeder; /** * @test @@ -178,4 +179,38 @@ class CompanyGatewayApiTest extends TestCase $this->assertEquals($arr['min_limit'], $new_arr['min_limit']); $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)); + } }