RT#42373: Add ACH support to B::OP::ElavonVirtualMerchant [passing company from Billi...
[freeside.git] / FS / FS / cust_main / Billing_Realtime.pm
index 0a61ad1..2a9e869 100644 (file)
@@ -522,6 +522,8 @@ sub realtime_bop {
           ? uc($options{'paytype'})
           : uc($self->getfield('paytype')) || 'PERSONAL CHECKING';
 
+      $content{company} = $self->company if $self->company;
+
       if ( $content{account_type} =~ /BUSINESS/i && $self->company ) {
         $content{account_name} = $self->company;
       } else {
@@ -1758,7 +1760,7 @@ sub realtime_verify_bop {
 
   my $ban = FS::banned_pay->ban_search(
     'payby'   => $bop_method2payby{'CC'},
-    'payinfo' => $options{payinfo},
+    'payinfo' => $options{payinfo} || $self->payinfo,
   );
   return "Banned credit card" if $ban && $ban->bantype ne 'warn';
 
@@ -1787,7 +1789,7 @@ sub realtime_verify_bop {
 
     if ( $options{method} eq 'CC' ) {
 
-      $content{card_number} = $options{payinfo};
+      $content{card_number} = $options{payinfo} || $self->payinfo;
       $paydate = exists($options{'paydate'})
                       ? $options{'paydate'}
                       : $self->paydate;
@@ -1860,8 +1862,8 @@ sub realtime_verify_bop {
     'paid'              => '1.00',
     '_date'             => '',
     'payby'             => $bop_method2payby{'CC'},
-    'payinfo'           => $options{payinfo},
-    'paymask'           => $options{paymask},
+    'payinfo'           => $options{payinfo} || $self->payinfo,
+    'paymask'           => $options{paymask} || $self->paymask,
     'paydate'           => $paydate,
     #'recurring_billing' => $content{recurring_billing},
     'pkgnum'            => $options{'pkgnum'},
@@ -1938,8 +1940,10 @@ sub realtime_verify_bop {
                                 );
 
     $reverse->content( 'action'        => 'Reverse Authorization',
+                       $self->_bop_auth(\%options),          
 
                        # B:OP
+                       'amount'        => '1.00',
                        'authorization' => $transaction->authorization,
                        'order_number'  => $ordernum,
 
@@ -1969,6 +1973,17 @@ sub realtime_verify_bop {
 
     }
 
+  } else { # is not success
+
+    # status is 'done' not 'declined', as in _realtime_bop_result
+    $cust_pay_pending->status('done');
+    $cust_pay_pending->statustext( $transaction->error_message || 'Unknown error' );
+    # could also record failure_status here,
+    #   but it's not supported by B::OP::vSecureProcessing...
+    #   need a B::OP module with (reverse) auth only to test it with
+    my $cpp_declined_err = $cust_pay_pending->replace;
+    return $cpp_declined_err if $cpp_declined_err;
+
   }
 
   ###