2019-10-03 05:21:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\DataMapper\DefaultSettings;
|
2019-11-11 13:21:19 +01:00
|
|
|
use App\DataMapper\FeesAndLimits;
|
2019-10-03 05:21:24 +02:00
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\ClientContact;
|
|
|
|
use App\Models\Company;
|
2020-08-17 05:03:21 +02:00
|
|
|
use App\Models\CompanyGateway;
|
2019-10-03 05:21:24 +02:00
|
|
|
use App\Models\User;
|
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 Faker\Factory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
2020-08-17 05:03:21 +02:00
|
|
|
use PaymentLibrariesSeeder;
|
2019-10-03 05:21:24 +02:00
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
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
|
|
|
|
2019-10-03 05:21:24 +02:00
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-03 12:59:19 +02:00
|
|
|
public function testCompanyGatewayEndPoints()
|
2019-10-03 05:21:24 +02:00
|
|
|
{
|
2020-08-15 12:44:05 +02:00
|
|
|
|
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([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
|
|
|
|
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([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
2019-10-03 13:50:50 +02:00
|
|
|
])->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([
|
2019-10-03 05:21:24 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
2019-10-03 12:59:19 +02:00
|
|
|
])->delete("/api/v1/company_gateways/{$cg_id}", $data);
|
2019-10-03 05:21:24 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
2020-08-15 12:44:05 +02:00
|
|
|
|
2019-10-03 05:21:24 +02:00
|
|
|
}
|
|
|
|
|
2019-11-11 13:21:19 +01:00
|
|
|
|
|
|
|
public function testCompanyGatewayFeesAndLimitsSuccess()
|
|
|
|
{
|
2020-08-15 12:44:05 +02:00
|
|
|
|
2019-11-11 13:21:19 +01:00
|
|
|
$fee = new FeesAndLimits;
|
|
|
|
|
|
|
|
$fee = (array)$fee;
|
|
|
|
|
|
|
|
$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([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
|
|
|
|
|
|
|
$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([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
|
|
|
])->get('/api/v1/company_gateways/'.$this->encodePrimaryKey($cg['data']['id']));
|
|
|
|
|
|
|
|
$cg = $response->json();
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testCompanyGatewayFeesAndLimitsFails()
|
|
|
|
{
|
2020-08-15 12:44:05 +02:00
|
|
|
|
2019-11-11 13:21:19 +01:00
|
|
|
$fee_and_limit['bank_transfer'] = new FeesAndLimits;
|
|
|
|
|
|
|
|
$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([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token
|
|
|
|
])->post('/api/v1/company_gateways', $data);
|
|
|
|
|
|
|
|
|
2020-02-26 11:46:35 +01:00
|
|
|
$response->assertStatus(200);
|
2019-11-11 13:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCompanyGatewayArrayBuilder()
|
|
|
|
{
|
2020-08-15 12:44:05 +02:00
|
|
|
|
2019-11-11 13:21:19 +01:00
|
|
|
$arr = [
|
|
|
|
'min_limit' => 1,
|
|
|
|
'max_limit' => 2
|
|
|
|
];
|
|
|
|
|
|
|
|
$fal = (array)new FeesAndLimits;
|
|
|
|
|
|
|
|
$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}}
|
|
|
|
$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);
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
$this->assertEquals(10, $company_gateway->calcGatewayFee(10));
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
$this->assertEquals(10, $company_gateway->calcGatewayFee(10));
|
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|