Untitled diff

Created Diff never expires
85 removals
514 lines
84 additions
517 lines
<?php
<?php
/**
/**
* Plugin Name: WooCommerce NMI Gateway
* Plugin Name: NMI Gateway for WooCommerce
* Plugin URI: https://www.vaultem.com/
* Plugin URI: http://www.patsatech.com/
* Description: WooCommerce Plugin powering payments through NMI Payment Gateway.
* Description: WooCommerce Plugin for accepting payment through NMI Gateway.
* Version: 1.6.4
* Version: 1.6.4
* Author: Vaultem
* Author: PatSaTECH
* Author URI: https://www.vaultem.com
* Author URI: http://www.patsatech.com
* Contributors: Vaultem
* Contributors: patsatech
* Requires at least: 3.5
* Requires at least: 3.5
* Tested up to: 4.1
* Tested up to: 4.1
*
*
* Text Domain: woo-nmi-vaultem
* Text Domain: woo-nmi-patsatech
* Domain Path: /lang/
* Domain Path: /lang/
*
*
* @package NMI Gateway for WooCommerce
* @package NMI Gateway for WooCommerce
* @author Vaultem
* @author PatSaTECH
*/
*/


add_action('plugins_loaded', 'init_woocommerce_nmipay', 0);
add_action('plugins_loaded', 'init_woocommerce_nmipay', 0);
function init_woocommerce_nmipay() {
function init_woocommerce_nmipay() {
if ( ! class_exists( 'WC_Payment_Gateway' ) ) { return; }
if ( ! class_exists( 'WC_Payment_Gateway' ) ) { return; }
load_plugin_textdomain('woo-nmi-vaultem', false, dirname( plugin_basename( __FILE__ ) ) . '/lang');
load_plugin_textdomain('woo-nmi-patsatech', false, dirname( plugin_basename( __FILE__ ) ) . '/lang');
class woocommerce_nmipay extends WC_Payment_Gateway {
class woocommerce_nmipay extends WC_Payment_Gateway {
public function __construct() {
public function __construct() {
global $woocommerce;
global $woocommerce;
$this->id = 'nmipay';
$this->id = 'nmipay';
$this->method_title = __( 'Woocommerce NMI Gateway', 'woo-nmi-vaultem' );
$this->method_title = __( 'Network Merchants Gateway', 'woo-nmi-patsatech' );
$this->icon = plugins_url( 'nmipay.png', __FILE__ );
$this->icon = plugins_url( 'nmipay.png', __FILE__ );
$this->has_fields = TRUE;
$this->has_fields = TRUE;
$this->nmi = 'https://secure.networkmerchants.com/api/transact.php';
$this->nmi = 'https://secure.networkmerchants.com/api/transact.php';
$this->alphacard = 'https://secure.alphacardgateway.com/api/transact.php';
$this->alphacard = 'https://secure.alphacardgateway.com/api/transact.php';
$this->llms = 'https://secure.llmsgateway.com/api/transact.php';
$this->llms = 'https://secure.llmsgateway.com/api/transact.php';
$this->powerpay = 'https://verifi.powerpay.biz/api/transact.php';
$this->powerpay = 'https://verifi.powerpay.biz/api/transact.php';
$this->sbg = 'https://secure.skybankgateway.com/api/transact.php';
$this->sbg = 'https://secure.skybankgateway.com/api/transact.php';
$this->mgg = 'https://secure.merchantguygateway.com/api/transact.php';
$this->mgg = 'https://secure.merchantguygateway.com/api/transact.php';
$this->durango = 'https://secure.durango-direct.com/api/transact.php';
$this->durango = 'https://secure.durango-direct.com/api/transact.php';
$this->tnbci = 'https://secure.tnbcigateway.com/api/transact.php';
$this->tnbci = 'https://secure.tnbcigateway.com/api/transact.php';
$this->payscape = 'https://secure.payscapegateway.com/api/transact.php';
$this->payscape = 'https://secure.payscapegateway.com/api/transact.php';
$this->paylinedata = 'https://secure.paylinedatagateway.com/api/transact.php';
$this->paylinedata = 'https://secure.paylinedatagateway.com/api/transact.php';
$this->inspire = 'https://secure.inspiregateway.net/api/transact.php';
$this->inspire = 'https://secure.inspiregateway.net/api/transact.php';
$this->safesave = 'https://secure.safesavegateway.com/api/transact.php';
$this->safesave = 'https://secure.safesavegateway.com/api/transact.php';
$this->tranzcrypt = 'https://secure.tranzcrypt.com/api/transact.php';
$this->tranzcrypt = 'https://secure.tranzcrypt.com/api/transact.php';
$this->planetauth = 'https://secure.planetauthorizegateway.com/api/transact.php';
$this->planetauth = 'https://secure.planetauthorizegateway.com/api/transact.php';
$this->cyogate = 'https://secure.cyogate.net/api/transact.php';
$this->cyogate = 'https://secure.cyogate.net/api/transact.php';
$this->supports = array(
$this->supports = array(
'products',
'products',
'refunds'
'refunds'
);
);
// Load the form fields.
// Load the form fields.
$this->init_form_fields();
$this->init_form_fields();
// Load the settings.
// Load the settings.
$this->init_settings();
$this->init_settings();
// Define user set variables
// Define user set variables
$this->title = $this->settings['title'];
$this->title = $this->settings['title'];
$this->description = $this->settings['description'];
$this->description = $this->settings['description'];
$this->username = $this->settings['username'];
$this->username = $this->settings['username'];
$this->password = $this->settings['password'];
$this->password = $this->settings['password'];
$this->provider = $this->settings['provider'];
$this->provider = $this->settings['provider'];
$this->woo_version = $this->get_woo_version();
$this->woo_version = $this->get_woo_version();
// Actions
// Actions
add_action( 'woocommerce_update_options_payment_gateways', array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_update_options_payment_gateways', array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
if ( !$this->is_valid_for_use() ) $this->enabled = false;
if ( !$this->is_valid_for_use() ) $this->enabled = false;
}
}
/**
/**
* Check if this gateway is enabled and available in the user's country
* Check if this gateway is enabled and available in the user's country
*/
*/
function is_valid_for_use() {
function is_valid_for_use() {
if ( !in_array( get_option('woocommerce_currency'), array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP') ) ) return false;
if ( !in_array( get_option('woocommerce_currency'), array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP') ) ) return false;
return true;
return true;
}
}
/**
/**
* Admin Panel Options
* Admin Panel Options
* - Options for bits like 'title' and availability on a country-by-country basis
* - Options for bits like 'title' and availability on a country-by-country basis
*
*
* @since 1.0.0
* @since 1.0.0
*/
*/
public function admin_options() {
public function admin_options() {
?>
?>
<h3><?php _e('NMI Payment Gateway', 'woo-nmi-vaultem'); ?></h3>
<h3><?php _e('NMI Pay', 'woo-nmi-patsatech'); ?></h3>
<p><?php _e('NMI WooCommerce gateway allows your customers to checkout using a credit card without leaving your website.', 'woo-nmi-vaultem'); ?></p>
<p><?php _e('NMI works by processing the Credit Card Payments on your site without enter their payment information.', 'woo-nmi-patsatech'); ?></p>
<table class="form-table">
<table class="form-table">
<?php
<?php
if ( $this->is_valid_for_use() ) :
if ( $this->is_valid_for_use() ) :
// Generate the HTML For the settings form.
// Generate the HTML For the settings form.
$this->generate_settings_html();
$this->generate_settings_html();
else :
else :
?>
?>
<div class="inline error"><p><strong><?php _e( 'Gateway Disabled', 'woo-nmi-vaultem' ); ?></strong>: <?php _e( 'NMI does not support your store currency.', 'woo-nmi-vaultem' ); ?></p></div>
<div class="inline error"><p><strong><?php _e( 'Gateway Disabled', 'woo-nmi-patsatech' ); ?></strong>: <?php _e( 'NMI does not support your store currency.', 'woo-nmi-patsatech' ); ?></p></div>
<?php
<?php
endif;
endif;
?>
?>
</table><!--/.form-table-->
</table><!--/.form-table-->
<?php
<?php
} // End admin_options()
} // End admin_options()
/**
/**
* Initialise Gateway Settings Form Fields
* Initialise Gateway Settings Form Fields
*/
*/
function init_form_fields() {
function init_form_fields() {
$this->form_fields = array(
$this->form_fields = array(
'enabled' => array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woo-nmi-vaultem' ),
'title' => __( 'Enable/Disable', 'woo-nmi-patsatech' ),
'type' => 'checkbox',
'type' => 'checkbox',
'label' => __( 'Enable NMI Payment Gateway', 'woo-nmi-vaultem' ),
'label' => __( 'Enable NMI Payment', 'woo-nmi-patsatech' ),
'default' => 'yes'
'default' => 'yes'
),
),
'title' => array(
'title' => array(
'title' => __( 'Title', 'woo-nmi-vaultem' ),
'title' => __( 'Title', 'woo-nmi-patsatech' ),
'type' => 'text',
'type' => 'text',
'description' => __( 'Description customers see during checkout.', 'woo-nmi-vaultem' ),
'description' => __( 'This controls the title which the user sees during checkout.', 'woo-nmi-patsatech' ),
'default' => __( 'Checkout via Credit Card', 'woo-nmi-vaultem' )
'default' => __( 'Network Merchants Gateway', 'woo-nmi-patsatech' )
),
),
'description' => array(
'description' => array(
'title' => __( 'Description', 'woo-nmi-vaultem' ),
'title' => __( 'Description', 'woo-nmi-patsatech' ),
'type' => 'textarea',
'type' => 'textarea',
'description' => __( 'Description customers see during checkout.', 'woo-nmi-vaultem' ),
'description' => __( 'This controls the description which the user sees during checkout.', 'woo-nmi-patsatech' ),
'default' => __("Pay by credit card.", 'woo-nmi-vaultem')
'default' => __("Pay via NMI; you can pay with your credit card.", 'woo-nmi-patsatech')
),
),
'username' => array(
'username' => array(
'title' => __( 'Username', 'woo-nmi-vaultem' ),
'title' => __( 'UserName', 'woo-nmi-patsatech' ),
'type' => 'text',
'type' => 'text',
'description' => __( 'Please enter your Username.', 'woo-nmi-vaultem' ),
'description' => __( 'Please enter your UserName; this is needed in order to take payment.', 'woo-nmi-patsatech' ),
'default' => ''
'default' => ''
),
),
'password' => array(
'password' => array(
'title' => __( 'Password', 'woo-nmi-vaultem' ),
'title' => __( 'Password', 'woo-nmi-patsatech' ),
'type' => 'text',
'type' => 'text',
'description' => __( 'Please enter your Password.', 'woo-nmi-vaultem' ),
'description' => __( 'Please enter your Password; this is needed in order to take payment.', 'woo-nmi-patsatech' ),
'default' => ''
'default' => ''
),
),
'provider' => array(
'provider' => array(
'title' => __('Payment Gateway', 'woo-nmi-vaultem'),
'title' => __('Payment Gateway', 'woo-nmi-patsatech'),
'type' => 'select',
'type' => 'select',
'options' => array(
'options' => array(
'nmi' => 'Network Merchants Inc',
'nmi' => 'Network Merchants Inc',
'alphacard' => 'Alpha Card Services',
'alphacard' => 'Alpha Card Services',
'llms' => 'LL Merchant Solutions',
'llms' => 'LL Merchant Solutions',
'powerpay' => 'PowerPay',
'powerpay' => 'PowerPay',
'sbg' => 'SkyBank',
'sbg' => 'SkyBank',
'mgg' => 'MerchantGuy',
'mgg' => 'MerchantGuy',
'durango' => 'Durango Merchant Services',
'durango' => 'Durango Merchant Services',
'tnbci' => 'TransNational Bankcard Inc',
'tnbci' => 'TransNational Bankcard Inc',
'payscape' => 'Payscape',
'payscape' => 'Payscape',
'paylinedata' => 'Payline Data',
'paylinedata' => 'Payline Data',
'inspire' => 'Inspire Commerce',
'inspire' => 'Inspire Commerce',
'safesave' => 'SafeSave Payments',
'safesave' => 'SafeSave Payments',
'tranzcrypt' => 'Tranzcrypt',
'tranzcrypt' => 'Tranzcrypt',
'planetauth' => 'PlanetAuthorize',
'planetauth' => 'PlanetAuthorize',
'cyogate' => 'CyoGate'
'cyogate' => 'CyoGate'
),
),
'description' => __( 'Please choose your Merchant Account Provider.', 'woo-nmi-vaultem' ),
'description' => __( 'Select your Merchant Account Provider.', 'woo-nmi-patsatech' ),
'default' => 'nmi'
'default' => 'nmi'
)
)
);
);
} // End init_form_fields()
} // End init_form_fields()
/**
/**
* There are no payment fields for nmi, but we want to show the description if set.
* There are no payment fields for nmi, but we want to show the description if set.
**/
**/
function payment_fields() {
function payment_fields() {
if ($this->description) echo wpautop(wptexturize($this->description)); ?>
if ($this->description) echo wpautop(wptexturize($this->description)); ?>
<p class="form-row" style="width:200px;">
<p class="form-row" style="width:200px;">
<label>Card Number <span class="required">*</span></label>
<label>Card Number <span class="required">*</span></label>
<input id="nmi_creditcard" class="swipe" style="width:180px;" type="text" size="16" autocomplete="on" maxlength="16" name="nmi_creditcard" />
<input class="input-text" style="width:180px;" type="text" size="16" autocomplete="off" maxlength="16" name="nmi_creditcard" />
</p>
</p>
<div class="clear"></div>
<div class="clear"></div>
<p class="form-row form-row-first" style="width:200px;">
<p class="form-row form-row-first" style="width:200px;">
<label>Expiration Month <span class="required">*</span></label>
<label>Expiration Month <span class="required">*</span></label>
<select id="nmi_expdatemonth" name="nmi_expdatemonth">
<select name="nmi_expdatemonth">
<option value="01">01</option>
<option value=01> 1 - January</option>
<option value="02">02</option>
<option value=02> 2 - February</option>
<option value="03">03</option>
<option value=03> 3 - March</option>
<option value="04">04</option>
<option value=04> 4 - April</option>
<option value="05">05</option>
<option value=05> 5 - May</option>
<option value="06">06</option>
<option value=06> 6 - June</option>
<option value="07">07</option>
<option value=07> 7 - July</option>
<option value="08">08</option>
<option value=08> 8 - August</option>
<option value="09">09</option>
<option value=09> 9 - September</option>
<option value="10">10</option>
<option value=10>10 - October</option>
<option value="11">11</option>
<option value=11>11 - November</option>
<option value="12">12</option>
<option value=12>12 - December</option>
</select>
</select>
</p>
</p>
<p class="form-row form-row-second" style="width:150px;">
<p class="form-row form-row-second" style="width:150px;">
<label>Expiration Year <span class="required">*</span></label>
<label>Expiration Year <span class="required">*</span></label>
<select id="nmi_expdateyear" name="nmi_expdateyear">
<select name="nmi_expdateyear">
<?php
<?php
$today = (int)date('y', time());
$today = (int)date('y', time());
$today1 = (int)date('Y', time());
$today1 = (int)date('Y', time());
for($i = 0; $i < 15; $i++)
for($i = 0; $i < 15; $i++)
{
{
?>
?>
<option value="<?php echo $today; ?>"><?php echo $today1; ?></option>
<option value="<?php echo $today; ?>"><?php echo $today1; ?></option>
<?php
<?php
$today++;
$today++;
$today1++;
$today1++;
}
}
?>
?>
</select>
</select>
</p>
</p>
<p class="form-row" style="width:200px;">
<label>Card CVV <span class="required">*</span></label>
<input class="input-text" style="width:100px;" type="text" autocomplete="off" size="5" maxlength="5" name="nmi_cvv" />
</p>
<div class="clear"></div>
<div class="clear"></div>
<?php
<?php
}
}
public function validate_fields(){
public function validate_fields(){
global $woocommerce;
global $woocommerce;
if (!$this->isCreditCardNumber($_POST['nmi_creditcard'])){
if (!$this->isCreditCardNumber($_POST['nmi_creditcard'])){
if( $this->woo_version >= 2.1 ){
if( $this->woo_version >= 2.1 ){
wc_add_notice( __('(Credit Card Number) is not valid.', 'woo-nmi-vaultem'), $notice_type = 'error' );
wc_add_notice( __('(Credit Card Number) is not valid.', 'woo-nmi-patsatech'), $notice_type = 'error' );
}else if( $this->woo_version < 2.1 ){
}else if( $this->woo_version < 2.1 ){
$woocommerce->add_error( __('(Credit Card Number) is not valid.', 'woo-nmi-vaultem') );
$woocommerce->add_error( __('(Credit Card Number) is not valid.', 'woo-nmi-patsatech') );
}else{
}else{
$woocommerce->add_error( __('(Credit Card Number) is not valid.', 'woo-nmi-vaultem') );
$woocommerce->add_error( __('(Credit Card Number) is not valid.', 'woo-nmi-patsatech') );
}
}
}
}
if (!$this->isCorrectExpireDate($_POST['nmi_expdatemonth'], $_POST['nmi_expdateyear'])){
if (!$this->isCorrectExpireDate($_POST['nmi_expdatemonth'], $_POST['nmi_expdateyear'])){
if( $this->woo_version >= 2.1 ){
if( $this->woo_version >= 2.1 ){
wc_add_notice( __('(Card Expire Date) is not valid.', 'woo-nmi-vaultem'), $notice_type = 'error' );
wc_add_notice( __('(Card Expire Date) is not valid.', 'woo-nmi-patsatech'), $notice_type = 'error' );
}else if( $this->woo_version < 2.1 ){
}else if( $this->woo_version < 2.1 ){
$woocommerce->add_error( __('(Card Expire Date) is not valid.', 'woo-nmi-vaultem') );
$woocommerce->add_error( __('(Card Expire Date) is not valid.', 'woo-nmi-patsatech') );
}else{
}else{
$woocommerce->add_error( __('(Card Expire Date) is not valid.', 'woo-nmi-vaultem') );
$woocommerce->add_error( __('(Card Expire Date) is not valid.', 'woo-nmi-patsatech') );
}
}
}
}
if (!$_POST['nmi_cvv']){
if (!$_POST['nmi_cvv']){
if( $this->woo_version >= 2.1 ){
if( $this->woo_version >= 2.1 ){
wc_add_notice( __('(Card CVV) is not entered.', 'woo-nmi-vaultem'), $notice_type = '' );
wc_add_notice( __('(Card CVV) is not entered.', 'woo-nmi-patsatech'), $notice_type = 'error' );
}else if( $this->woo_version < 2.1 ){
}else if( $this->woo_version < 2.1 ){
$woocommerce->add_error( __('(Card CVV) is not entered.', 'woo-nmi-vaultem') );
$woocommerce->add_error( __('(Card CVV) is not entered.', 'woo-nmi-patsatech') );
}else{
}else{
$woocommerce->add_error( __('(Card CVV) is not entered.', 'woo-nmi-vaultem') );
$woocommerce->add_error( __('(Card CVV) is not entered.', 'woo-nmi-patsatech') );
}
}
}
}
}
}
/**
/**
* Process the payment and return the result
* Process the payment and return the result
**/
**/
function process_payment( $order_id ) {
function process_payment( $order_id ) {
global $woocommerce;
global $woocommerce;
$order = new WC_Order( $order_id );
$order = new WC_Order( $order_id );
$provider = $this->provider;
$provider = $this->provider;
$nmi_adr = $this->$provider . '?';
$nmi_adr = $this->$provider . '?';
$nmi_args['type'] = 'sale';
$nmi_args['type'] = 'sale';
$nmi_args['ipaddress'] = $_SERVER['REMOTE_ADDR'];
$nmi_args['ipaddress'] = $_SERVER['REMOTE_ADDR'];
$nmi_args['username'] = $this->username;
$nmi_args['username'] = $this->username;
$nmi_args['password'] = $this->password;
$nmi_args['password'] = $this->password;
$nmi_args['currency'] = get_option('woocommerce_currency');
$nmi_args['currency'] = get_option('woocommerce_currency');
$nmi_args['ccnumber'] = $_POST["nmi_creditcard"];
$nmi_args['ccnumber'] = $_POST["nmi_creditcard"];
$nmi_args['cvv'] = $_POST["nmi_cvv"];
$nmi_args['cvv'] = $_POST["nmi_cvv"];
$nmi_args['ccexp'] = $_POST["nmi_expdatemonth"].'/'.$_POST["nmi_expdateyear"];
$nmi_args['ccexp'] = $_POST["nmi_expdatemonth"].'/'.$_POST["nmi_expdateyear"];
$nmi_args['orderid'] = $order_id;
$nmi_args['orderid'] = $order_id;
$nmi_args['firstname'] = $order->billing_first_name;
$nmi_args['firstname'] = $order->billing_first_name;
$nmi_args['lastname'] = $order->billing_last_name;
$nmi_args['lastname'] = $order->billing_last_name;
$nmi_args['company'] = $order->billing_company;
$nmi_args['company'] = $order->billing_company;
$nmi_args['address1'] = $order->billing_address_1;
$nmi_args['address1'] = $order->billing_address_1;
$nmi_args['address2'] = $order->billing_address_2;
$nmi_args['address2'] = $order->billing_address_2;
$nmi_args['city'] = $order->billing_city;
$nmi_args['city'] = $order->billing_city;
$nmi_args['state'] = $order->billing_state;
$nmi_args['state'] = $order->billing_state;
$nmi_args['zip'] = $order->billing_postcode;
$nmi_args['zip'] = $order->billing_postcode;
$nmi_args['country'] = $order->billing_country;
$nmi_args['country'] = $order->billing_country;
$nmi_args['email'] = $order->billing_email;
$nmi_args['email'] = $order->billing_email;
$nmi_args['shipping_firstname'] = $order->shipping_first_name;
$nmi_args['shipping_firstname'] = $order->shipping_first_name;
$nmi_args['shipping_lastname'] = $order->shipping_last_name;
$nmi_args['shipping_lastname'] = $order->shipping_last_name;
$nmi_args['shipping_company'] = $order->shipping_company;
$nmi_args['shipping_company'] = $order->shipping_company;
$nmi_args['shipping_address1'] = $order->shipping_address_1;
$nmi_args['shipping_address1'] = $order->shipping_address_1;
$nmi_args['shipping_address2'] = $order->shipping_address_2;
$nmi_args['shipping_address2'] = $order->shipping_address_2;
$nmi_args['shipping_city'] = $order->shipping_city;
$nmi_args['shipping_city'] = $order->shipping_city;
$nmi_args['shipping_state'] = $order->shipping_state;
$nmi_args['shipping_state'] = $order->shipping_state;
$nmi_args['shipping_zip'] = $order->shipping_postcode;
$nmi_args['shipping_zip'] = $order->shipping_postcode;
$nmi_args['shipping_country'] = $order->shipping_country;
$nmi_args['shipping_country'] = $order->shipping_country;
$nmi_args['invoice'] = $order->order_key;
$nmi_args['invoice'] = $order->order_key;
$AmountInput = number_format($order->order_total, 2, '.', '');
$AmountInput = number_format($order->order_total, 2, '.', '');
$nmi_args['amount'] = $AmountInput;
$nmi_args['amount'] = $AmountInput;
if ( in_array( $order->billing_country, array( 'US','CA' ) ) ) {
if ( in_array( $order->billing_country, array( 'US','CA' ) ) ) {
$order->billing_phone = str_replace( array( '( ', '-', ' ', ' )', '.' ), '', $order->billing_phone );
$order->billing_phone = str_replace( array( '( ', '-', ' ', ' )', '.' ), '', $order->billing_phone );
$nmi_args['phone'] = $order->billing_phone;
$nmi_args['phone'] = $order->billing_phone;
} else {
} else {
$nmi_args['phone'] = $order->billing_phone;
$nmi_args['phone'] = $order->billing_phone;
}
}
$name_value_pairs = array();
$name_value_pairs = array();
foreach ($nmi_args as $key => $value) {
foreach ($nmi_args as $key => $value) {
$name_value_pairs[] = $key . '=' . urlencode($value);
$name_value_pairs[] = $key . '=' . urlencode($value);
}
}
$gateway_values = implode('&', $name_value_pairs);
$gateway_values = implode('&', $name_value_pairs);
$response = wp_remote_post($nmi_adr.$gateway_values);
$response = wp_remote_post($nmi_adr.$gateway_values);
if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
parse_str($response['body'], $response);
parse_str($response['body'], $response);
if($response['response']== '1'){
if($response['response']== '1'){
// Payment completed
// Payment completed
$order->add_order_note( sprintf( __('The NMI Payment transaction is successful. The Transaction Id is %s.', 'woo-nmi-vaultem'), $response["transactionid"] ) );
$order->add_order_note( sprintf( __('The NMI Payment transaction is successful. The Transaction Id is %s.', 'woo-nmi-patsatech'), $response["transactionid"] ) );
$order->payment_complete( $response["transactionid"] );
$order->payment_complete( $response["transactionid"] );
return array(
return array(
'result' => 'success',
'result' => 'success',
'redirect' => $this->get_return_url($order)
'redirect' => $this->get_return_url($order)
);
);
}
}
else
else
{
{
if( $this->woo_version >= 2.1 ){
if( $this->woo_version >= 2.1 ){
wc_add_notice( sprintf( __('Transaction Failed. %s', 'woo-nmi-vaultem'), $response['responsetext'] ), $notice_type = 'error' );
wc_add_notice( sprintf( __('Transaction Failed. %s', 'woo-nmi-patsatech'), $response['responsetext'] ), $notice_type = 'error' );
}else if( $this->woo_version < 2.1 ){
}else if( $this->woo_version < 2.1 ){
$woocommerce->add_error( sprintf( __('Transaction Failed. %s', 'woo-nmi-vaultem'), $response['responsetext'] ) );
$woocommerce->add_error( sprintf( __('Transaction Failed. %s', 'woo-nmi-patsatech'), $response['responsetext'] ) );
}else{
}else{
$woocommerce->add_error( sprintf( __('Transaction Failed. %s', 'woo-nmi-vaultem'), $response['responsetext'] ) );
$woocommerce->add_error( sprintf( __('Transaction Failed. %s', 'woo-nmi-patsatech'), $response['responsetext'] ) );
}
}
}
}
}
}
else{
else{
if( $this->woo_version >= 2.1 ){
if( $this->woo_version >= 2.1 ){
wc_add_notice( sprintf( __('Gateway Error. Please Notify the Store Owner about this error. %s', 'woo-nmi-vaultem'), $statusMessage ), $notice_type = 'error' );
wc_add_notice( sprintf( __('Gateway Error. Please Notify the Store Owner about this error. %s', 'woo-nmi-patsatech'), $statusMessage ), $notice_type = 'error' );
}else if( $this->woo_version < 2.1 ){
}else if( $this->woo_version < 2.1 ){
$woocommerce->add_error( sprintf( __('Gateway Error. Please Notify the Store Owner about this error. %s', 'woo-nmi-vaultem'), $statusMessage ) );
$woocommerce->add_error( sprintf( __('Gateway Error. Please Notify the Store Owner about this error. %s', 'woo-nmi-patsatech'), $statusMessage ) );
}else{
}else{
$woocommerce->add_error( sprintf( __('Gateway Error. Please Notify the Store Owner about this error. %s', 'woo-nmi-vaultem'), $statusMessage ) );
$woocommerce->add_error( sprintf( __('Gateway Error. Please Notify the Store Owner about this error. %s', 'woo-nmi-patsatech'), $statusMessage ) );
}
}
}
}
}
}


/**
/**
* Process a refund if supported
* Process a refund if supported
* @param int $order_id
* @param int $order_id
* @param float $amount
* @param float $amount
* @param string $reason
* @param string $reason
* @return bool|wp_error True or false based on success, or a WP_Error object
* @return bool|wp_error True or false based on success, or a WP_Error object
*/
*/
public function process_refund( $order_id, $amount = null, $reason = '' ) {
public function process_refund( $order_id, $amount = null, $reason = '' ) {
$order = wc_get_order( $order_id );
$order = wc_get_order( $order_id );


if ( ! $order || ! $order->get_transaction_id() ) {
if ( ! $order || ! $order->get_transaction_id() ) {
return false;
return false;
}
}
$provider = $this->provider;
$provider = $this->provider;
$nmi_adr = $this->$provider . '?';
$nmi_adr = $this->$provider . '?';
if ( ! is_null( $amount ) ) {
if ( ! is_null( $amount ) ) {
$nmi_args['type'] = 'refund';
$nmi_args['type'] = 'refund';
$nmi_args['username'] = $this->username;
$nmi_args['username'] = $this->username;
$nmi_args['password'] = $this->password;
$nmi_args['password'] = $this->password;
$nmi_args['transactionid'] = $order->get_transaction_id();
$nmi_args['transactionid'] = $order->get_transaction_id();
$nmi_args['amount'] = number_format( $amount, 2, '.', '' );
$nmi_args['amount'] = number_format( $amount, 2, '.', '' );
}
}
$name_value_pairs = array();
$name_value_pairs = array();
foreach ($nmi_args as $key => $value) {
foreach ($nmi_args as $key => $value) {
$name_value_pairs[] = $key . '=' . urlencode($value);
$name_value_pairs[] = $key . '=' . urlencode($value);
}
}
$gateway_values = implode('&', $name_value_pairs);
$gateway_values = implode('&', $name_value_pairs);
$response = wp_remote_post($nmi_adr.$gateway_values);
$response = wp_remote_post($nmi_adr.$gateway_values);
if ( is_wp_error( $response ) ) {
if ( is_wp_error( $response ) ) {
return $response;
return $response;
}
}


if ( empty( $response['body'] ) ) {
if ( empty( $response['body'] ) ) {
return new WP_Error( 'nmi-error', __( 'Empty NMI response.', 'woocommerce' ) );
return new WP_Error( 'nmi-error', __( 'Empty NMI response.', 'woocommerce' ) );
}
}
parse_str($response['body'], $response);
parse_str($response['body'], $response);
if($response['response']== '1'){
if($response['response']== '1'){
$order->add_order_note( sprintf( __( 'Refund %s - Refund ID: %s', 'woocommerce' ), $response['responsetext'], $response['transactionid'] ) );
$order->add_order_note( sprintf( __( 'Refund %s - Refund ID: %s', 'woocommerce' ), $response['responsetext'], $response['transactionid'] ) );
return true;
return true;
}else if($response['response']== '2'){
}else if($response['response']== '2'){
$order->add_order_note( __( 'Transaction Declined', 'woocommerce' ) );
$order->add_order_note( __( 'Transaction Declined', 'woocommerce' ) );
return true;
return true;
}else if($response['response']== '3'){
}else if($response['response']== '3'){
$order->add_order_note( __( 'Error in transaction data or system error.', 'woocommerce' ) );
$order->add_order_note( __( 'Error in transaction data or system error.', 'woocommerce' ) );
return true;
return true;
}
}


return false;
return false;
}
}
private function isCreditCardNumber($toCheck){
private function isCreditCardNumber($toCheck){
if (!is_numeric($toCheck))
if (!is_numeric($toCheck))
return false;
return false;
$number = preg_replace('/[^0-9]+/', '', $toCheck);
$number = preg_replace('/[^0-9]+/', '', $toCheck);
$strlen = strlen($number);
$strlen = strlen($number);
$sum = 0;
$sum = 0;
if ($strlen < 13)
if ($strlen < 13)
return false;
return false;
for ($i=0; $i < $strlen; $i++) {
for ($i=0; $i < $strlen; $i++) {
$digit = substr($number, $strlen - $i - 1, 1);
$digit = substr($number, $strlen - $i - 1, 1);
if($i % 2 == 1)
if($i % 2 == 1)
{
{
$sub_total = $digit * 2;
$sub_total = $digit * 2;
if($sub_total > 9)
if($sub_total > 9)
{
{
$sub_total = 1 + ($sub_total - 10);
$sub_total = 1 + ($sub_total - 10);
}
}
}
}
else
else
{
{
$sub_total = $digit;
$sub_total = $digit;
}
}
$sum += $sub_total;
$sum += $sub_total;
}
}
if ($sum > 0 AND $sum % 10 == 0)
if ($sum > 0 AND $sum % 10 == 0)
return true;
return true;
return false;
return false;
}
}
private function isCorrectExpireDate($month, $year){
private function isCorrectExpireDate($month, $year){
$now = time();
$now = time();
$result = false;
$result = false;
$thisYear = (int)date('y', $now);
$thisYear = (int)date('y', $now);
$thisMonth = (int)date('m', $now);
$thisMonth = (int)date('m', $now);
if (is_numeric($year) && is_numeric($month)){
if (is_numeric($year) && is_numeric($month)){
if($thisYear == (int)$year){
if($thisYear == (int)$year){
$result = (int)$month >= $thisMonth;
$result = (int)$month >= $thisMonth;
} else if($thisYear < (int)$year){
} else if($thisYear < (int)$year){
$result = true;
$result = true;
}
}
}
}
return $result;
return $result;
}
}
function get_woo_version() {
function get_woo_version() {
// If get_plugins() isn't available, require it
// If get_plugins() isn't available, require it
if ( ! function_exists( 'get_plugins' ) )
if ( ! function_exists( 'get_plugins' ) )
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// Create the plugins folder and file variables
// Create the plugins folder and file variables
$plugin_folder = get_plugins( '/woocommerce' );
$plugin_folder = get_plugins( '/woocommerce' );
$plugin_file = 'woocommerce.php';
$plugin_file = 'woocommerce.php';
// If the plugin version number is set, return it
// If the plugin version number is set, return it
if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
return $plugin_folder[$plugin_file]['Version'];
return $plugin_folder[$plugin_file]['Version'];
} else {
} else {
// Otherwise return null
// Otherwise return null
return NULL;
return NULL;
}
}
}
}
}
}
/**
/**
* Add the gateway to WooCommerce
* Add the gateway to WooCommerce
**/
**/
function add_nmipay_gateway( $methods ) {
function add_nmipay_gateway( $methods ) {
$methods[] = 'woocommerce_nmipay'; return $methods;
$methods[] = 'woocommerce_nmipay'; return $methods;
}
}
add_filter('woocommerce_payment_gateways', 'add_nmipay_gateway' );
add_filter('woocommerce_payment_gateways', 'add_nmipay_gateway' );
}
}