From 40830a5b32be67b3618036d3916449664bd44e9d Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Mon, 4 Jun 2018 16:25:24 -0400 Subject: [PATCH] Added PayPal support to checkout and updated database Updated text displayed in alert when trying to register more attendees per submission than permitted. Updated database to version 1.0.0 in prep for first release. Added PayPal sandbox id/secret fields to database and management. Fixed problem with payment types not properly selected for checkout in checkout.php Fixed problem with checkout button after adding PayPal. --- classes/data/dataManagement.php | 41 ++- classes/regCartSupport.php | 37 +++ config/plugin.ini | 4 +- index.php | 2 +- js/frontRegApp.js | 2 +- models/admin/ajax/regPayPal.php | 238 ++++++++++++++++++ models/front/registrations/checkout.php | 62 +++-- .../front/registrations/checkoutProcess.php | 42 +++- ...V0.0.31.sql => create_database_V1.0.0.sql} | 6 + setup/databaseScripts/dbVersions.php | 5 +- ...e_V0.0.31.sql => drop_database_V1.0.0.sql} | 0 .../update_database_V0.0.31.sql | 2 +- .../update_database_V0.0.32.sql | 27 ++ .../update_database_V1.0.0.sql | 20 ++ setup/validActions.php | 3 +- views/admin/management/registrations.html | 56 +++++ views/front/registrations/checkout.html | 194 +++++++++++++- views/front/registrations/registration.html | 2 + views/front/registrations/summaryStore.html | 30 ++- 19 files changed, 707 insertions(+), 66 deletions(-) create mode 100644 models/admin/ajax/regPayPal.php rename setup/databaseScripts/{create_database_V0.0.31.sql => create_database_V1.0.0.sql} (99%) rename setup/databaseScripts/{drop_database_V0.0.31.sql => drop_database_V1.0.0.sql} (100%) create mode 100644 setup/databaseScripts/update_database_V0.0.32.sql create mode 100644 setup/databaseScripts/update_database_V1.0.0.sql diff --git a/classes/data/dataManagement.php b/classes/data/dataManagement.php index 1aa84ae..8616293 100644 --- a/classes/data/dataManagement.php +++ b/classes/data/dataManagement.php @@ -293,8 +293,8 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract 'reg_merchant_solutions_test' => array ( 'field' => 'reg_merchant_solutions_test', 'type' => 'list', - 'list' => $this->config['proc_test_mode'], - 'default' => $this->config['proc_test_mode_numb']['Local Approval Test'], + 'list' => $this->config['proc_test_mode'], + 'default' => $this->config['proc_test_mode_numb']['Local Approval Test'], 'use' => 'a' ), @@ -313,6 +313,43 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract 'use' => 'a' ), + // PayPal Client ID + 'reg_paypal_clientid' => array ( + 'field' => 'reg_paypal_clientid', + 'type' => 'text', + 'use' => 'a' + ), + + // PayPal Secret + 'reg_paypal_secret' => array ( + 'field' => 'reg_paypal_secret', + 'type' => 'text', + 'use' => 'a' + ), + + // PayPal Sandbox Client ID + 'reg_paypal_sandbox_clientid' => array ( + 'field' => 'reg_paypal_sandbox_clientid', + 'type' => 'text', + 'use' => 'a' + ), + + // PayPal Sandbox Secret + 'reg_paypal_sandbox_secret' => array ( + 'field' => 'reg_paypal_sandbox_secret', + 'type' => 'text', + 'use' => 'a' + ), + + // PayPal Test Mode + 'reg_paypal_test' => array ( + 'field' => 'reg_paypal_test', + 'type' => 'list', + 'list' => $this->config['paypal_test_mode'], + 'default' => $this->config['paypal_test_mode_numb']['Sandbox'], + 'use' => 'a' + ), + // Always Use Full Billing Info 'reg_full_billing_info' => array ( 'field' => 'reg_full_billing_info', diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php index a77d150..939b1db 100644 --- a/classes/regCartSupport.php +++ b/classes/regCartSupport.php @@ -398,6 +398,9 @@ class GlmRegCartSupport $grandTotal = 0; $haveEvents = false; + // Build separate array of charges to use for payment processors + $this->cart['chargeItems'] = array(); + // If we have a cart and a good request array if ($this->cart && is_array($this->cart['request'])) { @@ -562,6 +565,15 @@ class GlmRegCartSupport $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['registrantRate'] = $registrantCharges; $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['registrantDiscounts'] = $registrantDiscounts; + // Add to charges summary array + $this->cart['chargeItems'][] = array( + 'quantity' => 1, + 'name' => + $this->config['terms']['reg_term_event_cap'].': '.$event['event_name'].', '. + $this->config['terms']['reg_term_attendee_cap'].': '.$registrant['fname'].' '.$registrant['lname'], + 'price' => $rateRegistrantCharges + ); + } // Add a more familiar date/time @@ -609,6 +621,14 @@ class GlmRegCartSupport $classCharges += ( $rateBaseCharge + $rateRegistrantCharges); $classDiscounts += $rateDiscounts; + // Add to charges summary array + $this->cart['chargeItems'][] = array( + 'quantity' => 1, + 'name' => + $this->config['terms']['reg_term_level_cap'].': '.$rate['rate_name'], + 'price' => $rateBaseCharge + $rateDisconts + ); + } if ($deleteRateNow) { @@ -727,6 +747,15 @@ class GlmRegCartSupport $totalCharges += $eventCharges; $totalDiscounts += $eventDiscounts; + // Add to charges summary array + if ($eventDiscounts != 0) { + $this->cart['chargeItems'][] = array( + 'quantity' => 1, + 'name' => $event['event_name'].' Discounts', + 'price' => -$eventDiscounts + ); + } + } if ($deleteEventNow) { @@ -760,6 +789,14 @@ class GlmRegCartSupport $code['thisDiscount'] = $thisDiscount; $this->cart['globalPayCodes'][$code['id']] = $code; + + // Add to charges summary array + $this->cart['chargeItems'][] = array( + 'quantity' => 1, + 'name' => 'Payment Code: '.$code['code'], + 'price' => -$thisDiscount + ); + } } diff --git a/config/plugin.ini b/config/plugin.ini index f63c94a..c73bb20 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -36,7 +36,7 @@ payment_method[3] = 'Cash' payment_method[4] = 'Check' ; payment_method[5] = 'Call from Merchant' payment_method[6] = 'Credit Card' -; payment_method[7] = 'PayPal' +payment_method[7] = 'PayPal' payment_method [10] = 'Payment Pending' payment_method_numb['NoCharge'] = 1 @@ -45,7 +45,7 @@ payment_method_numb['Cash'] = 3 payment_method_numb['Check'] = 4 ; payment_method_numb['CallFromMerchant'] = 5 payment_method_numb['CreditCard'] = 6 -; payment_method_numb['PayPal'] = 7 +payment_method_numb['PayPal'] = 7 payment_method_numb['Pending'] = 10 ; Default payment method is Credit Card diff --git a/index.php b/index.php index 10137cc..a1fc56c 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.31'); +define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_VERSION', '1.0.0'); // 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.27'); diff --git a/js/frontRegApp.js b/js/frontRegApp.js index c7bc321..e946ffb 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -944,7 +944,7 @@ app.Views.Front.RegTime = Backbone.View.extend({ // add new account addNewAccount: function(){ if ( app.checkForMaxAttendees() === true ) { - alert( 'You\'re only allowed to have ' + app.attendeeMaxPerReg + ' ' + app.attendeePlurCapTerm + ' per Registration!' ); + alert( app.attendeePlurCapTerm + ' are currently limited to ' + app.attendeeMaxPerReg + ' per submission for this ' + app.eventCapTerm + '!'); return; } // check for the lock diff --git a/models/admin/ajax/regPayPal.php b/models/admin/ajax/regPayPal.php new file mode 100644 index 0000000..c03b3a7 --- /dev/null +++ b/models/admin/ajax/regPayPal.php @@ -0,0 +1,238 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +// Load PayPal Payment CLass +require_once GLM_MEMBERS_PLUGIN_LIB_PATH . '/paymentProcessors/PayPal/paymentGateway.php'; + +// Load Registrations Support +require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/regCartSupport.php'; + + +/** + * This class processes AJAX requests for the PayPal payment actions + */ +class GlmMembersAdmin_ajax_regPayPal extends GlmRegCartSupport +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * PayPal Account Data + * + * @var $account + * @access public + */ + public $account = false; + /** + * PayPal Payment Data + * + * @var $payment + * @access public + */ + public $payment = false; + + /* + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for data class + // parent::__construct(false, false); + + // Build Account Array + + + // Build Payment Array + $this->account = array( + 'clientID' => $this->config['settings']['reg_paypal_clientid'], + 'secret' => $this->config['settings']['reg_paypal_secret'], + 'returnURL' => GLM_MEMBERS_PLUGIN_ADMIN_AJAX_URL.'?PayPalAction=Approved', + 'cancelURL' => GLM_MEMBERS_PLUGIN_ADMIN_AJAX_URL.'?PayPalAction=Canceled', + 'test' => $this->config['settings']['reg_paypal_test'] + ); + + } + + /* + * Perform Model Action + * + * This model performs the various PayPal request and call back actions + * + * This model action does not return, it simply does it's work then calls wp_die(); + * + * @param $actionData + * + */ + public function modelAction( $actionData = false ) + { + + // Add cart ID and check value to URLs + $cartId = false; + if (isset($_SESSION['cartID'])) { + $cartId = $_SESSION['cartID']; + } elseif (isset($_REQUEST['cart'])) { + $cartId = $_REQUEST['cart'] - 0; + } + $cartCheck = false; + if (isset($_SESSION['cartCheck'])) { + $cartCheck = $_SESSION['cartCheck']; + } elseif (isset($_REQUEST['cartCheck'])) { + $cartCheck = $_REQUEST['cartCheck']; + } + + // Make sure we have good cart ID and Cart Check + $cartCheckExpected = md5($cartId.GLM_MEMBERS_REGISTRATIONS_PLUGIN_SECRET); + if (!$cartId || $cartId <= 0 || !$cartCheck || $cartCheck != $cartCheckExpected ) { + wp_die('Invalid Cart'); + } + + // Save Cart ID and CartCheck + $_SESSION['cartID'] = $cartId; + $_SESSION['cartCheck'] = $cartCheck; + + // Get Cart Data + $this->getRegistrationCart($cartId); + if (!$this->cart['status']) { + wp_die('Cart Not Found'); + } + + // Build Payment Array + $this->payment = array( + 'name' => $this->config['settings']['reg_org_name'], + 'charge' => substr($this->cart['request']['total'], 1, -1), + 'invoice' => $cartId, + 'description' => $this->config['terms']['reg_term_registrations_name'], + 'items' => array() + ); + + // Add items + foreach ($this->cart['events'] as $event) { + $this->payment['items'][] = array( + 'quantity' => 1, + 'name' => 'Total for all requested '.$this->config['terms']['reg_term_registration_plur_cap'], + 'price' => substr($this->cart['request']['total'], 1, -1) + ); + } + +// echo "
".print_r($this->account,1).print_r($this->payment,1)."
"; +// echo "
".print_r($this->cart,1)."
"; +// echo "REQUEST = $request"; + + // Set default action and try to get any requested action + $request = false; + if (isset($_REQUEST) && isset($_REQUEST) && isset($_REQUEST['PayPalAction']) && trim($_REQUEST['PayPalAction']) != '') { + $request = $_REQUEST['PayPalAction']; + } + + // Check for certain actions related to sending user to PayPal site for approval + switch ($request) { + + case 'Approved': + + echo "Return link followed.

"; + + // Save Payer ID + $_SESSION['payerID'] = $_REQUEST['PayerID']; // NEED TO FILTER THIS FOR PRODUCTION + + // Create PayPal object with existing access object from the session + $PayPal = new PaymentGateway($this->account, $_SESSION['access'], $_SESSION['trans']); + + // Execute the PayPal payment + $r = $PayPal->executePayment($_SESSION['payerID']); + + echo "

Payment Executed Successfully

".print_r($r,1)."
"; + + exit; + + break; + + case 'Canceled': + + echo "Payment Cancelled

"; + exit; + break; + + // Display PayPal login and get approval + default: + + // Clear any existing PayPal transaction data in session + unset($_SESSION['trans']); + + // Create the PayPal object (note no previous access object) + $PayPal = new PaymentGateway($this->account, false, false); + + // Was there an error? + if (!$PayPal->status) { + echo "Received an error: ".$PayPal->error; + exit; + } + + // Store access information +// Do we need this? $_SESSION['access'] = $PayPal->access; + + // Try to enter Payment + $PayPal->processPayment($this->payment, $contact); + + // Was there an error? + if (!$PayPal->status) { + echo "Received an error: ".$PayPal->error."

"; + + exit; + } + + // Store Transaction data to session + $_SESSION['trans'] = $PayPal->trans; + + // Get Approval for this transaction from PayPal + $trans = $_SESSION['trans']; + + header('Location: '.$trans->urls->approval_url->href); + + exit; + + break; + } + + } +} diff --git a/models/front/registrations/checkout.php b/models/front/registrations/checkout.php index f03805d..f032264 100644 --- a/models/front/registrations/checkout.php +++ b/models/front/registrations/checkout.php @@ -137,7 +137,11 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport $this->checkRegistrationRequest($cartId); // Check if cart has been successfully checked out or has been marked canceled. - if ($this->cart['request']['status']['value'] > 0) { + $statusCheck = array( + $this->config['submission_status_numb']['CART'], + $this->config['submission_status_numb']['PAYMENT_PEND'] + ); + if (!in_array($this->cart['request']['status']['value'], $statusCheck)) { $messages[] = "This request has already been submitted!
The information below is a summary of your submitted request."; @@ -318,15 +322,16 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport $view = 'checkout'; - require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataManagement.php'; $Management = new GlmDataRegistrationsManagement($this->wpdb, $this->config); $management = $Management->getEntry(1); - // Get all payment methods and assume they might all be available - $availPaymentMethods = $management['reg_payment_methods']['bitmap']; - foreach ($availPaymentMethods as $methKey=>$methVal) { - $availPaymentMethods[$methKey]['default'] = true; + // Get all payment methods and select the ones that are enabled in managemnt + $availPaymentMethods = array(); + foreach ($management['reg_payment_methods']['bitmap'] as $methKey=>$methVal) { + if ($methVal['default']) { + $availPaymentMethods[$methKey] = $methVal; + } } // For each event in cart, check each payment method. Only methods enabled in all events are available. @@ -338,6 +343,7 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport if (!$payMethodVal['default'] && isset($availPaymentMethods[$payMethodKey])) { unset($availPaymentMethods[$payMethodKey]); } + } } @@ -362,28 +368,32 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport // Compile template data $templateData = array( - 'page' => 'checkout', - 'regAccountId' => $this->cart['request']['account'], - 'regAccount' => $regAccount, - 'cartId' => $cartId, - 'haveCart' => $haveCart, - 'cart' => $this->cart, - 'checkoutUrl' => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/', - 'loggedIn' => $loggedIn, - 'regUrl' => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/', - 'assetUrl' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_ASSETS_URL, - 'haveMessages' => count($messages) > 0, - 'messages' => $messages, - 'defaultPayMethod' => $payMethod, - 'payMethods' => $availPaymentMethods, - 'payMethodsNumb' => $this->config['payment_method_numb'], - 'misc' => $misc, - 'checkoutPageText' => $misc['checkout_page_text'], - 'globalTerms' => $misc['reg_terms'], - 'eventCustomFieldsFidPrefix' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG.'-customfields-reg-event-' + 'page' => 'checkout', + 'regAccountId' => $this->cart['request']['account'], + 'regAccount' => $regAccount, + 'cartId' => $cartId, + 'cartCheck' => md5($cartId.GLM_MEMBERS_REGISTRATIONS_PLUGIN_SECRET), + 'haveCart' => $haveCart, + 'cart' => $this->cart, + 'checkoutUrl' => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/', + 'loggedIn' => $loggedIn, + 'regUrl' => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/', + 'assetUrl' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_ASSETS_URL, + 'haveMessages' => count($messages) > 0, + 'messages' => $messages, + 'defaultPayMethod' => $payMethod, + 'payMethods' => $availPaymentMethods, + 'payMethodsNumb' => $this->config['payment_method_numb'], + 'misc' => $misc, + 'checkoutPageText' => $misc['checkout_page_text'], + 'globalTerms' => $misc['reg_terms'], + 'eventCustomFieldsFidPrefix' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG.'-customfields-reg-event-', + 'payPalClientId' => $this->config['settings']['reg_paypal_clientid'], + 'payPalSandboxClientId' => $this->config['settings']['reg_paypal_sandbox_clientid'], + 'payPalMode' => $this->config['settings']['reg_paypal_test'] ); - // echo "
".print_r($templateData,1)."
"; + // echo "payMethods
".print_r($availPaymentMethods,1)."
"; // Return status, any suggested view, and any data to controller return array( diff --git a/models/front/registrations/checkoutProcess.php b/models/front/registrations/checkoutProcess.php index 7fb2e45..8b51c2c 100644 --- a/models/front/registrations/checkoutProcess.php +++ b/models/front/registrations/checkoutProcess.php @@ -268,12 +268,6 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport } - /* - * Process any Custom Fields - */ - -// ******* NEED TO DO THIS ??? ******** - /* * Process Payment? */ @@ -560,8 +554,40 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport break; // Pay Pal -// case $this->config['payment_method_numb']['PayPal']: -// break; + case $this->config['payment_method_numb']['PayPal']: + + // Check for valid PayPal payment + $payPalPaymentID = filter_input(INPUT_POST, 'payPalPaymentID', FILTER_SANITIZE_STRING); + $payPalPaymentTime = filter_input(INPUT_POST, 'payPalPaymentTime', FILTER_SANITIZE_STRING); + $payPalPaymentState = filter_input(INPUT_POST, 'payPalPaymentState', FILTER_SANITIZE_STRING); + + // If we don't have a valid payment, add to messages array + if (!$payPalPaymentID || !$payPalPaymentTime || !$payPalPaymentState || $payPalPaymentState != "completed") { + $messages[] = 'Sorry, we were unable to determine the status of your PayPal payment. Please check your PayPal account to see if the amount has been paid and if so, call us for assitance.'; + } else { + + // We have a valid payment + $cartStatus = $this->config['submission_status_numb']['COMPLETE']; + + // Store PayPal confirmation information in the CreditCard related fields. + $reqData = array_merge( + $reqData, + array( + 'cc_name' => 'PayPal', + 'cc_conf' => $payPalPaymentID.' - '.$payPalPaymentTime + ) + ); + $reqFormat = array_merge( + $reqFormat, + array( + '%s', + '%s', + ) + ); + + } + + break; // Payment Method unknown default: diff --git a/setup/databaseScripts/create_database_V0.0.31.sql b/setup/databaseScripts/create_database_V1.0.0.sql similarity index 99% rename from setup/databaseScripts/create_database_V0.0.31.sql rename to setup/databaseScripts/create_database_V1.0.0.sql index 1b0abac..1f1382c 100644 --- a/setup/databaseScripts/create_database_V0.0.31.sql +++ b/setup/databaseScripts/create_database_V1.0.0.sql @@ -91,6 +91,12 @@ CREATE TABLE {prefix}management ( reg_merchant_solutions_test TINYINT NULL, -- Merchant Solutions test mode - List - see proc_test_mode in plugin.ini reg_merchant_solutions_conf BOOLEAN NULL, -- Flag to send payment confirmation Email reg_merchant_solutions_merchant_email TINYTEXT NULL, -- Merchant Solutions will send copy of confirmation E-Mail + -- PayPal Credentials + reg_paypal_clientid TINYTEXT NULL, -- PayPal Client ID + reg_paypal_secret TINYTEXT NULL, -- PayPal Secret + reg_paypal_sandbox_clientid TINYTEXT NULL, -- PayPal Client ID + reg_paypal_sandbox_secret TINYTEXT NULL, -- PayPal Secret + reg_paypal_test TINYINT NULL, -- PayPal test mode - List - see -- Billing settings reg_full_billing_info BOOLEAN NULL, -- Always request full billing information in checkout page regardless of the following settings reg_bill_info_req_no_charge SMALLINT NULL, -- Bitmap of fields to use in checkout for these types of payments - See billing_field in plugin.conf diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 8775429..863ef9e 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -44,7 +44,10 @@ $glmMembersRegistrationsDbVersions = array( '0.0.28' => array('version' => '0.0.28', 'tables' => 18, 'date' => '04/12/2018'), '0.0.29' => array('version' => '0.0.29', 'tables' => 18, 'date' => '05/04/2018'), '0.0.30' => array('version' => '0.0.30', 'tables' => 18, 'date' => '05/14/2018'), - '0.0.31' => array('version' => '0.0.31', 'tables' => 18, 'date' => '05/15/2018') + '0.0.31' => array('version' => '0.0.31', 'tables' => 18, 'date' => '05/15/2018'), + '0.0.32' => array('version' => '0.0.32', 'tables' => 18, 'date' => '05/22/2018'), + + '1.0.0' => array('version' => '1.0.0', 'tables' => 18, 'date' => '06/04/2018') ); diff --git a/setup/databaseScripts/drop_database_V0.0.31.sql b/setup/databaseScripts/drop_database_V1.0.0.sql similarity index 100% rename from setup/databaseScripts/drop_database_V0.0.31.sql rename to setup/databaseScripts/drop_database_V1.0.0.sql diff --git a/setup/databaseScripts/update_database_V0.0.31.sql b/setup/databaseScripts/update_database_V0.0.31.sql index 7029af4..72dc01c 100644 --- a/setup/databaseScripts/update_database_V0.0.31.sql +++ b/setup/databaseScripts/update_database_V0.0.31.sql @@ -1,6 +1,6 @@ -- Gaslight Media Members Database - Registratiuons Add-On -- File Updated: 2018-04-12 --- Database Version: 0.0.30 +-- Database Version: 0.0.31 -- Database Update From Previous Version Script -- -- To permit each query below to be executed separately, diff --git a/setup/databaseScripts/update_database_V0.0.32.sql b/setup/databaseScripts/update_database_V0.0.32.sql new file mode 100644 index 0000000..b8ca636 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.32.sql @@ -0,0 +1,27 @@ +-- Gaslight Media Members Database - Registratiuons Add-On +-- File Updated: 2018-05-22 +-- Database Version: 0.0.32 +-- 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}management ADD COLUMN reg_paypal_clientid TINYTEXT; + +---- + +ALTER TABLE {prefix}management ADD COLUMN reg_paypal_secret TINYTEXT; + +---- + +ALTER TABLE {prefix}management ADD COLUMN reg_paypal_test TINYINT; + +---- + +UPDATE {prefix}management + SET reg_paypal_clientid = '', + reg_paypal_secret = '', + reg_paypal_test = 3 +; + + diff --git a/setup/databaseScripts/update_database_V1.0.0.sql b/setup/databaseScripts/update_database_V1.0.0.sql new file mode 100644 index 0000000..ce99b41 --- /dev/null +++ b/setup/databaseScripts/update_database_V1.0.0.sql @@ -0,0 +1,20 @@ +-- Gaslight Media Members Database - Registratiuons Add-On +-- File Updated: 2018-05-22 +-- Database Version: 0.0.32 +-- 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}management ADD COLUMN reg_paypal_sandbox_clientid TINYTEXT; + +---- + +ALTER TABLE {prefix}management ADD COLUMN reg_paypal_sandbox_secret TINYTEXT; + +---- + +UPDATE {prefix}management + SET reg_paypal_sandbox_clientid = '', + reg_paypal_sandbox_secret = '' +; diff --git a/setup/validActions.php b/setup/validActions.php index 689fff3..14cae63 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -69,7 +69,8 @@ $glmMembersRegistrationsAddOnValidActions = array( 'registrantsListExport' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, 'setupEventRegQueue' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, 'runEventRegQueue' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, - 'getAuthorizeNetSeal' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG + 'getAuthorizeNetSeal' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, + 'regPayPal' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG ), 'registrations' => array( 'index' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, diff --git a/views/admin/management/registrations.html b/views/admin/management/registrations.html index 30371b1..c9067d5 100644 --- a/views/admin/management/registrations.html +++ b/views/admin/management/registrations.html @@ -136,6 +136,9 @@ + + +

Authorize.net

@@ -203,6 +206,8 @@ + + @@ -248,6 +253,57 @@ {if $regSettings.fieldFail.reg_merchant_solutions_merchant_email}

{$regSettings.fieldFail.reg_merchant_solutions_merchant_email}

{/if} + + + + + +

PayPal

+ + + Production Client ID: + + + {if $regSettings.fieldFail.reg_paypal_clientid}

{$regSettings.fieldFail.reg_paypal_clientid}

{/if} + + + + Production Secret: + + + {if $regSettings.fieldFail.reg_paypal_secret}

{$regSettings.fieldFail.reg_paypal_secret}

{/if} + + + + Sandbox Client ID: + + + {if $regSettings.fieldFail.reg_paypal_sandbox_clientid}

{$regSettings.fieldFail.reg_paypal_sandbox_clientid}

{/if} + + + + Sandbox Secret: + + + {if $regSettings.fieldFail.reg_paypal_sandbox_secret}

{$regSettings.fieldFail.reg_paypal_sandbox_secret}

{/if} + + + + Test Mode: + + + + + + +

Other General Options

diff --git a/views/front/registrations/checkout.html b/views/front/registrations/checkout.html index 0bea245..de6a044 100644 --- a/views/front/registrations/checkout.html +++ b/views/front/registrations/checkout.html @@ -156,7 +156,7 @@ {if $cart.grandTotal > 0}
-
+

Payment Information

{foreach $payMethods as $payMethod} @@ -178,7 +178,7 @@ {else if $pmName == "Cash"} {* Nothing here for now *} {else if $pmName == "Check"} -
+
Name on Check{if $regAccount.fieldRequired.cc_name} *{/if}
@@ -194,7 +194,7 @@
{else if $pmName == "CreditCard"} -
+
{if $settings.reg_proc_methods == 2 && $regAccount.fieldData.customer_profile_id != ''} {* If using Authorize.net and have a stored credit card profile *}
@@ -260,8 +260,20 @@
{/if}
+ {else if $pmName == "PayPal"} +
+
+
+   +
+
+ PayPal payment information will be requested when you select the "Pay with PayPal" button below. +
+
+
+ {else} -
+
{/if} @@ -328,12 +340,14 @@
{if $settings.reg_show_navigation_aids} -
Your {$terms.reg_term_registration} is not complete until you click here! +
Your {$terms.reg_term_registration} is not complete until you click here!
{/if} - + +
+
Please wait while we process your {$terms.reg_term_registration} request. If you don't see a new page, your {$terms.reg_term_registration} request may not have been processed.

Something may have gone wrong.

@@ -350,9 +364,17 @@
- - - + +
+
+
+
+
+ NOTE: Your {$terms.reg_term_registration_plur} are not complete until you accept the PayPal payment and see the checkout summary page! +
+
+
+
{/if} {* / if have cart *} @@ -376,14 +398,46 @@ $('.payMethodInput').attr('disabled', true); // Show the selected pay method inputs and enable just those - $('#payMethod_' + payMethodNumb).removeClass('glm-hidden'); + $('.payMethod_' + payMethodNumb).removeClass('glm-hidden'); $('.payMethodInput_' + payMethodNumb).removeAttr('disabled'); + + if (payMethodNumb == {$payMethodsNumb.PayPal}) { + $('#regSubmitButton').addClass('glm-hidden'); + $('#payPalPayButton').removeClass('glm-hidden'); + $('#payPalPayButton').removeAttr('disabled'); + } else { + $('#regSubmitButton').removeClass('glm-hidden'); + $('#payPalPayButton').addClass('glm-hidden'); + $('#payPalPayButton').attr('disabled','disabled'); + } } // Dissable checkout button when first clicked to prevent multiple attempts + var payPalSubmitOK = false; $("#checkoutForm").submit(function(e){ + // Check if this is a PayPal payment request + if (!$('#payPalPayButton').attr('disabled')) { + + // Check if this is a re-submit by our PayPal payment code below + if (payPalSubmitOK) { + return true; + } + + // Display our PayPal payment dialog box and fix some CSS + $( "#payPalPaymentDialog" ).dialog("open"); + $( "#payPalPaymentDialog" ).css({ + "width": "100%" + }); + + // Display the Pay by PayPal button in our dialog box + displayPayPalButton(); + + // Don't actually do a submit yet + return false; + } + // If something else is preventing submission, stop here. Use this with custom fields when there are required fields. if (e.isDefaultPrevented()) { return false; @@ -406,7 +460,7 @@ // Start with all pay method inputs dissabled $( document ).ready(function() { - + // Dialog box to show when submitting checkout page $( "#regSubmitDialog" ).dialog({ autoOpen: false, @@ -419,6 +473,18 @@ width: 600 }); + // Dialog box to show a PayPal payment button + $( "#payPalPaymentDialog" ).dialog({ + autoOpen: false, + width: 600, + modal: true, + 'buttons': { + 'I don\'t wish to pay with PayPal': function(event) { + $(this).dialog("close"); + } + } + }); + // Start with all payment method sections hidden $('.payMethodInput').attr('disabled', true); @@ -463,7 +529,6 @@ $(".expire-input").mask("00/00"); $(".cvv-input").mask("000#"); - // Registration not submitted Dialog actions {if $settings.reg_not_submitted_dialog} @@ -509,5 +574,110 @@ {/if} + // When the checkout button is clicked and a PayPal payment is requested, this code is called to create a PayPal button inside of the dialog box + var payPalButtonGenerated = false; + function displayPayPalButton() { + + if (payPalButtonGenerated) { + return; + } + payPalButtonGenerated = true; + + + // PayPal button actions + paypal.Button.render({ + + // Set your environment + + {if $payPalMode} + env: 'sandbox', + {else} + env: 'production', + {/if} + + // Specify the style of the button + style: { + label: 'pay', + size: 'large', // small | medium | large | responsive + shape: 'rect', // pill | rect + color: 'blue' // gold | blue | silver | black + }, + + // To create a PayPal see app: https://developer.paypal.com/developer/applications/create + client: { + sandbox: '{$payPalSandboxClientId}', + production: '{$payPalClientId}' + }, + + // Wait for the PayPal button to be clicked + payment: function(data, actions) { + return actions.payment.create({ + invoice_number: '{$cartId}', + payment: { + payer: { + payer_info: { + first_name: '{$cart.request.bill_fname}', + last_name: '{$cart.request.bill_lname}', + email: '{$cart.request.bill_email}' + } + }, + transactions: [ + { + description: '{$settings.reg_org_name} {$reg.term.registration_plur_cap}', + invoice_number: '{$cartId}', + amount: { + total: '{$cart.grandTotal}', + currency: 'USD' + }, + item_list: { + items: [ + {foreach $cart.chargeItems as $item} + { + name: '{$item.name}', + quantity: {$item.quantity}, + price: {$item.price}, + currency: 'USD' + }, + {/foreach} + ] + } + } + ] + } + }); + }, + onCancel: function(data, actions) { + $('#payPalPaymentWarningMessage').html('You canceled the PayPal Payment. Payment is required to submit your {$terms.reg_term_registration_plur}. If you don\'t wish to pay with PayPal, click the button below and select another payment method.'); + }, + onError: function(err) { + $('#payPalPaymentWarningMessage').html('There was a problem with your PayPal Payment. Payment is required to submit your {$terms.reg_term_registration_plur}. If you\'re unable to pay with PayPal, click the button below and select another payment method.'); + }, + // Wait for the payment to be authorized by the customer + onAuthorize: function(data, actions) { + return actions.payment.execute().then(function(data) { + + var sale = data.transactions[0].related_resources[0].sale; + + // Notify submit code above that it's OK to checkout + payPalSubmitOK = true; + + $( "#payPalPaymentDialog" ).dialog("close"); + + // Add PayPal payment details to form + $("#checkoutForm").append( + '' + +'' + +'' + ); + // Now try to submit the form again + $("#checkoutForm").submit(); + }); + } + + }, '#paypal-button-container'); + + } + + }); diff --git a/views/front/registrations/registration.html b/views/front/registrations/registration.html index f8b06bc..0ea3c75 100644 --- a/views/front/registrations/registration.html +++ b/views/front/registrations/registration.html @@ -492,6 +492,8 @@ var app = { attendeeCount: 0, attendeeMaxPerReg: parseInt( {$regEvent.attendee_max_per_reg} ), attendeePlurCapTerm: '{$terms.reg_term_attendee_plur_cap}', + attendeeCapTerm: '{$terms.reg_term_attendee_cap}', + eventCapTerm: '{$terms.reg_term_event_cap}', checkForMaxAttendees: function(){ if ( app.attendeeMaxPerReg ) { // Here we need to see how many registrants total in each class. diff --git a/views/front/registrations/summaryStore.html b/views/front/registrations/summaryStore.html index 5c664e6..60482e1 100644 --- a/views/front/registrations/summaryStore.html +++ b/views/front/registrations/summaryStore.html @@ -151,14 +151,16 @@ - {if $request.pay_method.value == $payMethodsNumb.CreditCard} + {if $request.pay_method.value == $payMethodsNumb.NoCharge} - - - - - - + {/if} + {if $request.pay_method.value == $payMethodsNumb.OnArrival} + + + {/if} + {if $request.pay_method.value == $payMethodsNumb.Cash} + + {/if} {if $request.pay_method.value == $payMethodsNumb.Check} @@ -166,13 +168,19 @@ {/if} - {if $request.pay_method.value == $payMethodsNumb.Cash} + {if $request.pay_method.value == $payMethodsNumb.CreditCard} - + + + + + + {/if} - {if $request.pay_method.value == $payMethodsNumb.OnArrival} + {if $request.pay_method.value == $payMethodsNumb.PayPal} - + + {/if} {if $request.pay_method.value == $payMethodsNumb.Pending} -- 2.17.1
Payment Method:{$request.pay_method.name}
Credit Card:{$request.cc_type.name}
Name on Card:{$request.cc_name}
Card Number:{$request.cc_numb}
Expiration:{$request.cc_exp}
Confirmation Code:{$request.cc_conf}
Total Charged:{$request.total}
Payment Method:{$request.pay_method.name}
To be paid on arrival:{$request.total}
Payment Method:{$request.pay_method.name}
Total Paid:{$request.total}
Payment Method:{$request.pay_method.name}
Check Number:{$request.cc_numb}
Total Paid:{$request.total}
Payment Method:{$request.pay_method.name}
Total Paid:{$request.total}
Credit Card:{$request.cc_type.name}
Name on Card:{$request.cc_name}
Card Number:{$request.cc_numb}
Expiration:{$request.cc_exp}
Confirmation Code:{$request.cc_conf}
Total Charged:{$request.total}
Payment Method:{$request.pay_method.name}
To be paid on arrival:{$request.total}
Total Paid:{$request.total}
Confirmation code:{$request.cc_conf}
Payment Method:{$request.pay_method.name}