* Extends the WooCommerce base gateway class. See the following URL.
* http://docs.woothemes.com/wc-apidocs/class-WC_Payment_Gateway.html
*
+ * Development Credentials
+ * Merchant Name Gaslight Media
+ * Profile ID 94100012117800000059
+ * Profile Key cBCBDBscxFpIRCJzcBqnKFORrBcNJXCt
+ * Request URL https://cert.merchante-solutions.com/mes-api/tridentApi
+ *
*/
class GlmMesGateway extends WC_Payment_Gateway
{
/**
- * Gateway ID
- *
- * @var $id
- * @access public
- */
- public $id = 'merchant_e_solutions';
- /**
- * Gateway Title
+ * Cards Accepted
*
- * @var $title
+ * @var $visa
+ * @var $mastercard
+ * @var $amex
* @access public
*/
- public $title;
- /**
- * Gateway Description
+ public $visa = false;
+ public $mastercard = false;
+ public $amex = false;
+ /**
+ * Transaction Mode
*
- * @var $description
+ * @var $transaction_mode
* @access public
*/
- public $description;
+ public $transaction_mode;
/**
* Gateway Icon URL
*
* @var $icon
* @access public
*/
- public $icon = false;
- /**
- * Show Payment Fields
- *
- * @var $has_fields
- * @access public
- */
- public $has_fields = true;
- /**
- * Title of this Payment Gateway
- *
- * @var $method_title
- * @access public
- */
- public $method_title = 'Merchant e-Solutions';
- /**
+ public $icon;
+ /**
* Profile ID
*
* @var $profile_id
* @access public
*/
public $url;
+ /**
+ * Credit Card Months
+ *
+ * @var $cc_months
+ * @access public
+ */
+ public $cc_months;
+ /**
+ * Credit Card Exp Years
+ *
+ * @var $cc_start_year
+ * @var $cc_end_year
+ * @access public
+ */
+ public $cc_start_year;
+ public $cc_end_year;
+ /**
+ * Cleaned User Input Array
+ *
+ * @var $glm_mes_in
+ * @access public
+ */
+ public $glm_mes_in;
+
public function __construct ()
// Add filter for our gateway
add_filter( 'woocommerce_payment_gateways', array( $this, 'glmMesAddGateway') );
+ $this->id = GLM_MES_ID;
+
+ // Title of gateway and description displayed in WooCommerce Checkout configuration pages
+ $this->method_title = __( GLM_MES_SHORT_NAME, GLM_MES_ID );
+ $this->method_description = __( GLM_MES_DESCRIPTION, GLM_MES_ID );
+
+ // Icon displayed with gateway in checkout page
+ $this -> icon = GLM_MES_ICON;
+
+ // Displays checkout fields for "direct" integration
+ $this->has_fields = true;
+
+ // Supports the default credit card form
+ $this->supports = array( 'default_credit_card_form' );
+
// Setup Fields and Settings
$this->init_form_fields();
$this->init_settings();
- $this -> title = $this -> settings['title'];
- $this -> description = $this -> settings['description'];
+ // Get the title and description for this checkout method to use in checkout page
+ $this->title = $this->get_option( 'title' );
+ $this->description = $this->get_option( 'description' );
+
+ // Add credit cards available to the description
+ $this->description .= '<h4>Credit Cards Accepted</h4><p>'
+ .($this->settings['visa'] == 'yes' ? '<img src="'.GLM_MES_ASSETS_URL.'/visa.png">' : '')
+ .($this->settings['mastercard'] == 'yes' ? '<img src="'.GLM_MES_ASSETS_URL.'/mastercard.png">' : '')
+ .($this->settings['amex'] == 'yes' ? '<img src="'.GLM_MES_ASSETS_URL.'/amex.png">' : '')
+ .'</p>';
+
+ // Set the transaction mode selected in the WooCommerce Checkout configuration page for this gateway
+ $this -> transaction_mode = $this->settings['transaction_mode'];
// Determine if we're in test or production mode
switch ($this -> settings['transaction_mode']) {
// Description to customer at checkout
'description' => array(
- 'title' => __( 'Customer Message', 'woocommerce' ),
+ 'title' => __( 'Description', 'woocommerce' ),
'type' => 'textarea',
- 'default' => ''
+ 'default' => 'A description of this payment method to the user at checkout. Include cards accepted, etc.'
+ ),
+
+ 'sep_0' => array(
+ 'title' => __( 'Credit Cards Accepted', 'woocommerce' ),
+ 'type' => 'title',
+ 'description' => '',
+ ),
+
+ // Visa
+ 'visa' => array(
+ 'title' => __( '', 'woocommerce' ),
+ 'type' => 'checkbox',
+ 'label' => __( 'Visa', 'woocommerce' ),
+ 'desc_tip' => false,
+ 'default' => 'no'
+ ),
+
+ // MasterCard
+ 'mastercard' => array(
+ 'title' => __( '', 'woocommerce' ),
+ 'type' => 'checkbox',
+ 'label' => __( 'MasterCard', 'woocommerce' ),
+ 'desc_tip' => false,
+ 'default' => 'no'
+ ),
+
+ // Amex
+ 'amex' => array(
+ 'title' => __( '', 'woocommerce' ),
+ 'type' => 'checkbox',
+ 'label' => __( 'American Express', 'woocommerce' ),
+ 'desc_tip' => false,
+ 'default' => 'no'
),
'sep_1' => array(
}
+/*
// Set Payment Fields
public function payment_fields()
{
- require_once (GLM_MES_PLUGIN_PATH . '/views/paymentForm.html');
+ // Set start and end years for card expiration
+ $this->cc_start_year = date('Y');
+ $this->cc_end_year = $this->cc_start_year + GLM_MES_EXPIRE_YEARS;
+
+ if (GLM_MES_DEBUG_VERBOSE) {
+ wc_add_notice('GLM MeS Gateway: Parameters available to payment form...<p><pre>'.print_r($this,1).'</pre></p>', 'success' );
+ }
+
+ require_once (GLM_MES_PATH . '/views/paymentForm.php');
}
// Validate Payment Fields
public function validate_fields()
{
+// $this->$glm_mes_in['account_number'] =
+// $this->sanitize_text_field( )
}
+*/
/*
* Process order with MES Gateway
*/
public function process_payment( $order_id ) {
+ // Get a copy of our order
global $woocommerce;
- $order = new WC_Order( $order_id );
+ $custOrder = new WC_Order( $order_id );
+
+ // Get our invoice number
+ $invNumb = str_replace( "#", "", $custOrder->get_order_number() );
+
+ // Clean up the submitted credit card data
+ $ccNumb = str_replace( array(' ', '-' ), '', $_POST[GLM_MES_ID.'-card-number'] );
+ $cc_exp = str_replace( array( '/', ' '), '', $_POST[GLM_MES_ID.'-card-expiry'] );
+ $cc_cvc = ( isset( $_POST[GLM_MES_ID.'-card-cvc'] ) ) ? $_POST[GLM_MES_ID.'-card-cvc'] : '';
+
+ /* Some other things available to us
+ $custOrder->billing_first_name,
+ $custOrder->billing_last_name,
+ $custOrder->billing_address_1,
+ $custOrder->billing_city,
+ $custOrder->billing_state,
+ $custOrder->billing_postcode,
+ $custOrder->billing_country,
+ $custOrder->billing_phone,
+ $custOrder->billing_email,
+ $custOrder->shipping_first_name,
+ $custOrder->shipping_last_name,
+ $custOrder->shipping_company,
+ $custOrder->shipping_address_1,
+ $custOrder->shipping_city,
+ $custOrder->shipping_country,
+ $custOrder->shipping_state,
+ $custOrder->shipping_postcode,
+ $custOrder->user_id,
+ $_SERVER['REMOTE_ADDR'],
+ */
if (GLM_MES_DEBUG_VERBOSE) {
wc_add_notice('GLM MeS Gateway: process_payment() called', 'success' );
+ wc_add_notice('GLM MeS Gateway: Customer Order Data<p><pre>'.print_r($custOrder,1).'</pre></p>', 'success' );
}
// Create transaction object
- require_once (GLM_MES_PLUGIN_CLASS_PATH . '/MesTridentGateway.php');
+ require_once (GLM_MES_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" );
+ $trans->setAvsRequest( $custOrder->billing_address_1, $custOrder->billing_postcode );
+ $trans->setRequestField('cvv2', $cc_cvc);
+ $trans->setRequestField('invoice_number', $invNumb);
+ $trans->setTransactionData( $ccNumb, $cc_exp, $custOrder->order_total );
// Call the MeS Gateway
$trans->setHost($this->host);
$trans->execute();
if (GLM_MES_DEBUG_VERBOSE) {
- wc_add_notice('GLM MeS Gateway: Transaction Response<p>'.$this->ErrorMessage.'<br><pre>'.print_r($tran->ResponseFields,1).'</pre></p>', 'success');
+ wc_add_notice('GLM MeS Gateway: Response Fields<p><pre>'.print_r($tran2->ResponseFields,1).'</pre></p>', 'success');
}
// Check result
- if( $tran->isApproved() ) {
+ if( $trans->isApproved() ) {
$paymentState = 'approved';
} else {
$paymentState = 'fail';
+ $errorMsg = $trans->ResponseFields['auth_response_text'];
}
// Take action based on payment state
case 'fail':
// Tell the user we had a payment failure
- wc_add_notice( __('Payment error:', 'woothemes') . $error_message, 'error' );
+ wc_add_notice( __("<h4>We're sorry, there was a problem with your payment...</h4><p><b>Reason:</b> ".$errorMsg.'</p><p>Please check your credit card information and try again.', 'woothemes') . $error_message, 'error' );
+
+ if (GLM_MES_DEBUG && !GLM_MES_DEBUG_VERBOSE) {
+ wc_add_notice('GLM MeS Gateway: Response Fields<p><pre>'.print_r($trans->ResponseFields,1).'</pre></p>', 'success');
+ }
+
return;
break;
* Set standard defined parameters
*/
-define('GLM_MES_PLUGIN_NAME', 'Gaslight Media WooCommerce Merchant e-Solutions Gateway');
-define('GLM_MES_PLUGIN_DIR', 'glm-woocommerce-merchant-e-solutions-gateway');
+define('GLM_MES_NAME', 'Gaslight Media WooCommerce Merchant e-Solutions Gateway');
+define('GLM_MES_SHORT_NAME', 'GLM Merchant e-Solutions');
+define('GLM_MES_DESCRIPTION', 'A Merchant e-Solutions payment Gateway plug-in for WooCommerce.');
+define('GLM_MES_ID', 'glm-merchant_e_solutions');
// Plugin Versions
-define('GLM_MES_PLUGIN_VERSION', 0.1);
-define('GLM_MES_PLUGIN_DB_VERSION', 0.1);
+define('GLM_MES_VERSION', 0.1);
// Directories
-define('GLM_MES_PLUGIN_PATH', dirname(__FILE__));
-define('GLM_MES_PLUGIN_CLASS_PATH', GLM_MES_PLUGIN_PATH.'/classes');
+define('GLM_MES_DIR', 'glm-woocommerce-merchant-e-solutions-gateway');
+define('GLM_MES_PATH', dirname(__FILE__));
+define('GLM_MES_CLASS_PATH', GLM_MES_PATH.'/classes');
+define('GLM_MES_ASSETS_PATH', GLM_MES_PATH.'/assets');
+
+// URLs
+$pUrl = plugins_url( GLM_MES_DIR );
+define('GLM_MES_URL', $pUrl);
+define('GLM_MES_ASSETS_URL', GLM_MES_URL.'/assets');
+
+// Optional Gateway Icon
+//define('GLM_MES_ICON', GLM_MES_ASSETS_URL.'/{place_icon_filename_here');
+define('GLM_MES_ICON', null);
+
+// Other Settings
+define('GLM_MES_EXPIRE_YEARS', 10);
?>
\ No newline at end of file
+++ /dev/null
-
- <style type="text/css">
- #payment ul.payment_methods li label[for='glm_mes_gateway_payment'] img:nth-child(n+2) {
- margin-left:1px;
- }
- .woocommerce #payment ul.payment_methods li .glm_mes_gateway_payment img, .woocommerce-page #payment ul.payment_methods li .glm_mes_gateway_payment img {
- margin-left:0;
- }
- </style>
- <label for="glm_mes_gateway_payment">
- Credit Card (put images of accepted cards here)
- </label>
- <div class="payment_box glm_mes_gateway_payment" >
- <p>Safe and Secure Credit Card Payment.</p>
- <p>TEST MODE ENABLED</p>
- <select name="wc-intuit-qbms-test-condition">
- <option value="">Test an Error Condition:</option>
- <option value="10200_comm">CC Processing Gateway comm error</option>
- <option value="10201_login">Processing Gateway login error</option>
- <option value="10301_ccinvalid">Invalid CC account number</option>
- <option value="10400_insufffunds">Insufficient funds</option>
- <option value="10401_decline">Transaction declined</option>
- <option value="10403_acctinvalid">Invalid merchant account</option>
- <option value="10404_referral">Declined pending voice auth</option>
- <option value="10406_capture">Capture error</option>
- <option value="10500_general">General error</option>
- <option value="10000_avscvdfail">AVS Failure</option>
- </select>
- <fieldset>
- <div class="wc-intuit-qbms-new-payment-method-form js-wc-intuit-qbms-new-payment-method-form" >
- <p class="form-row form-row-first">
- <label for="wc-intuit-qbms-account-number">Credit Card Number <span class="required">*</span></label>
- <input type="text" class="input-text js-wc-payment-gateway-account-number" id="wc-intuit-qbms-account-number" name="wc-intuit-qbms-account-number" maxlength="19" autocomplete="off" value="4111111111111111" />
- </p>
-
- <p class="form-row form-row-last">
- <label for="wc-intuit-qbms-exp-month">Expiration Date <span class="required">*</span></label>
- <select name="wc-intuit-qbms-exp-month" id="wc-intuit-qbms-exp-month" class="js-wc-payment-gateway-card-exp-month" style="width:auto;">
- <option value="">Month</option>
- <option value="01" selected='selected'>01</option>
- <option value="02" >02</option>
- <option value="03" >03</option>
- <option value="04" >04</option>
- <option value="05" >05</option>
- <option value="06" >06</option>
- <option value="07" >07</option>
- <option value="08" >08</option>
- <option value="09" >09</option>
- <option value="10" >10</option>
- <option value="11" >11</option>
- <option value="12" >12</option>
- </select>
- <select name="wc-intuit-qbms-exp-year" id="wc-intuit-qbms-exp-year" class="js-wc-payment-gateway-card-exp-year" style="width:auto;">
- <option value="">Year</option>
- <option value="2015" >2015</option>
- <option value="2016" selected='selected'>2016</option>
- <option value="2017" >2017</option>
- <option value="2018" >2018</option>
- <option value="2019" >2019</option>
- <option value="2020" >2020</option>
- <option value="2021" >2021</option>
- <option value="2022" >2022</option>
- <option value="2023" >2023</option>
- <option value="2024" >2024</option>
- <option value="2025" >2025</option>
- </select>
- </p>
- <div class="clear"></div>
-
- <p class="form-row form-row-wide">
- <label for="wc-intuit-qbms-csc">Card Security Code <span class="required">*</span></label>
- <input type="text" class="input-text js-wc-intuit-qbms-csc js-wc-payment-gateway-csc" id="wc-intuit-qbms-csc" name="wc-intuit-qbms-csc" maxlength="4" style="width:60px" autocomplete="off" value="123" />
- </p>
- <div class="clear js-wc-intuit-qbms-csc-clear"></div>
- </div>
- </fieldset>
- </div>
-
\ No newline at end of file
--- /dev/null
+
+ <style type="text/css">
+ .form-row {
+ margin-bottom: 1em !important;
+ }
+ .glm-mes-field {
+ clear: both;
+ }
+ .glm-test-mode {
+ border: 1px solid black;
+ width: 95%;
+ text-align: center;
+ padding: 5px;
+ margin-bottom: 10px;
+ background-color: lightblue;
+ }
+ #glm-mes-section {
+ clear: both;
+ }
+ .glm-mes-card-types {
+ margin: 0px !important;
+ }
+ .glm-mes-card-img {
+ padding-right: .5em !important;
+ }
+ .glm-form-input-text {
+ background: #fff !important;
+ }
+ </style>
+
+<?php
+ if ($this->transaction_mode == 'test') {
+ echo '<div class="glm-test-mode">Operating in Test Mode</div>';
+ }
+?>
+
+ <div id="glm-mes-section">
+ <p><?php echo $this->customer_message; ?></p>
+ <div class="glm-mes-cc-form" >
+ <p class="form-row">
+ <label>Cards Accepted</label>
+ <div class="glm-mes-card-types">
+ <?php
+ if ($this->visa == 'yes') { echo '<img class="glm-mes-card-img" src="'.GLM_MES_ASSETS_URL.'/visa.png">'; }
+ if ($this->mastercard == 'yes') { echo '<img class="glm-mes-card-img" src="'.GLM_MES_ASSETS_URL.'/mastercard.png">'; }
+ if ($this->amex == 'yes') { echo '<img class="glm-mes-card-img" src="'.GLM_MES_ASSETS_URL.'/amex.png">'; }
+ ?>
+ </div>
+ </p>
+ <p> </p>
+ <p class="form-row">
+ <label for="glm_mes_account-number">Credit Card Number <span class="required">*</span></label>
+ <input type="text" class="input-text glm-form-input-text" id="glm-mes-account-number" name="glm_mes_account_number" maxlength="19" autocomplete="off" value="" />
+ </p>
+ <p class="form-row">
+ <label for="glm-mes-name-on-card">Name on Card <span class="required">*</span></label>
+ <input type="text" class="input-text glm-form-input-text" id="glm-mes-name-on-card" name="glm_mes_name_on_card" maxlength="60" autocomplete="off" value="" />
+ </p>
+ <p class="form-row">
+ <label for="glm-mes-exp-month">Expiration Date <span class="required">*</span></label>
+ <select name="glm_mes_exp_month" id="glm-mes-exp-month" class="" style="width:auto;">
+ <option value="">Month</option>
+<?php
+ foreach ($this->cc_months as $k=>$v) {
+ echo '<option value="'.$k.'"'.($this->cc_month_month==$k?' selected="selected"':'').'>'.$k.' - '.$v.'</option>';
+ }
+?>
+ </select>
+ <select name="glm_mes_exp_year" id="glm-mes-exp-year" class="" style="width:auto;">
+ <option value="">Year</option>
+<?php
+ for ($y=$this->cc_start_year ; $y<=$this->cc_end_year ; $y++) {
+ echo '<option value="'.$y.'"'.($this->glm_mes_exp_year==$y?' selected="selected"':'').'>'.$y.'</option>';
+ }
+?>
+ </select>
+ </p>
+ <p class="form-row">
+ <label for="glm-mes-security-code">Card Security Code <span class="required">*</span></label>
+ <input type="text" class="input-text glm-form-input-text" id="glm-mes-security-code" name="glm-mes-security-code" maxlength="4" style="width:60px" autocomplete="off" value="" />
+ </p>
+ </div>
+ </div>
+
\ No newline at end of file