Skip to content

Commit

Permalink
Working on gateway fees
Browse files Browse the repository at this point in the history
  • Loading branch information
hillelcoren committed Mar 17, 2017
1 parent 7b2f46b commit b2cfc8b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
9 changes: 5 additions & 4 deletions app/Models/AccountGatewaySettings.php
Expand Up @@ -49,6 +49,11 @@ public function areFeesEnabled()
return floatval($this->fee_amount) || floatval($this->fee_percent);
}

public function hasTaxes()
{
return floatval($this->fee_tax_rate1) || floatval($this->fee_tax_rate1);
}

public function feesToString()
{
$parts = [];
Expand All @@ -61,10 +66,6 @@ public function feesToString()
$parts[] = (floor($this->fee_percent * 1000) / 1000) . '%';
}

if ($this->fee_location == FEE_LOCATION_ITEM && (floatval($this->fee_tax_rate1) || floatval($this->fee_tax_rate1))) {
$parts[] = trans('texts.tax');
}

return join(' + ', $parts);
}
}
13 changes: 12 additions & 1 deletion app/Ninja/Datatables/AccountGatewayDatatable.php
Expand Up @@ -97,7 +97,7 @@ function ($model) {
[
'fees',
function ($model) {
if (! $model->gateway_fee_location) {
if (! $feeLocation = $model->gateway_fee_location) {
return trans('texts.fees_disabled');
}

Expand All @@ -118,6 +118,17 @@ function ($model) {
$html .= $gatewayType->name . ' — ';
}
$html .= $accountGatewaySettings->feesToString();

if ($feeLocation == FEE_LOCATION_ITEM) {
if ($accountGatewaySettings->hasTaxes()) {
$html .= ' + ' . trans('texts.tax');
}
} else {
$field = ($feeLocation == FEE_LOCATION_CHARGE1 ? 'custom_invoice_taxes1' : 'custom_invoice_taxes1');
if (\Auth::user()->account->$field) {
$html .= ' + ' . trans('texts.tax');
}
}
};
return $html ?: trans('texts.no_fees');
},
Expand Down
10 changes: 6 additions & 4 deletions resources/lang/en/texts.php
Expand Up @@ -2401,7 +2401,7 @@
'fees' => 'Fees',
'fee' => 'Fee',
'set_limits_fees' => 'Set :gateway_type Limits/Fees',
'fees_tax_help' => 'Enable line item taxes to set fee tax rates.',
'fees_tax_help' => 'Enable line item taxes to set the fee tax rates.',
'fees_sample' => 'The fee for a :amount invoice would be :total.',
'discount_sample' => 'The discount for a :amount invoice would be :total.',
'no_fees' => 'No Fees',
Expand All @@ -2410,12 +2410,14 @@
'location' => 'Location',
'line_item' => 'Line Item',
'surcharge' => 'Surcharge',
'first_surcharge' => 'Enabled - Use first surcharge',
'second_surcharge' => 'Enabled - Use second surcharge',
'location_first_surcharge' => 'Enabled - First surcharge',
'location_second_surcharge' => 'Enabled - Second surcharge',
'location_line_item' => 'Enabled - Line item',
'online_payment_surcharge' => 'Online Payment Surcharge',
'gateway_fees' => 'Gateway Fees',
'fees_disabled' => 'Fees are disabled',
'gateway_fees_help' => 'Automatically add an online payment surcharge [partial payments are not supported].',
//'gateway_fees_help' => 'Automatically add an online payment surcharge [partial payments are not supported].',
'gateway_fees_help' => 'Automatically add an online payment surcharge or line item.<br/>Use \'Line item\' to support partial payments.',
'gateway' => 'Gateway',

);
Expand Down
23 changes: 14 additions & 9 deletions resources/views/accounts/payments.blade.php
Expand Up @@ -27,9 +27,9 @@
<br/>
{!! Former::select('gateway_fee_location')
->addOption(trans('texts.disabled'), '')
->addOption(trans('texts.first_surcharge') . ($account->custom_invoice_label1 ? ' | ' . $account->custom_invoice_label1 : ''), FEE_LOCATION_CHARGE1)
->addOption(trans('texts.second_surcharge') . ($account->custom_invoice_label2 ? ' | ' . $account->custom_invoice_label2 : '' ), FEE_LOCATION_CHARGE2)
//->addOption(trans('texts.line_item'), FEE_LOCATION_ITEM)
->addOption(trans('texts.location_first_surcharge') . ($account->custom_invoice_label1 ? ' | ' . $account->custom_invoice_label1 : ''), FEE_LOCATION_CHARGE1)
->addOption(trans('texts.location_second_surcharge') . ($account->custom_invoice_label2 ? ' | ' . $account->custom_invoice_label2 : '' ), FEE_LOCATION_CHARGE2)
->addOption(trans('texts.location_line_item'), FEE_LOCATION_ITEM)
->help('gateway_fees_help')
->label('gateway_fees')!!}
<br/>
Expand Down Expand Up @@ -164,13 +164,14 @@
{!! Former::text('fee_tax_rate1') !!}
{!! Former::text('fee_tax_name2') !!}
{!! Former::text('fee_tax_rate2') !!}
</div>

<br/><div id="feeSample" class="help-block"></div>
</div><br/>

@if (false && !$account->invoice_item_taxes && $account->invoice_taxes && count($taxRates))
<br/><div class="help-block">{{ trans('texts.fees_tax_help') }}</div>
@endif
<div class="help-block">
<span id="feeSample"></span>
@if ($account->gateway_fee_location == FEE_LOCATION_ITEM && !$account->invoice_item_taxes && $account->invoice_taxes && count($taxRates))
{{ trans('texts.fees_tax_help') }}
@endif
</div>

<br/><b>{{ trans('texts.gateway_fees_disclaimer') }}</b>

Expand Down Expand Up @@ -252,6 +253,10 @@ function showLimitsModal(gateway_type, gateway_type_id) {
$('#paymentLimitsModal').modal('show');
updateFeeSample();
@if ($account->gateway_fee_location == FEE_LOCATION_ITEM)
$('#taxDiv').show();
@endif
}
var limitsSlider = document.getElementById('payment-limits-slider');
Expand Down

0 comments on commit b2cfc8b

Please sign in to comment.