mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Fixes for tests
This commit is contained in:
parent
5698a8a8d1
commit
3ec593f7ef
@ -44,7 +44,7 @@ class ClientGatewayToken extends BaseModel
|
||||
|
||||
public function gateway()
|
||||
{
|
||||
return $this->hasOne(CompanyGateway::class);
|
||||
return $this->belongsTo(CompanyGateway::class);
|
||||
}
|
||||
|
||||
public function gateway_type()
|
||||
|
@ -46,29 +46,47 @@ class AutoBillInvoice extends AbstractService
|
||||
|
||||
private function getGateway($amount)
|
||||
{
|
||||
|
||||
$gateway_tokens = $this->client->gateway_tokens->orderBy('is_default', 'DESC');
|
||||
|
||||
$billing_gateway_token = null;
|
||||
|
||||
$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;
|
||||
return $this->validGatewayLimits($token, $amount);
|
||||
|
||||
})->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();
|
||||
|
||||
|
||||
if (!config('ninja.testvars.stripe')) {
|
||||
$this->markTestSkipped('Skip test no company gateways installed');
|
||||
}
|
||||
}
|
||||
|
||||
public function testGatewayExists()
|
||||
@ -67,59 +69,36 @@ class CompanyGatewayTest extends TestCase
|
||||
//confirm amount filtering works
|
||||
$amount = 100;
|
||||
|
||||
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)
|
||||
$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);
|
||||
$this->assertFalse($this->checkSieve($cg, $amount));
|
||||
|
||||
$amount = 235;
|
||||
|
||||
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;
|
||||
|
||||
$this->assertTrue($passes);
|
||||
$this->assertTrue($this->checkSieve($cg, $amount));
|
||||
|
||||
$amount = 70000;
|
||||
|
||||
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;
|
||||
|
||||
$this->assertFalse($passes);
|
||||
$this->assertFalse($this->checkSieve($cg, $amount));
|
||||
|
||||
}
|
||||
|
||||
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…
Reference in New Issue
Block a user