From: Steve Sutton Date: Fri, 4 Oct 2019 14:19:56 +0000 (-0400) Subject: Fix issue where refreshing the invoice page was resubmitting to Authorize. X-Git-Tag: v1.0.38^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=328276998a63dfc2931f34a1c8a0fd9a366fc7a6;p=WP-Plugins%2Fglm-member-db-billing.git Fix issue where refreshing the invoice page was resubmitting to Authorize. Created a session which is checked before resubmitting to payment. Session will store the invoice id which can be used to show the invoice. --- diff --git a/index.php b/index.php index 59178f7..fa5e95f 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * Plugin Name: GLM Members Billing * Plugin URI: http://www.gaslightmedia.com/ * Description: This is glmAssociate Billing Module - * Version: 1.0.37 + * Version: 1.0.38 * Author: Gaslight Media * Author URI: http://www.gaslightmedia.com/ * License: GPL2 @@ -19,7 +19,7 @@ * @package glmMembersBillingAddOn * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @version 1.0.37 + * @version 1.0.38 */ /* @@ -37,7 +37,7 @@ * so that we're sure the other add-ons see an up to date * version from this plugin. */ -define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.37'); +define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.38'); // Database Version define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.26'); diff --git a/models/front/billing/renew.php b/models/front/billing/renew.php index 18cf554..6487914 100644 --- a/models/front/billing/renew.php +++ b/models/front/billing/renew.php @@ -212,54 +212,59 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling case 'renewMembership': $error = false; - $view = 'renewMembership'; - - $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); - if ( $member_invoice_id ) { - $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); + if ( isset( $_SESSION['billing_renewal_paid'] ) && $_SESSION['billing_renewal_paid'] ) { + // They're refreshing the page with the invoice on it. + // Reshow the invoice. } else { - $error = true; - } + $view = 'renewMembership'; - $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); - - $invoice_data = array( - 'account_id' => $accountID, - 'renew_type_id' => filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ), - 'amount' => $_REQUEST['total_renew_amount'], - 'due_date' => date( 'Y-m-d' ), - 'member_invoice' => $member_invoice, - 'employee_data' => $employees, - 'employees' => isset( $_REQUEST['employees'] ) ? $_REQUEST['employees'] : array(), - ); - if ( !$invoice_data ) { - $error = true; - } + $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); + if ( $member_invoice_id ) { + $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); + } else { + $error = true; + } + + $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); - // Before we create an invoice for this member see if they already have one. - // If we find one then delete it. - $old_invoice_ids = $this->wpdb->get_results( - $this->wpdb->prepare( - "SELECT id - FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices - WHERE paid <> true - AND renewal = true - AND account = %d", - $accountID - ), - ARRAY_A - ); - if ( isset( $old_invoice_ids ) && $old_invoice_ids ) { - foreach ( $old_invoice_ids as $old_invoices ) { - if ( $inv_id = filter_var( $old_invoices['id'], FILTER_VALIDATE_INT ) ) { - $BillingSupport->removeInvoiceById( $inv_id ); + $invoice_data = array( + 'account_id' => $accountID, + 'renew_type_id' => filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ), + 'amount' => $_REQUEST['total_renew_amount'], + 'due_date' => date( 'Y-m-d' ), + 'member_invoice' => $member_invoice, + 'employee_data' => $employees, + 'employees' => isset( $_REQUEST['employees'] ) ? $_REQUEST['employees'] : array(), + ); + if ( !$invoice_data ) { + $error = true; + } + + // Before we create an invoice for this member see if they already have one. + // If we find one then delete it. + $old_invoice_ids = $this->wpdb->get_results( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices + WHERE paid <> true + AND renewal = true + AND account = %d", + $accountID + ), + ARRAY_A + ); + if ( isset( $old_invoice_ids ) && $old_invoice_ids ) { + foreach ( $old_invoice_ids as $old_invoices ) { + if ( $inv_id = filter_var( $old_invoices['id'], FILTER_VALIDATE_INT ) ) { + $BillingSupport->removeInvoiceById( $inv_id ); + } } } - } - // Create the invoice for this member. - $invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data ); - if ( !$invoice_id ) { - $error = true; + // Create the invoice for this member. + $invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data ); + if ( !$invoice_id ) { + $error = true; + } } // Now that the invoice is created. Do payment Processing. @@ -292,54 +297,62 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling // Need to see if there's an account for this member. $account = $Accounts->editEntry( $accountID ); } else { - // Look at the payment option given - $payment_option = filter_var( $_REQUEST['payment_option'], FILTER_SANITIZE_STRING ); - - switch ( $payment_option ) { - case 'pay_by_credit_card': - // Do the Payment Processing. - $processErrors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] ); - if ( $processErrors ) { - if ( isset( $processErrors ) && is_array( $processErrors ) && count( $processErrors ) > 0 ) { - $error = true; - $BillingSupport->removeInvoiceById( $invoice_id ); - foreach ( $processErrors as $error ) { - $messages[] = ''.$error.''; + if ( isset( $_SESSION['billing_renewal_paid'] ) && $_SESSION['billing_renewal_paid'] ) { + // They're refreshing the page with the invoice on it. + // Reshow the invoice. + $invoice_id = $_SESSION['billing_renewal_paid']; + } else { + // Look at the payment option given + $payment_option = filter_var( $_REQUEST['payment_option'], FILTER_SANITIZE_STRING ); + + switch ( $payment_option ) { + case 'pay_by_credit_card': + // Do the Payment Processing. + $processErrors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] ); + if ( $processErrors ) { + 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; } - } else if ( isset( $processErrors ) && $processErrors ) { - $error = true; - $messages[] = ''.$processErrors.''; - } else { - $paymentSuccess = true; - } - $view = 'renew'; + $view = 'renew'; - // Get list of payable invoice_types - $payable_types = $BillingSupport->getAllPayableInvoiceTypes(); + // Get list of payable invoice_types + $payable_types = $BillingSupport->getAllPayableInvoiceTypes(); - $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); - if ( $member_invoice_id ) { - $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); - } + $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); + if ( $member_invoice_id ) { + $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); + } - // Get a list of this accounts employees. If they have any. - $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + // Get a list of this accounts employees. If they have any. + $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); - // Load DataClass for Management. - require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php'; - $Management = new GlmDataBillingManagement( $this->wpdb, $this->config ); - $management = $Management->getEntry( 1 ); + // Load DataClass for Management. + require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php'; + $Management = new GlmDataBillingManagement( $this->wpdb, $this->config ); + $management = $Management->getEntry( 1 ); - // Need to see if there's an account for this member. - $account = $Accounts->editEntry( $accountID ); + // Need to see if there's an account for this member. + $account = $Accounts->editEntry( $accountID ); + } + break; + case 'pay_by_check': + break; } - break; - case 'pay_by_check': - break; } // If there's no error reported then show the invoice if ( !$error ) { + // Create a session for renewal paid. + $_SESSION['billing_renewal_paid'] = $invoice_id; // Now need to show the invoice. $view = 'viewInvoice'; diff --git a/views/front/billing/renew.html b/views/front/billing/renew.html index 3809422..5372714 100644 --- a/views/front/billing/renew.html +++ b/views/front/billing/renew.html @@ -67,8 +67,8 @@ -{* Include the Payment Form template *} -{include file='common/billing/paymentForm.html'} + {* Include the Payment Form template *} + {include file='common/billing/paymentForm.html'} @@ -129,5 +129,3 @@ jQuery(document).ready(function($){ }); - -