mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Working on Autobill
This commit is contained in:
parent
c406e0771c
commit
6a11fae857
@ -48,14 +48,27 @@ class AutoBillInvoice extends AbstractService
|
||||
{
|
||||
$gateway_tokens = $this->client->gateway_tokens->orderBy('is_default', 'DESC');
|
||||
|
||||
$gateways->filter(function ($method) use ($amount) {
|
||||
if ($method->min_limit !== null && $amount < $method->min_limit) {
|
||||
return false;
|
||||
}
|
||||
$billing_gateway_token = null;
|
||||
|
||||
if ($method->max_limit !== null && $amount > $method->min_limit) {
|
||||
$gateway_tokens->filter(function ($token) use ($amount){
|
||||
|
||||
if(isset($token->gateway->fees_and_limits))
|
||||
$fees_and_limits = $token->gateway->fees_and_limits->{"1"};
|
||||
else
|
||||
return true;
|
||||
|
||||
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit)
|
||||
return false;
|
||||
|
||||
if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->min_limit)
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
|
||||
})->all()->first();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
69
tests/Feature/CompanyGatewayTest.php
Normal file
69
tests/Feature/CompanyGatewayTest.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\CompanyGateway;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers App\Models\CompanyGateway
|
||||
*/
|
||||
class CompanyGatewayTest extends TestCase
|
||||
{
|
||||
use MockAccountData;
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testGatewayExists()
|
||||
{
|
||||
|
||||
$company_gateway = CompanyGateway::first();
|
||||
$this->assertNotNull($company_gateway);
|
||||
|
||||
}
|
||||
|
||||
public function testFeesAndLimitsExists()
|
||||
{
|
||||
$data = [];
|
||||
$data[1]['min_limit'] = 234;
|
||||
$data[1]['max_limit'] = 65317;
|
||||
$data[1]['fee_amount'] = 0.00;
|
||||
$data[1]['fee_percent'] = 0.000;
|
||||
$data[1]['fee_tax_name1'] = '';
|
||||
$data[1]['fee_tax_rate1'] = '';
|
||||
$data[1]['fee_tax_name2'] = '';
|
||||
$data[1]['fee_tax_rate2'] = '';
|
||||
$data[1]['fee_tax_name3'] = '';
|
||||
$data[1]['fee_tax_rate3'] = 0;
|
||||
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $this->company->id;
|
||||
$cg->user_id = $this->user->id;
|
||||
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
||||
$cg->require_cvv = true;
|
||||
$cg->show_billing_address = true;
|
||||
$cg->show_shipping_address = true;
|
||||
$cg->update_details = true;
|
||||
$cg->config = encrypt(config('ninja.testvars.stripe'));
|
||||
$cg->fees_and_limits = $data;
|
||||
$cg->save();
|
||||
|
||||
$this->assertNotNull($cg->fees_and_limits);
|
||||
$this->assertNotNull($cg->fees_and_limits->{"1"});
|
||||
|
||||
|
||||
//confirm amount filtering works
|
||||
}
|
||||
}
|
@ -11,9 +11,11 @@
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\DataMapper\BaseSettings;
|
||||
use App\DataMapper\ClientSettings;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\DataMapper\FeesAndLimits;
|
||||
use App\Factory\ClientFactory;
|
||||
use App\Factory\CompanyUserFactory;
|
||||
use App\Factory\CreditFactory;
|
||||
@ -32,6 +34,7 @@ use App\Models\InvoiceInvitation;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Support\Carbon;
|
||||
@ -341,17 +344,18 @@ trait MockAccountData
|
||||
$gs->save();
|
||||
|
||||
if (config('ninja.testvars.stripe')) {
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $this->company->id;
|
||||
$cg->user_id = $this->user->id;
|
||||
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
||||
$cg->require_cvv = true;
|
||||
$cg->show_billing_address = true;
|
||||
$cg->show_shipping_address = true;
|
||||
$cg->update_details = true;
|
||||
$cg->config = encrypt(config('ninja.testvars.stripe'));
|
||||
$cg->save();
|
||||
|
||||
$data = [];
|
||||
$data[1]['min_limit'] = 234;
|
||||
$data[1]['max_limit'] = 65317;
|
||||
$data[1]['fee_amount'] = 0.00;
|
||||
$data[1]['fee_percent'] = 0.000;
|
||||
$data[1]['fee_tax_name1'] = '';
|
||||
$data[1]['fee_tax_rate1'] = '';
|
||||
$data[1]['fee_tax_name2'] = '';
|
||||
$data[1]['fee_tax_rate2'] = '';
|
||||
$data[1]['fee_tax_name3'] = '';
|
||||
$data[1]['fee_tax_rate3'] = 0;
|
||||
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $this->company->id;
|
||||
@ -362,11 +366,26 @@ trait MockAccountData
|
||||
$cg->show_shipping_address = true;
|
||||
$cg->update_details = true;
|
||||
$cg->config = encrypt(config('ninja.testvars.stripe'));
|
||||
$cg->fees_and_limits = $data;
|
||||
$cg->save();
|
||||
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $this->company->id;
|
||||
$cg->user_id = $this->user->id;
|
||||
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
||||
$cg->require_cvv = true;
|
||||
$cg->show_billing_address = true;
|
||||
$cg->show_shipping_address = true;
|
||||
$cg->update_details = true;
|
||||
$cg->fees_and_limits = $data;
|
||||
$cg->config = encrypt(config('ninja.testvars.stripe'));
|
||||
$cg->save();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function buildLineItems()
|
||||
{
|
||||
$line_items = [];
|
||||
@ -377,46 +396,6 @@ trait MockAccountData
|
||||
|
||||
$line_items[] = $item;
|
||||
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
// $line_items[] = $item;
|
||||
|
||||
return $line_items;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user