2020-10-12 06:30:53 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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-10-12 06:30:53 +02:00
|
|
|
*
|
2022-06-08 06:25:44 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-10-12 06:30:53 +02:00
|
|
|
*/
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\CompanyGateway;
|
2020-10-12 11:38:55 +02:00
|
|
|
use App\Models\GatewayType;
|
2020-10-12 06:30:53 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
class CompanyGatewayResolutionTest extends TestCase
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
use MockAccountData;
|
|
|
|
|
2020-10-12 11:38:55 +02:00
|
|
|
public $cg;
|
|
|
|
|
|
|
|
public $cg1;
|
|
|
|
|
2020-10-12 06:30:53 +02:00
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->withoutMiddleware(
|
|
|
|
ThrottleRequests::class
|
|
|
|
);
|
|
|
|
|
|
|
|
if (! config('ninja.testvars.stripe')) {
|
|
|
|
$this->markTestSkipped('Skip test no company gateways installed');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
|
|
|
|
$this->withoutExceptionHandling();
|
|
|
|
|
2021-01-27 02:06:25 +01:00
|
|
|
CompanyGateway::whereNotNull('id')->delete();
|
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
$data = [];
|
|
|
|
$data[1]['min_limit'] = -1;
|
|
|
|
$data[1]['max_limit'] = -1;
|
|
|
|
$data[1]['fee_amount'] = 0.00;
|
|
|
|
$data[1]['fee_percent'] = 2;
|
|
|
|
$data[1]['fee_tax_name1'] = 'GST';
|
|
|
|
$data[1]['fee_tax_rate1'] = 10;
|
|
|
|
$data[1]['fee_tax_name2'] = 'GST';
|
|
|
|
$data[1]['fee_tax_rate2'] = 10;
|
|
|
|
$data[1]['fee_tax_name3'] = 'GST';
|
|
|
|
$data[1]['fee_tax_rate3'] = 10;
|
2022-03-16 11:50:22 +01:00
|
|
|
$data[1]['adjust_fee_percent'] = false;
|
2020-11-25 15:19:52 +01:00
|
|
|
$data[1]['fee_cap'] = 0;
|
2021-01-27 02:06:25 +01:00
|
|
|
$data[1]['is_enabled'] = true;
|
2020-11-25 15:19:52 +01:00
|
|
|
|
|
|
|
$data[2]['min_limit'] = -1;
|
|
|
|
$data[2]['max_limit'] = -1;
|
|
|
|
$data[2]['fee_amount'] = 0.00;
|
|
|
|
$data[2]['fee_percent'] = 1;
|
|
|
|
$data[2]['fee_tax_name1'] = 'GST';
|
|
|
|
$data[2]['fee_tax_rate1'] = 10;
|
|
|
|
$data[2]['fee_tax_name2'] = 'GST';
|
|
|
|
$data[2]['fee_tax_rate2'] = 10;
|
|
|
|
$data[2]['fee_tax_name3'] = 'GST';
|
|
|
|
$data[2]['fee_tax_rate3'] = 10;
|
2022-03-16 11:50:22 +01:00
|
|
|
$data[2]['adjust_fee_percent'] = false;
|
2020-11-25 15:19:52 +01:00
|
|
|
$data[2]['fee_cap'] = 0;
|
2021-01-27 02:06:25 +01:00
|
|
|
$data[2]['is_enabled'] = true;
|
2020-11-25 15:19:52 +01:00
|
|
|
|
|
|
|
//disable ach here
|
|
|
|
$json_config = json_decode(config('ninja.testvars.stripe'));
|
|
|
|
|
|
|
|
$this->cg = new CompanyGateway;
|
|
|
|
$this->cg->company_id = $this->company->id;
|
|
|
|
$this->cg->user_id = $this->user->id;
|
|
|
|
$this->cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
|
|
|
$this->cg->require_cvv = true;
|
|
|
|
$this->cg->require_billing_address = true;
|
|
|
|
$this->cg->require_shipping_address = true;
|
|
|
|
$this->cg->update_details = true;
|
|
|
|
$this->cg->config = encrypt(json_encode($json_config));
|
|
|
|
$this->cg->fees_and_limits = $data;
|
|
|
|
$this->cg->save();
|
2020-10-12 06:30:53 +02:00
|
|
|
}
|
|
|
|
|
2020-10-12 11:38:55 +02:00
|
|
|
/**
|
|
|
|
* @covers \App\Models\CompanyGateway::calcGatewayFee()
|
|
|
|
*/
|
2020-10-12 06:30:53 +02:00
|
|
|
public function testGatewayResolution()
|
|
|
|
{
|
2021-01-04 14:07:50 +01:00
|
|
|
$fee = $this->cg->calcGatewayFee(10, GatewayType::CREDIT_CARD, false);
|
2020-10-12 11:38:55 +02:00
|
|
|
$this->assertEquals(0.2, $fee);
|
2020-10-12 06:30:53 +02:00
|
|
|
}
|
2020-10-12 13:02:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \App|Models\Client::validGatewayForAmount()
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function testValidationForGatewayAmount()
|
|
|
|
{
|
|
|
|
$this->assertTrue($this->client->validGatewayForAmount($this->cg->fees_and_limits->{1}, 10));
|
|
|
|
$this->assertTrue($this->client->validGatewayForAmount($this->cg->fees_and_limits->{2}, 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAvailablePaymentMethodsCount()
|
|
|
|
{
|
|
|
|
$amount = 10;
|
|
|
|
|
|
|
|
$this->assertInstanceOf("\\stdClass", $this->cg->fees_and_limits);
|
2020-11-25 15:19:52 +01:00
|
|
|
$this->assertObjectHasAttribute('min_limit', $this->cg->fees_and_limits->{1});
|
2020-10-12 13:02:02 +02:00
|
|
|
|
2021-01-27 02:06:25 +01:00
|
|
|
$payment_methods = $this->client->service()->getPaymentMethods($amount);
|
2020-10-12 13:02:02 +02:00
|
|
|
|
2021-01-29 14:06:29 +01:00
|
|
|
$this->assertEquals(2, count($payment_methods));
|
2020-10-12 13:02:02 +02:00
|
|
|
}
|
|
|
|
|
2021-01-27 02:06:25 +01:00
|
|
|
public function testRemoveMethods()
|
2020-10-12 13:02:02 +02:00
|
|
|
{
|
2021-01-27 02:06:25 +01:00
|
|
|
$amount = 10;
|
|
|
|
|
|
|
|
CompanyGateway::whereNotNull('id')->delete();
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
$data[1]['min_limit'] = -1;
|
|
|
|
$data[1]['max_limit'] = -1;
|
|
|
|
$data[1]['fee_amount'] = 0.00;
|
|
|
|
$data[1]['fee_percent'] = 2;
|
|
|
|
$data[1]['fee_tax_name1'] = 'GST';
|
|
|
|
$data[1]['fee_tax_rate1'] = 10;
|
|
|
|
$data[1]['fee_tax_name2'] = 'GST';
|
|
|
|
$data[1]['fee_tax_rate2'] = 10;
|
|
|
|
$data[1]['fee_tax_name3'] = 'GST';
|
|
|
|
$data[1]['fee_tax_rate3'] = 10;
|
|
|
|
$data[1]['adjust_fee_percent'] = true;
|
|
|
|
$data[1]['fee_cap'] = 0;
|
|
|
|
$data[1]['is_enabled'] = true;
|
|
|
|
|
|
|
|
$data[2]['min_limit'] = -1;
|
|
|
|
$data[2]['max_limit'] = -1;
|
|
|
|
$data[2]['fee_amount'] = 0.00;
|
|
|
|
$data[2]['fee_percent'] = 1;
|
|
|
|
$data[2]['fee_tax_name1'] = 'GST';
|
|
|
|
$data[2]['fee_tax_rate1'] = 10;
|
|
|
|
$data[2]['fee_tax_name2'] = 'GST';
|
|
|
|
$data[2]['fee_tax_rate2'] = 10;
|
|
|
|
$data[2]['fee_tax_name3'] = 'GST';
|
|
|
|
$data[2]['fee_tax_rate3'] = 10;
|
|
|
|
$data[2]['adjust_fee_percent'] = true;
|
|
|
|
$data[2]['fee_cap'] = 0;
|
|
|
|
$data[2]['is_enabled'] = false;
|
|
|
|
|
|
|
|
//disable ach here
|
|
|
|
$json_config = json_decode(config('ninja.testvars.stripe'));
|
2020-10-12 13:02:02 +02:00
|
|
|
|
2021-01-27 02:06:25 +01:00
|
|
|
$this->cg = new CompanyGateway;
|
|
|
|
$this->cg->company_id = $this->company->id;
|
|
|
|
$this->cg->user_id = $this->user->id;
|
|
|
|
$this->cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
|
|
|
$this->cg->require_cvv = true;
|
|
|
|
$this->cg->require_billing_address = true;
|
|
|
|
$this->cg->require_shipping_address = true;
|
|
|
|
$this->cg->update_details = true;
|
|
|
|
$this->cg->config = encrypt(json_encode($json_config));
|
|
|
|
$this->cg->fees_and_limits = $data;
|
2020-10-12 13:02:02 +02:00
|
|
|
$this->cg->save();
|
|
|
|
|
2021-01-27 02:06:25 +01:00
|
|
|
// nlog($this->client->service()->getPaymentMethods($amount));
|
|
|
|
|
|
|
|
$this->assertEquals(2, count($this->client->service()->getPaymentMethods($amount)));
|
2020-10-12 13:02:02 +02:00
|
|
|
|
|
|
|
}
|
2022-03-16 11:50:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
public function testEnableFeeAdjustment()
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
$data[1]['min_limit'] = -1;
|
|
|
|
$data[1]['max_limit'] = -1;
|
|
|
|
$data[1]['fee_amount'] = 0.3;
|
|
|
|
$data[1]['fee_percent'] = 1.75;
|
|
|
|
$data[1]['fee_tax_name1'] = '';
|
|
|
|
$data[1]['fee_tax_rate1'] = 0;
|
|
|
|
$data[1]['fee_tax_name2'] = '';
|
|
|
|
$data[1]['fee_tax_rate2'] = 0;
|
|
|
|
$data[1]['fee_tax_name3'] = '';
|
|
|
|
$data[1]['fee_tax_rate3'] = 0;
|
|
|
|
$data[1]['adjust_fee_percent'] = true;
|
|
|
|
$data[1]['fee_cap'] = 0;
|
|
|
|
$data[1]['is_enabled'] = true;
|
|
|
|
|
|
|
|
$data[2]['min_limit'] = -1;
|
|
|
|
$data[2]['max_limit'] = -1;
|
|
|
|
$data[2]['fee_amount'] = 0.30;
|
|
|
|
$data[2]['fee_percent'] = 1.75;
|
|
|
|
$data[2]['fee_tax_name1'] = '';
|
|
|
|
$data[2]['fee_tax_rate1'] = 0;
|
|
|
|
$data[2]['fee_tax_name2'] = '';
|
|
|
|
$data[2]['fee_tax_rate2'] = 0;
|
|
|
|
$data[2]['fee_tax_name3'] = '';
|
|
|
|
$data[2]['fee_tax_rate3'] = 0;
|
|
|
|
$data[2]['adjust_fee_percent'] = true;
|
|
|
|
$data[2]['fee_cap'] = 0;
|
|
|
|
$data[2]['is_enabled'] = true;
|
|
|
|
|
|
|
|
//disable ach here
|
|
|
|
$json_config = json_decode(config('ninja.testvars.stripe'));
|
|
|
|
|
|
|
|
$this->cg = new CompanyGateway;
|
|
|
|
$this->cg->company_id = $this->company->id;
|
|
|
|
$this->cg->user_id = $this->user->id;
|
|
|
|
$this->cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
|
|
|
$this->cg->require_cvv = true;
|
|
|
|
$this->cg->require_billing_address = true;
|
|
|
|
$this->cg->require_shipping_address = true;
|
|
|
|
$this->cg->update_details = true;
|
|
|
|
$this->cg->config = encrypt(json_encode($json_config));
|
|
|
|
$this->cg->fees_and_limits = $data;
|
|
|
|
$this->cg->save();
|
|
|
|
|
|
|
|
|
|
|
|
$fee = $this->cg->calcGatewayFee(89, GatewayType::CREDIT_CARD, false);
|
|
|
|
$this->assertEquals(1.89, $fee);
|
|
|
|
|
|
|
|
}
|
2020-10-12 06:30:53 +02:00
|
|
|
}
|