From c85d36a31cd15e8d06f9dfc7d2591f918d278d89 Mon Sep 17 00:00:00 2001 From: Christopher Burger Date: Fri, 11 May 2018 11:29:36 -0400 Subject: RT# 79737 - Added ability to us a cc surcharge of a flat fee. Conflicts: FS/FS/cust_main/Billing_Realtime.pm httemplate/elements/tr-select-payment_options.html --- FS/FS/ClientAPI/MasonComponent.pm | 1 + FS/FS/ClientAPI/MyAccount.pm | 1 + FS/FS/Conf.pm | 8 ++++++++ FS/FS/cust_main/Billing_Realtime.pm | 20 ++++++++++++++------ 4 files changed, 24 insertions(+), 6 deletions(-) (limited to 'FS') diff --git a/FS/FS/ClientAPI/MasonComponent.pm b/FS/FS/ClientAPI/MasonComponent.pm index 3a4bfe133..d615c271c 100644 --- a/FS/FS/ClientAPI/MasonComponent.pm +++ b/FS/FS/ClientAPI/MasonComponent.pm @@ -63,6 +63,7 @@ my %session_callbacks = ( 'process-skip_first' => $conf->exists('selfservice_process-skip_first'), 'num_payments' => scalar($cust_main->cust_pay), 'surcharge_percentage' => scalar($conf->config('credit-card-surcharge-percentage', $cust_main->agentnum)), + 'surcharge_flatfee' => scalar($conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum)), ); @$argsref = ( %args ); diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index d604491af..476ef0789 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -935,6 +935,7 @@ sub payment_info { $return{paybatch} = $return{payunique}; #back compat $return{credit_card_surcharge_percentage} = $conf->config('credit-card-surcharge-percentage', $cust_main->agentnum); + $return{credit_card_surcharge_flatfee} = $conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum); return { 'error' => '', %return, diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index c58ca33f4..8b18a3c3c 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -886,6 +886,14 @@ my $validate_email = sub { $_[0] =~ 'per_agent' => 1, }, + { + 'key' => 'credit-card-surcharge-flatfee', + 'section' => 'credit_cards', + 'description' => 'Add a credit card surcharge to invoices, as a flat fee.', + 'type' => 'text', + 'per_agent' => 1, + }, + { 'key' => 'discount-show-always', 'section' => 'billing', diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm index 63ae777e6..ae41c70c4 100644 --- a/FS/FS/cust_main/Billing_Realtime.pm +++ b/FS/FS/cust_main/Billing_Realtime.pm @@ -358,16 +358,24 @@ sub realtime_bop { if $conf->config('credit-card-surcharge-percentage', $self->agentnum) && $options{method} eq 'CC'; + my $cc_surcharge_flat = 0; + $cc_surcharge_flat = $conf->config('credit-card-surcharge-flatfee', $self->agentnum) + if $conf->config('credit-card-surcharge-flatfee', $self->agentnum) + && $options{method} eq 'CC'; + # always add cc surcharge if called from event - if($options{'cc_surcharge_from_event'} && $cc_surcharge_pct > 0) { - $cc_surcharge = $options{'amount'} * $cc_surcharge_pct / 100; + if($options{'cc_surcharge_from_event'} && ($cc_surcharge_pct > 0 || $cc_surcharge_flat > 0)) { + if ($options{'amount'} > 0) { + $cc_surcharge = ($options{'amount'} * ($cc_surcharge_pct / 100)) + $cc_surcharge_flat; $options{'amount'} += $cc_surcharge; $options{'amount'} = sprintf("%.2f", $options{'amount'}); # round (again)? + } } - elsif($cc_surcharge_pct > 0) { # we're called not from event (i.e. from a - # payment screen), so consider the given - # amount as post-surcharge - $cc_surcharge = $options{'amount'} - ($options{'amount'} / ( 1 + $cc_surcharge_pct/100 )); + elsif($cc_surcharge_pct > 0 || $cc_surcharge_flat > 0) { + # we're called not from event (i.e. from a + # payment screen), so consider the given + # amount as post-surcharge + $cc_surcharge = $options{'amount'} - (($options{'amount'} - $cc_surcharge_flat) / ( 1 + $cc_surcharge_pct/100 )) if $options{'amount'} > 0; } $cc_surcharge = sprintf("%.2f",$cc_surcharge) if $cc_surcharge > 0; -- cgit v1.2.1