[freeside-commits] freeside/FS/FS/ClientAPI PrepaidPhone.pm, 1.3, 1.4

Ivan,,, ivan at wavetail.420.am
Mon Nov 24 02:11:24 PST 2008


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

Modified Files:
	PrepaidPhone.pm 
Log Message:
add debugging, hopefully fix seconds returned finally, RT#4100

Index: PrepaidPhone.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/ClientAPI/PrepaidPhone.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- PrepaidPhone.pm	24 Nov 2008 08:47:53 -0000	1.3
+++ PrepaidPhone.pm	24 Nov 2008 10:11:22 -0000	1.4
@@ -1,13 +1,13 @@
 package FS::ClientAPI::PrepaidPhone;
 
 use strict;
-#use vars qw($DEBUG $me);
+use vars qw($DEBUG $me);
 use FS::Record qw(qsearchs);
 use FS::rate;
 use FS::svc_phone;
 
-#$DEBUG = 0;
-#$me = '[FS::ClientAPI::PrepaidPhone]';
+$DEBUG = 0;
+$me = '[FS::ClientAPI::PrepaidPhone]';
 
 #TODO:
 # - shared-secret auth? (set a conf value)
@@ -96,6 +96,9 @@
   my @part_pkg = ( $part_pkg, map $_->dst_pkg, $part_pkg->bill_part_pkg_link );
   #XXX uuh, behavior indeterminate if you have more than one voip_cdr+prefix
   #add-on, i guess.
+  warn "$me ". scalar(@part_pkg). ': '.
+       join('/', map { $_->plan. $_->option('rating_method') } @part_pkg )
+    if $DEBUG;
   @part_pkg =
     grep { $_->plan eq 'voip_cdr' && $_->option('rating_method') eq 'prefix' }
          @part_pkg;
@@ -105,10 +108,26 @@
     #'balance' => $cust_pkg->cust_main->balance,
   );
 
+  warn "$me: ". scalar(@part_pkg). ': '.
+       join('/', map { $_->plan. $_->option('rating_method') } @part_pkg )
+    if $DEBUG;
   return \%return unless @part_pkg;
 
+  warn "$me searching for rate ". $part_pkg[0]->option('ratenum')
+    if $DEBUG;
+
   my $rate = qsearchs('rate', { 'ratenum'=>$part_pkg[0]->option('ratenum') } );
 
+  unless ( $rate ) {
+    my $error = 'ratenum '. $part_pkg[0]->option('ratenum'). ' not found';
+    warn "$me $error"
+      if $DEBUG;
+    return { 'error'=>$error };
+  }
+
+  warn "$me found rate ". $rate->ratenum
+    if $DEBUG;
+
   #rate the call and arrive at a max # of seconds for the customer's balance
 
   my( $rate_countrycode, $rate_phonenum );
@@ -138,7 +157,13 @@
   }
 
   #XXX granularity?  included minutes?  another day...
-  $return{'seconds'} = int(60 * $cust_main->balance / $rate_detail->min_charge);
+  if ( $cust_main->balance >= 0 ) {
+    return { 'error'=>'No balance' };
+  } else {
+    $return{'seconds'} = int(60 * abs($cust_main->balance) / $rate_detail->min_charge);
+  }
+
+  warn "$me returning seconds: ". $return{'seconds'};
 
   return \%return;
  



More information about the freeside-commits mailing list