[freeside-commits] branch FREESIDE_3_BRANCH updated. cfde6a0e4f1c3c129a1a2d8b6c4e38930c71f998

Christopher Burger burgerc at freeside.biz
Tue Jun 25 05:58:06 PDT 2019


The branch, FREESIDE_3_BRANCH has been updated
       via  cfde6a0e4f1c3c129a1a2d8b6c4e38930c71f998 (commit)
       via  5ebcddd3d2cb95a02eaba0a8fc301b9c0d7e3e73 (commit)
      from  6ceeed875a6d93495dcf0e22212e7ad86024a60b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit cfde6a0e4f1c3c129a1a2d8b6c4e38930c71f998
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Jun 25 08:27:29 2019 -0400

    RT# 82137 - default payment amount now has processing fee in total if processing fee exists.

diff --git a/httemplate/elements/tr-amount_fee.html b/httemplate/elements/tr-amount_fee.html
index 31877f119..7797f6c2b 100644
--- a/httemplate/elements/tr-amount_fee.html
+++ b/httemplate/elements/tr-amount_fee.html
@@ -137,6 +137,8 @@ if ( $amount > 0 ) {
 
   $processing_fee = $opt{'processing_fee'} if $opt{'processing_fee'} > 0;
 
+  $amount += $processing_fee; ## needed if processing fee is checked on default.
+
   $amount = sprintf("%.2f", $amount);
 }
 

commit 5ebcddd3d2cb95a02eaba0a8fc301b9c0d7e3e73
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Mon Jun 24 13:27:17 2019 -0400

    RT# 82137 - Added ability for processing fee to be pain on seperate invoice.
    
    Conflicts:
            FS/FS/Conf.pm
            httemplate/elements/tr-select-payment_options.html

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 597e2c945..c5abe59f9 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2854,6 +2854,17 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'processing-fee_on_separate_invoice',
+    'section'     => 'billing',
+    'description' => 'Places the processing fee on a separate invoice by itself.  Only works with real time processing.',
+    'type'        => 'checkbox',
+    'validate'    => sub {
+                        my $conf = new FS::Conf;
+                        !$conf->config('batch-enable_payby') ? '' : 'You can not set this option while batch processing is enabled.';
+                     },
+  },
+
+  {
     'key'         => 'payby-default',
     'section'     => 'UI',
     'description' => 'Default payment type.  HIDE disables display of billing information and sets customers to BILL.',
@@ -4071,6 +4082,11 @@ and customer address. Include units.',
     'description' => 'Enable batch processing for the specified payment types.',
     'type'        => 'selectmultiple',
     'select_enum' => [qw( CARD CHEK )],
+    'validate'    => sub {
+                        ## can not create a new invoice and pay it silently with batch processing, only realtime processing.
+                        my $conf = new FS::Conf;
+                        !$conf->exists('processing-fee_on_separate_invoice') ? '' : 'You can not enable batch processing while processing-fee_on_separate_invoice option is enabled.';
+                     },
   },
 
   {
diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm
index ed5d094f5..54b3847c9 100644
--- a/FS/FS/cust_main/Billing_Realtime.pm
+++ b/FS/FS/cust_main/Billing_Realtime.pm
@@ -897,16 +897,19 @@ sub _realtime_bop_result {
     my $dbh = dbh;
 
     #start a transaction, insert the cust_pay and set cust_pay_pending.status to done in a single transction
-
-    my $error = $cust_pay->insert($options{'manual'} ? ( 'manual' => 1 ) : () );
+    my $error = $cust_pay->insert(
+      $options{'manual'} ? ( 'manual' => 1 ) : (),
+      $options{'processing-fee'} > 0 ? ( 'processing-fee' => $options{'processing-fee'} ) : (),
+    );
 
     if ( $error ) {
       $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
       $cust_pay->invnum(''); #try again with no specific invnum
       $cust_pay->paynum('');
-      my $error2 = $cust_pay->insert( $options{'manual'} ?
-                                      ( 'manual' => 1 ) : ()
-                                    );
+      my $error2 = $cust_pay->insert(
+        $options{'manual'} ? ( 'manual' => 1 ) : (),
+        $options{'processing-fee'} > 0 ? ( 'processing-fee' => $options{'processing-fee'} ) : (),
+      );
       if ( $error2 ) {
         # gah.  but at least we have a record of the state we had to abort in
         # from cust_pay_pending now.
@@ -1043,11 +1046,23 @@ sub _realtime_bop_result {
     if ($options{'processing-fee'} > 0) {
       my $pf_cust_pkg;
       my $processing_fee_text = 'Payment Processing Fee';
+
+      my $conf = new FS::Conf;
+
+      my $pf_seperate_bill;
+      my $pf_bill_now;
+      if ($conf->exists('processing-fee_on_separate_invoice')) {
+        $pf_seperate_bill = 'Y';
+        $pf_bill_now = '1';
+      }
+
       my $pf_change_error = $self->charge({
             'amount'  => $options{'processing-fee'},
             'pkg'   => $processing_fee_text,
             'setuptax'  => 'Y',
             'cust_pkg_ref' => \$pf_cust_pkg,
+            'separate_bill' => $pf_seperate_bill,
+            'bill_now' => $pf_bill_now,
       });
 
       if($pf_change_error) {
@@ -1062,17 +1077,41 @@ sub _realtime_bop_result {
         # but keep going...
       }
 
-      my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum });
-      unless ( $cust_bill ) {
-        warn "race condition + invoice deletion just happened";
-        return '';
-      }
+      if ($conf->exists('processing-fee_on_separate_invoice')) {
+        my $cust_bill_pkg = qsearchs( 'cust_bill_pkg', { 'pkgnum' => $pf_cust_pkg->pkgnum } );
+
+        my $pf_cust_bill = qsearchs('cust_bill', { 'invnum' => $cust_bill_pkg->invnum });
+        unless ( $pf_cust_bill ) {
+          warn "no processing fee inv found!";
+          return '';
+        }
+
+        my $pf_apply_error = $pf_cust_bill->apply_payments_and_credits;
+
+        my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum });
+        unless ( $cust_bill ) {
+          warn "race condition + invoice deletion just happened";
+         return '';
+        }
+
+        my $grand_pf_error = $cust_bill->apply_payments_and_credits;
+
+        warn "cannot apply Processing fee to invoice #$invnum: $grand_pf_error - $pf_apply_error"
+          if $grand_pf_error || $pf_apply_error;
+      } ## processing-fee_on_separate_invoice
+      else {
+        my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum });
+        unless ( $cust_bill ) {
+          warn "race condition + invoice deletion just happened";
+          return '';
+        }
 
-      my $grand_pf_error =
-        $cust_bill->add_cc_surcharge($pf_cust_pkg->pkgnum,$options{'processing-fee'});
+        my $grand_pf_error =
+          $cust_bill->add_cc_surcharge($pf_cust_pkg->pkgnum,$options{'processing-fee'});
 
-      warn "cannot add Processing fee to invoice #$invnum: $grand_pf_error"
-        if $grand_pf_error;
+        warn "cannot add Processing fee to invoice #$invnum: $grand_pf_error"
+          if $grand_pf_error;
+      } ## no processing-fee_on_separate_invoice
     } #end if $options{'processing-fee'}
 
       } #end if ( $options{'cc_surcharge'} > 0 || $options{'processing-fee'} > 0)
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index 3e368f6ca..3f6b8e8cf 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -381,6 +381,8 @@ sub insert {
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
+  $self->{'processing_fee'} = $options{'processing-fee'};
+
   #payment receipt
   my $trigger = $conf->config('payment_receipt-trigger', 
                               $self->cust_main->agentnum) || 'cust_pay';
@@ -741,6 +743,8 @@ sub send_message_receipt {
 
       my %substitutions = ();
       $substitutions{invnum} = $cust_bill->invnum if $cust_bill;
+      $substitutions{'processing_fee'} = $self->{'processing_fee'};
+
 
       my $msg_template = qsearchs('msg_template',{ msgnum => $msgnum});
       unless ($msg_template) {
diff --git a/httemplate/config/config-process.cgi b/httemplate/config/config-process.cgi
index d84edce00..6af7d2322 100644
--- a/httemplate/config/config-process.cgi
+++ b/httemplate/config/config-process.cgi
@@ -155,7 +155,9 @@ foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
     }
   } elsif ( $type eq 'checkbox' ) {
     if ( defined $cgi->param($i->key.$n) ) {
-      push @touch, $i->key;
+      my $error = &{$i->validate}('', $n) if $i->validate;
+      push @error, $error if $error;
+      push @touch, $i->key if !$error;
     } else {
       push @delete, $i->key;
     }
@@ -167,7 +169,7 @@ foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
     if ( scalar(@{[ $cgi->param($i->key.$n) ]}) && $cgi->param($i->key.$n) ne '' ) {
       my $error = &{$i->validate}([ $cgi->param($i->key.$n) ], $n) if $i->validate;
       push @error, $error if $error;
-      $conf->set($i->key, join("\n", @{[ $cgi->param($i->key.$n) ]} ), $agentnum);
+      $conf->set($i->key, join("\n", @{[ $cgi->param($i->key.$n) ]} ), $agentnum) if !$error;
     } else {
       $conf->delete($i->key, $agentnum);
     }
diff --git a/httemplate/elements/tr-amount_fee.html b/httemplate/elements/tr-amount_fee.html
index 1cd59bbc3..31877f119 100644
--- a/httemplate/elements/tr-amount_fee.html
+++ b/httemplate/elements/tr-amount_fee.html
@@ -38,7 +38,7 @@
         <TD>
           <TABLE><TR>
             <TD BGCOLOR="#ffffff">
-             <INPUT TYPE="checkbox" NAME="processing_fee" ID="processing_fee" VALUE="<% $processing_fee %>" onclick="<% $opt{prefix} %>process_fee_changed()">
+             <INPUT TYPE="checkbox" NAME="processing_fee" ID="processing_fee" VALUE="<% $processing_fee %>" onclick="<% $opt{prefix} %>process_fee_changed()" checked>
             </TD>
             <TD>
              Apply a processing fee of <% $processing_fee %> .</FONT>

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm                          | 16 ++++++++
 FS/FS/cust_main/Billing_Realtime.pm    | 67 +++++++++++++++++++++++++++-------
 FS/FS/cust_pay.pm                      |  4 ++
 httemplate/config/config-process.cgi   |  6 ++-
 httemplate/elements/tr-amount_fee.html |  4 +-
 5 files changed, 80 insertions(+), 17 deletions(-)




More information about the freeside-commits mailing list