[freeside-commits] freeside/FS/FS/cust_main Billing_Realtime.pm, 1.13, 1.14

Erik Levinson levinse at wavetail.420.am
Sat Jan 22 20:56:12 PST 2011


Update of /home/cvs/cvsroot/freeside/FS/FS/cust_main
In directory wavetail.420.am:/tmp/cvs-serv17423/FS/FS/cust_main

Modified Files:
	Billing_Realtime.pm 
Log Message:
add possibly finished credit card surcharge, RT11237

Index: Billing_Realtime.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main/Billing_Realtime.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -d -r1.13 -r1.14
--- Billing_Realtime.pm	21 Jan 2011 22:20:34 -0000	1.13
+++ Billing_Realtime.pm	23 Jan 2011 04:56:10 -0000	1.14
@@ -912,6 +912,8 @@
 
       # have a CC surcharge portion --> one-time charge
       if ( $options{'cc_surcharge'} > 0 ) { 
+	    # XXX: this whole block needs to be in a transaction?
+
 	  my $invnum;
 	  $invnum = $options{'invnum'} if $options{'invnum'};
 	  unless ( $invnum ) { # probably from a payment screen
@@ -942,26 +944,28 @@
 				    'cust_pkg_ref' => \$cust_pkg,
 				});
 	  if($charge_error) {
-		warn 'Unable to add CC surcharge';
+		warn 'Unable to add CC surcharge cust_pkg';
 		return '';
 	  }
 				    
-	  my $cust_bill_pkg = new FS::cust_bill_pkg({
-	    'invnum' => $invnum,
-	    'pkgnum' => $cust_pkg->pkgnum,
-	    'setup' => $options{'cc_surcharge'},
-	  });
-	  my $cbp_error = $cust_bill_pkg->insert;
+	  $cust_pkg->setup(time);
+	  my $cp_error = $cust_pkg->replace;
+	  if($cp_error) {
+	      warn 'Unable to set setup time on cust_pkg for cc surcharge';
+	    # but keep going...
+	  }
 
-	  if ( $cbp_error) {
-		warn 'Cannot add CC surcharge line item to invoice #'.$invnum;
-		return '';
-	  } else {
 	        my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum });
-		warn 'invoice for cc surcharge: ' . Dumper($cust_bill) if $DEBUG;
-		$cust_bill->apply_payments_and_credits;
+	  unless ( $cust_bill ) {
+	      warn "race condition + invoice deletion just happened";
+	      return '';
 	  }
 
+	  my $grand_error = 
+	    $cust_bill->add_cc_surcharge($cust_pkg->pkgnum,$options{'cc_surcharge'});
+
+	  warn "cannot add CC surcharge to invoice #$invnum: $grand_error"
+	    if $grand_error;
       }
 
       return ''; #no error



More information about the freeside-commits mailing list