Fixes for tests

This commit is contained in:
David Bomba 2020-10-12 20:38:55 +11:00
parent f063337ec4
commit 65a1f150d5
7 changed files with 72 additions and 35 deletions

View File

@ -176,7 +176,7 @@ class PaymentController extends Controller
// $fee_totals += $fee_tax; // $fee_totals += $fee_tax;
// } // }
$first_invoice->service()->addGatewayFee($gateway, $invoice_totals)->save(); $first_invoice->service()->addGatewayFee($gateway, $payment_method_id, $invoice_totals)->save();
/** /**
* *

View File

@ -232,6 +232,8 @@ class CompanyGateway extends BaseModel
return false; return false;
} }
info(print_r($this->fees_and_limits,1));
return $this->fees_and_limits->{$gateway_type_id}; return $this->fees_and_limits->{$gateway_type_id};
// $fees_and_limits = new \stdClass; // $fees_and_limits = new \stdClass;
@ -250,7 +252,7 @@ class CompanyGateway extends BaseModel
* @param Client $client The client object * @param Client $client The client object
* @return string The fee amount formatted in the client currency * @return string The fee amount formatted in the client currency
*/ */
public function calcGatewayFeeLabel($amount, Client $client, GatewayType $gateway_type_id = GatewayType::CREDIT_CARD) :string public function calcGatewayFeeLabel($amount, Client $client, $gateway_type_id = GatewayType::CREDIT_CARD) :string
{ {
$label = ''; $label = '';
@ -268,8 +270,10 @@ class CompanyGateway extends BaseModel
return $label; return $label;
} }
public function calcGatewayFee($amount, $include_taxes = false, GatewayType $gateway_type_id = GatewayType::CREDIT_CARD) public function calcGatewayFee($amount, $include_taxes = false, $gateway_type_id = GatewayType::CREDIT_CARD)
{ {
info($gateway_type_id);
$fees_and_limits = $this->getFeesAndLimits($gateway_type_id); $fees_and_limits = $this->getFeesAndLimits($gateway_type_id);
if (! $fees_and_limits) { if (! $fees_and_limits) {

View File

@ -31,18 +31,22 @@ class AddGatewayFee extends AbstractService
private $amount; private $amount;
public function __construct(CompanyGateway $company_gateway, Invoice $invoice, float $amount) private $gateway_type_id;
public function __construct(CompanyGateway $company_gateway, int $gateway_type_id, Invoice $invoice, float $amount)
{ {
$this->company_gateway = $company_gateway; $this->company_gateway = $company_gateway;
$this->invoice = $invoice; $this->invoice = $invoice;
$this->amount = $amount; $this->amount = $amount;
$this->gateway_type_id = $gateway_type_id;
} }
public function run() public function run()
{ {
$gateway_fee = round($this->company_gateway->calcGatewayFee($this->amount), $this->invoice->client->currency()->precision); $gateway_fee = round($this->company_gateway->calcGatewayFee($this->amount, $this->gateway_type_id), $this->invoice->client->currency()->precision);
if((int)$gateway_fee == 0) if((int)$gateway_fee == 0)
return $this->invoice; return $this->invoice;
@ -78,7 +82,7 @@ class AddGatewayFee extends AbstractService
$invoice_item->quantity = 1; $invoice_item->quantity = 1;
$invoice_item->cost = $gateway_fee; $invoice_item->cost = $gateway_fee;
if ($fees_and_limits = $this->company_gateway->getFeesAndLimits()) { if ($fees_and_limits = $this->company_gateway->getFeesAndLimits($this->gateway_type_id)) {
$invoice_item->tax_rate1 = $fees_and_limits->fee_tax_rate1; $invoice_item->tax_rate1 = $fees_and_limits->fee_tax_rate1;
$invoice_item->tax_rate2 = $fees_and_limits->fee_tax_rate2; $invoice_item->tax_rate2 = $fees_and_limits->fee_tax_rate2;
$invoice_item->tax_rate3 = $fees_and_limits->fee_tax_rate3; $invoice_item->tax_rate3 = $fees_and_limits->fee_tax_rate3;

View File

@ -93,9 +93,9 @@ class InvoiceService
return $this; return $this;
} }
public function addGatewayFee(CompanyGateway $company_gateway, float $amount) public function addGatewayFee(CompanyGateway $company_gateway, $gateway_type_id, float $amount)
{ {
$this->invoice = (new AddGatewayFee($company_gateway, $this->invoice, $amount))->run(); $this->invoice = (new AddGatewayFee($company_gateway, $gateway_type_id, $this->invoice, $amount))->run();
return $this; return $this;
} }

View File

@ -95,6 +95,7 @@ class InvoiceTransformer extends EntityTransformer
'vendor_id' => (string) $this->encodePrimaryKey($invoice->vendor_id), 'vendor_id' => (string) $this->encodePrimaryKey($invoice->vendor_id),
'status_id' => (string) ($invoice->status_id ?: 1), 'status_id' => (string) ($invoice->status_id ?: 1),
'design_id' => (string) $this->encodePrimaryKey($invoice->design_id), 'design_id' => (string) $this->encodePrimaryKey($invoice->design_id),
'recurring_id' => (string) $this->encodePrimaryKey($invoice->recurring_id),
'created_at' => (int) $invoice->created_at, 'created_at' => (int) $invoice->created_at,
'updated_at' => (int) $invoice->updated_at, 'updated_at' => (int) $invoice->updated_at,
'archived_at' => (int) $invoice->deleted_at, 'archived_at' => (int) $invoice->deleted_at,

View File

@ -18,6 +18,7 @@ use App\Listeners\Credit\CreateCreditInvitation;
use App\Models\Client; use App\Models\Client;
use App\Models\CompanyGateway; use App\Models\CompanyGateway;
use App\Models\Credit; use App\Models\Credit;
use App\Models\GatewayType;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Payment; use App\Models\Payment;
use App\Models\Paymentable; use App\Models\Paymentable;
@ -41,6 +42,10 @@ class CompanyGatewayResolutionTest extends TestCase
use DatabaseTransactions; use DatabaseTransactions;
use MockAccountData; use MockAccountData;
public $cg;
public $cg1;
public function setUp() :void public function setUp() :void
{ {
parent::setUp(); parent::setUp();
@ -64,7 +69,7 @@ class CompanyGatewayResolutionTest extends TestCase
$data = []; $data = [];
$data[1]['min_limit'] = -1; $data[1]['min_limit'] = -1;
$data[1]['max_limit'] = -1; $data[1]['max_limit'] = -1;
$data[1]['fee_amount'] = 1.00; $data[1]['fee_amount'] = 0.00;
$data[1]['fee_percent'] = 2; $data[1]['fee_percent'] = 2;
$data[1]['fee_tax_name1'] = 'GST'; $data[1]['fee_tax_name1'] = 'GST';
$data[1]['fee_tax_rate1'] = 10; $data[1]['fee_tax_rate1'] = 10;
@ -74,21 +79,33 @@ class CompanyGatewayResolutionTest extends TestCase
$data[1]['fee_tax_rate3'] = 10; $data[1]['fee_tax_rate3'] = 10;
$data[1]['fee_cap'] = 0; $data[1]['fee_cap'] = 0;
$json_config = config('ninja.testvars.stripe'); $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]['fee_cap'] = 0;
$json_config = json_decode(config('ninja.testvars.stripe'));
$json_config->enable_ach = "0"; $json_config->enable_ach = "0";
//disable ach here //disable ach here
$cg = new CompanyGateway; $this->cg = new CompanyGateway;
$cg->company_id = $this->company->id; $this->cg->company_id = $this->company->id;
$cg->user_id = $this->user->id; $this->cg->user_id = $this->user->id;
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $this->cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
$cg->require_cvv = true; $this->cg->require_cvv = true;
$cg->show_billing_address = true; $this->cg->show_billing_address = true;
$cg->show_shipping_address = true; $this->cg->show_shipping_address = true;
$cg->update_details = true; $this->cg->update_details = true;
$cg->config = encrypt(json_encode($json_config)); $this->cg->config = encrypt(json_encode($json_config));
$cg->fees_and_limits = $data; $this->cg->fees_and_limits = $data;
$cg->save(); $this->cg->save();
$data = []; $data = [];
$data[2]['min_limit'] = -1; $data[2]['min_limit'] = -1;
@ -104,23 +121,34 @@ class CompanyGatewayResolutionTest extends TestCase
$data[2]['fee_cap'] = 0; $data[2]['fee_cap'] = 0;
//ensable ach here //ensable ach here
$cg = new CompanyGateway; $this->cg1 = new CompanyGateway;
$cg->company_id = $this->company->id; $this->cg1->company_id = $this->company->id;
$cg->user_id = $this->user->id; $this->cg1->user_id = $this->user->id;
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $this->cg1->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
$cg->require_cvv = true; $this->cg1->require_cvv = true;
$cg->show_billing_address = true; $this->cg1->show_billing_address = true;
$cg->show_shipping_address = true; $this->cg1->show_shipping_address = true;
$cg->update_details = true; $this->cg1->update_details = true;
$cg->config = encrypt(config('ninja.testvars.stripe')); $this->cg1->config = encrypt(config('ninja.testvars.stripe'));
$cg->fees_and_limits = $data; $this->cg1->fees_and_limits = $data;
$cg->save(); $this->cg1->save();
} }
/**
* @covers \App\Models\CompanyGateway::calcGatewayFee()
*/
public function testGatewayResolution() public function testGatewayResolution()
{ {
$this->assertTrue(true);
//i want to test here resolution of bank_transfers inside and outside of fees and limits. //i want to test here resolution of bank_transfers inside and outside of fees and limits.
$fee = $this->cg->calcGatewayFee(10, false, GatewayType::CREDIT_CARD);
$this->assertEquals(0.2, $fee);
$fee = $this->cg->calcGatewayFee(10, false, GatewayType::BANK_TRANSFER);
$this->assertEquals(0.1, $fee);
} }
} }

View File

@ -142,7 +142,7 @@ class CompanyGatewayTest extends TestCase
$balance = $this->invoice->balance; $balance = $this->invoice->balance;
$this->invoice = $this->invoice->service()->addGatewayFee($cg, $this->invoice->balance)->save(); $this->invoice = $this->invoice->service()->addGatewayFee($cg, GatewayType::CREDIT_CARD, $this->invoice->balance)->save();
$this->invoice = $this->invoice->calc()->getInvoice(); $this->invoice = $this->invoice->calc()->getInvoice();
$items = $this->invoice->line_items; $items = $this->invoice->line_items;