From 244f72c916e67e72164f2d943d1ad122ab25fb90 Mon Sep 17 00:00:00 2001
From: Chuck Scott
Date: Fri, 15 Dec 2017 15:18:40 -0500
Subject: [PATCH] Fixed problems with payment list on checkout page.
Now properly checks for default payment option and tries to display that option.
Now checks for management settings for which payment options are enabled.
Now checks events in the cart to determine which available payment methods are enabled for all events in the cart.
Minor update to admin custom fields page for events to support new fields.
---
classes/regCartSupport.php | 4 ++
models/front/registrations/checkout.php | 30 ++++++----
.../registrations/eventEditCustomFields.html | 7 +--
views/front/registrations/checkout.html | 57 ++++++++++---------
4 files changed, 55 insertions(+), 43 deletions(-)
diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php
index cef7cbd..fa61942 100644
--- a/classes/regCartSupport.php
+++ b/classes/regCartSupport.php
@@ -217,6 +217,10 @@ class GlmRegCartSupport
if ($this->cart['events']) {
foreach ($this->cart['events'] as $eventKey => $event) {
+ // Get accepted payment methods
+ $e = $RegEvent->getEntry($event['reg_event']);
+ $this->cart['events'][$eventKey]['payment_methods'] = $e['payment_methods'];
+
// Get list of event classes requested for this event
$this->cart['events'][$eventKey]['classes'] = $RequestClass->getList("T.reg_request_event = ".$event['id']);
diff --git a/models/front/registrations/checkout.php b/models/front/registrations/checkout.php
index d3049c2..c95c452 100644
--- a/models/front/registrations/checkout.php
+++ b/models/front/registrations/checkout.php
@@ -218,14 +218,6 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport
$regReq['fieldData']['cc_cvv'] = $actionData['cardData']['cc_cvv'];
}
- // Set default payment method
- $payMethod = $this->config['default_payment_method'];
-
- // Get any payment method specified or selected on checkout attempt
- if (isset($actionData['payMethod'])) {
- $payMethod = $actionData['payMethod'];
- }
-
// Add credit card and other payment field data to $regAccount['fieldData'] for use on form
$regAccount['fieldData']['cc_type'] = $regReq['fieldData']['cc_type'];
$regAccount['fieldRequired']['cc_type'] = true;
@@ -262,6 +254,24 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport
$Management = new GlmDataRegistrationsManagement($this->wpdb, $this->config);
$management = $Management->getEntry(1);
+ // Get accepted pay methods and block out any not selected for an event
+ $availPaymentMethods = $management['reg_payment_methods']['bitmap'];
+ foreach ($this->cart['events'] as $event) {
+ foreach ($event['payment_methods']['bitmap'] as $payMethodKey=>$payMethodVal) {
+ if (!$payMethodVal['default']) {
+ $availPaymentMethods[$payMethodKey]['default'] = 0;
+ }
+ }
+ }
+
+ // Set default payment method
+ $payMethod = $this->config['default_payment_method'];
+
+ // Get any payment method specified or selected on checkout attempt
+ if (isset($actionData['payMethod'])) {
+ $payMethod = $actionData['payMethod'];
+ }
+
// Get misc texts
require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataMisc.php';
$Misc = new GlmDataRegistrationsMisc($this->wpdb, $this->config);
@@ -286,8 +296,8 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport
'assetUrl' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_ASSETS_URL,
'haveMessages' => count($messages) > 0,
'messages' => $messages,
- 'payMethod' => $payMethod,
- 'payMethods' => $management['reg_payment_methods']['bitmap'],
+ 'defaultPayMethod' => $payMethod,
+ 'payMethods' => $availPaymentMethods,
'payMethodsNumb' => $this->config['payment_method_numb'],
'misc' => $misc,
'checkoutPageText' => $misc['checkout_page_text'],
diff --git a/views/admin/registrations/eventEditCustomFields.html b/views/admin/registrations/eventEditCustomFields.html
index a5283fd..3496ac7 100644
--- a/views/admin/registrations/eventEditCustomFields.html
+++ b/views/admin/registrations/eventEditCustomFields.html
@@ -15,7 +15,6 @@
These are additional fields of information that will be requested for this event in each submission.
- {else if $pmname == "CreditCard"}
+ {else if $pmName == "CreditCard"}
-
+
Name on Card:
-
+
Card Type:
-
{else}
-
+
{/if}
{/if}
+
+ {/if} {* default is set *}
{/foreach}
@@ -363,17 +366,21 @@
$('.payMethodSelector').on('change', function() {
// Get the value from the selected Payment Method
- var payMethod = $(this).val();
+ var payMethodNumb = $(this).val();
+ payMethodSelection(payMethodNumb);
+
+ });
+ function payMethodSelection(payMethodNumb) {
// Hide all pay method inputs and dissable them all
$('.payMethodSelection').addClass('glm-hidden');
$('.payMethodInput').attr('disabled', true);
// Show the selected pay method inputs and enable just those
- $('#payMethod_' + payMethod).removeClass('glm-hidden');
- $('.payMethodInput_' + payMethod).removeAttr('disabled');
-
- });
+ $('#payMethod_' + payMethodNumb).removeClass('glm-hidden');
+ $('.payMethodInput_' + payMethodNumb).removeAttr('disabled');
+
+ }
// Dissable checkout button when first clicked to prevent multiple attempts
$("#checkoutForm").submit(function(e){
@@ -416,11 +423,7 @@
// Start with all payment method sections hidden
$('.payMethodInput').attr('disabled', true);
- // When a payment method is selected, show that section
- if ({$payMethod}) {
- $('#payMethod_' + {$payMethod}).removeClass('glm-hidden');
- $('.payMethodInput_' + {$payMethod}).removeAttr('disabled');
- }
+ payMethodSelection({$defaultPayMethod});
});
--
2.17.1