diff --git a/app/Models/AccountGatewaySettings.php b/app/Models/AccountGatewaySettings.php
index b7402d82367e..b2e96050f3e7 100644
--- a/app/Models/AccountGatewaySettings.php
+++ b/app/Models/AccountGatewaySettings.php
@@ -2,6 +2,8 @@
namespace App\Models;
+use Utils;
+
/**
* Class AccountGatewaySettings.
*/
@@ -41,4 +43,28 @@ class AccountGatewaySettings extends EntityModel
{
// to Disable created_at
}
+
+ public function areFeesEnabled()
+ {
+ return floatval($this->fee_amount) || floatval($this->fee_percent);
+ }
+
+ public function feesToString()
+ {
+ $parts = [];
+
+ if (floatval($this->fee_amount)) {
+ $parts[] = Utils::formatMoney($this->fee_amount);
+ }
+
+ if (floatval($this->fee_percent)) {
+ $parts[] = $this->fee_percent . '%';
+ }
+
+ if (floatval($this->fee_tax_rate1) || floatval($this->fee_tax_rate1)) {
+ $parts[] = trans('texts.tax');
+ }
+
+ return join(' + ', $parts);
+ }
}
diff --git a/app/Ninja/Datatables/AccountGatewayDatatable.php b/app/Ninja/Datatables/AccountGatewayDatatable.php
index 814ace071cc9..e816caebacbd 100644
--- a/app/Ninja/Datatables/AccountGatewayDatatable.php
+++ b/app/Ninja/Datatables/AccountGatewayDatatable.php
@@ -12,6 +12,7 @@ use Utils;
class AccountGatewayDatatable extends EntityDatatable
{
private static $accountGateways;
+ private static $accountGatewaySettings;
public $entityType = ENTITY_ACCOUNT_GATEWAY;
@@ -62,26 +63,16 @@ class AccountGatewayDatatable extends EntityDatatable
[
'limit',
function ($model) {
- if ($model->gateway_id == GATEWAY_CUSTOM) {
- $gatewayTypes = [GATEWAY_TYPE_CUSTOM];
- } else {
- $accountGateway = $this->getAccountGateway($model->id);
- $paymentDriver = $accountGateway->paymentDriver();
- $gatewayTypes = $paymentDriver->gatewayTypes();
- $gatewayTypes = array_diff($gatewayTypes, [GATEWAY_TYPE_TOKEN]);
- }
-
+ $gatewayTypes = $this->getGatewayTypes($model->id, $model->gateway_id);
$html = '';
foreach ($gatewayTypes as $gatewayTypeId) {
- $accountGatewaySettings = AccountGatewaySettings::scope()->where('account_gateway_settings.gateway_type_id',
- '=', $gatewayTypeId)->first();
- $gatewayType = GatewayType::find($gatewayTypeId);
+ $accountGatewaySettings = $this->getAccountGatewaySetting($gatewayTypeId);
+ $gatewayType = Utils::getFromCache($gatewayTypeId, 'gatewayTypes');
if (count($gatewayTypes) > 1) {
if ($html) {
$html .= '
';
}
-
$html .= $gatewayType->name . ' — ';
}
@@ -106,7 +97,25 @@ class AccountGatewayDatatable extends EntityDatatable
[
'fees',
function ($model) {
- return 'Fees description...';
+ $gatewayTypes = $this->getGatewayTypes($model->id, $model->gateway_id);
+ $html = '';
+ foreach ($gatewayTypes as $gatewayTypeId) {
+ $accountGatewaySettings = $this->getAccountGatewaySetting($gatewayTypeId);
+ if (! $accountGatewaySettings || ! $accountGatewaySettings->areFeesEnabled()) {
+ continue;
+ }
+
+ $gatewayType = Utils::getFromCache($gatewayTypeId, 'gatewayTypes');
+
+ if (count($gatewayTypes) > 1) {
+ if ($html) {
+ $html .= '
';
+ }
+ $html .= $gatewayType->name . ' — ';
+ }
+ $html .= $accountGatewaySettings->feesToString();
+ };
+ return $html ?: trans('texts.no_fees');
},
],
];
@@ -168,9 +177,7 @@ class AccountGatewayDatatable extends EntityDatatable
$actions[] = [
trans('texts.set_limits_fees', ['gateway_type' => $gatewayType->name]),
function () use ($gatewayType) {
- $accountGatewaySettings = AccountGatewaySettings::scope()
- ->where('account_gateway_settings.gateway_type_id', '=', $gatewayType->id)
- ->first();
+ //$accountGatewaySettings = $this->getAccountGatewaySetting($gatewayType->id);
//$min = $accountGatewaySettings && $accountGatewaySettings->min_limit !== null ? $accountGatewaySettings->min_limit : 'null';
//$max = $accountGatewaySettings && $accountGatewaySettings->max_limit !== null ? $accountGatewaySettings->max_limit : 'null';
return "javascript:showLimitsModal('{$gatewayType->name}', {$gatewayType->id})";
@@ -200,4 +207,30 @@ class AccountGatewayDatatable extends EntityDatatable
return static::$accountGateways[$id];
}
+
+ private function getAccountGatewaySetting($gatewayTypeId)
+ {
+ if (isset(static::$accountGatewaySettings[$gatewayTypeId])) {
+ return static::$accountGatewaySettings[$gatewayTypeId];
+ }
+
+ static::$accountGatewaySettings[$gatewayTypeId] = AccountGatewaySettings::scope()
+ ->where('account_gateway_settings.gateway_type_id', '=', $gatewayTypeId)->first();
+
+ return static::$accountGatewaySettings[$gatewayTypeId];
+ }
+
+ private function getGatewayTypes($id, $gatewayId)
+ {
+ if ($gatewayId == GATEWAY_CUSTOM) {
+ $gatewayTypes = [GATEWAY_TYPE_CUSTOM];
+ } else {
+ $accountGateway = $this->getAccountGateway($id);
+ $paymentDriver = $accountGateway->paymentDriver();
+ $gatewayTypes = $paymentDriver->gatewayTypes();
+ $gatewayTypes = array_diff($gatewayTypes, [GATEWAY_TYPE_TOKEN]);
+ }
+
+ return $gatewayTypes;
+ }
}
diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php
index 871e1ba77f79..415803f51d68 100644
--- a/resources/lang/en/texts.php
+++ b/resources/lang/en/texts.php
@@ -2405,6 +2405,7 @@ $LANG = array(
'fee_percent' => 'Percent',
'fees_tax_help' => 'Enable line item taxes to set fee tax rates.',
'fees_sample' => 'The fee for a :amount invoice would be :total.',
+ 'no_fees' => 'No Fees',
);
diff --git a/resources/views/accounts/payments.blade.php b/resources/views/accounts/payments.blade.php
index a502178d1bd0..b253d0f80268 100644
--- a/resources/views/accounts/payments.blade.php
+++ b/resources/views/accounts/payments.blade.php
@@ -51,7 +51,7 @@
->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false)
->setOptions('bAutoWidth', false)
- ->setOptions('aoColumns', [[ "sWidth"=> "30%" ], ["sWidth"=> "30%"], ["sWidth"=> "20%"], ["sWidth"=> "20%"]])
+ ->setOptions('aoColumns', [[ "sWidth"=> "24%" ], ["sWidth"=> "27%"], ["sWidth"=> "27%"], ["sWidth"=> "20%"]])
->setOptions('aoColumnDefs', [['bSortable'=>false, 'aTargets'=>[1, 2, 3]]])
->render('datatable') !!}
@@ -234,7 +234,7 @@
}
$('#paymentLimitsModal').modal('show');
-
+
updateFeeSample();
}