[freeside-commits] freeside/FS/FS/ClientAPI MyAccount.pm, 1.120, 1.121 Signup.pm, 1.64, 1.65

Mark Wells mark at wavetail.420.am
Tue Dec 21 01:12:47 PST 2010


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

Modified Files:
	MyAccount.pm Signup.pm 
Log Message:
changes to support eWay third-party payment, #10208

Index: MyAccount.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/ClientAPI/MyAccount.pm,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -w -d -r1.120 -r1.121
--- MyAccount.pm	21 Dec 2010 06:26:11 -0000	1.120
+++ MyAccount.pm	21 Dec 2010 09:12:45 -0000	1.121
@@ -237,6 +237,28 @@
   }
 }
 
+sub payment_gateway {
+  # internal use only
+  # takes a cust_main and a cust_payby entry, returns the payment_gateway
+  my $conf = new FS::Conf;
+  my $cust_main = shift;
+  my $cust_payby = shift;
+  my $gatewaynum = $conf->config('selfservice-payment_gateway');
+  if ( $gatewaynum ) {
+    my $pg = qsearchs('payment_gateway', { gatewaynum => $gatewaynum });
+    die "configured gatewaynum $gatewaynum not found!" if !$pg;
+    return $pg;
+  }
+  else {
+    return '' if ! FS::payby->realtime($cust_payby);
+    my $pg = $cust_main->agent->payment_gateway(
+      'method'  => FS::payby->payby2bop($cust_payby),
+      'nofatal' => 1
+    );
+    return $pg;
+  }
+}
+
 sub access_info {
   my $p = shift;
 
@@ -262,18 +284,11 @@
   my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
     or return { 'error' => "unknown custnum $custnum" };
 
-  $info->{hide_payment_fields} =
-  [
-    map { my $pg = '';
-          if ( FS::payby->realtime($_) ) {
-            $pg = $cust_main->agent->payment_gateway(
-              'method'  => FS::payby->payby2bop($_),
-              'nofatal' => 1,
-            );
-          }
+  $info->{'hide_payment_fields'} = [ 
+    map { 
+      my $pg = payment_gateway($cust_main, $_);
           $pg && $pg->gateway_namespace eq 'Business::OnlineThirdPartyPayment';
-        }
-    @{ $info->{cust_paybys} }
+    } @{ $info->{cust_paybys} }
   ];
 
   $info->{'self_suspend_reason'} = 
@@ -532,18 +547,11 @@
   my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
     or return { 'error' => "unknown custnum $custnum" };
 
-  $return{hide_payment_fields} =
-  [
-    map { my $pg = '';
-          if ( FS::payby->realtime($_) ) {
-            $pg = $cust_main->agent->payment_gateway(
-              'method'  => FS::payby->payby2bop($_),
-              'nofatal' => 1,
-            );
-          }
+  $return{'hide_payment_fields'} = [
+    map { 
+      my $pg = payment_gateway($cust_main, $_);
           $pg && $pg->gateway_namespace eq 'Business::OnlineThirdPartyPayment';
-        }
-    @{ $return{cust_paybys} }
+    } @{ $return{cust_paybys} }
   ];
 
   $return{balance} = $cust_main->balance; #XXX pkg-balances?
@@ -692,6 +700,7 @@
     'paycvv'   => $paycvv,
     'pkgnum'   => $session->{'pkgnum'},
     'discount_term' => $discount_term,
+    'selfservice' => 1,
     map { $_ => $p->{$_} } @{ $payby2fields{$payby} }
   );
   return { 'error' => $error } if $error;
@@ -746,18 +755,27 @@
   my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
     or return { 'error' => "unknown custnum $custnum" };
 
+  my $amount;
+  if ( $p->{'amount'} ) {
+    $amount = $p->{'amount'};
+  }
+  elsif ( $session->{'pkgnum'} ) {
+    $amount = $cust_main->balance_pkgnum( $session->{'pkgnum'} );
+  }
+  else {
+    $amount = $cust_main->balance;
+  }
+
   my $error = $cust_main->realtime_collect(
     'method'     => $p->{'method'},
+    'amount'     => $amount,
     'pkgnum'     => $session->{'pkgnum'},
     'session_id' => $p->{'session_id'},
     'apply'      => 1,
+    'selfservice'=> 1,
   );
   return { 'error' => $error } unless ref( $error );
 
-  my $amount = $session->{'pkgnum'}
-                 ? $cust_main->balance_pkgnum( $session->{'pkgnum'} )
-                 : $cust_main->balance;
-
   return { 'error' => '', amount => $amount, %$error };
 }
 
@@ -1410,7 +1428,7 @@
 
     my $bill_error =    $cust_main->bill
                      || $cust_main->apply_payments_and_credits
-                     || $cust_main->realtime_collect;
+                     || $cust_main->realtime_collect('selfservice' => 1);
 
     if (    $cust_main->balance > $old_balance
          && $cust_main->balance > 0

Index: Signup.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/ClientAPI/Signup.pm,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -w -d -r1.64 -r1.65
--- Signup.pm	28 Oct 2010 22:21:55 -0000	1.64
+++ Signup.pm	21 Dec 2010 09:12:45 -0000	1.65
@@ -321,6 +321,16 @@
     warn "$me has agent $agent\n" if $DEBUG > 1;
     if ( $agent ) { #else complain loudly?
       $signup_info->{'hide_payment_fields'} = [];
+      my $gatewaynum = $conf->config('selfservice-payment_gateway');
+      if ( $gatewaynum ) {
+        my $pg = qsearchs('payment_gateway', { gatewaynum => $gatewaynum });
+        die "configured gatewaynum $gatewaynum not found!" if !$pg;
+        my $hide = $pg->gateway_namespace eq 'Business::OnlineThirdPartyPayment';
+        $signup_info->{'hide_payment_fields'} = [
+          map { $hide } @{$signup_info->{'payby'}}
+        ];
+      }
+      else {
       foreach my $payby (@{$signup_info->{payby}}) {
         warn "$me checking $payby payment fields\n" if $DEBUG > 1;
         my $hide = 0;
@@ -338,6 +348,7 @@
           }
         }
         push @{$signup_info->{'hide_payment_fields'}}, $hide;
+        } # foreach $payby
       }
     }
     warn "$me done setting agent-specific payment flag\n" if $DEBUG > 1;
@@ -698,6 +709,7 @@
     $bill_error = $cust_main->realtime_collect(
        method        => FS::payby->payby2bop( $packet->{payby} ),
        depend_jobnum => $placeholder->jobnum,
+       selfservice   => 1,
     );
     #warn "$me error collecting from new customer: $bill_error"
     #  if $bill_error;
@@ -787,11 +799,18 @@
 
   my $conf = new FS::Conf;
 
+  my $payment_gateway;
+  if ( my $gwnum = $conf->config('selfservice-payment_gateway') ) {
+    $payment_gateway = qsearchs('payment_gateway', { 'gatewaynum' => $gwnum })
+      or die "configured gatewaynum $gwnum not found!";
+  }
+  else {
   my $url = $packet->{url};
-  my $payment_gateway =
-    qsearchs('payment_gateway', { 'gateway_callback_url' => popurl(0, $url) } );
 
-  unless ($payment_gateway) {
+    $payment_gateway = qsearchs('payment_gateway', 
+        { 'gateway_callback_url' => popurl(0, $url) } 
+      );
+    if (!$payment_gateway) { 
 
     my ( $processor, $login, $password, $action, @bop_options ) =
       $conf->config('business-onlinepayment');
@@ -809,7 +828,7 @@
       gateway_action    => $action,
       options   => [ ( @bop_options ) ],
     });
-
+    }
   }
  
   die "No real-time third party processor is enabled - ".
@@ -847,7 +866,10 @@
 
   my $cust_main = $cust_pay_pending->cust_main;
   my $bill_error =
-    $cust_main->realtime_botpp_capture( $cust_pay_pending, %{$packet->{data}} );
+    $cust_main->realtime_botpp_capture( $cust_pay_pending, 
+      %{$packet->{data}},
+      apply => 1,
+  );
 
   return { 'error'      => ( $bill_error->{bill_error} ? '_decline' : '' ),
            %$bill_error,



More information about the freeside-commits mailing list