Fix issue with payments in admin when Authorize gives an error.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 15 May 2018 16:11:40 +0000 (12:11 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 15 May 2018 16:11:40 +0000 (12:11 -0400)
Pass error message through.

classes/billingSupport.php
models/admin/member/billing.php

index ce3e2a0..451997e 100644 (file)
@@ -717,6 +717,8 @@ class GlmBillingSupport
             'payments'   => $payments,
         );
 
+        // echo '<pre>$templateData: ' . print_r( $templateData, true ) . '</pre>';
+
         $invoiceHtml = $this->generateInvoiceHtml( $templateData, 'admin/billing/invoiceStore.html' );
         return $invoiceHtml;
     }
@@ -1354,6 +1356,11 @@ class GlmBillingSupport
                     'ccResult' => $ccResult,
                 );
 
+            } else {
+                $result = array(
+                    'status' => 0,
+                    'errors' => $ccResult['description']
+                );
             }
 
         } else {
@@ -1465,6 +1472,7 @@ class GlmBillingSupport
     {
         $payment_id = implode( '-', $invoices );
         $result = $this->processPayment( $account_id, $payment_id, $amount );
+        // echo '<pre>$result: ' . print_r( $result, true ) . '</pre>';
         if ( $result['status'] === 1 ) {
 
             // Need to record the payment.
@@ -1477,9 +1485,9 @@ class GlmBillingSupport
             // Record the payment.
             $this->recordPayment( $payment_id, $account_id, $amount, $invoices );
 
-            $errors = $result['errors'];
+            return false;
         } else {
-            $errors = $result['errors'];
+            return $result['errors'];
         }
     }
 
index 3c6ea00..f1b0c15 100644 (file)
@@ -547,8 +547,11 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 // Make the Payment using Billing Support Class
                 $errors = $BillingSupport->makePayment( $account_id, $invoices, $amount );
 
+                // echo '<pre>$errors: ' . print_r( $errors, true ) . '</pre>';
+
                 if ( $errors ) {
                     $paymentError = true;
+                    $messages[] = $errors;
                     // Load DataClass for Management.
                     require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataManagement.php';
                     $Management = new GlmDataBillingManagement( $this->wpdb, $this->config );
@@ -601,7 +604,9 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             }
 
 
-            $view = 'statements';
+            if ( !$errors ) {
+                $view = 'statements';
+            }
 
             break;