Updates for billing.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 15 May 2018 17:41:28 +0000 (13:41 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 15 May 2018 17:41:28 +0000 (13:41 -0400)
Add ability on invoice page to delete invoices. with confirmation.
Return errors when using renewal form on front or admin side.

classes/billingSupport.php
config/plugin.ini
models/admin/billing/invoices.php
models/admin/member/billing.php
models/front/billing/renew.php
views/admin/billing/invoices.html

index 451997e..1d2cf54 100644 (file)
@@ -1411,7 +1411,7 @@ class GlmBillingSupport
             }
 
 
-            $errors = $result['errors'];
+            $errors = array();//$result['errors'];
 
         } else {
             $errors = $result['errors'];
@@ -1497,7 +1497,7 @@ class GlmBillingSupport
      * @param int $invoice_id Id of invoice to delete.
      *
      * @access public
-     * @return void
+     * @return int|false The number of invoices updated or false on error.
      */
     public function removeInvoiceById( $invoice_id )
     {
@@ -1506,7 +1506,7 @@ class GlmBillingSupport
             array( 'invoice' => $invoice_id ),
             array( '%d' )
         );
-        $this->wpdb->delete(
+        $result = $this->wpdb->delete(
             GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices',
             array( 'id' => $invoice_id ),
             array( '%d' )
@@ -1516,6 +1516,7 @@ class GlmBillingSupport
             array( 'type' => $this->config['transaction_numb']['Invoice'], 'type_id' => $invoice_id ),
             array( '%d', '%d' )
         );
+        return $result;
     }
 
     /**
index 87ff93a..978db5e 100644 (file)
@@ -97,10 +97,10 @@ proc_dir[99]                                    = 'TestByCardNumber'
 ;
 ; Card processing test modes
 ;
+proc_test_mode[0]                               = 'Production Mode'
 proc_test_mode[1]                               = 'Local Transaction Approval Test'
 proc_test_mode[2]                               = 'Local Transaction Decline Test'
 proc_test_mode[3]                               = 'On-Line Transaction Test'
-proc_test_mode[99]                              = 'Production Mode'
 
 proc_test_mode_numb['Local Approval Test']      =  1
 proc_test_mode_numb['Local Decline Test']       =  2
index 608ef61..3680758 100644 (file)
@@ -320,10 +320,12 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             break;
 
         case 'delete':
-            // Need to remove any line items for the invoice also
-            // $invoices = $this->deleteTransactions($this->invoice_id);
+            $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+            if ( isset( $_REQUEST['invoice_id'] ) && $invoice_id = filter_var( $_REQUEST['invoice_id'], FILTER_VALIDATE_INT ) ) {
+                $deleteNumber = $BillingSupport->removeInvoiceById( $invoice_id );
+            }
 
-            if ($invoices) {
+            if ( $deleteNumber ) {
                 $invoiceDeleted = true;
             } else {
                 $invoiceDeleteError = true;
index df7ea0a..4059216 100644 (file)
@@ -302,14 +302,18 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 case 'pay_by_credit_card':
                     // Do the Payment Processing.
                     $processErrors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] );
+                    // echo '<pre>$processErrors: ' . print_r( $processErrors, true ) . '</pre>';
                     if ( $processErrors ) {
-                        if ( count( $processErrors ) > 0 ) {
+                        if ( isset( $processErrors ) && is_array( $processErrors ) && count( $processErrors ) > 0 ) {
                             $error = true;
                             $BillingSupport->removeInvoiceById( $invoice_id );
                             foreach ( $processErrors as $error ) {
                                 $messages[] = '<span style="color: red;">'.$error.'</span>';
                             }
                             $paymentError = true;
+                        } else if ( isset( $processErrors ) && $processErrors ) {
+                            $error = true;
+                            $messages[] = '<span style="color: red;">'.$processErrors.'</span>';
                         } else {
                             $paymentSuccess = true;
                         }
@@ -341,43 +345,46 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
                 // If there's no error reported then show the invoice
                 // Now need to show the invoice.
-                $view = 'viewInvoice';
+                if ( !$error ) {
+                    $view = 'viewInvoice';
 
-                // Get the invoice.
-                $invoiceHtml = $BillingSupport->viewInvoice( $invoice_id );
+                    // Get the invoice.
+                    $invoiceHtml = $BillingSupport->viewInvoice( $invoice_id );
 
-                // If the member_type is changing then update member
-                // Get current member type
-                $member_id = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT );
-                if ( $member_id ) {
-                    $current_member_type = $this->wpdb->get_var(
-                        $this->wpdb->prepare(
-                            "SELECT member_type
-                               FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
-                              WHERE id = %d",
-                            $member_id
-                        )
-                    );
-                    $new_type = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT );
-                    $new_member_type = $this->wpdb->get_var(
-                        $this->wpdb->prepare(
-                            "SELECT member_type
-                               FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
-                              WHERE id = %d",
-                            $new_type
-                        )
-                    );
-                    // TODO: Need to reset account invoice_type also
-                    if ( $current_member_type != $new_member_type ) {
-                        $this->update(
-                            GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members',
-                            array( 'member_type' => $new_member_type ),
-                            array( 'id' => $member_id ),
-                            array( '%d' ),
-                            array( '%d' )
+                    // If the member_type is changing then update member
+                    // Get current member type
+                    $member_id = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT );
+                    if ( $member_id ) {
+                        $current_member_type = $this->wpdb->get_var(
+                            $this->wpdb->prepare(
+                                "SELECT member_type
+                                   FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                                  WHERE id = %d",
+                                $member_id
+                            )
+                        );
+                        $new_type = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT );
+                        $new_member_type = $this->wpdb->get_var(
+                            $this->wpdb->prepare(
+                                "SELECT member_type
+                                   FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
+                                  WHERE id = %d",
+                                $new_type
+                            )
                         );
+                        // TODO: Need to reset account invoice_type also
+                        if ( $current_member_type != $new_member_type ) {
+                            $this->update(
+                                GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members',
+                                array( 'member_type' => $new_member_type ),
+                                array( 'id' => $member_id ),
+                                array( '%d' ),
+                                array( '%d' )
+                            );
+                        }
                     }
                 }
+
             }
 
             break;
index 1fda26d..6065947 100644 (file)
@@ -280,12 +280,17 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
                     // Do the Payment Processing.
                     $processErrors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] );
                     if ( $processErrors ) {
-                        if ( count( $processErrors ) > 0 ) {
+                        if ( isset( $processErrors ) && is_array( $processErrors ) && count( $processErrors ) > 0 ) {
                             $error = true;
                             $BillingSupport->removeInvoiceById( $invoice_id );
                             foreach ( $processErrors as $error ) {
                                 $messages[] = '<span style="color: red;">'.$error.'</span>';
                             }
+                        } else if ( isset( $processErrors ) && $processErrors ) {
+                            $error = true;
+                            $messages[] = '<span style="color: red;">'.$processErrors.'</span>';
+                        } else {
+                            $paymentSuccess = true;
                         }
                         $view = 'renew';
 
index c84bdde..efd76ad 100644 (file)
@@ -56,6 +56,7 @@
             <th style="width: 70px;">Balance</th>
             <th style="width: 100px;">Pay Invoice</th>
             <th style="width: 50px;">View</th>
+            <th style="width: 50px;">Delete</th>
         </tr>
     </thead>
     <tbody>
@@ -80,6 +81,7 @@
                     <td> {$t.balance} </td>
                     <td> {if $t.paid.value}&nbsp;{else}<a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&option=makepayment&member={$t.member_id}">Pay Invoice</a>{/if} </td>
                     <td> <a href="{$thisUrl}?page={$thisPage}&glm_action=invoices&option=view&id={$t.id}">View</a> </td>
+                    <td> <a onClick="return confirm('This will delete the invoice. This cannot be undone. Are you Sure?');" href="{$thisUrl}?page={$thisPage}&glm_action=invoices&option=delete&invoice_id={$t.id}">Delete</a> </td>
                 </tr>
             {/foreach}
         {else}