Skip to content

Commit

Permalink
* Label module with "sandbox" if sandbox testing server is used (admi…
Browse files Browse the repository at this point in the history
…n and frontend)

* Add gateway connection test dialog
* Show a warning in the admin if the module is enabled and the client id and secret fields are still empty
* Only load the module on the frontend if the client id and secret fields have been configured
* Add button theme configuration parameter
* Add locale defined in the module language file
  • Loading branch information
haraldpdl committed Mar 31, 2014
1 parent 95a94b6 commit cb7b02c
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 23 deletions.
47 changes: 47 additions & 0 deletions catalog/admin/ext/modules/content/paypal/login.php
@@ -0,0 +1,47 @@
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2014 osCommerce
Released under the GNU General Public License
*/

chdir('../../../../');
require('includes/application_top.php');

require('../includes/languages/' . $language . '/modules/content/login/cm_paypal_login.php');
require('../includes/modules/content/login/cm_paypal_login.php');

if (defined('MODULE_CONTENT_PAYPAL_LOGIN_STATUS')) {
$paypal_login = new cm_paypal_login();

$params = array('code' => 'oscom2_conn_test');

$response = $paypal_login->getToken($params);

if ( is_array($response) && isset($response['error']) ) {
echo '<h1 id="ppctresult">' . MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_SUCCESS_TITLE . '</h1>';

if (MODULE_CONTENT_PAYPAL_LOGIN_SERVER_TYPE == 'Live') {
echo '<p>' . MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_SUCCESS_TEXT_LIVE . '</p>';
} else {
echo '<p>' . MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_SUCCESS_TEXT_TEST . '</p>';
}
} else {
echo '<h1 id="ppctresult">' . MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_ERROR_TITLE . '</h1>';

if (MODULE_CONTENT_PAYPAL_LOGIN_SERVER_TYPE == 'Live') {
echo '<p>' . MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_ERROR_TEXT_LIVE . '</p>';
} else {
echo '<p>' . MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_ERROR_TEXT_TEST . '</p>';
}
}
} else {
echo '<h1 id="ppctresult">' . MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_TITLE_ERROR . '</h1>' .
'<p>' . MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_NOT_INSTALLED . '</p>';
}
?>
Expand Up @@ -5,16 +5,34 @@
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2013 osCommerce
Copyright (c) 2014 osCommerce
Released under the GNU General Public License
*/

define('MODULE_CONTENT_PAYPAL_LOGIN_TITLE', 'PayPal Login');
define('MODULE_CONTENT_PAYPAL_LOGIN_DESCRIPTION', 'Enable Log In with PayPal with seamless checkout for PayPal Express Checkout payments');
define('MODULE_CONTENT_PAYPAL_LOGIN_TITLE', 'Log In with PayPal');
define('MODULE_CONTENT_PAYPAL_LOGIN_DESCRIPTION', 'Enable Log In with PayPal with seamless checkout for PayPal Express Checkout payments<br /><br /><img src="images/icon_popup.gif" border="0">&nbsp;<a href="https://www.paypal.com" target="_blank" style="text-decoration: underline; font-weight: bold;">Visit PayPal Website</a>');

define('MODULE_CONTENT_PAYPAL_LOGIN_TEMPLATE_TITLE', 'Log In with PayPal');
define('MODULE_CONTENT_PAYPAL_LOGIN_TEMPLATE_CONTENT', 'Have a PayPal account? Securely log in with PayPal to shop even faster!');
define('MODULE_CONTENT_PAYPAL_LOGIN_TEMPLATE_SANDBOX', 'Test Mode: The Sandbox server is currently selected.');

define('MODULE_CONTENT_PAYPAL_LOGIN_ERROR_ADMIN_CONFIGURATION', 'This module will not load until the Client ID and Secret parameters have been configured. Please edit and configure the settings of this module.');

define('MODULE_CONTENT_PAYPAL_LOGIN_LANGUAGE_LOCALE', 'en-us');

define('MODULE_CONTENT_PAYPAL_LOGIN_EMAIL_PASSWORD', 'An account has automatically been created for you with the following e-mail address and password:' . "\n\n" . 'Store Account E-Mail Address: %s' . "\n" . 'Store Account Password: %s' . "\n\n");

define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_LINK_TITLE', 'Test Gateway Connection');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_TITLE', 'Gateway Connection Test');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_GENERAL_ERROR', 'An error occurred. Please refresh the page and try again.');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_GENERAL_TEXT', 'Testing connection to gateway..');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_BUTTON_CLOSE', 'Close');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_SUCCESS_TITLE', 'Success!');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_SUCCESS_TEXT_LIVE', 'A connection to the live gateway can been made.');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_SUCCESS_TEXT_TEST', 'A connection to the test gateway can been made.');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_ERROR_TITLE', 'Error!');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_ERROR_TEXT_LIVE', 'A connection to the live gateway could not be made.<br /><br />Disable Verify SSL Certificate in the module configuration and try again.');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_ERROR_TEXT_TEST', 'A connection to the test gateway could not be made.<br /><br />Disable Verify SSL Certificate in the module configuration and try again.');
define('MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_NOT_INSTALLED', 'The Log In with PayPal content module is not installed. Please install it and try again.');
?>
162 changes: 142 additions & 20 deletions catalog/includes/modules/content/login/cm_paypal_login.php
Expand Up @@ -19,34 +19,50 @@ class cm_paypal_login {
var $enabled = false;

function cm_paypal_login() {
$this->signature = 'paypal|paypal_login|1.0|2.3';

$this->code = get_class($this);
$this->group = basename(dirname(__FILE__));

$this->title = MODULE_CONTENT_PAYPAL_LOGIN_TITLE;
$this->description = MODULE_CONTENT_PAYPAL_LOGIN_DESCRIPTION;

if ( defined('MODULE_CONTENT_PAYPAL_LOGIN_STATUS') ) {
$this->description .= $this->getTestLinkInfo();

if ( MODULE_CONTENT_PAYPAL_LOGIN_SERVER_TYPE == 'Sandbox' ) {
$this->title .= ' (Sandbox)';
}

$this->sort_order = MODULE_CONTENT_PAYPAL_LOGIN_SORT_ORDER;
$this->enabled = (MODULE_CONTENT_PAYPAL_LOGIN_STATUS == 'True');
}

if ( $this->enabled === true ) {
if ( !tep_not_null(MODULE_CONTENT_PAYPAL_LOGIN_CLIENT_ID) || !tep_not_null(MODULE_CONTENT_PAYPAL_LOGIN_SECRET) ) {
$this->description = '<div class="secWarning">' . MODULE_CONTENT_PAYPAL_LOGIN_ERROR_ADMIN_CONFIGURATION . '</div>' . $this->description;
}
}
}

function execute() {
global $HTTP_GET_VARS, $oscTemplate;

if ( isset($HTTP_GET_VARS['action']) ) {
if ( ($HTTP_GET_VARS['action'] == 'paypal_login') && isset($HTTP_GET_VARS['code']) ) {
$this->preLogin();
} elseif ( $HTTP_GET_VARS['action'] == 'paypal_login_process' ) {
$this->postLogin();
if ( tep_not_null(MODULE_CONTENT_PAYPAL_LOGIN_CLIENT_ID) && tep_not_null(MODULE_CONTENT_PAYPAL_LOGIN_SECRET) ) {
if ( isset($HTTP_GET_VARS['action']) ) {
if ( ($HTTP_GET_VARS['action'] == 'paypal_login') && isset($HTTP_GET_VARS['code']) ) {
$this->preLogin();
} elseif ( $HTTP_GET_VARS['action'] == 'paypal_login_process' ) {
$this->postLogin();
}
}
}

ob_start();
include(DIR_WS_MODULES . 'content/' . $this->group . '/templates/paypal_login.php');
$template = ob_get_clean();
ob_start();
include(DIR_WS_MODULES . 'content/' . $this->group . '/templates/paypal_login.php');
$template = ob_get_clean();

$oscTemplate->addContent($template, $this->group);
$oscTemplate->addContent($template, $this->group);
}
}

function preLogin() {
Expand Down Expand Up @@ -238,23 +254,88 @@ function check() {
return defined('MODULE_CONTENT_PAYPAL_LOGIN_STATUS');
}

function install() {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable PayPal Login Module', 'MODULE_CONTENT_PAYPAL_LOGIN_STATUS', 'True', 'Do you want to enable the PayPal Login module?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Client ID', 'MODULE_CONTENT_PAYPAL_LOGIN_CLIENT_ID', '', 'Your PayPal Application Client ID.', '6', '1', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Secret', 'MODULE_CONTENT_PAYPAL_LOGIN_SECRET', '', 'Your PayPal Application Secret.', '6', '1', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Server Type', 'MODULE_CONTENT_PAYPAL_LOGIN_SERVER_TYPE', 'Sandbox', 'Which server should be used? Live for production or Sandbox for testing.', '6', '1', 'tep_cfg_select_option(array(\'Live\', \'Sandbox\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Verify SSL Certificate', 'MODULE_CONTENT_PAYPAL_LOGIN_VERIFY_SSL', 'True', 'Verify gateway server SSL certificate on connection?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Proxy Server', 'MODULE_CONTENT_PAYPAL_LOGIN_PROXY', '', 'Send API requests through this proxy server. (host:port, eg: 123.45.67.89:8080 or proxy.example.com:8080)', '6', '1', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Width', 'MODULE_CONTENT_PAYPAL_LOGIN_CONTENT_WIDTH', 'Full', 'Should the content be shown in a full or half width container?', '6', '1', 'tep_cfg_select_option(array(\'Full\', \'Half\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_CONTENT_PAYPAL_LOGIN_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
function install($parameter = null) {
$params = $this->getParams();

if (isset($parameter)) {
if (isset($params[$parameter])) {
$params = array($parameter => $params[$parameter]);
} else {
$params = array();
}
}

foreach ($params as $key => $data) {
$sql_data_array = array('configuration_title' => $data['title'],
'configuration_key' => $key,
'configuration_value' => (isset($data['value']) ? $data['value'] : ''),
'configuration_description' => $data['desc'],
'configuration_group_id' => '6',
'sort_order' => '0',
'date_added' => 'now()');

if (isset($data['set_func'])) {
$sql_data_array['set_function'] = $data['set_func'];
}

if (isset($data['use_func'])) {
$sql_data_array['use_function'] = $data['use_func'];
}

tep_db_perform(TABLE_CONFIGURATION, $sql_data_array);
}
}

function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}

function keys() {
return array('MODULE_CONTENT_PAYPAL_LOGIN_STATUS', 'MODULE_CONTENT_PAYPAL_LOGIN_CLIENT_ID', 'MODULE_CONTENT_PAYPAL_LOGIN_SECRET', 'MODULE_CONTENT_PAYPAL_LOGIN_SERVER_TYPE', 'MODULE_CONTENT_PAYPAL_LOGIN_VERIFY_SSL', 'MODULE_CONTENT_PAYPAL_LOGIN_PROXY', 'MODULE_CONTENT_PAYPAL_LOGIN_CONTENT_WIDTH', 'MODULE_CONTENT_PAYPAL_LOGIN_SORT_ORDER');
$keys = array_keys($this->getParams());

if ($this->check()) {
foreach ($keys as $key) {
if (!defined($key)) {
$this->install($key);
}
}
}

return $keys;
}

function getParams() {
$params = array('MODULE_CONTENT_PAYPAL_LOGIN_STATUS' => array('title' => 'Enable Log In with PayPal',
'desc' => 'Do you want to enable the Log In with PayPal module?',
'value' => 'True',
'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
'MODULE_CONTENT_PAYPAL_LOGIN_CLIENT_ID' => array('title' => 'Client ID',
'desc' => 'Your PayPal Application Client ID.'),
'MODULE_CONTENT_PAYPAL_LOGIN_SECRET' => array('title' => 'Secret',
'desc' => 'Your PayPal Application Secret.'),
'MODULE_CONTENT_PAYPAL_LOGIN_THEME' => array('title' => 'Theme',
'desc' => 'Which theme should be used for the button?',
'value' => 'Blue',
'set_func' => 'tep_cfg_select_option(array(\'Blue\', \'Neutral\'), '),
'MODULE_CONTENT_PAYPAL_LOGIN_SERVER_TYPE' => array('title' => 'Server Type',
'desc' => 'Which server should be used? Live for production or Sandbox for testing.',
'value' => 'Sandbox',
'set_func' => 'tep_cfg_select_option(array(\'Live\', \'Sandbox\'), '),
'MODULE_CONTENT_PAYPAL_LOGIN_VERIFY_SSL' => array('title' => 'Verify SSL Certificate',
'desc' => 'Verify gateway server SSL certificate on connection?',
'value' => 'True',
'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
'MODULE_CONTENT_PAYPAL_LOGIN_PROXY' => array('title' => 'Proxy Server',
'desc' => 'Send API requests through this proxy server. (host:port, eg: 123.45.67.89:8080 or proxy.example.com:8080)'),
'MODULE_CONTENT_PAYPAL_LOGIN_CONTENT_WIDTH' => array('title' => 'Content Width',
'desc' => 'Should the content be shown in a full or half width container?',
'value' => 'Full',
'set_func' => 'tep_cfg_select_option(array(\'Full\', \'Half\'), '),
'MODULE_CONTENT_PAYPAL_LOGIN_SORT_ORDER' => array('title' => 'Sort order of display',
'desc' => 'Sort order of display. Lowest is displayed first.',
'value' => '0'));

return $params;
}

function sendRequest($url, $parameters = null) {
Expand Down Expand Up @@ -371,5 +452,46 @@ function getUserInfo($params) {

return $result_array;
}

function getTestLinkInfo() {
$dialog_title = MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_TITLE;
$dialog_general_error = MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_GENERAL_ERROR;
$dialog_button_close = MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_BUTTON_CLOSE;

$js = <<<EOD
<script type="text/javascript">
$(function() {
$('#tcdprogressbar').progressbar({
value: false
});
});
function openTestConnectionDialog() {
var d = $('<div>').html($('#testConnectionDialog').html()).dialog({
autoOpen: false,
modal: true,
title: '{$dialog_title}',
buttons: {
'{$dialog_button_close}': function () {
$(this).dialog('destroy');
}
}
});
d.load('ext/modules/content/paypal/login.php', function() {
if ( $('#ppctresult').length < 1 ) {
d.html('{$dialog_general_error}');
}
}).dialog('open');
}
</script>
EOD;

$info = '<p><img src="images/icons/locked.gif" border="0">&nbsp;<a href="javascript:openTestConnectionDialog();" style="text-decoration: underline; font-weight: bold;">' . MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_LINK_TITLE . '</a></p>' .
'<div id="testConnectionDialog" style="display: none;"><p>' . MODULE_CONTENT_PAYPAL_LOGIN_DIALOG_CONNECTION_GENERAL_TEXT . '</p><div id="tcdprogressbar"></div></div>' .
$js;

return $info;
}
}
?>
15 changes: 15 additions & 0 deletions catalog/includes/modules/content/login/templates/paypal_login.php
Expand Up @@ -2,6 +2,13 @@
<h2><?php echo MODULE_CONTENT_PAYPAL_LOGIN_TEMPLATE_TITLE; ?></h2>

<div class="contentText">

<?php
if ( MODULE_CONTENT_PAYPAL_LOGIN_SERVER_TYPE == 'Sandbox' ) {
echo ' <p class="messageStackError">' . MODULE_CONTENT_PAYPAL_LOGIN_TEMPLATE_SANDBOX . '</p>';
}
?>

<p><?php echo MODULE_CONTENT_PAYPAL_LOGIN_TEMPLATE_CONTENT; ?></p>

<div id="PayPalLoginButton" style="text-align: right; padding-top: 5px;"></div>
Expand All @@ -17,6 +24,14 @@
if ( MODULE_CONTENT_PAYPAL_LOGIN_SERVER_TYPE == 'Sandbox' ) {
echo ' "authend": "sandbox",';
}

if ( MODULE_CONTENT_PAYPAL_LOGIN_THEME == 'Neutral' ) {
echo ' "theme": "neutral",';
}

if ( defined('MODULE_CONTENT_PAYPAL_LOGIN_LANGUAGE_LOCALE') && tep_not_null(MODULE_CONTENT_PAYPAL_LOGIN_LANGUAGE_LOCALE) ) {
echo ' "locale": "' . MODULE_CONTENT_PAYPAL_LOGIN_LANGUAGE_LOCALE . '",';
}
?>

"appid": "<?php echo MODULE_CONTENT_PAYPAL_LOGIN_CLIENT_ID; ?>",
Expand Down

0 comments on commit cb7b02c

Please sign in to comment.