From 3d66265c25ff917b9a74cd371bf9f22a033142e0 Mon Sep 17 00:00:00 2001
From: Chuck Scott
Check credentials for Merchant e-Solutions settings.
', 'error' ); + + if (GLM_MES_DEBUG_VERBOSE) { + wc_add_notice('Supplied Credentials:ID:'.$this->ProfileId.'
Key:'.$this->ProfileKey.'
Check .
No Response Received!
', 'error' ); + } + + if (GLM_MES_DEBUG_VERBOSE) { + wc_add_notice('GLM MeS Gateway: parseResponse() called'.print_r($responseFields,1).'', 'success' ); + } + + foreach ($responseFields as $field) { + $nameValue = explode("=", $field); + $this->ResponseFields[$nameValue[0]] = $nameValue[1]; + } + + } + + function processRequest () + { + + if (GLM_MES_DEBUG_VERBOSE) { + wc_add_notice('GLM MeS Gateway: processRequest() called', 'success' ); + } + + $ch = curl_init(); + + if ($this->Post) // Use POST + { + curl_setopt($ch, CURLOPT_POST, TRUE); + curl_setopt($ch, CURLOPT_POSTFIELDS, $this->url); + curl_setopt($ch, CURLOPT_URL, $this->ApiHost); + // Use GET(cURL default) + } else { + curl_setopt($ch, CURLOPT_URL, + $url = $this->ApiHost . "?" . $this->url); + } + + curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); + curl_setopt($ch, CURLOPT_HEADER, 0); + + if (! $this->isBlank($this->ProxyHost)) { + curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); + curl_setopt($ch, CURLOPT_PROXY, $this->ProxyHost); + } + + curl_setopt($ch, CURLOPT_TIMEOUT, 120); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + + $this->parseResponse(curl_exec($ch)); + + $this->CurlInfo = curl_getinfo($ch); + + if (GLM_MES_DEBUG_VERBOSE) { + wc_add_notice('GLM MeS Gateway: Curl Action Info
'.print_r($this->CurlInfo,1).'', 'success'); + } + + } + + function setAvsRequest ($cardholderStreetAddr, $cardholderZip) + { + $this->setRequestField("cardholder_street_address", + $cardholderStreetAddr); + $this->setRequestField("cardholder_zip", $cardholderZip); + } + + function setHost ($host) + { + if (GLM_MES_DEBUG_VERBOSE) { + wc_add_notice('GLM MeS Gateway: setHost() called', 'success'); + } + + $this->ApiHost = $host; + } + + function setProfile ($profileId, $profileKey) + { + $this->ProfileId = $profileId; + $this->ProfileKey = $profileKey; + } + + function setProxyHost ($proxyHost) + { + $this->ProxyHost = $proxyHost; + } + + function setRequestField ($fieldName, $fieldValue) + { + $this->RequestFields[$fieldName] = urlencode($fieldValue); + } + + function setTransactionData ($cardNumber, $expDate, $tranAmount = 0.0) + { + $this->RequestFields['card_number'] = $cardNumber; + $this->RequestFields['card_exp_date'] = $expDate; + $this->RequestFields['transaction_amount'] = $tranAmount; + } + + function setPost ($bool) + { + $this->Post = $bool; + } + + function setDynamicData ($name, $city, $state, $zip, $mcc, $phone) + { + $this->RequestFields['merchant_name'] = $name; + $this->RequestFields['merchant_city'] = $city; + $this->RequestFields['merchant_state'] = $state; + $this->RequestFields['merchant_zip'] = $zip; + $this->RequestFields['merchant_category_code'] = $mcc; + $this->RequestFields['merchant_phone'] = $phone; + } +} + +class TpgPreAuth extends TpgTransaction +{ + + function TpgPreAuth ($profileId = '', $profileKey = '') + { + $this->TpgTransaction($profileId, $profileKey); + $this->TranType = "P"; // pre-auth + } + + function setStoredData ($cardId, $amount) + { + $this->RequestFields['card_id'] = $cardId; + $this->RequestFields['transaction_amount'] = $amount; + } + + function setFXData ($amt, $rid, $curr) + { + $this->RequestFields['fx_amount'] = $amt; + $this->RequestFields['fx_rate_id'] = $rid; + $this->RequestFields['currency_code'] = $curr; + } + + function setEcommInd ($ind) + { + $this->RequestFields['moto_ecommerce_ind'] = $ind; + } +} + +class TpgSale extends TpgTransaction +{ + + function TpgSale ($profileId, $profileKey, $setings) + { + + $this->settings = $settings; + + if (GLM_MES_DEBUG_VERBOSE) { + wc_add_notice('GLM MeS Gateway: TpgSale() called
', 'success' ); + } + + $this->TpgTransaction($profileId, $profileKey); + $this->TranType = "D"; + } + + function setStoredData ($cardId, $amount) + { + $this->RequestFields['card_id'] = $cardId; + $this->RequestFields['transaction_amount'] = $amount; + } + + function setFXData ($amt, $rid, $curr) + { + $this->RequestFields['fx_amount'] = $amt; + $this->RequestFields['fx_rate_id'] = $rid; + $this->RequestFields['currency_code'] = $curr; + } + + function setEcommInd ($ind) + { + $this->RequestFields['moto_ecommerce_ind'] = $ind; + } +} + +class TpgCredit extends TpgTransaction +{ + + function TpgCredit ($profileId, $profileKey) + { + $this->TpgTransaction($profileId, $profileKey); + $this->TranType = "C"; + } + + function setStoredData ($cardId, $amount) + { + $this->RequestFields['card_id'] = $cardId; + $this->RequestFields['transaction_amount'] = $amount; + } +} + +class TpgSettle extends TpgTransaction +{ + + function TpgSettle ($profileId, $profileKey, $tranId, $settleAmount = 0) + { + $this->TpgTransaction($profileId, $profileKey); + $this->RequestFields['transaction_id'] = $tranId; + $this->RequestFields['transaction_amount'] = $settleAmount; + $this->TranType = "S"; + } + + function setSettlementAmount ($settleAmount) + { + $this->RequestFields['transaction_amount'] = $settleAmount; + } +} + +class TpgRefund extends TpgTransaction +{ + + function TpgRefund ($profileId, $profileKey, $tranId) + { + $this->TpgTransaction($profileId, $profileKey); + $this->RequestFields['transaction_id'] = $tranId; + $this->TranType = "U"; + } + + function setStoredData ($cardId, $amount) + { + $this->RequestFields['card_id'] = $cardId; + $this->RequestFields['transaction_amount'] = $amount; + } +} + +class TpgVoid extends TpgTransaction +{ + + function TpgVoid ($profileId, $profileKey, $tranId) + { + $this->TpgTransaction($profileId, $profileKey); + $this->RequestFields['transaction_id'] = $tranId; + $this->TranType = "V"; + } + + function setStoredData ($cardId, $amount) + { + $this->RequestFields['card_id'] = $cardId; + $this->RequestFields['transaction_amount'] = $amount; + } +} + +class TpgOffline extends TpgTransaction +{ + + function TpgOffline ($profileId, $profileKey, $authCode) + { + $this->TpgTransaction($profileId, $profileKey); + $this->RequestFields['auth_code'] = $authCode; + $this->TranType = "O"; + } + + function setStoredData ($cardId, $amount) + { + $this->RequestFields['card_id'] = $cardId; + $this->RequestFields['transaction_amount'] = $amount; + } +} + +class TpgStoreData extends TpgTransaction +{ + + function TpgStoreData ($profileId, $profileKey) + { + $this->TpgTransaction($profileId, $profileKey); + $this->TranType = "T"; + } +} + +class TpgRemoveData extends TpgTransaction +{ + + function TpgRemoveData ($profileId, $profileKey, $cardId) + { + $this->TpgTransaction($profileId, $profileKey); + $this->RequestFields['card_id'] = $cardId; + $this->TranType = "X"; + } +} + +?> \ No newline at end of file diff --git a/classes/glmMesGateway.php b/classes/glmMesGateway.php index b2e141d..fa3f8cd 100644 --- a/classes/glmMesGateway.php +++ b/classes/glmMesGateway.php @@ -24,13 +24,27 @@ class GlmMesGateway extends WC_Payment_Gateway { - /** + /** * Gateway ID * * @var $id * @access public */ public $id = 'merchant_e_solutions'; + /** + * Gateway Title + * + * @var $title + * @access public + */ + public $title; + /** + * Gateway Description + * + * @var $description + * @access public + */ + public $description; /** * Gateway Icon URL * @@ -53,28 +67,65 @@ class GlmMesGateway extends WC_Payment_Gateway */ public $method_title = 'Merchant e-Solutions'; /** - * Payment Gateway Description + * Profile ID * - * @var $method_description + * @var $profile_id * @access public */ - public $method_description = 'Processes credit card payments through the Merchant e-Solutions Payment Gateway'; + public $profile_id; + /** + * Profile Key + * + * @var $profile_key + * @access public + */ + public $profile_key; + /** + * Processing URL + * + * @var $url + * @access public + */ + public $url; public function __construct () { - // Add filter for our gateway add_filter( 'woocommerce_payment_gateways', array( $this, 'glmMesAddGateway') ); // Setup Fields and Settings - $this->glmMesInitFormFields(); - $this->glmMesInitSettings(); + $this->init_form_fields(); + $this->init_settings(); + + $this -> title = $this -> settings['title']; + $this -> description = $this -> settings['description']; + + // Determine if we're in test or production mode + switch ($this -> settings['transaction_mode']) { + + case 'test': + $this->profile_id = $this -> settings['test_profile_id']; + $this->profile_key = $this -> settings['test_profile_key']; + $this->host = $this -> settings['test_url']; + break; + + case 'production': + $this->profile_id = $this -> settings['prod_profile_id']; + $this->profile_key = $this -> settings['prod_profile_key']; + $this->host = $this -> settings['prod_url']; + break; + + } - // Get any settings - $this->title = $this->get_option('title'); + if (!defined('GLM_MES_DEBUG')) { + $d = ($this -> settings['mes_debug'] == 'yes'); + define('GLM_MES_DEBUG', $d); + $d = ($this -> settings['mes_debug_verbose'] == 'yes'); + define('GLM_MES_DEBUG_VERBOSE', $d); + } - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'glmMesProcessAdminOptions' ) ); + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); } @@ -92,7 +143,7 @@ class GlmMesGateway extends WC_Payment_Gateway */ - public function glmMesInitFormFields() + public function init_form_fields() { $this->form_fields = array( @@ -119,35 +170,112 @@ class GlmMesGateway extends WC_Payment_Gateway 'title' => __( 'Customer Message', 'woocommerce' ), 'type' => 'textarea', 'default' => '' - ) - ); + ), - } + 'sep_1' => array( + 'title' => __( 'Test Mode Credentials', 'woocommerce' ), + 'type' => 'title', + 'description' => '', + ), - // Initialize Settings - public function glmMesInitSettings() - { + // MeS Gateway Profile ID + 'test_profile_id' => array( + 'title' => __( 'Test Profile ID', 'woocommerce' ), + 'type' => 'text', + 'default' => __( '9410000xxxxx00000001', 'woocommerce' ), + 'desc_tip' => false, + ), - } + // MeS Gateway Profile Key + 'test_profile_key' => array( + 'title' => __( 'Test Profile Key', 'woocommerce' ), + 'type' => 'text', + 'default' => __( 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'woocommerce' ), + 'desc_tip' => false, + ), - // Init Form Fields - public function glmMesProcessAdminOptions() - { + // MeS Gateway Test URL + 'test_url' => array( + 'title' => __( 'Test URL', 'woocommerce' ), + 'type' => 'text', + 'default' => __( 'https://cert.merchante-solutions.com/mes-api/tridentApi', 'woocommerce' ), + 'desc_tip' => false, + ), - } + 'sep_2' => array( + 'title' => __( '
Production Mode Credentials', 'woocommerce' ), + 'type' => 'title', + 'description' => '', + ), - // Process Admin Options - public function glmProcessAdminOptions() - { + // MeS Gateway Profile ID + 'prod_profile_id' => array( + 'title' => __( 'Production Profile ID', 'woocommerce' ), + 'type' => 'text', + 'default' => __( '9410000xxxxx00000001', 'woocommerce' ), + 'desc_tip' => false, + ), + + // MeS Gateway Profile Key + 'prod_profile_key' => array( + 'title' => __( 'Production Profile Key', 'woocommerce' ), + 'type' => 'text', + 'default' => __( 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'woocommerce' ), + 'desc_tip' => false, + ), + + // MeS Gateway Test URL + 'prod_url' => array( + 'title' => __( 'Production URL', 'woocommerce' ), + 'type' => 'text', + 'default' => __( 'https://cert.merchante-solutions.com/mes-api/tridentApi', 'woocommerce' ), + 'desc_tip' => false, + ), + + 'sep_3' => array( + 'title' => __( '
Mode Selection', 'woocommerce' ), + 'type' => 'title', + 'description' => '', + ), + + // Set Transaction Mode + 'transaction_mode' => array( + 'title' => __( 'Transaction Mode', 'woocommerce' ), + 'type' => 'select', + 'label' => __( 'Must be in "Production Mode" for live transactions.', 'woocommerce' ), + 'description' => __( 'See MeS Payment Certification Form to apply for required ID and Key below.', 'woocommerce' ), + 'default' => 'test', + 'desc_tip' => false, + 'options' => array( + 'test' => __( 'Test Mode', 'woocommerce' ), + 'production' => __( 'Production Mode', 'woocommerce' ) + ) + ), + + // Set Debug Mode + 'mes_debug' => array( + 'title' => __( 'Enable Debug Information', 'woocommerce' ), + 'type' => 'checkbox', + 'label' => __( '', 'woocommerce' ), + 'default' => 'no' + ), + + // Set Debug Verbose Mode + 'mes_debug_verbose' => array( + 'title' => __( 'Enable Verbose Debug', 'woocommerce' ), + 'type' => 'checkbox', + 'label' => __( '', 'woocommerce' ), + 'default' => 'no' + ) + + ); } // Set Payment Fields public function payment_fields() { - require_once (GLM_MES_PLUGIN_PATH . '/views/paymentForm.html'); - } // Validate Payment Fields @@ -164,12 +292,39 @@ class GlmMesGateway extends WC_Payment_Gateway global $woocommerce; $order = new WC_Order( $order_id ); - /* - * Process order here - * - * Returns various status states - */ - $paymentState = 'complete'; + if (GLM_MES_DEBUG_VERBOSE) { + wc_add_notice('GLM MeS Gateway: process_payment() called', 'success' ); + } + + // Create transaction object + require_once (GLM_MES_PLUGIN_CLASS_PATH . '/MesTridentGateway.php'); + $trans = new TpgSale( $this->profile_id, $this->profile_key, $this->settings ); + + // Set transaction data + $trans->setAvsRequest( '123 Main Street', '55555' ); + $trans->setRequestField('cvv2', '123'); + $trans->setRequestField('invoice_number','123456'); + $trans->setTransactionData( "4012888812348882", "1212", "1.00" ); + + // Call the MeS Gateway + $trans->setHost($this->host); + + if (GLM_MES_DEBUG_VERBOSE) { + wc_add_notice('GLM MeS Gateway: Transaction Request
'.print_r($trans,1).'', 'success'); + } + + $trans->execute(); + + if (GLM_MES_DEBUG_VERBOSE) { + wc_add_notice('GLM MeS Gateway: Transaction Response
'.$this->ErrorMessage.'
'.print_r($tran->ResponseFields,1).'', 'success'); + } + + // Check result + if( $tran->isApproved() ) { + $paymentState = 'approved'; + } else { + $paymentState = 'fail'; + } // Take action based on payment state switch ($paymentState) { diff --git a/classes/glmMesPluginSupport.php b/classes/glmMesPluginSupport.php deleted file mode 100644 index d38a172..0000000 --- a/classes/glmMesPluginSupport.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release classes/glmMesPluginSupport.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ - * @link http://dev.gaslightmedia.com/ - */ - -/* - * This class provides some standard methods used by this plugin - */ -class GlmMesPluginSupport -{ - - -} - -?> \ No newline at end of file diff --git a/config/plugin.ini b/config/plugin.ini deleted file mode 100644 index e6be830..0000000 --- a/config/plugin.ini +++ /dev/null @@ -1,41 +0,0 @@ -; -; Main Configuration File -; GLM WooCommerce Merchant e-Solutions Gateway -; -; Custom configurations for development and developer configuration at bottom of file. -; - -[common] - -; -; Site Configuration Options -; - -; Debug Options -debug = false -debug_verbose = false - -; Site Time Zone -timezone = America/Detroit - -; -; End of site configuration options -; - -; Phrases -phrase['phrase_test'] = 'test' - -; -; Override sections for various servers by GLM_HOST_ID -; - -[production:common] - - -[development:common] - - -[chuck:common] -debug = true -debug_verbose = false - diff --git a/controllers/controller.php b/controllers/controller.php deleted file mode 100644 index 6d91a15..0000000 --- a/controllers/controller.php +++ /dev/null @@ -1,80 +0,0 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release controllers/controller.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ - * @link http://dev.gaslightmedia.com/ - */ - -// Load glmMesPluginSupport class -// require_once (GLM_MES_PLUGIN_PATH . '/classes/glmMesPluginSupport.php'); - -/* - * This class controls which models are used. - */ -class glmMesController // extends GlmMesPluginSupport -{ - - /** - * WordPress Database Object - * - * @var $wpdb - * @access public - */ - public $wpdb; - - /** - * Plugin Configuration Data - * - * @var $config - * @access public - */ - public $config; - - public function __construct ($wpdb, $config) - { - - // Save WordPress Database object - $this->wpdb = $wpdb; - - // Save plugin configuration object - $this->config = $config; - - add_action( 'plugins_loaded', array( $this, 'initMesGateway') ); - - } - - /** - * Initialize MES Gateway - * - * @return void - * @access public - */ - public function initMesGateway() - { - require_once (GLM_MES_PLUGIN_PATH . '/classes/glmMesGateway.php'); - new glmMesGateway(); - - } - - - /** - * Controller - * - * @return void - * @access public - */ - public function controller () - { - - } -} -?> \ No newline at end of file diff --git a/deactivate.php b/deactivate.php index ed8deb3..0e6bc67 100644 --- a/deactivate.php +++ b/deactivate.php @@ -14,9 +14,6 @@ * @link http://dev.gaslightmedia.com/ */ -// Load glmMesPluginSupport class -require_once (GLM_MES_PLUGIN_PATH . '/classes/glmMesPluginSupport.php'); - /* * This class performs all necessary additional work when this * plugin is deactivated. @@ -24,13 +21,6 @@ require_once (GLM_MES_PLUGIN_PATH . '/classes/glmMesPluginSupport.php'); class glmMesPluginDeactivate // extends glmMesPluginSupport { - /** - * WordPress Database Object - * - * @var $wpdb - * @access public - */ - public $wpdb; /** * Plugin Configuration Data * @@ -44,19 +34,14 @@ class glmMesPluginDeactivate // extends glmMesPluginSupport * * Performs all the work for this model */ - public function __construct ($wpdb, $config) + public function __construct () { // Make sure the current user has this capability if (!current_user_can('activate_plugins')) { die(); } + } - // Save WordPress Database object - $this->wpdb = $wpdb; - - // Save plugin configuration object - $this->config = $config; - } } ?> \ No newline at end of file diff --git a/defines.php b/defines.php index 454a5ff..c1c0035 100644 --- a/defines.php +++ b/defines.php @@ -8,42 +8,12 @@ define('GLM_MES_PLUGIN_NAME', 'Gaslight Media WooCommerce Merchant e-Solutions Gateway'); define('GLM_MES_PLUGIN_DIR', 'glm-woocommerce-merchant-e-solutions-gateway'); -// Determine which system we're running on - If not provided, assume PRODUCTION -$host = getenv('GLM_HOST_ID'); -if (trim($host) == '') { - $host = 'PRODUCTION'; -} -define('GLM_MES_PLUGIN_HOST', $host); - -// Determine current http/https protocol -$pageProtocol = 'http'; -if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') { - $pageProtocol = 'https'; -} -define('GLM_MES_PLUGIN_HTTP_PROTOCOL', $pageProtocol); - // Plugin Versions define('GLM_MES_PLUGIN_VERSION', 0.1); define('GLM_MES_PLUGIN_DB_VERSION', 0.1); -// URLs -$adminURL = admin_url('admin.php'); -define('GLM_MES_PLUGIN_ADMIN_URL', $adminURL); -define('GLM_MES_PLUGIN_URL', plugin_dir_url(__FILE__)); -$pageUri = explode('?', $_SERVER['REQUEST_URI']); // Bust this up to access URL path and script name only -define('GLM_MES_PLUGIN_BASE_URL', WP_PLUGIN_URL.'/'.GLM_MES_PLUGIN_DIR); -define('GLM_MES_PLUGIN_CURRENT_URL', $pageProtocol.'://'.$_SERVER['SERVER_NAME'].$pageUri[0]); -define('GLM_MES_PLUGIN_MEDIA_URL', WP_CONTENT_URL.'/plugins/'.GLM_MES_PLUGIN_DIR.'/media'); - - // Directories define('GLM_MES_PLUGIN_PATH', dirname(__FILE__)); define('GLM_MES_PLUGIN_CLASS_PATH', GLM_MES_PLUGIN_PATH.'/classes'); -define('GLM_MES_PLUGIN_CONFIG_PATH', GLM_MES_PLUGIN_PATH.'/config'); - - -// Database table prefixes -global $wpdb; -define('GLM_MES_PLUGIN_DB_PREFIX', $wpdb->prefix.'glm_MES_'); ?> \ No newline at end of file diff --git a/index.php b/index.php index 57d5e1d..34454e6 100644 --- a/index.php +++ b/index.php @@ -42,26 +42,6 @@ // Get standard defined parameters require_once('defines.php'); -// Get plugin configuration -$configData = parse_ini_file(GLM_MES_PLUGIN_PATH.'/config/plugin.ini', true); -$config = $configData['common']; - -// Override parameters according to GLM_HOST_ID -$hostSection = strtolower(GLM_MES_PLUGIN_HOST).':common'; -if (isset($configData[$hostSection])) { - $config = array_replace($config, $configData[strtolower(GLM_MES_PLUGIN_HOST).':common']); -} else { - $startupNotices .= - '
Bad configuration file section name or section not found: '. $hostSection
- .'
See plugin '.GLM_MES_PLUGIN_PATH.'config/plugin.ini file.'
- .'
Also check that the server "GLM_HOST_ID" environment parameter exists and matches a section in the above ini file.