freeside/FS/FS/ClientAPI MyAccount.pm,1.18,1.19

ivan ivan at pouncequick.420.am
Mon May 3 08:40:13 PDT 2004


Update of /home/cvs/cvsroot/freeside/FS/FS/ClientAPI
In directory pouncequick:/tmp/cvs-serv22038

Modified Files:
	MyAccount.pm 
Log Message:
1. order_pkg accepts svcpart + (svc_external: id, title / svc_acct: domain)  

Index: MyAccount.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/ClientAPI/MyAccount.pm,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- MyAccount.pm	20 Apr 2004 20:24:36 -0000	1.18
+++ MyAccount.pm	3 May 2004 15:40:10 -0000	1.19
@@ -12,6 +12,8 @@
 use FS::Msgcat qw(gettext);
 use FS::svc_acct;
 use FS::svc_domain;
+use FS::svc_external;
+use FS::part_svc;
 use FS::cust_main;
 use FS::cust_bill;
 use FS::cust_main_county;
@@ -406,35 +408,61 @@
   my $error = $cust_pkg->check;
   return { 'error' => $error } if $error;
 
-  my $svc_acct = new FS::svc_acct ( {
-    'svcpart'   => $p->{'svcpart'} || $cust_pkg->part_pkg->svcpart('svc_acct'),
-    map { $_ => $p->{$_} }
-      qw( username _password sec_phrase popnum ),
-  } );
+  my @svc = ();
+  unless ( $p->{'svcpart'} eq 'none' ) {
 
-  my @acct_snarf;
-  my $snarfnum = 1;
-  while ( length($p->{"snarf_machine$snarfnum"}) ) {
-    my $acct_snarf = new FS::acct_snarf ( {
-      'machine'   => $p->{"snarf_machine$snarfnum"},
-      'protocol'  => $p->{"snarf_protocol$snarfnum"},
-      'username'  => $p->{"snarf_username$snarfnum"},
-      '_password' => $p->{"snarf_password$snarfnum"},
+    my $svcdb;
+    my $svcpart = '';
+    if ( $p->{'svcpart'} =~ /^(\d+)$/ ) {
+      $svcpart = $1;
+      my $part_svc = qsearchs('part_svc', { 'svcpart' => $svcpart } );
+      return { 'error' => "Unknown svcpart $svcpart" } unless $part_svc;
+      $svcdb = $part_svc->svcdb;
+    } else {
+      $svcdb = 'svc_acct';
+    }
+    $svcpart ||= $cust_pkg->part_pkg->svcpart($svcdb);
+
+    my %fields = (
+      'svc_acct'     => [ qw( username _password sec_phrase popnum ) ],
+      'svc_domain'   => [ qw( domain ) ],
+      'svc_external' => [ qw( id title ) ],
+    );
+  
+    my $svc_x = "FS::$svcdb"->new( {
+      'svcpart'   => $svcpart,
+      map { $_ => $p->{$_} } @{$fields{$svcdb}}
     } );
-    $snarfnum++;
-    push @acct_snarf, $acct_snarf;
-  }
-  $svc_acct->child_objects( \@acct_snarf );
+    
+    if ( $svcdb eq 'svc_acct' ) {
+      my @acct_snarf;
+      my $snarfnum = 1;
+      while ( length($p->{"snarf_machine$snarfnum"}) ) {
+        my $acct_snarf = new FS::acct_snarf ( {
+          'machine'   => $p->{"snarf_machine$snarfnum"},
+          'protocol'  => $p->{"snarf_protocol$snarfnum"},
+          'username'  => $p->{"snarf_username$snarfnum"},
+          '_password' => $p->{"snarf_password$snarfnum"},
+        } );
+        $snarfnum++;
+        push @acct_snarf, $acct_snarf;
+      }
+      $svc_x->child_objects( \@acct_snarf );
+    }
+    
+    my $y = $svc_x->setdefault; # arguably should be in new method
+    return { 'error' => $y } if $y && !ref($y);
+  
+    $error = $svc_x->check;
+    return { 'error' => $error } if $error;
 
-  my $y = $svc_acct->setdefault; # arguably should be in new method
-  return { 'error' => $y } if $y && !ref($y);
+    push @svc, $svc_x;
 
-  $error = $svc_acct->check;
-  return { 'error' => $error } if $error;
+  }
 
   use Tie::RefHash;
   tie my %hash, 'Tie::RefHash';
-  %hash = ( $cust_pkg => [ $svc_acct ] );
+  %hash = ( $cust_pkg => \@svc );
   #msgcat
   $error = $cust_main->order_pkgs( \%hash, '', 'noexport' => 1 );
   return { 'error' => $error } if $error;
@@ -449,7 +477,8 @@
     $cust_main->apply_credits;
     $bill_error = $cust_main->collect;
 
-    if ( $cust_main->balance > $old_balance ) {
+    if ( $cust_main->balance > $old_balance
+         && $cust_main->payby !~ /^(BILL|DCRD|DCHK)$/ ) {
       $cust_pkg->cancel('quiet'=>1);
       return { 'error' => '_decline' };
     } else {




More information about the freeside-commits mailing list