mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 12:34:35 -04:00
Fixes for tests
This commit is contained in:
parent
5698a8a8d1
commit
3ec593f7ef
@ -44,7 +44,7 @@ class ClientGatewayToken extends BaseModel
|
|||||||
|
|
||||||
public function gateway()
|
public function gateway()
|
||||||
{
|
{
|
||||||
return $this->hasOne(CompanyGateway::class);
|
return $this->belongsTo(CompanyGateway::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function gateway_type()
|
public function gateway_type()
|
||||||
|
@ -46,29 +46,47 @@ class AutoBillInvoice extends AbstractService
|
|||||||
|
|
||||||
private function getGateway($amount)
|
private function getGateway($amount)
|
||||||
{
|
{
|
||||||
|
|
||||||
$gateway_tokens = $this->client->gateway_tokens->orderBy('is_default', 'DESC');
|
$gateway_tokens = $this->client->gateway_tokens->orderBy('is_default', 'DESC');
|
||||||
|
|
||||||
$billing_gateway_token = null;
|
$billing_gateway_token = null;
|
||||||
|
|
||||||
$gateway_tokens->filter(function ($token) use ($amount){
|
$gateway_tokens->filter(function ($token) use ($amount){
|
||||||
|
|
||||||
if(isset($token->gateway->fees_and_limits))
|
return $this->validGatewayLimits($token, $amount);
|
||||||
$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();
|
})->all()->first();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a given gateway token is able
|
||||||
|
* to process the payment after passing through the
|
||||||
|
* fees and limits check
|
||||||
|
*
|
||||||
|
* @param CompanyGateway $cg The CompanyGateway instance
|
||||||
|
* @param float $amount The amount to be paid
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validGatewayLimits($cg, $amount) : bool
|
||||||
|
{
|
||||||
|
if(isset($cg->fees_and_limits))
|
||||||
|
$fees_and_limits = $cg->fees_and_limits->{"1"};
|
||||||
|
else
|
||||||
|
$passes = true;
|
||||||
|
|
||||||
|
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit) {
|
||||||
|
info("amount {$amount} less than ". $fees_and_limits->min_limit);
|
||||||
|
$passes = false;
|
||||||
|
}
|
||||||
|
else if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->max_limit){
|
||||||
|
info("amount {$amount} greater than ". $fees_and_limits->max_limit);
|
||||||
|
$passes = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$passes = true;
|
||||||
|
|
||||||
|
return $passes;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@ class CompanyGatewayTest extends TestCase
|
|||||||
|
|
||||||
$this->makeTestData();
|
$this->makeTestData();
|
||||||
|
|
||||||
|
if (!config('ninja.testvars.stripe')) {
|
||||||
|
$this->markTestSkipped('Skip test no company gateways installed');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGatewayExists()
|
public function testGatewayExists()
|
||||||
@ -67,59 +69,36 @@ class CompanyGatewayTest extends TestCase
|
|||||||
//confirm amount filtering works
|
//confirm amount filtering works
|
||||||
$amount = 100;
|
$amount = 100;
|
||||||
|
|
||||||
if(isset($cg->fees_and_limits))
|
$this->assertFalse($this->checkSieve($cg, $amount));
|
||||||
$fees_and_limits = $cg->fees_and_limits->{"1"};
|
|
||||||
else
|
|
||||||
$passes = true;
|
|
||||||
|
|
||||||
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit)
|
|
||||||
$passes = false;
|
|
||||||
else if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->max_limit)
|
|
||||||
$passes = false;
|
|
||||||
else
|
|
||||||
$passes = true;
|
|
||||||
|
|
||||||
$this->assertFalse($passes);
|
|
||||||
|
|
||||||
$amount = 235;
|
$amount = 235;
|
||||||
|
|
||||||
if(isset($cg->fees_and_limits))
|
$this->assertTrue($this->checkSieve($cg, $amount));
|
||||||
$fees_and_limits = $cg->fees_and_limits->{"1"};
|
|
||||||
else
|
|
||||||
$passes = true;
|
|
||||||
|
|
||||||
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit) {
|
|
||||||
info("amount {$amount} less than ". $fees_and_limits->min_limit);
|
|
||||||
$passes = false;
|
|
||||||
}
|
|
||||||
else if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->max_limit){
|
|
||||||
info("amount {$amount} greater than ". $fees_and_limits->max_limit);
|
|
||||||
$passes = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$passes = true;
|
|
||||||
|
|
||||||
$this->assertTrue($passes);
|
|
||||||
|
|
||||||
$amount = 70000;
|
$amount = 70000;
|
||||||
|
|
||||||
if(isset($cg->fees_and_limits))
|
$this->assertFalse($this->checkSieve($cg, $amount));
|
||||||
$fees_and_limits = $cg->fees_and_limits->{"1"};
|
|
||||||
else
|
|
||||||
$passes = true;
|
|
||||||
|
|
||||||
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit) {
|
|
||||||
info("amount {$amount} less than ". $fees_and_limits->min_limit);
|
|
||||||
$passes = false;
|
|
||||||
}
|
|
||||||
else if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->max_limit){
|
|
||||||
info("amount {$amount} greater than ". $fees_and_limits->max_limit);
|
|
||||||
$passes = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$passes = true;
|
|
||||||
|
|
||||||
$this->assertFalse($passes);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkSieve($cg, $amount)
|
||||||
|
{
|
||||||
|
if(isset($cg->fees_and_limits))
|
||||||
|
$fees_and_limits = $cg->fees_and_limits->{"1"};
|
||||||
|
else
|
||||||
|
$passes = true;
|
||||||
|
|
||||||
|
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit) {
|
||||||
|
info("amount {$amount} less than ". $fees_and_limits->min_limit);
|
||||||
|
$passes = false;
|
||||||
|
}
|
||||||
|
else if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->max_limit){
|
||||||
|
info("amount {$amount} greater than ". $fees_and_limits->max_limit);
|
||||||
|
$passes = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$passes = true;
|
||||||
|
|
||||||
|
return $passes;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user