new status for pending third-party payments, fix for #12808
authormark <mark>
Thu, 12 May 2011 19:57:01 +0000 (19:57 +0000)
committermark <mark>
Thu, 12 May 2011 19:57:01 +0000 (19:57 +0000)
FS/FS/ClientAPI/Signup.pm
FS/FS/cust_main/Billing_Realtime.pm
FS/FS/cust_pay_pending.pm
httemplate/view/cust_main/payment_history/pending_payment.html

index b18f21f..6c9e812 100644 (file)
@@ -904,8 +904,8 @@ sub capture_payment {
     return { error => '_decline', bill_error => $bill_error };
   }
 
-  if ($cust_pay_pending->status ne 'pending') {
-    my $bill_error = "Payment with id $paypendingnum is not pending, but ".
+  if ($cust_pay_pending->status ne 'thirdparty') {
+    my $bill_error = "Payment with id $paypendingnum is not thirdparty, but ".
                      $cust_pay_pending->status.  "; Transaction aborted.";
     return { error => '_decline', bill_error => $bill_error };
   }
index caa3ab3..fd19241 100644 (file)
@@ -522,6 +522,19 @@ sub realtime_bop {
     'custnum' => $self->custnum,
     'status'  => { op=>'!=', value=>'done' } 
   });
+
+  #for third-party payments only, remove pending payments if they're in the 
+  #'thirdparty' (waiting for customer action) state.
+  if ( $namespace eq 'Business::OnlineThirdPartyPayment' ) {
+    foreach ( grep { $_->status eq 'thirdparty' } @pending ) {
+      my $error = $_->delete;
+      warn "error deleting unfinished third-party payment ".
+          $_->paypendingnum . ": $error\n"
+        if $error;
+    }
+    @pending = grep { $_->status ne 'thirdparty' } @pending;
+  }
+
   return "A payment is already being processed for this customer (".
          join(', ', map 'paypendingnum '. $_->paypendingnum, @pending ).
          "); $options{method} transaction aborted."
@@ -594,6 +607,9 @@ sub realtime_bop {
 
   if ( $transaction->is_success() && $namespace eq 'Business::OnlineThirdPartyPayment' ) {
 
+    $cust_pay_pending->status('thirdparty');
+    my $cpp_err = $cust_pay_pending->replace;
+    return { error => $cpp_err } if $cpp_err;
     return { reference => $cust_pay_pending->paypendingnum,
              map { $_ => $transaction->$_ } qw ( popup_url collectitems ) };
 
index e54690e..f03ed1f 100644 (file)
@@ -96,6 +96,10 @@ Aquires basic lock on payunique
 
 Transaction is pending with the gateway
 
+=item thirdparty
+
+Customer has been sent to an off-site payment gateway to complete processing
+
 =item authorized
 
 Only used for two-stage transactions that require a separate capture step
index 40805b1..7d21f89 100644 (file)
@@ -33,6 +33,7 @@ my $info = $payby ? "($payby$payinfo)" : '';
 
 my %statusaction = (
   'new'        => 'delete',
+  'thirdparty' => 'delete',
   'pending'    => 'complete',
   'captured'   => 'capture',
 );