Skip to content

Commit

Permalink
Stripe Modules:
Browse files Browse the repository at this point in the history
Introduce Stripe.js payment module
Introduce Stripe Cards Management content module
  • Loading branch information
haraldpdl committed Jun 5, 2014
1 parent 74cc316 commit daf7d9b
Show file tree
Hide file tree
Showing 5 changed files with 1,171 additions and 0 deletions.
118 changes: 118 additions & 0 deletions catalog/ext/modules/content/account/stripe/cards.php
@@ -0,0 +1,118 @@
<?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');

if (!tep_session_is_registered('customer_id')) {
$navigation->set_snapshot();
tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
}

if ( defined('MODULE_PAYMENT_INSTALLED') && tep_not_null(MODULE_PAYMENT_INSTALLED) && in_array('stripe.php', explode(';', MODULE_PAYMENT_INSTALLED)) ) {
if ( !class_exists('stripe') ) {
include(DIR_WS_LANGUAGES . $language . '/modules/payment/stripe.php');
include(DIR_WS_MODULES . 'payment/stripe.php');
}

$stripe = new stripe();

if ( !$stripe->enabled ) {
tep_redirect(tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
}
} else {
tep_redirect(tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
}

require(DIR_WS_LANGUAGES . $language . '/modules/content/account/cm_account_stripe_cards.php');
require('includes/modules/content/account/cm_account_stripe_cards.php');
$stripe_cards = new cm_account_stripe_cards();

if ( !$stripe_cards->isEnabled() ) {
tep_redirect(tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
}

if ( isset($HTTP_GET_VARS['action']) ) {
if ( ($HTTP_GET_VARS['action'] == 'delete') && isset($HTTP_GET_VARS['id']) && is_numeric($HTTP_GET_VARS['id']) && isset($HTTP_GET_VARS['formid']) && ($HTTP_GET_VARS['formid'] == md5($sessiontoken))) {
$token_query = tep_db_query("select id, stripe_token from customers_stripe_tokens where id = '" . (int)$HTTP_GET_VARS['id'] . "' and customers_id = '" . (int)$customer_id . "'");

if ( tep_db_num_rows($token_query) ) {
$token = tep_db_fetch_array($token_query);

list($customer, $card) = explode(':|:', $token['stripe_token'], 2);

$stripe->deleteCard($card, $customer, $token['id']);

$messageStack->add_session('cards', MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_SUCCESS_DELETED, 'success');
}
}

tep_redirect(tep_href_link('ext/modules/content/account/stripe/cards.php', '', 'SSL'));
}

$breadcrumb->add(MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_NAVBAR_TITLE_1, tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
$breadcrumb->add(MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_NAVBAR_TITLE_2, tep_href_link('ext/modules/content/account/stripe/cards.php', '', 'SSL'));

require(DIR_WS_INCLUDES . 'template_top.php');
?>

<h1><?php echo MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_HEADING_TITLE; ?></h1>

<?php
if ($messageStack->size('cards') > 0) {
echo $messageStack->output('cards');
}
?>

<div class="contentContainer">
<?php echo MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_TEXT_DESCRIPTION; ?>

<h2><?php echo MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_SAVED_CARDS_TITLE; ?></h2>

<div class="contentText">

<?php
$tokens_query = tep_db_query("select id, card_type, number_filtered, expiry_date from customers_stripe_tokens where customers_id = '" . (int)$customer_id . "' order by date_added");

if ( tep_db_num_rows($tokens_query) > 0 ) {
while ( $tokens = tep_db_fetch_array($tokens_query) ) {
?>

<div>
<span style="float: right;"><?php echo tep_draw_button(SMALL_IMAGE_BUTTON_DELETE, 'trash', tep_href_link('ext/modules/content/account/stripe/cards.php', 'action=delete&id=' . (int)$tokens['id'] . '&formid=' . md5($sessiontoken), 'SSL')); ?></span>
<p><strong><?php echo tep_output_string_protected($tokens['card_type']); ?></strong>&nbsp;&nbsp;****<?php echo tep_output_string_protected($tokens['number_filtered']) . '&nbsp;&nbsp;' . tep_output_string_protected(substr($tokens['expiry_date'], 0, 2) . '/' . substr($tokens['expiry_date'], 2)); ?></p>
</div>

<?php
}
} else {
?>

<div style="background-color: #FEEFB3; border: 1px solid #9F6000; margin: 10px 0px; padding: 5px 10px; border-radius: 10px;">
<?php echo MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_TEXT_NO_CARDS; ?>
</div>

<?php
}
?>

</div>

<div class="buttonSet">
<?php echo tep_draw_button(IMAGE_BUTTON_BACK, 'triangle-1-w', tep_href_link(FILENAME_ACCOUNT, '', 'SSL')); ?>
</div>
</div>

<?php
require(DIR_WS_INCLUDES . 'template_bottom.php');
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
@@ -0,0 +1,30 @@
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2014 osCommerce
Released under the GNU General Public License
*/

define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_TITLE', 'Stripe Cards Management Page');
define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_DESCRIPTION', 'Adds a Stripe Cards management page to the My Account area');

define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_ERROR_MAIN_MODULE', 'This module will not load until the Stripe payment module has been installed, configured, and is enabled. Please install and configure the Stripe payment module.');

define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_LINK_TITLE', 'Manage saved payment cards.');

define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_NAVBAR_TITLE_1', 'My Account');
define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_NAVBAR_TITLE_2', 'Saved Cards');

define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_HEADING_TITLE', 'Saved Cards');
define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_TEXT_DESCRIPTION', '<p>Saved payment cards are stored securely and safely in a certified and audited PCI Service Provider Level 1 environment, the most stringent level of certification available. This high level of security provides convenience in allowing saved cards to be used for next purchases without the card information having to be re-typed again for each order made.</p><p>New cards can be securely saved during the process of your next order.</p>');

define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_SAVED_CARDS_TITLE', 'Saved Cards');
define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_TEXT_NO_CARDS', '<p>No cards have been saved yet.</p>');

define('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_SUCCESS_DELETED', 'The card has been successfully deleted.');
?>
39 changes: 39 additions & 0 deletions catalog/includes/languages/english/modules/payment/stripe.php
@@ -0,0 +1,39 @@
<?php
/*
$Id: $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2014 osCommerce
Released under the GNU General Public License
*/

define('MODULE_PAYMENT_STRIPE_TEXT_TITLE', 'Stripe');
define('MODULE_PAYMENT_STRIPE_TEXT_PUBLIC_TITLE', 'Credit Card');
define('MODULE_PAYMENT_STRIPE_TEXT_DESCRIPTION', '<img src="images/icon_info.gif" border="0" />&nbsp;<a href="http://library.oscommerce.com/Package&en&stripe&oscom23&stripe_js" target="_blank" style="text-decoration: underline; font-weight: bold;">View Online Documentation</a><br /><br /><img src="images/icon_popup.gif" border="0">&nbsp;<a href="https://www.stripe.com" target="_blank" style="text-decoration: underline; font-weight: bold;">Visit Stripe Website</a>');

define('MODULE_PAYMENT_STRIPE_ERROR_ADMIN_CURL', 'This module requires cURL to be enabled in PHP and will not load until it has been enabled on this webserver.');
define('MODULE_PAYMENT_STRIPE_ERROR_ADMIN_CONFIGURATION', 'This module will not load until the Publishable Key and Secret Key parameters have been configured. Please edit and configure the settings of this module.');

define('MODULE_PAYMENT_STRIPE_CREDITCARD_NEW', 'Enter a new Card');
define('MODULE_PAYMENT_STRIPE_CREDITCARD_OWNER', 'Name on Card:');
define('MODULE_PAYMENT_STRIPE_CREDITCARD_NUMBER', 'Card Number:');
define('MODULE_PAYMENT_STRIPE_CREDITCARD_EXPIRY', 'Expiry Date:');
define('MODULE_PAYMENT_STRIPE_CREDITCARD_CVC', 'Security Code:');
define('MODULE_PAYMENT_STRIPE_CREDITCARD_SAVE', 'Save Card for next purchase?');

define('MODULE_PAYMENT_STRIPE_ERROR_TITLE', 'There has been an error processing your credit card');
define('MODULE_PAYMENT_STRIPE_ERROR_GENERAL', 'Please try again and if problems persist, please try another payment method.');
define('MODULE_PAYMENT_STRIPE_ERROR_CARDSTORED', 'The stored card could not be found. Please try again and if problems persist, please try another payment method.');

define('MODULE_PAYMENT_STRIPE_DIALOG_CONNECTION_LINK_TITLE', 'Test API Server Connection');
define('MODULE_PAYMENT_STRIPE_DIALOG_CONNECTION_TITLE', 'API Server Connection Test');
define('MODULE_PAYMENT_STRIPE_DIALOG_CONNECTION_GENERAL_TEXT', 'Testing connection to server..');
define('MODULE_PAYMENT_STRIPE_DIALOG_CONNECTION_BUTTON_CLOSE', 'Close');
define('MODULE_PAYMENT_STRIPE_DIALOG_CONNECTION_TIME', 'Connection Time:');
define('MODULE_PAYMENT_STRIPE_DIALOG_CONNECTION_SUCCESS', 'Success!');
define('MODULE_PAYMENT_STRIPE_DIALOG_CONNECTION_FAILED', 'Failed! Please review the Verify SSL Certificate settings and try again.');
define('MODULE_PAYMENT_STRIPE_DIALOG_CONNECTION_ERROR', 'An error occurred. Please refresh the page, review your settings, and try again.');
?>
@@ -0,0 +1,93 @@
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2014 osCommerce
Released under the GNU General Public License
*/

class cm_account_stripe_cards {
var $code;
var $group;
var $title;
var $description;
var $sort_order;
var $enabled = false;

function cm_account_stripe_cards() {
global $language;

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

$this->title = MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_TITLE;
$this->description = MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_DESCRIPTION;

if ( defined('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_STATUS') ) {
$this->sort_order = MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_SORT_ORDER;
$this->enabled = (MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_STATUS == 'True');
}

$this->public_title = MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_LINK_TITLE;

$stripe_enabled = false;

if ( defined('MODULE_PAYMENT_INSTALLED') && tep_not_null(MODULE_PAYMENT_INSTALLED) && in_array('stripe.php', explode(';', MODULE_PAYMENT_INSTALLED)) ) {
if ( !class_exists('stripe') ) {
include(DIR_FS_CATALOG . 'includes/languages/' . $language . '/modules/payment/stripe.php');
include(DIR_FS_CATALOG . 'includes/modules/payment/stripe.php');
}

$stripe = new stripe();

if ( $stripe->enabled ) {
$stripe_enabled = true;

if ( MODULE_PAYMENT_STRIPE_TRANSACTION_SERVER == 'Test' ) {
$this->title .= ' [Test]';
$this->public_title .= ' (' . $stripe->code . '; Test)';
}
}
}

if ( $stripe_enabled !== true ) {
$this->enabled = false;

$this->description = '<div class="secWarning">' . MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_ERROR_MAIN_MODULE . '</div>' . $this->description;
}
}

function execute() {
global $oscTemplate;

$oscTemplate->_data['account']['account']['links']['stripe_cards'] = array('title' => $this->public_title,
'link' => tep_href_link('ext/modules/content/account/stripe/cards.php', '', 'SSL'),
'icon' => 'newwin');
}

function isEnabled() {
return $this->enabled;
}

function check() {
return defined('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_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 Stripe Card Management', 'MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_STATUS', 'True', 'Do you want to enable the Stripe Card Management 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 ('Sort Order', 'MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
}

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

function keys() {
return array('MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_STATUS', 'MODULE_CONTENT_ACCOUNT_STRIPE_CARDS_SORT_ORDER');
}
}
?>

0 comments on commit daf7d9b

Please sign in to comment.