Recalculating gateway fees depending on gateway type

This commit is contained in:
David Bomba 2020-10-12 15:30:53 +11:00
parent c8770f09ca
commit 046805995a
3 changed files with 83 additions and 2 deletions

View File

@ -512,7 +512,7 @@ class Client extends BaseModel implements HasLocalePreference
foreach ($gateways as $gateway) {
foreach ($gateway->driver($this)->gatewayTypes() as $type) {
if(property_exists($gateway, 'fees_and_limits') property_exists($gateway->fees_and_limits, $type)){
if(property_exists($gateway, 'fees_and_limits') && property_exists($gateway->fees_and_limits, $type)){
$fees_and_limits_for_payment_type = $gateway->fees_and_limits->{$type};
}
else

View File

@ -69,7 +69,7 @@ class AutoBillInvoice extends AbstractService
return $this->finalizePaymentUsingCredits();
info("balance remains to be paid!!");
$gateway_token = $this->getGateway($amount);
/* Bail out if no payment methods available */
@ -79,6 +79,8 @@ class AutoBillInvoice extends AbstractService
/* $gateway fee */
$fee = $gateway_token->gateway->calcGatewayFee($amount);
//determine exact fee as per PaymentController
/* Build payment hash */
$payment_hash = PaymentHash::create([
'hash' => Str::random(128),

View File

@ -0,0 +1,79 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Feature;
use App\Factory\CreditFactory;
use App\Factory\InvoiceItemFactory;
use App\Helpers\Invoice\InvoiceSum;
use App\Listeners\Credit\CreateCreditInvitation;
use App\Models\Client;
use App\Models\CompanyGateway;
use App\Models\Credit;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Paymentable;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Carbon;
use Illuminate\Validation\ValidationException;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
*/
class CompanyGatewayResolutionTest extends TestCase
{
use MakesHash;
use DatabaseTransactions;
use MockAccountData;
public function setUp() :void
{
parent::setUp();
$this->withoutMiddleware(
ThrottleRequests::class
);
if (! config('ninja.testvars.stripe')) {
$this->markTestSkipped('Skip test no company gateways installed');
}
$this->faker = \Faker\Factory::create();
Model::reguard();
$this->makeTestData();
$this->withoutExceptionHandling();
$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();
}
public function testGatewayResolution()
{
$this->assertTrue(true);
}
}