From: Chuck Scott Date: Fri, 3 Apr 2015 05:04:26 +0000 (-0400) Subject: Cleaned up a bunch more and started using WooCommerce Default CC Form. X-Git-Tag: v1.0.1~7 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=52b4b042c911e8adaf097cf8804d6831ae902424;p=WP-Plugins%2Fglm-woocommerce-merchant-e-solutions-gateway.git Cleaned up a bunch more and started using WooCommerce Default CC Form. --- diff --git a/assets/amex.png b/assets/amex.png new file mode 100644 index 0000000..492d40a Binary files /dev/null and b/assets/amex.png differ diff --git a/assets/credit.png b/assets/credit.png new file mode 100644 index 0000000..0b8f49a Binary files /dev/null and b/assets/credit.png differ diff --git a/assets/dankort.png b/assets/dankort.png new file mode 100644 index 0000000..400f57c Binary files /dev/null and b/assets/dankort.png differ diff --git a/assets/diners.png b/assets/diners.png new file mode 100644 index 0000000..72e1808 Binary files /dev/null and b/assets/diners.png differ diff --git a/assets/discover.png b/assets/discover.png new file mode 100644 index 0000000..7e36dd7 Binary files /dev/null and b/assets/discover.png differ diff --git a/assets/forbru.png b/assets/forbru.png new file mode 100644 index 0000000..2668cdb Binary files /dev/null and b/assets/forbru.png differ diff --git a/assets/google.png b/assets/google.png new file mode 100644 index 0000000..ab9566b Binary files /dev/null and b/assets/google.png differ diff --git a/assets/jcb.png b/assets/jcb.png new file mode 100644 index 0000000..9bb0cba Binary files /dev/null and b/assets/jcb.png differ diff --git a/assets/laser.png b/assets/laser.png new file mode 100644 index 0000000..2f24179 Binary files /dev/null and b/assets/laser.png differ diff --git a/assets/maestro.png b/assets/maestro.png new file mode 100644 index 0000000..38fdb4b Binary files /dev/null and b/assets/maestro.png differ diff --git a/assets/mastercard.png b/assets/mastercard.png new file mode 100644 index 0000000..af9b1d7 Binary files /dev/null and b/assets/mastercard.png differ diff --git a/assets/money.png b/assets/money.png new file mode 100644 index 0000000..a99814a Binary files /dev/null and b/assets/money.png differ diff --git a/assets/paypa.png b/assets/paypa.png new file mode 100644 index 0000000..4fad9d8 Binary files /dev/null and b/assets/paypa.png differ diff --git a/assets/shopify.png b/assets/shopify.png new file mode 100644 index 0000000..f40146b Binary files /dev/null and b/assets/shopify.png differ diff --git a/assets/solo.png b/assets/solo.png new file mode 100644 index 0000000..c236ecc Binary files /dev/null and b/assets/solo.png differ diff --git a/assets/visa.png b/assets/visa.png new file mode 100644 index 0000000..ffd17c5 Binary files /dev/null and b/assets/visa.png differ diff --git a/classes/MesTridentGateway.php b/classes/MesTridentGateway.php index 1d9bce7..2978140 100644 --- a/classes/MesTridentGateway.php +++ b/classes/MesTridentGateway.php @@ -106,6 +106,7 @@ class TpgTransaction wc_add_notice('GLM MeS Gateway: TpgTransaction::execute() called', 'success' ); } + $url = ''; if ($this->isValid()) { $url .= "profile_id=" . $this->ProfileId; $url .= "&profile_key=" . $this->ProfileKey; @@ -180,7 +181,7 @@ class TpgTransaction $this->ResponseRaw = $response; $responseFields = explode("&", $response); - if (GLM_MES_DEBUG && count($responseField) == 0) { + if (GLM_MES_DEBUG && count($responseFields) == 0) { wc_add_notice('GLM MeS Gateway: parseResponse()

No Response Received!

', 'error' ); } @@ -324,11 +325,9 @@ class TpgPreAuth extends TpgTransaction class TpgSale extends TpgTransaction { - function TpgSale ($profileId, $profileKey, $setings) + function TpgSale ($profileId, $profileKey) { - $this->settings = $settings; - if (GLM_MES_DEBUG_VERBOSE) { wc_add_notice('GLM MeS Gateway: TpgSale() called

', 'success' ); } diff --git a/classes/glmMesGateway.php b/classes/glmMesGateway.php index fa3f8cd..c83ad79 100644 --- a/classes/glmMesGateway.php +++ b/classes/glmMesGateway.php @@ -20,53 +20,42 @@ * 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 @@ -87,6 +76,30 @@ class GlmMesGateway extends WC_Payment_Gateway * @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 () @@ -94,12 +107,38 @@ class GlmMesGateway extends WC_Payment_Gateway // 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 .= '

Credit Cards Accepted

' + .($this->settings['visa'] == 'yes' ? '' : '') + .($this->settings['mastercard'] == 'yes' ? '' : '') + .($this->settings['amex'] == 'yes' ? '' : '') + .'

'; + + // 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']) { @@ -167,9 +206,42 @@ class GlmMesGateway extends WC_Payment_Gateway // 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( @@ -272,39 +344,83 @@ class GlmMesGateway extends WC_Payment_Gateway } +/* // 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...

'.print_r($this,1).'

', '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

'.print_r($custOrder,1).'

', '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); @@ -316,14 +432,15 @@ class GlmMesGateway extends WC_Payment_Gateway $trans->execute(); if (GLM_MES_DEBUG_VERBOSE) { - wc_add_notice('GLM MeS Gateway: Transaction Response

'.$this->ErrorMessage.'

'.print_r($tran->ResponseFields,1).'

', 'success'); + wc_add_notice('GLM MeS Gateway: Response Fields

'.print_r($tran2->ResponseFields,1).'

', '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 @@ -353,7 +470,12 @@ class GlmMesGateway extends WC_Payment_Gateway case 'fail': // Tell the user we had a payment failure - wc_add_notice( __('Payment error:', 'woothemes') . $error_message, 'error' ); + wc_add_notice( __("

We're sorry, there was a problem with your payment...

Reason: ".$errorMsg.'

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

'.print_r($trans->ResponseFields,1).'

', 'success'); + } + return; break; diff --git a/defines.php b/defines.php index c1c0035..53400ec 100644 --- a/defines.php +++ b/defines.php @@ -5,15 +5,30 @@ * 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 diff --git a/index.php b/index.php index 34454e6..c12332b 100644 --- a/index.php +++ b/index.php @@ -64,7 +64,7 @@ require_once('defines.php'); // Activate function glmMesPluginActivate () { - require_once (GLM_MES_PLUGIN_PATH . '/activate.php'); + require_once (GLM_MES_PATH . '/activate.php'); new glmMesPluginActivate(); } register_activation_hook(__FILE__, 'glmMesPluginActivate'); @@ -72,7 +72,7 @@ register_activation_hook(__FILE__, 'glmMesPluginActivate'); // Deactivate function glmMesPluginDeactivate () { - require_once (GLM_MES_PLUGIN_PATH . '/deactivate.php'); + require_once (GLM_MES_PATH . '/deactivate.php'); $x = new glmMesPluginDeactivate(); return false; } @@ -95,7 +95,7 @@ add_action( 'plugins_loaded', 'initMesGateway' ); */ function initMesGateway() { - require_once (GLM_MES_PLUGIN_CLASS_PATH . '/glmMesGateway.php'); + require_once (GLM_MES_CLASS_PATH . '/glmMesGateway.php'); new glmMesGateway(); } diff --git a/views/paymentForm.html b/views/paymentForm.html deleted file mode 100644 index 4448b20..0000000 --- a/views/paymentForm.html +++ /dev/null @@ -1,78 +0,0 @@ - - - -
-

Safe and Secure Credit Card Payment.

-

TEST MODE ENABLED

- -
-
-

- - -

- -

- - - -

-
- -

- - -

-
-
-
-
- \ No newline at end of file diff --git a/views/paymentForm.php b/views/paymentForm.php new file mode 100644 index 0000000..cd42544 --- /dev/null +++ b/views/paymentForm.php @@ -0,0 +1,84 @@ + + + +transaction_mode == 'test') { + echo '
Operating in Test Mode
'; + } +?> + +
+

customer_message; ?>

+
+

+ +

+ visa == 'yes') { echo ''; } + if ($this->mastercard == 'yes') { echo ''; } + if ($this->amex == 'yes') { echo ''; } + ?> +
+

+

 

+

+ + +

+

+ + +

+

+ + + +

+

+ + +

+
+
+ \ No newline at end of file