Fixing bugs for payments
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 31 Jul 2019 12:08:59 +0000 (08:08 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 31 Jul 2019 12:08:59 +0000 (08:08 -0400)
Deal with payment errors.

models/admin/member/billing.php
views/admin/billing/makePaymentAdjustmentAjax.html

index 1ece124..aadad5a 100644 (file)
@@ -575,7 +575,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
                 case 'mark_paid':
                     $_REQUEST['transaction_time'] = date( 'Y-m-d H:i:s' );
-                    $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] );
+                    $nvoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] );
                     // Mark this invoice as paid
                     // Create new payment.
                     $payment_id = $BillingSupport->createPayment( $accountID, $_REQUEST['total_renew_amount'], 'Marked Paid' );
@@ -685,7 +685,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                         $accountUpdated = true;
                     }
                     if ( $this->ajaxSide ) {
-                        trigger_error( 'Account Ajax Hit', E_USER_NOTICE );
+                        // trigger_error( 'Account Ajax Hit', E_USER_NOTICE );
                         header( 'Content-type:application/json;charset=utf-8', true );
                         echo json_encode( $account, true );
                         exit;
@@ -988,6 +988,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             break;
 
         case 'createMemberPayment':
+            // trigger_error( print_r( $_REQUEST['invoices'], true), E_USER_NOTICE );
             $view           = 'paymentProcess';
             $account_id     = filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT );
             $amount         = filter_var( $_REQUEST['amount'], FILTER_VALIDATE_FLOAT );
@@ -995,18 +996,31 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             $payment_data   = filter_var( $_REQUEST['payment_data'], FILTER_SANITIZE_STRING );
             $invoices       = filter_var( $_REQUEST['invoices'], FILTER_VALIDATE_INT, array( 'flags' => FILTER_REQUIRE_ARRAY ) );
 
+            // trigger_error( print_r(
+            //     array(
+            //         'account_id'     => $account_id,
+            //         'amount'         => $amount,
+            //         'payment_method' => $payment_method,
+            //         'payment_data'   => $payment_data,
+            //         'invoices'       => $invoices,
+            //     ), true ), E_USER_NOTICE );
             if ( $account_id && $amount && $payment_method && !empty( $invoices ) ) {
                 // Create new payment.
                 $payment_id = $BillingSupport->createPayment( $account_id, $amount, $payment_method, $payment_data );
+                // trigger_error( "payment_id: $payment_id", E_USER_NOTICE );
 
                 if ( $payment_id ) {
+                    // trigger_error( "before recordPayment", E_USER_NOTICE );
                     // Record the payment.
                     $BillingSupport->recordPayment( $payment_id, $account_id, $amount, $invoices, $this->config['transaction_numb']['Payment'] );
+                    // trigger_error( "after recordPayment", E_USER_NOTICE );
                 }
             } else {
                 $payment_id = false;
             }
+            // trigger_error( print_r( $this->ajaxSide, true), E_USER_NOTICE );
             if ( $this->ajaxSide ) {
+                $invoiceData = $invoices;
                 if ( !empty( $invoices ) ) {
                     $invoiceData = array_map( array( $BillingSupport, 'getInvoiceById' ), $invoices );
                 }
@@ -1014,9 +1028,11 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                     'payment_id' => $payment_id,
                     'invoices'   => $invoiceData
                 );
+                // trigger_error( print_r( $return, true), E_USER_NOTICE );
                 header( 'Content-type:application/json;charset=utf-8', true );
                 echo json_encode( $return, true );
                 exit;
+                // rsp:  <h1>Error thrown</h1><p>Call to a member function remove_role() on boolean</p>
             }
             break;
 
index 072215b..e08bf98 100644 (file)
@@ -122,19 +122,23 @@ jQuery(document).ready(function($){
             if ( rsp ) {
                 var $sucessModal = $('#billingSuccess');
                 $sucessModal.foundation('open').trigger('resizeme.zp.reveal');
-                if ( rsp.invoices.length > 0 ) {
+                if ( rsp.invoices != undefined && rsp.invoices.length > 0 ) {
                     // Loop over the invoices and update the ones if found on this page.
                     for ( var i in rsp.invoices ) {
                         // Update the balance due
                         $('#balance-' + rsp.invoices[i].id ).html( rsp.invoices[i].balance );
                         // If the invoices is marked 'Paid' then remove the make payment
                         // or pay invoices links and the send invoices line
-                        if ( rsp.invoices[i].paid ) {
+                        if ( rsp.invoices.length && rsp.invoices[i].paid ) {
                             $('#make-a-payment-' + rsp.invoices[i].id).remove();
                             $('#pay-invoice-' + rsp.invoices[i].id).remove();
                             $('#send-invoice-' + rsp.invoices[i].id).remove();
+                        } else {
+                            //console.log('rsp: ', rsp);
                         }
                     }
+                } else {
+                    //console.log('rsp: ', rsp);
                 }
                 return true;
             } else {