2017-03-15 16:24:01 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models\Traits;
|
|
|
|
|
2017-03-15 19:10:40 +01:00
|
|
|
use App\Models\GatewayType;
|
2017-03-15 16:24:01 +01:00
|
|
|
use App\Models\InvoiceItem;
|
|
|
|
use App\Models\AccountGatewaySettings;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ChargesFees
|
|
|
|
*/
|
|
|
|
trait ChargesFees
|
|
|
|
{
|
|
|
|
public function calcGatewayFee($gatewayTypeId = false, $includeTax = true)
|
|
|
|
{
|
2017-03-16 15:03:17 +01:00
|
|
|
$account = $this->account;
|
|
|
|
$settings = $account->getGatewaySettings($gatewayTypeId);
|
2017-03-15 16:24:01 +01:00
|
|
|
$fee = 0;
|
|
|
|
|
|
|
|
if (! $settings) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($settings->fee_amount) {
|
|
|
|
$fee += $settings->fee_amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($settings->fee_percent) {
|
2017-03-16 15:03:17 +01:00
|
|
|
$fee += $this->amount * $settings->fee_percent / 100;
|
2017-03-15 16:24:01 +01:00
|
|
|
}
|
|
|
|
|
2017-03-16 15:03:17 +01:00
|
|
|
if ($account->gateway_fee_location == FEE_LOCATION_ITEM && $includeTax) {
|
2017-03-15 16:24:01 +01:00
|
|
|
$preTaxFee = $fee;
|
|
|
|
|
|
|
|
if ($settings->fee_tax_rate1) {
|
|
|
|
$fee += $preTaxFee * $settings->fee_tax_rate1 / 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($settings->fee_tax_rate2) {
|
|
|
|
$fee += $preTaxFee * $settings->fee_tax_rate2 / 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return round($fee, 2);
|
|
|
|
}
|
|
|
|
}
|