From 199fd77931536c361e59bb1eac6c62f9c33d46eb Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Tue, 9 Jan 2018 17:18:34 -0500 Subject: [PATCH] Added Payment Codes to front-end. Also fixed problem with overwriting account data on checkout. Updated database with a few changes for payment codes. --- classes/data/dataPaymentCode.php | 11 +- classes/data/dataRegRequestPayCode.php | 184 +++++++++++++++++- classes/regCartSupport.php | 16 +- index.php | 2 +- models/admin/registrations/events.php | 6 +- .../front/registrations/checkoutProcess.php | 12 +- ...0.0.21.sql => create_database_V0.0.22.sql} | 3 + setup/databaseScripts/dbVersions.php | 3 +- ..._V0.0.21.sql => drop_database_V0.0.22.sql} | 0 .../update_database_V0.0.22.sql | 17 ++ .../registrations/eventPaymentCodes.html | 58 +++--- views/front/registrations/cart.html | 13 +- 12 files changed, 276 insertions(+), 49 deletions(-) rename setup/databaseScripts/{create_database_V0.0.21.sql => create_database_V0.0.22.sql} (99%) rename setup/databaseScripts/{drop_database_V0.0.21.sql => drop_database_V0.0.22.sql} (100%) create mode 100644 setup/databaseScripts/update_database_V0.0.22.sql diff --git a/classes/data/dataPaymentCode.php b/classes/data/dataPaymentCode.php index cde64f4..297d88d 100644 --- a/classes/data/dataPaymentCode.php +++ b/classes/data/dataPaymentCode.php @@ -154,7 +154,15 @@ class GlmDataRegistrationsPaymentCode extends GlmDataAbstract 'amount' => array ( 'field' => 'amount', 'type' => 'float', - 'required' => false, + 'use' => 'a' + ), + + // Expire Date + 'expire_date' => array( + 'field' => 'expire_date', + 'type' => 'date', + 'default' => 'CURDATE() + INTERVAL 1 MONTH', + 'required' => true, 'use' => 'a' ), @@ -162,7 +170,6 @@ class GlmDataRegistrationsPaymentCode extends GlmDataAbstract 'descr' => array ( 'field' => 'descr', 'type' => 'text', - 'required' => false, 'use' => 'a' ) diff --git a/classes/data/dataRegRequestPayCode.php b/classes/data/dataRegRequestPayCode.php index f7b0201..38d24c7 100644 --- a/classes/data/dataRegRequestPayCode.php +++ b/classes/data/dataRegRequestPayCode.php @@ -124,6 +124,14 @@ class GlmDataRegistrationsRequestPayCode extends GlmDataAbstract 'use' => 'a' ), + // Pointer to payment code + 'code' => array ( + 'field' => 'code', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + // Pointer to reg_request table entry 'reg_request' => array ( 'field' => 'reg_request', @@ -135,12 +143,186 @@ class GlmDataRegistrationsRequestPayCode extends GlmDataAbstract // Total Credit applied to cart using this code 'credit' => array ( 'field' => 'credit', - 'type' => 'float', 'required' => false, + 'type' => 'float', 'default' => 0, 'use' => 'a' + ), + + // Current expire date - Now always getting from the payment_code table + 'expire_date' => array( + 'field' => 'payment_code', + 'as' => 'expire_date', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'payment_code', + 'p_field' => 'expire_date', + 'required' => true, + 'use' => 'lgneud' + ), + + // Type + 'code_type_numb' => array( + 'field' => 'payment_code', + 'as' => 'code_type_numb', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'payment_code', + 'p_field' => 'code_type', + 'required' => true, + 'use' => 'lg' + ), + + // Type + 'amount' => array( + 'field' => 'payment_code', + 'as' => 'amount', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'payment_code', + 'p_field' => 'amount', + 'required' => true, + 'use' => 'lg' ) + + + ); } + + /** + * Entry Post Processing Call-Back Method + * + * Perform post-processing for all result entries. + * + * @param array $r Array of field result data for a single entry + * @param string $a Action being performed (l, i, g, ...) + * + * @return object Class object + * + */ + public function entryPostProcessing( $r, $action ) + { + + // If doing the following actions + if (in_array($action, array('l','g'))) { + + // Get the type name + $r['code_type'] = $this->config['pay_code_type'][$r['code_type_numb']]; + + // Convert expire date to standard + $expTime = strtotime($r['expire_date']); + $r['expire_date'] = array( + 'date' => date('m/d/Y', $expTime), + 'timestamp' => $expTime, + 'mysql_date' => $r['expire_date'] + ); + + } + + return $r; + } + + + /** + * Get current pay codes for this request and remove expired + * + * @param integer $requestId ID of registration request + * + * @return object Class object + */ + public function getAndExpireRegPayCodes($requestId, $newCode = '') + { + + $messages = array(); + + // Check for new Payment Code + if ($newCode != '') { + + require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataPaymentCode.php'; + $PayCode = new GlmDataRegistrationsPaymentCode($this->wpdb, $this->config); + + // Check if a good payment Code + $pCode = $PayCode->getList("T.code = '".trim($_REQUEST['regPaymentCode'])."'"); + if ($pCode && count($pCode) > 0) { + + $payCode = current($pCode); + + // Check if payment code has expired + if ($payCode['expire_date']['timestamp'] < time()) { + $messages[] = 'Payment code "'.$payCode['code'].'" is past expiration date and no longer accepted.'; + } else { + + // Check if the payment code has not yet been added + $reqCode = $this->getList("T.reg_request = $requestId && payment_code = ".$payCode['id']); + If (!$reqCode) { + + $this->wpdb->insert( + GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_request_pay_code', + array( + 'payment_code' => $payCode['id'], + 'code' => $payCode['code'], + 'reg_request' => $requestId, + 'credit' => 0 + ), + array( + '%d', + '%s', + '%d', + '%f' + ) + ); + } else { + $messages[] = 'Payment code "'.$newCode.'" has already been added.'; + } + } + } else { + $messages[] = 'Payment code "'.$newCode.'" is not valid.'; + } + } + + + $regPayCodes = $this->getList("T.reg_request = $requestId"); + + if (!regPayCodes) { + return false; + } + + // Remove requested payment codes + if (isset($_REQUEST['deletePayCode'])) { + + $delCode = $_REQUEST['deletePayCode'] - 0; + + // If there's a code saved that matches the delete code, drop it + if ($delCode > 0 && isset($regPayCodes[$delCode])) { + $messages[] = 'Payment code "'.$regPayCodes[$delCode]['code'].'" has been removed.'; + unset($regPayCodes[$delCode]); + $this->deleteEntry($delCode, true); + } + } + + // Remove expired payment codes + $expired = ''; + $sep = ''; + foreach ($regPayCodes as $key=>$code) { + if ($code['expire_date']['timestamp'] < time()) { + $this->deleteEntry($code['id'], true); + $expired .= $sep.$code['code']; + $sep = ', '; + unset($regPayCodes[$key]); + } + } + + // If any were expired, add a message + if ($expired != '') { + $messages[] = 'These payment codes have expired and have been removed from your cart: '.$expired; + } + + return array( + 'messages' => $messages, + 'payCodes' => $regPayCodes + ); + } + + + + } diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php index 885181b..ae44e20 100644 --- a/classes/regCartSupport.php +++ b/classes/regCartSupport.php @@ -26,6 +26,7 @@ require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequestEv require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequestClass.php'; require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequestRate.php'; require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequestRegistrant.php'; +require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequestPayCode.php'; class GlmRegCartSupport { @@ -175,6 +176,7 @@ class GlmRegCartSupport $RequestClass = new GlmDataRegistrationsRequestClass($this->wpdb, $this->config); $RequestRate = new GlmDataRegistrationsRegRequestRate($this->wpdb, $this->config); $RequestRegistrant = new GlmDataRegistrationsRequestRegistrant($this->wpdb, $this->config); + $RequestPayCode = new GlmDataRegistrationsRequestPayCode($this->wpdb, $this->config); // First purge any expired pending registration holds $this->purgeOldRegTimePending(); @@ -210,8 +212,16 @@ class GlmRegCartSupport // Add submitting account if not guest submission (at this point) $this->addAccountToCart($this->cart['request']['account']); - // Add any payment codes - + // Get any payment codes and check for any new ones. + $newCodeRequested = false; + if (isset($_REQUEST['regPaymentCode'])) { + $newCodeRequested = trim($_REQUEST['regPaymentCode']); + } + $codes = $RequestPayCode->getAndExpireRegPayCodes($requestId, $newCodeRequested); + if (count($codes['messages']) > 0) { + $this->cart['messages'] = array_merge($this->cart['messages'], $codes['messages']); + } + $this->cart['payCodes'] = $codes['payCodes']; // Get list of events being requested $this->cart['events'] = $RequestEvent->getList("T.reg_request = $requestId"); @@ -371,8 +381,6 @@ class GlmRegCartSupport $RequestRate = new GlmDataRegistrationsRegRequestRate($this->wpdb, $this->config); $RequestRegistrant = new GlmDataRegistrationsRequestRegistrant($this->wpdb, $this->config); - $this->cart['messages'] = array(); - $totalRegistrants = 0; $totalCharges = 0; $totalDiscounts = 0; diff --git a/index.php b/index.php index 9f7ca72..32e0124 100644 --- a/index.php +++ b/index.php @@ -44,7 +44,7 @@ if (!defined('ABSPATH')) { * version from this plugin. */ define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_VERSION', '0.0.21'); +define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_VERSION', '0.0.22'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.10.17'); diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php index 53370b8..6bfc3fa 100644 --- a/models/admin/registrations/events.php +++ b/models/admin/registrations/events.php @@ -166,8 +166,6 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent case 'paymentCodes': - - require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataPaymentCode.php'; $PayCode = new GlmDataRegistrationsPaymentCode($this->wpdb, $this->config); @@ -180,13 +178,12 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent case 'update': $payCodeId = ($_REQUEST['payCodeId'] - 0); - $PayCode->updateEntry($payCodeId); + $x = $PayCode->updateEntry($payCodeId); break; case 'delete': $payCodeId = ($_REQUEST['payCodeId'] - 0); if ( $payCodeId > 0 ) { -echo "ID = $payCodeId

"; $PayCode->deleteEntry( $payCodeId, true ); } break; @@ -197,6 +194,7 @@ echo "ID = $payCodeId

"; // *** NEED TO FIX ref_type to include other possible one for events $payCodes = $PayCode->getList("T.ref_type = 20 AND T.ref_dest = $regEventID"); + if ($payCodes) { $havePayCodes = true; } diff --git a/models/front/registrations/checkoutProcess.php b/models/front/registrations/checkoutProcess.php index 16faf92..5feedc6 100644 --- a/models/front/registrations/checkoutProcess.php +++ b/models/front/registrations/checkoutProcess.php @@ -168,9 +168,9 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport */ // Check if we need to collect billing account information or if it's the same as the main contact - if (isset($_REQUEST['billing_same']) && $_REQUEST['billing_same']) { - $billingSame = true; - } +// if (isset($_REQUEST['billing_same']) && $_REQUEST['billing_same']) { +// $billingSame = true; +// } if (count($messages) == 0) { @@ -184,7 +184,7 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport // Try to update the account information and if that works get the data for editing again if ($accountId > 0) { - +/* $regAccount = $Account->updateEntry($accountId); // If there was a problem, indicate that @@ -193,8 +193,9 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport // Otherwise get the data again prepaired for editing } else { +*/ $regAccount = $Account->editEntry($accountId); - } + // } } // Otherwise this is a guest so try to create the account using the submitted data @@ -489,6 +490,7 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport $reqFormat[] = '%d'; // Billing data + $reqData = array_merge( $reqData, array( diff --git a/setup/databaseScripts/create_database_V0.0.21.sql b/setup/databaseScripts/create_database_V0.0.22.sql similarity index 99% rename from setup/databaseScripts/create_database_V0.0.21.sql rename to setup/databaseScripts/create_database_V0.0.22.sql index 02b6cea..565d81b 100644 --- a/setup/databaseScripts/create_database_V0.0.21.sql +++ b/setup/databaseScripts/create_database_V0.0.22.sql @@ -190,6 +190,7 @@ CREATE TABLE {prefix}payment_code ( ref_dest INT NULL, -- Pointer to the specific entity of ref_type code TINYTEXT NULL, -- Text code user must enter to use amount FLOAT, -- Amount of discount if not type "Free" - Either $ amount or percent + expire_date DATE NULL, -- Expiration Date descr TEXT NULL, PRIMARY KEY (id), INDEX (ref_dest), @@ -538,8 +539,10 @@ CREATE TABLE {prefix}reg_request_registrant ( CREATE TABLE {prefix}reg_request_pay_code ( id INT NOT NULL AUTO_INCREMENT, payment_code INT NULL, -- Pointer to payment code + code TINYTEXT NULL, -- Copy of Payment Code text in case payment code is deleted or changed reg_request INT NULL, -- Pointer to the registration request record credit DOUBLE PRECISION NULL, -- Total credit for this payment code + expire_date DATE NULL, -- Expiration Date - NOT USING NOW - Getting from payment_code table allways PRIMARY KEY (id), INDEX (payment_code), INDEX (reg_request) diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 751677a..b8dc1f1 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -34,7 +34,8 @@ $glmMembersRegistrationsDbVersions = array( '0.0.18' => array('version' => '0.0.18', 'tables' => 15, 'date' => '11/7/2017'), '0.0.19' => array('version' => '0.0.19', 'tables' => 15, 'date' => '11/22/2017'), '0.0.20' => array('version' => '0.0.20', 'tables' => 16, 'date' => '01/02/2018'), - '0.0.21' => array('version' => '0.0.21', 'tables' => 17, 'date' => '01/08/2018') + '0.0.21' => array('version' => '0.0.21', 'tables' => 17, 'date' => '01/08/2018'), + '0.0.22' => array('version' => '0.0.22', 'tables' => 17, 'date' => '01/09/2018') ); diff --git a/setup/databaseScripts/drop_database_V0.0.21.sql b/setup/databaseScripts/drop_database_V0.0.22.sql similarity index 100% rename from setup/databaseScripts/drop_database_V0.0.21.sql rename to setup/databaseScripts/drop_database_V0.0.22.sql diff --git a/setup/databaseScripts/update_database_V0.0.22.sql b/setup/databaseScripts/update_database_V0.0.22.sql new file mode 100644 index 0000000..3556e04 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.22.sql @@ -0,0 +1,17 @@ +-- Gaslight Media Members Database - Registratiuons Add-On +-- File Created: 10/03/17 11:00:00 +-- Database Version: 0.0.16 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +ALTER TABLE {prefix}reg_request_pay_code ADD COLUMN code TINYTEXT; + +---- + +ALTER TABLE {prefix}reg_request_pay_code ADD COLUMN expire_date DATE; + +---- + +ALTER TABLE {prefix}payment_code ADD COLUMN expire_date DATE; diff --git a/views/admin/registrations/eventPaymentCodes.html b/views/admin/registrations/eventPaymentCodes.html index e710ebe..41bdda9 100644 --- a/views/admin/registrations/eventPaymentCodes.html +++ b/views/admin/registrations/eventPaymentCodes.html @@ -24,7 +24,7 @@ - {$regEventID} + @@ -40,12 +40,18 @@ - + Payment Amount: + + Expiration Date: + + + + Payment Description: @@ -80,18 +86,13 @@ - - - - - + + + + + + - - {if $havePayCodes} {assign var="i" value="0"} {foreach $payCodes as $p} @@ -144,12 +150,8 @@ {else} {/if} - - + + - - + +
Payment Code: - -
+
Payment Code Type:Payment Code Type:
Expiration Date: + +
Payment Description: @@ -129,13 +136,12 @@ Payment Code Type Amount Expire Date Description Uses  
-
{$p.code}
-
-
{$p.code_type.name}
-
{$p.code}
{$p.code_type.name}
{if $p.code_type.value==20} ${$p.amount|number_format:2} @@ -157,12 +159,8 @@ {$p.amount|number_format:2}% {/if} -
{$p.descr}
-
- (n/a) -
{$p.expire_date.date}
{$p.descr}
Edit
Delete
@@ -201,18 +199,19 @@ }); $('.editPaymentCode').click( function() { var paycodeID = $(this).attr('data-paycodeID'); - var paycodeType = $('#paymentType_' + paycodeID).html(); - var paycodeDescr = $('#paymentDescription_' + paycodeID).html(); - var paycodeAmount = $(this).attr('data-payAmount'); var paycode = $('#paymentCode_' + paycodeID).html(); + var paycodeType = $('#paymentType_' + paycodeID).html(); var paycodeTypeValue = $('#paymentType_' + paycodeID).data('value'); + var paycodeExpire = $('#paymentExpire_' + paycodeID).html(); + var paycodeAmount = $(this).attr('data-payAmount'); + var paycodeDescr = $('#paymentDescr_' + paycodeID).html(); $('#payCodeId').val(paycodeID); - $('#edit-code').val(paycode); + $('#edit-type').val(paycodeType); $('#edit-amount').val(paycodeAmount); + $('#edit-expire').val(paycodeExpire); $('#edit-descr').val(paycodeDescr); - $('#edit-type').val(paycodeType); $("#edit-code-type option").filter(function() { return parseInt($(this).val()) === parseInt(paycodeTypeValue); @@ -259,6 +258,9 @@ }); + // Various input masks for credit card input + $(".date-input-mask").mask("00/00/0000"); + }); diff --git a/views/front/registrations/cart.html b/views/front/registrations/cart.html index d0c6b48..67eb67f 100644 --- a/views/front/registrations/cart.html +++ b/views/front/registrations/cart.html @@ -43,12 +43,19 @@

Selected Registrations

-
+
If you have a "payment Code", please enter it here: - - + +
+ {assign var="codeSep" value=""} + {if $cart.payCodes} +

Accepted Payment Codes: +    + {foreach $cart.payCodes as $code}{$codeSep}{$code.code}{assign var="codeSep" value=", "}{/foreach} +

+ {/if}
{assign var="summaryType" value="cart"} -- 2.17.1