From 59476e2df63bad3befcbdf80b04cb1c4e9e64536 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 15 May 2018 13:41:28 -0400 Subject: [PATCH] Updates for billing. Add ability on invoice page to delete invoices. with confirmation. Return errors when using renewal form on front or admin side. --- classes/billingSupport.php | 7 +-- config/plugin.ini | 2 +- models/admin/billing/invoices.php | 8 ++-- models/admin/member/billing.php | 73 +++++++++++++++++-------------- models/front/billing/renew.php | 7 ++- views/admin/billing/invoices.html | 2 + 6 files changed, 58 insertions(+), 41 deletions(-) diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 451997e..1d2cf54 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -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; } /** diff --git a/config/plugin.ini b/config/plugin.ini index 87ff93a..978db5e 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -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 diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index 608ef61..3680758 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -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; diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index df7ea0a..4059216 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -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 '
$processErrors: ' . print_r( $processErrors, true ) . '
'; 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[] = ''.$error.''; } $paymentError = true; + } else if ( isset( $processErrors ) && $processErrors ) { + $error = true; + $messages[] = ''.$processErrors.''; } 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; diff --git a/models/front/billing/renew.php b/models/front/billing/renew.php index 1fda26d..6065947 100644 --- a/models/front/billing/renew.php +++ b/models/front/billing/renew.php @@ -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[] = ''.$error.''; } + } else if ( isset( $processErrors ) && $processErrors ) { + $error = true; + $messages[] = ''.$processErrors.''; + } else { + $paymentSuccess = true; } $view = 'renew'; diff --git a/views/admin/billing/invoices.html b/views/admin/billing/invoices.html index c84bdde..efd76ad 100644 --- a/views/admin/billing/invoices.html +++ b/views/admin/billing/invoices.html @@ -56,6 +56,7 @@ Balance Pay Invoice View + Delete @@ -80,6 +81,7 @@ {$t.balance} {if $t.paid.value} {else}Pay Invoice{/if} View + Delete {/foreach} {else} -- 2.17.1