merge webpay support in with autoselection of old realtime_bop and realtime_refund_bop
[freeside.git] / FS / FS / ClientAPI / MyAccount.pm
index cbc3dba..c6a4e00 100644 (file)
@@ -353,6 +353,9 @@ sub payment_info {
       'paytypes' => [ @FS::cust_main::paytypes ],
 
       'paybys' => [ $conf->config('signup_server-payby') ],
+      'cust_paybys' => [ map { FS::payby->payby2payment($_) }
+                                 $conf->config('signup_server-payby')
+                       ],
 
       'stateid_label' => FS::Msgcat::_gettext('stateid'),
       'stateid_state_label' => FS::Msgcat::_gettext('stateid_state'),
@@ -375,6 +378,18 @@ sub payment_info {
   my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
     or return { 'error' => "unknown custnum $custnum" };
 
+  $return{hide_payment_fields} =
+  [
+    map { FS::payby->realtime($_) &&
+          $cust_main
+            ->agent
+            ->payment_gateway( 'method' => FS::payby->payby2bop($_) )
+            ->gateway_namespace
+            eq 'Business::OnlineThirdPartyPayment'
+        }
+    @{ $return{cust_paybys} }
+  ];
+
   $return{balance} = $cust_main->balance;
 
   $return{payname} = $cust_main->payname
@@ -499,7 +514,7 @@ sub process_payment {
     'payinfo'  => $payinfo,
     'paydate'  => $p->{'year'}. '-'. $p->{'month'}. '-01',
     'payname'  => $payname,
-    'paybatch' => $paybatch,
+    'paybatch' => $paybatch, #this doesn't actually do anything
     'paycvv'   => $paycvv,
     map { $_ => $p->{$_} } @{ $payby2fields{$payby} }
   );
@@ -531,6 +546,26 @@ sub process_payment {
 
 }
 
+sub realtime_collect {
+
+  my $p = shift;
+
+  my $session = _cache->get($p->{'session_id'})
+    or return { 'error' => "Can't resume session" }; #better error message
+
+  my $custnum = $session->{'custnum'};
+
+  my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+    or return { 'error' => "unknown custnum $custnum" };
+
+  my $error = $cust_main->realtime_collect( 'method'     => $p->{'method'},
+                                            'session_id' => $p->{'session_id'},
+                                          );
+  return { 'error' => $error } unless ref( $error );
+
+  return { 'error' => '', amount => $cust_main->balance, %$error };
+}
+
 sub process_payment_order_pkg {
   my $p = shift;
 
@@ -921,6 +956,7 @@ sub order_pkg {
     my %fields = (
       'svc_acct'     => [ qw( username domsvc _password sec_phrase popnum ) ],
       'svc_domain'   => [ qw( domain ) ],
+      'svc_phone'    => [ qw( phonenum pin sip_password ) ],
       'svc_external' => [ qw( id title ) ],
     );
   
@@ -1120,7 +1156,7 @@ sub renew_info {
 
   #return { 'error' => 'No active packages to renew.' } unless @cust_pkg;
 
-  my $total = 0;
+  my $total = $cust_main->balance;
 
   my @array = map {
                     $total += $_->part_pkg->base_recur;
@@ -1130,7 +1166,7 @@ sub renew_info {
                       'bill_date_pretty'  => time2str('%x', $_->bill),
                       'renew_date'        => $renew_date,
                       'renew_date_pretty' => time2str('%x', $renew_date),
-                      'amount'            => sprintf('.%2f', $total),
+                      'amount'            => sprintf('%.2f', $total),
                     };
                   }
                   @cust_pkg;