Merge branch 'master' of git.freeside.biz:/home/git/freeside
authorIvan Kohler <ivan@freeside.biz>
Fri, 11 May 2018 18:12:03 +0000 (11:12 -0700)
committerIvan Kohler <ivan@freeside.biz>
Fri, 11 May 2018 18:12:03 +0000 (11:12 -0700)
FS/FS/ClientAPI/MasonComponent.pm
FS/FS/ClientAPI/MyAccount.pm
FS/FS/Conf.pm
FS/FS/cust_main/Billing_Realtime.pm
httemplate/elements/tr-amount_fee.html
httemplate/elements/tr-select-payment_options.html
httemplate/misc/payment.cgi

index 3a4bfe1..d615c27 100644 (file)
@@ -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 );
 
index 66697ef..e4fef95 100644 (file)
@@ -921,6 +921,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,
index 2f8ac24..5c6c411 100644 (file)
@@ -781,6 +781,14 @@ my $validate_email = sub { $_[0] =~
   },
 
   {
+    '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'     => 'invoicing',
     'description' => 'Generate a line item on an invoice even when a package is discounted 100%',
index dcf5b7b..78f2cbc 100644 (file)
@@ -421,6 +421,8 @@ sub realtime_bop {
     $options{amount} = $amount;
   }
 
+  return '' unless $options{amount} > 0;
+
   # set fields from passed cust_payby
   _bop_cust_payby_options(\%options);
 
@@ -454,16 +456,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;
index 9c13f59..9e6d9e9 100644 (file)
@@ -94,6 +94,9 @@ if ( $amount > 0 ) {
   $amount += $amount * $opt{'surcharge_percentage'}/100
     if $opt{'surcharge_percentage'} > 0;
 
+  $amount += $opt{'surcharge_flatfee'}
+    if $opt{'surcharge_flatfee'} > 0;
+
   $amount = sprintf("%.2f", $amount);
 }
 
index 2304c22..8859b9b 100644 (file)
@@ -17,6 +17,11 @@ Example:
           ? scalar($conf->config('credit-card-surcharge-percentage', $cust_main->agentnum))
           : 0
       ),
+    'surcharge_flatfee' =>
+      ( $payby eq 'CARD'
+          ? scalar($conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum))
+          : 0
+      ),
   )
 
 </%doc>
index 5bfa29d..de060b0 100644 (file)
              ? scalar($conf->config('credit-card-surcharge-percentage', $cust_main->agentnum))
              : 0
          ),
+       'surcharge_flatfee:Q' =>
+         ( $payby eq 'CARD'
+             ? scalar($conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum))
+             : 0
+         ),
   &>
 
 % if ( $conf->exists('part_pkg-term_discounts') ) {