mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactoring gateway fees and limits
This commit is contained in:
parent
046805995a
commit
f063337ec4
@ -226,19 +226,21 @@ class CompanyGateway extends BaseModel
|
||||
return $this->getConfigField('publishableKey');
|
||||
}
|
||||
|
||||
public function getFeesAndLimits()
|
||||
public function getFeesAndLimits($gateway_type_id)
|
||||
{
|
||||
if (is_null($this->fees_and_limits) || empty($this->fees_and_limits)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fees_and_limits = new \stdClass;
|
||||
return $this->fees_and_limits->{$gateway_type_id};
|
||||
|
||||
foreach ($this->fees_and_limits as $key => $value) {
|
||||
$fees_and_limits = $this->fees_and_limits->{$key};
|
||||
}
|
||||
// $fees_and_limits = new \stdClass;
|
||||
|
||||
return $fees_and_limits;
|
||||
// foreach ($this->fees_and_limits as $key => $value) {
|
||||
// $fees_and_limits = $this->fees_and_limits->{$key};
|
||||
// }
|
||||
|
||||
// return $fees_and_limits;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,7 +250,7 @@ class CompanyGateway extends BaseModel
|
||||
* @param Client $client The client object
|
||||
* @return string The fee amount formatted in the client currency
|
||||
*/
|
||||
public function calcGatewayFeeLabel($amount, Client $client) :string
|
||||
public function calcGatewayFeeLabel($amount, Client $client, GatewayType $gateway_type_id = GatewayType::CREDIT_CARD) :string
|
||||
{
|
||||
$label = '';
|
||||
|
||||
@ -256,7 +258,7 @@ class CompanyGateway extends BaseModel
|
||||
return $label;
|
||||
}
|
||||
|
||||
$fee = $this->calcGatewayFee($amount);
|
||||
$fee = $this->calcGatewayFee($amount, $gateway_type_id);
|
||||
|
||||
if ($fee > 0) {
|
||||
$fee = Number::formatMoney(round($fee, 2), $client);
|
||||
@ -266,12 +268,9 @@ class CompanyGateway extends BaseModel
|
||||
return $label;
|
||||
}
|
||||
|
||||
public function calcGatewayFee($amount, $include_taxes = false)
|
||||
public function calcGatewayFee($amount, $include_taxes = false, GatewayType $gateway_type_id = GatewayType::CREDIT_CARD)
|
||||
{
|
||||
$fees_and_limits = $this->getFeesAndLimits();
|
||||
//dd($fees_and_limits);
|
||||
//
|
||||
// info(var_dump($$fees_and_limits));
|
||||
$fees_and_limits = $this->getFeesAndLimits($gateway_type_id);
|
||||
|
||||
if (! $fees_and_limits) {
|
||||
return 0;
|
||||
|
@ -79,7 +79,7 @@ class AutoBillInvoice extends AbstractService
|
||||
/* $gateway fee */
|
||||
$fee = $gateway_token->gateway->calcGatewayFee($amount);
|
||||
|
||||
//determine exact fee as per PaymentController
|
||||
//todo determine exact fee as per PaymentController
|
||||
|
||||
/* Build payment hash */
|
||||
$payment_hash = PaymentHash::create([
|
||||
|
@ -10,6 +10,7 @@
|
||||
*/
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\DataMapper\FeesAndLimits;
|
||||
use App\Factory\CreditFactory;
|
||||
use App\Factory\InvoiceItemFactory;
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
@ -60,6 +61,49 @@ class CompanyGatewayResolutionTest extends TestCase
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
|
||||
$data = [];
|
||||
$data[1]['min_limit'] = -1;
|
||||
$data[1]['max_limit'] = -1;
|
||||
$data[1]['fee_amount'] = 1.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]['fee_cap'] = 0;
|
||||
|
||||
$json_config = config('ninja.testvars.stripe');
|
||||
$json_config->enable_ach = "0";
|
||||
|
||||
//disable ach here
|
||||
$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(json_encode($json_config));
|
||||
$cg->fees_and_limits = $data;
|
||||
$cg->save();
|
||||
|
||||
$data = [];
|
||||
$data[2]['min_limit'] = -1;
|
||||
$data[2]['max_limit'] = -1;
|
||||
$data[2]['fee_amount'] = 1.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]['fee_cap'] = 0;
|
||||
|
||||
//ensable ach here
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $this->company->id;
|
||||
$cg->user_id = $this->user->id;
|
||||
@ -69,11 +113,14 @@ class CompanyGatewayResolutionTest extends TestCase
|
||||
$cg->show_shipping_address = true;
|
||||
$cg->update_details = true;
|
||||
$cg->config = encrypt(config('ninja.testvars.stripe'));
|
||||
$cg->fees_and_limits = $data;
|
||||
$cg->save();
|
||||
}
|
||||
|
||||
public function testGatewayResolution()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
|
||||
//i want to test here resolution of bank_transfers inside and outside of fees and limits.
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\GatewayType;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Tests\MockAccountData;
|
||||
@ -178,12 +179,12 @@ class CompanyGatewayTest extends TestCase
|
||||
|
||||
$total = 10.93;
|
||||
$total_invoice_count = 5;
|
||||
$total_gateway_fee = round($cg->calcGatewayFee($total, true), 2);
|
||||
$total_gateway_fee = round($cg->calcGatewayFee($total, true, GatewayType::CREDIT_CARD), 2);
|
||||
|
||||
$this->assertEquals(1.58, $total_gateway_fee);
|
||||
|
||||
/*simple pro rata*/
|
||||
$fees_and_limits = $cg->getFeesAndLimits();
|
||||
$fees_and_limits = $cg->getFeesAndLimits(GatewayType::CREDIT_CARD);
|
||||
|
||||
/*Calculate all subcomponents of the fee*/
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user