RT#30600: Auto Apply for CC payments [v3 merge]
authorJonathan Prykop <jonathan@freeside.biz>
Thu, 25 Feb 2016 15:14:26 +0000 (09:14 -0600)
committerJonathan Prykop <jonathan@freeside.biz>
Thu, 25 Feb 2016 17:53:43 +0000 (11:53 -0600)
FS/FS/cust_main/Billing_Realtime.pm
httemplate/misc/payment.cgi
httemplate/misc/process/payment.cgi

index e9a3db2..345568a 100644 (file)
@@ -129,7 +129,9 @@ specified invoice.  If the customer has exactly one open invoice, that
 invoice number will be assumed.  If you don't specify an I<invnum> you might 
 want to call the B<apply_payments> method or set the I<apply> option.
 
-I<apply> can be set to true to apply a resulting payment.
+I<apply> can be set to true to run B<apply_payments_and_credits> on success.
+
+I<no_auto_apply> can be set to true to prevent resulting payment from being automatically applied.
 
 I<quiet> can be set true to surpress email decline notices.
 
@@ -870,7 +872,7 @@ sub _realtime_bop_result {
        'processor'      => $payment_gateway->gateway_module,
        'auth'           => $transaction->authorization,
        'order_number'   => $order_number || '',
-
+       'no_auto_apply'  => $options{'no_auto_apply'} ? 'Y' : '',
     } );
     #doesn't hurt to know, even though the dup check is in cust_pay_pending now
     $cust_pay->payunique( $options{payunique} )
index a48aa01..2f76b85 100644 (file)
   </TD>
 </TR>
 
+% my $disallow_no_auto_apply = 0;
 % if ( $conf->exists("batch-enable")
 %      || grep $payby eq $_, $conf->config('batch-enable_payby')
 %    ) {
 %
 %     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
+%       $disallow_no_auto_apply = 1;
 
           <INPUT TYPE="hidden" NAME="batch" VALUE="1">
 
 
           <TR>
             <TD COLSPAN=2>
-              <INPUT TYPE="checkbox" NAME="batch" VALUE="1">
+              <INPUT TYPE="checkbox" NAME="batch" VALUE="1" ID="batch_checkbox" ONCHANGE="change_batch_checkbox()">
               <% mt('Add to current batch') |h %> 
             </TD>
           </TR>
   </TD>
 </TR>
 
+% unless ($disallow_no_auto_apply) {
+%   # false laziness with edit/cust_pay.cgi
+
+<TR ID="apply_box_row">
+  <TD COLSPAN=2>
+    <% mt('Auto-apply to invoices') |h %>
+    <SELECT NAME="apply" ID="apply_box">
+      <OPTION VALUE="yes" SELECTED><% mt('yes') |h %></OPTION> 
+      <OPTION VALUE=""><% mt('not now') |h %></OPTION>
+      <OPTION VALUE="never"><% mt('never') |h %></OPTION>
+    </SELECT>
+  </TD>
+</TR>
+
+% # this can go away if no_auto_apply handling gets added to batch payment processing
+<SCRIPT>
+function change_batch_checkbox () {
+  if (document.getElementById('batch_checkbox').checked) {
+    document.getElementById('apply_box').disabled = true;
+    document.getElementById('apply_box_row').style.display = 'none';
+  } else {
+    document.getElementById('apply_box').disabled = false;
+    document.getElementById('apply_box_row').style.display = '';
+  }
+}
+</SCRIPT>
+
+% }
+
 </TABLE>
 
 <BR>
index 78038f8..7da7bef 100644 (file)
@@ -218,6 +218,7 @@ if ( $cgi->param('batch') ) {
     'paycvv'     => $paycvv,
     'paynum_ref' => \$paynum,
     'discount_term' => $discount_term,
+    'no_auto_apply' => ($cgi->param('apply') eq 'never') ? 'Y' : '',
     map { $_ => scalar($cgi->param($_)) } @{$payby2fields{$payby}}
   );
   errorpage($error) if $error;
@@ -238,7 +239,7 @@ if ( $cgi->param('batch') ) {
 
   }
 
-  $cust_main->apply_payments;
+  $cust_main->apply_payments if ($cgi->param('apply') eq 'yes');
 
 }