mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Working on gateways and gateway fees
This commit is contained in:
parent
c7512f1572
commit
2ffca37e74
@ -181,19 +181,20 @@ class Client extends BaseModel
|
||||
|
||||
//** Reduce gateways so that only one TYPE is present in the list ie. cannot have multiple credit card options
|
||||
$payment_methods_collections = collect($payment_methods);
|
||||
|
||||
$payment_methods_intersect = $payment_methods_collections->intersectByKeys( $payment_methods_collections->flatten(1)->unique() );
|
||||
|
||||
$payment_list = $payment_methods_intersect->map(function ($value, $key) {
|
||||
|
||||
$gateway = $gateways->where('id', $key)->first();
|
||||
|
||||
$fee_label = $gateway->calcGatewayFee($amount, $this);
|
||||
$fee_label = $gateway->calcGatewayFeeLabel($amount, $this);
|
||||
|
||||
return [
|
||||
'company_gateway_id' => $key,
|
||||
'payment_method_id' => $value,
|
||||
'url' => $label
|
||||
'label' => ctrans('texts.'$gateway->type->alias) . $fee_label,
|
||||
'url' => $label,
|
||||
'label' => ctrans('texts.' . $gateway->type->alias) . $fee_label,
|
||||
];
|
||||
|
||||
});
|
||||
|
@ -14,6 +14,7 @@ namespace App\Models;
|
||||
use App\Models\Company;
|
||||
use App\Models\Gateway;
|
||||
use App\Models\GatewayType;
|
||||
use App\Utils\Number;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CompanyGateway extends BaseModel
|
||||
@ -128,6 +129,11 @@ class CompanyGateway extends BaseModel
|
||||
return ! empty($this->config('enablePayPal'));
|
||||
}
|
||||
|
||||
public function feesEnabled()
|
||||
{
|
||||
return floatval($this->fee_amount) || floatval($this->fee_percent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the formatted fee amount for the gateway
|
||||
*
|
||||
@ -135,11 +141,44 @@ class CompanyGateway extends BaseModel
|
||||
* @param Client $client The client object
|
||||
* @return string The fee amount formatted in the client currency
|
||||
*/
|
||||
public function calcGatewayFee($amount, Client $client) :string
|
||||
public function calcGatewayFeeLabel($amount, Client $client) :string
|
||||
{
|
||||
$label = '';
|
||||
|
||||
$fee = '';
|
||||
if(!$this->feesEnabled())
|
||||
return $label;
|
||||
|
||||
$fee = $this->calcGatewayFee($amount);
|
||||
|
||||
if($fee > 0 ){
|
||||
$fee = Number::formatMoney(round($fee, 2), $client->currency(), $client->country(), $client->getMergedSettings());
|
||||
$label = ' - ' . $fee . ' ' . ctrans('texts.fee');
|
||||
}
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
|
||||
public function calcGatewayFee($amount)
|
||||
{
|
||||
$fee = 0;
|
||||
|
||||
if ($this->fee_amount)
|
||||
$fee += $this->fee_amount;
|
||||
|
||||
if ($this->fee_percent)
|
||||
$fee += $amount * $this->fee_percent / 100;
|
||||
|
||||
$pre_tax_fee = $fee;
|
||||
|
||||
if ($this->fee_tax_rate1)
|
||||
$fee += $pre_tax_fee * $this->fee_tax_rate1 / 100;
|
||||
|
||||
|
||||
if ($this->fee_tax_rate2)
|
||||
$fee += $pre_tax_fee * $this->fee_tax_rate2 / 100;
|
||||
|
||||
|
||||
return $fee;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user