2019-10-03 05:21:24 +02:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-14 13:11:46 +02:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2019-10-03 05:21:24 +02:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2019-11-11 13:21:19 +01:00
|
|
|
use App\DataMapper\FeesAndLimits;
|
2023-01-22 05:11:33 +01:00
|
|
|
use App\Factory\CompanyGatewayFactory;
|
2020-08-17 05:03:21 +02:00
|
|
|
use App\Models\CompanyGateway;
|
2021-01-04 14:07:50 +01:00
|
|
|
use App\Models\GatewayType;
|
2019-11-11 13:21:19 +01:00
|
|
|
use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver;
|
2019-10-03 05:21:24 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2020-08-19 00:33:58 +02:00
|
|
|
* @covers App\Models\CompanyGateway
|
2019-10-03 05:21:24 +02:00
|
|
|
*/
|
2019-10-03 06:27:17 +02:00
|
|
|
class CompanyGatewayApiTest extends TestCase
|
2019-10-03 05:21:24 +02:00
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
use MockAccountData;
|
2019-11-11 13:21:19 +01:00
|
|
|
use CompanyGatewayFeesAndLimitsSaver;
|
2019-10-03 12:59:19 +02:00
|
|
|
|
2024-08-22 08:57:52 +02:00
|
|
|
protected function setUp(): void
|
2019-10-03 05:21:24 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
}
|
|
|
|
|
2023-01-22 05:11:33 +01:00
|
|
|
public function testBulkActions()
|
|
|
|
{
|
|
|
|
$cg = CompanyGatewayFactory::create($this->company->id, $this->user->id);
|
|
|
|
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
|
|
|
$cg->save();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'action' => 'archive',
|
|
|
|
'ids' => [$cg->hashed_id]
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways/bulk', $data)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ids' => [$cg->hashed_id],
|
|
|
|
'action' => 'restore'
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways/bulk', $data)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'ids' => [$cg->hashed_id],
|
|
|
|
'action' => 'delete'
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways/bulk', $data)
|
|
|
|
->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-24 02:25:48 +02:00
|
|
|
public function testCompanyGatewayEndPointsWithIncorrectFields()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '',
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2021-07-24 02:25:48 +02:00
|
|
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCompanyGatewayEndPointsWithInvalidFields()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '$#%^&*(',
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2021-07-24 02:25:48 +02:00
|
|
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
}
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
public function testCompanyGatewayEndPoints()
|
2019-10-03 05:21:24 +02:00
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
2019-10-03 12:59:19 +02:00
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
2019-10-03 05:21:24 +02:00
|
|
|
];
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
/* POST */
|
2019-10-03 05:21:24 +02:00
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2019-10-03 05:21:24 +02:00
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
$cg = $response->json();
|
|
|
|
|
|
|
|
$cg_id = $cg['data']['id'];
|
|
|
|
|
|
|
|
$this->assertNotNull($cg_id);
|
2019-10-03 05:21:24 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
/* PUT */
|
2019-10-03 05:21:24 +02:00
|
|
|
$data = [
|
|
|
|
'config' => 'changed',
|
|
|
|
];
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->put('/api/v1/company_gateways/'.$cg_id, $data);
|
2019-10-03 05:21:24 +02:00
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
$response->assertStatus(200);
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->delete("/api/v1/company_gateways/{$cg_id}", $data);
|
2019-10-03 05:21:24 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
2019-11-11 13:21:19 +01:00
|
|
|
|
|
|
|
public function testCompanyGatewayFeesAndLimitsSuccess()
|
|
|
|
{
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee = new FeesAndLimits();
|
2019-11-11 13:21:19 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$fee = (array) $fee;
|
2019-11-11 13:21:19 +01:00
|
|
|
|
|
|
|
$fee_and_limit['1'] = ['min_limit' => 1];
|
|
|
|
$fee_and_limit['2'] = ['min_limit' => 1];
|
|
|
|
$fee_and_limit['3'] = ['min_limit' => 1];
|
|
|
|
$fee_and_limit['4'] = ['min_limit' => 1];
|
|
|
|
$fee_and_limit['5'] = ['min_limit' => 1];
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
|
|
|
'fees_and_limits' => $fee_and_limit,
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2019-11-11 13:21:19 +01:00
|
|
|
|
|
|
|
$cg = $response->json();
|
|
|
|
|
|
|
|
$cg_id = $cg['data']['id'];
|
|
|
|
|
|
|
|
$this->assertNotNull($cg_id);
|
|
|
|
|
|
|
|
$cg_fee = $cg['data']['fees_and_limits'];
|
|
|
|
|
|
|
|
$this->assertNotNull($cg_fee);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/company_gateways/'.$this->encodePrimaryKey($cg['data']['id']));
|
2019-11-11 13:21:19 +01:00
|
|
|
|
|
|
|
$cg = $response->json();
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
2022-01-03 02:35:31 +01:00
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/company_gateways');
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/company_gateways?filter=x');
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
2019-11-11 13:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCompanyGatewayFeesAndLimitsFails()
|
|
|
|
{
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee_and_limit['bank_transfer'] = new FeesAndLimits();
|
2019-11-11 13:21:19 +01:00
|
|
|
|
|
|
|
$fee_and_limit['bank_transfer']->adjust_fee_percent = 10;
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
|
|
|
'fees_and_limits' => $fee_and_limit,
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2019-11-11 13:21:19 +01:00
|
|
|
|
2020-02-26 11:46:35 +01:00
|
|
|
$response->assertStatus(200);
|
2019-11-11 13:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCompanyGatewayArrayBuilder()
|
|
|
|
{
|
|
|
|
$arr = [
|
|
|
|
'min_limit' => 1,
|
2020-09-06 11:38:10 +02:00
|
|
|
'max_limit' => 2,
|
2019-11-11 13:21:19 +01:00
|
|
|
];
|
|
|
|
|
2024-08-22 08:57:52 +02:00
|
|
|
$fal = (array) new FeesAndLimits();
|
2019-11-11 13:21:19 +01:00
|
|
|
|
|
|
|
$new_arr = array_replace($fal, $arr);
|
|
|
|
|
|
|
|
$this->assertEquals($arr['min_limit'], $new_arr['min_limit']);
|
|
|
|
$this->assertTrue(array_key_exists('fee_amount', $new_arr));
|
|
|
|
}
|
2020-08-17 05:03:21 +02:00
|
|
|
|
|
|
|
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}}
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee = new FeesAndLimits();
|
2020-08-17 05:03:21 +02:00
|
|
|
$fee->fee_amount = 10;
|
|
|
|
// $fee->fee_percent = 2;
|
|
|
|
// $fee->fee_tax_name1 = 'GST';
|
|
|
|
// $fee->fee_tax_rate1 = '10.0';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$fee_arr[1] = (array) $fee;
|
2020-08-17 05:03:21 +02:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
|
|
|
'fees_and_limits' => $fee_arr,
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2020-08-17 05:03:21 +02:00
|
|
|
|
2020-08-17 05:51:16 +02:00
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
$id = $this->decodePrimaryKey($arr['data']['id']);
|
|
|
|
|
|
|
|
$company_gateway = CompanyGateway::find($id);
|
|
|
|
|
2021-01-04 14:07:50 +01:00
|
|
|
$this->assertEquals(10, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
|
2020-08-17 05:51:16 +02:00
|
|
|
}
|
|
|
|
|
2020-08-17 06:27:21 +02:00
|
|
|
public function testFeesAndLimitsFeePercentCalcuation()
|
2020-08-17 05:51:16 +02:00
|
|
|
{
|
|
|
|
//{"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}}
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee = new FeesAndLimits();
|
2020-08-17 05:51:16 +02:00
|
|
|
//$fee->fee_amount = 10;
|
2020-09-06 11:38:10 +02:00
|
|
|
$fee->fee_percent = 2;
|
2020-08-17 05:51:16 +02:00
|
|
|
// $fee->fee_tax_name1 = 'GST';
|
|
|
|
// $fee->fee_tax_rate1 = '10.0';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$fee_arr[1] = (array) $fee;
|
2020-08-17 05:51:16 +02:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
|
|
|
'fees_and_limits' => $fee_arr,
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2020-08-17 05:51:16 +02:00
|
|
|
|
2020-08-17 05:03:21 +02:00
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
$id = $this->decodePrimaryKey($arr['data']['id']);
|
|
|
|
|
|
|
|
$company_gateway = CompanyGateway::find($id);
|
|
|
|
|
2021-01-04 14:07:50 +01:00
|
|
|
$this->assertEquals(0.2, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
|
2020-08-17 06:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFeesAndLimitsFeePercentAndAmountCalcuation()
|
|
|
|
{
|
|
|
|
//{"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}}
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee = new FeesAndLimits();
|
2020-08-17 06:27:21 +02:00
|
|
|
$fee->fee_amount = 10;
|
2020-09-06 11:38:10 +02:00
|
|
|
$fee->fee_percent = 2;
|
2020-08-17 06:27:21 +02:00
|
|
|
// $fee->fee_tax_name1 = 'GST';
|
|
|
|
// $fee->fee_tax_rate1 = '10.0';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$fee_arr[1] = (array) $fee;
|
2020-08-17 06:27:21 +02:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
|
|
|
'fees_and_limits' => $fee_arr,
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2020-08-17 06:27:21 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
$id = $this->decodePrimaryKey($arr['data']['id']);
|
|
|
|
|
|
|
|
$company_gateway = CompanyGateway::find($id);
|
|
|
|
|
2021-01-04 14:07:50 +01:00
|
|
|
$this->assertEquals(10.2, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
|
2020-08-17 06:27:21 +02:00
|
|
|
}
|
|
|
|
|
2022-01-08 04:54:02 +01:00
|
|
|
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}}
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee = new FeesAndLimits();
|
2022-01-08 04:54:02 +01:00
|
|
|
$fee->fee_amount = 0;
|
|
|
|
$fee->fee_percent = 100;
|
2022-03-16 11:40:11 +01:00
|
|
|
$fee->adjust_fee_percent = false;
|
2022-01-08 04:54:02 +01:00
|
|
|
// $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([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2022-01-08 04:54:02 +01:00
|
|
|
|
|
|
|
$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()
|
|
|
|
{
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee = new FeesAndLimits();
|
2022-01-08 04:54:02 +01:00
|
|
|
$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([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2022-01-08 04:54:02 +01:00
|
|
|
|
|
|
|
$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));
|
|
|
|
}
|
|
|
|
|
2020-08-17 06:27:21 +02:00
|
|
|
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}}
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee = new FeesAndLimits();
|
2020-08-17 06:27:21 +02:00
|
|
|
$fee->fee_amount = 10;
|
|
|
|
// $fee->fee_percent = 2;
|
|
|
|
$fee->fee_tax_name1 = 'GST';
|
|
|
|
$fee->fee_tax_rate1 = '10.0';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$fee_arr[1] = (array) $fee;
|
2020-08-17 06:27:21 +02:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
|
|
|
'fees_and_limits' => $fee_arr,
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2020-08-17 06:27:21 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
$id = $this->decodePrimaryKey($arr['data']['id']);
|
|
|
|
|
|
|
|
$company_gateway = CompanyGateway::find($id);
|
|
|
|
|
2021-01-04 14:07:50 +01:00
|
|
|
$this->assertEquals(11, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD, true));
|
2020-08-31 06:27:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFeesAndLimitsFeePercentAndAmountAndTaxCalcuationInclusiveTaxes()
|
|
|
|
{
|
|
|
|
//{"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}}
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee = new FeesAndLimits();
|
2020-08-31 06:27:47 +02:00
|
|
|
$fee->fee_amount = 10;
|
|
|
|
// $fee->fee_percent = 2;
|
|
|
|
$fee->fee_tax_name1 = 'GST';
|
|
|
|
$fee->fee_tax_rate1 = '10.0';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$fee_arr[1] = (array) $fee;
|
2020-08-31 06:27:47 +02:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
|
|
|
'fees_and_limits' => $fee_arr,
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2020-08-31 06:27:47 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
$id = $this->decodePrimaryKey($arr['data']['id']);
|
|
|
|
|
|
|
|
$company_gateway = CompanyGateway::find($id);
|
|
|
|
|
2021-01-04 14:07:50 +01:00
|
|
|
$this->assertEquals(10, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD));
|
2020-08-17 05:03:21 +02:00
|
|
|
}
|
2020-08-17 08:23:12 +02:00
|
|
|
|
|
|
|
public function testFeesAndLimitsFeePercentAndAmountAndDoubleTaxCalcuation()
|
|
|
|
{
|
|
|
|
//{"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}}
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee = new FeesAndLimits();
|
2020-08-17 08:23:12 +02:00
|
|
|
$fee->fee_amount = 10;
|
|
|
|
// $fee->fee_percent = 2;
|
|
|
|
$fee->fee_tax_name1 = 'GST';
|
|
|
|
$fee->fee_tax_rate1 = '10.0';
|
|
|
|
$fee->fee_tax_name2 = 'GST';
|
|
|
|
$fee->fee_tax_rate2 = '10.0';
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$fee_arr[1] = (array) $fee;
|
2020-08-17 08:23:12 +02:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
|
|
|
'fees_and_limits' => $fee_arr,
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2020-08-17 08:23:12 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
$id = $this->decodePrimaryKey($arr['data']['id']);
|
|
|
|
|
|
|
|
$company_gateway = CompanyGateway::find($id);
|
|
|
|
|
2021-01-04 14:07:50 +01:00
|
|
|
$this->assertEquals(12, $company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD, true));
|
2020-08-17 08:23:12 +02:00
|
|
|
}
|
2020-08-19 00:33:58 +02:00
|
|
|
|
|
|
|
public function testFeesAndLimitsFeePercentAndAmountAndDoubleTaxCalcuationWithFeeCap()
|
|
|
|
{
|
|
|
|
//{"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}}
|
2024-08-22 08:57:52 +02:00
|
|
|
$fee = new FeesAndLimits();
|
2020-08-19 00:33:58 +02:00
|
|
|
$fee->fee_amount = 10;
|
|
|
|
// $fee->fee_percent = 2;
|
|
|
|
$fee->fee_tax_name1 = 'GST';
|
|
|
|
$fee->fee_tax_rate1 = '10.0';
|
|
|
|
$fee->fee_tax_name2 = 'GST';
|
|
|
|
$fee->fee_tax_rate2 = '10.0';
|
|
|
|
$fee->fee_cap = 1;
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$fee_arr[1] = (array) $fee;
|
2020-08-19 00:33:58 +02:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'config' => 'random config',
|
|
|
|
'gateway_key' => '3b6621f970ab18887c4f6dca78d3f8bb',
|
|
|
|
'fees_and_limits' => $fee_arr,
|
|
|
|
];
|
|
|
|
|
|
|
|
/* POST */
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
2020-08-19 00:33:58 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
$id = $this->decodePrimaryKey($arr['data']['id']);
|
|
|
|
|
|
|
|
$company_gateway = CompanyGateway::find($id);
|
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
$this->assertEquals(1.2, round($company_gateway->calcGatewayFee(10, GatewayType::CREDIT_CARD, true), 1));
|
2020-08-19 00:33:58 +02:00
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|