Changeset 2219471
- Timestamp:
- 12/30/2019 07:26:57 AM (6 years ago)
- Location:
- woo-authorize-addon/trunk
- Files:
-
- 32 added
- 1 edited
-
css (added)
-
css/authorize-net.css (added)
-
css/style.css (added)
-
images (added)
-
images/amex.jpg (added)
-
images/dinersclub.jpg (added)
-
images/discover.jpg (added)
-
images/jcb.jpg (added)
-
images/maestro.jpg (added)
-
images/mastercard.jpg (added)
-
images/visa.jpg (added)
-
includes (added)
-
includes/class-woo-wcauthnet-cim-api.php (added)
-
includes/class-woo-wcauthnet-credit-card-gateway-premium.php (added)
-
includes/class-woo-wcauthnet-credit-card-gateway.php (added)
-
includes/class-woo-wcauthnet-premium.php (added)
-
includes/class-woo-wcauthnet-privacy.php (added)
-
includes/class-woo-wcauthnet.php (added)
-
includes/waa-woocommerce-compatibility.php (added)
-
js (added)
-
js/authorize-net-myaccount.min.js (added)
-
js/authorize-net.min.js (added)
-
js/unminified (added)
-
js/unminified/authorize-net-myaccount.js (added)
-
js/unminified/authorize-net.js (added)
-
readme.txt (added)
-
templates (added)
-
templates/admin (added)
-
templates/admin/settings-tab.php (added)
-
templates/authorize-net-credit-card-form.php (added)
-
templates/authorize-net-credit-card-table.php (added)
-
templates/authorize-net-payment-form.php (added)
-
woo-authorize-addon.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woo-authorize-addon/trunk/woo-authorize-addon.php
r2215674 r2219471 1 1 <?php 2 2 /** 3 * Plugin Name: Addon for Authorize and WooCommerce4 * Description: Addon for Authorize and WooCommerceallows you to accept payments on your Woocommerce store. It accpets credit card payments and processes them securely with your merchant account.5 * Version: 2.0.13 * Plugin Name: Woo Authorize Addon 4 * Description: Woo Authorize Addon allows you to accept payments on your Woocommerce store. It accpets credit card payments and processes them securely with your merchant account. 5 * Version: 1.1.1 6 6 * WC requires at least:2.3 7 7 * WC tested up to: 3.8.1 … … 13 13 * License: GPLv3 14 14 * @package WooCommerce 15 * @category Woocommerce Payment Gateway 15 * @category Woocommerce Payment Gateway WC_Authorizenet_Gateway 16 16 */ 17 if (!defined('ABSPATH'))18 exit;19 17 20 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 21 22 if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { 23 24 deactivate_plugins(plugin_basename(__FILE__)); 25 add_action('load-plugins.php', function() { 26 add_filter('gettext', 'change_text_auth', 99, 3); 27 }); 28 29 function change_text_auth($translated_text, $untranslated_text, $domain) { 30 $old = array( 31 "Plugin <strong>activated</strong>.", 32 "Selected plugins <strong>activated</strong>." 33 ); 34 35 $new = "Please activate <b>Woocommerce</b> Plugin to use WooCommerce Authorize.Net Addon plugin"; 36 37 if (in_array($untranslated_text, $old, true)) { 38 $translated_text = $new; 39 remove_filter(current_filter(), __FUNCTION__, 99); 40 } 41 return $translated_text; 42 } 43 44 return FALSE; 18 if ( ! defined( 'WOO_WCAUTHNET' ) ) { 19 define( 'WOO_WCAUTHNET', true ); 20 } 21 if( ! defined( 'WOO_WCAUTHNET_VERSION' ) ){ 22 define( 'WOO_WCAUTHNET_VERSION', '1.1.1' ); 45 23 } 46 24 25 if ( ! defined( 'WOO_WCAUTHNET_PREMIUM' ) ) { 26 define( 'WOO_WCAUTHNET_PREMIUM', true ); 27 } 47 28 48 require 'vendor/autoload.php'; 29 if ( ! defined( 'WOO_WCAUTHNET_PREMIUM_INIT' ) ) { 30 define( 'WOO_WCAUTHNET_PREMIUM_INIT', plugin_dir_url( __FILE__ ) ); 31 } 49 32 50 use net\authorize\api\contract\v1 as AnetAPI; 51 use net\authorize\api\controller as AnetController; 33 if ( ! defined( 'WOO_WCAUTHNET_URL' ) ) { 34 define( 'WOO_WCAUTHNET_URL', plugin_dir_url( __FILE__ ) ); 35 } 52 36 37 if ( ! defined( 'WOO_WCAUTHNET_DIR' ) ) { 38 define( 'WOO_WCAUTHNET_DIR', plugin_dir_path( __FILE__ ) ); 39 } 40 41 if ( ! defined( 'WOO_WCAUTHNET_INIT' ) ) { 42 define( 'WOO_WCAUTHNET_INIT', plugin_basename( __FILE__ ) ); 43 } 44 45 if ( ! defined( 'WOO_WCAUTHNET_FILE' ) ) { 46 define( 'WOO_WCAUTHNET_FILE', __FILE__ ); 47 } 48 49 if ( ! defined( 'WOO_WCAUTHNET_INC' ) ) { 50 define( 'WOO_WCAUTHNET_INC', WOO_WCAUTHNET_DIR . 'includes/' ); 51 } 52 53 if ( ! defined( 'WOO_WCAUTHNET_SLUG' ) ) { 54 define( 'WOO_WCAUTHNET_SLUG', 'woo-woocommerce-authorizenet-payment-gateway' ); 55 } 56 57 if ( ! defined( 'ABSPATH' ) ) { 58 exit; // Exit if accessed directly 59 } 60 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 53 61 /** 54 * 55 * @return boolean 56 */ 57 function authorizenet_init() { 62 * Check if WooCommerce is active 63 **/ 64 if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 65 add_action('admin_notices', 'woo_wcauthnet_install_woocommerce_admin_notice'); 66 } 58 67 59 function add_authorizenet_gateway_class($methods) { 60 $methods[] = 'WC_Authorizenet_Gateway'; 61 return $methods; 62 } 63 64 add_filter('woocommerce_payment_gateways', 'add_authorizenet_gateway_class'); 65 66 if (class_exists('WC_Payment_Gateway')) { 67 68 class WC_Authorizenet_Gateway extends WC_Payment_Gateway { 69 70 public function __construct() { 71 $this->id = 'authorizenet'; 72 $this->has_fields = true; 73 $this->method_title = 'Authorize'; 74 $this->init_form_fields(); 75 $this->init_settings(); 76 $this->supports = array('products', 'refunds'); 77 $this->title = $this->get_option('authorizenet_title'); 78 $this->authorizenet_apilogin = $this->get_option('authorizenet_apilogin'); 79 $this->authorizenet_transactionkey = $this->get_option('authorizenet_transactionkey'); 80 $this->authorizenet_sandbox = $this->get_option('authorizenet_sandbox'); 81 if ($this->authorizenet_sandbox == 'live') { 82 $this->authlink = \net\authorize\api\constants\ANetEnvironment::PRODUCTION; 83 } else { 84 $this->authlink = \net\authorize\api\constants\ANetEnvironment::SANDBOX; 85 } 86 $this->mode = $this->get_option('mode'); 87 $this->authorizenet_cardtypes = $this->get_option('authorizenet_cardtypes'); 88 $this->authorizenet_enable_for_methods = $this->get_option('authorizenet_enable_for_methods', array()); 89 90 if (is_admin()) { 91 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 92 } 93 } 94 95 /** 96 * admin_options 97 */ 98 public function admin_options() { 99 ?> 100 <h3><?php _e('Authorize.Net addon for WooCommerce', 'woocommerce'); ?></h3> 101 <p><?php _e('Authorize.Net is a payment gateway service provider allowing merchants to accept credit card.', 'woocommerce'); ?></p> 102 <table class="form-table"> 103 <?php $this->generate_settings_html(); ?> 104 </table> 105 <?php 106 } 107 108 /** 109 * init_form_fields 110 */ 111 public function init_form_fields() { 112 $this->form_fields = array( 113 'enabled' => array( 114 'title' => __('Enable/Disable', 'woocommerce'), 115 'type' => 'checkbox', 116 'label' => __('Enable Authorize.Net', 'woocommerce'), 117 'default' => 'yes' 118 ), 119 'authorizenet_title' => array( 120 'title' => __('Title', 'woocommerce'), 121 'type' => 'text', 122 'description' => __('This controls the title which the buyer sees during checkout.', 'woocommerce'), 123 'default' => __('Authorize.Net', 'woocommerce'), 124 'desc_tip' => true, 125 ), 126 'authorizenet_apilogin' => array( 127 'title' => __('API Login ID', 'woocommerce'), 128 'type' => 'text', 129 'description' => __('This is the API Login ID Authorize.net.', 'woocommerce'), 130 'default' => '', 131 'desc_tip' => true, 132 'placeholder' => 'Authorize.Net API Login ID' 133 ), 134 'authorizenet_transactionkey' => array( 135 'title' => __('Transaction Key', 'woocommerce'), 136 'type' => 'text', 137 'description' => __('This is the Transaction Key of Authorize.Net.', 'woocommerce'), 138 'default' => '', 139 'desc_tip' => true, 140 'placeholder' => 'Authorize.Net Transaction Key' 141 ), 142 'authorizenet_sandbox' => array( 143 'title' => __('Mode', 'woocommerce'), 144 'type' => 'select', 145 'class' => 'chosen_select', 146 'css' => 'width: 350px;', 147 'desc_tip' => __('Select the mode to accept.', 'woocommerce'), 148 'options' => array( 149 'sandbox' => 'SandBox (Test)', 150 'live' => 'Live', 151 ), 152 'default' => 'sandbox', 153 ), 154 'show_accepted_auth' => array( 155 'title' => __('Show Accepted Card Icons', 'woocommerce'), 156 'type' => 'select', 157 'class' => 'chosen_select', 158 'css' => 'width: 350px;', 159 'desc_tip' => __('Select the mode to accept.', 'woocommerce'), 160 'options' => array( 161 'yes' => 'Yes', 162 'no' => 'No', 163 ), 164 'default' => 'yes', 165 ), 166 'authorizenet_cardtypes' => array( 167 'title' => __('Accepted Cards', 'woocommerce'), 168 'type' => 'multiselect', 169 'class' => 'chosen_select', 170 'css' => 'width: 350px;', 171 'desc_tip' => __('Select the card types to accept.', 'woocommerce'), 172 'options' => array( 173 'mastercard' => 'MasterCard', 174 'visa' => 'Visa', 175 'discover' => 'Discover', 176 'amex' => 'American Express', 177 'jcb' => 'JCB', 178 'dinersclub' => 'Dinners Club', 179 ), 180 'default' => array('mastercard', 'visa', 'discover', 'amex'), 181 ), 182 ); 183 } 184 185 /** 186 * 187 * @return boolean 188 */ 189 public function is_available() { 190 $order = null; 191 192 if (empty($this->authorizenet_apilogin) || empty($this->authorizenet_transactionkey)) { 193 return false; 194 } 195 196 return parent::is_available(); 197 } 198 199 /** 200 * payment_fields 201 */ 202 public function payment_fields() { 203 $this->form(); 204 } 205 206 /** 207 * 208 * @param type $name 209 * @return type 210 */ 211 public function field_name($name) { 212 return $this->supports('tokenization') ? '' : ' name="' . esc_attr($this->id . '-' . $name) . '" '; 213 } 214 215 /** 216 * load form 217 */ 218 public function form() { 219 wp_enqueue_script('wc-credit-card-form'); 220 $fields = array(); 221 $cvc_field = '<p class="form-row form-row-last"> 222 <label for="ei_authorize-card-cvc">' . __('Card Code', 'woocommerce') . ' <span class="required">*</span></label> 223 <input id="ei_authorize-card-cvc" class="input-text wc-credit-card-form-card-cvc" type="text" autocomplete="off" placeholder="' . esc_attr__('CVC', 'woocommerce') . '" ' . $this->field_name('card-cvc') . ' /> 224 </p>'; 225 $default_fields = array( 226 'card-number-field' => '<p class="form-row form-row-wide"> 227 <label for="ei_authorize-card-number">' . __('Card Number', 'woocommerce') . ' <span class="required">*</span></label> 228 <input id="ei_authorize-card-number" class="input-text wc-credit-card-form-card-number" type="text" maxlength="20" autocomplete="off" placeholder="•••• •••• •••• ••••" ' . $this->field_name('card-number') . ' /> 229 </p>', 230 'card-expiry-field' => '<p class="form-row form-row-first"> 231 <label for="ei_authorize-card-expiry">' . __('Expiry (MM/YY)', 'woocommerce') . ' <span class="required">*</span></label> 232 <input id="ei_authorize-card-expiry" class="input-text wc-credit-card-form-card-expiry" type="text" autocomplete="off" placeholder="' . esc_attr__('MM / YY', 'woocommerce') . '" ' . $this->field_name('card-expiry') . ' /> 233 </p>', 234 'card-cvc-field' => $cvc_field 235 ); 236 237 $fields = wp_parse_args($fields, apply_filters('woocommerce_credit_card_form_fields', $default_fields, $this->id)); 238 ?> 239 240 <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class='wc-credit-card-form wc-payment-form'> 241 <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> 242 <?php 243 foreach ($fields as $field) { 244 echo $field; 245 } 246 ?> 247 <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> 248 <div class="clear"></div> 249 </fieldset> 250 <?php 251 } 252 253 /** 254 * 255 * @return type 256 */ 257 public function get_icon() { 258 $icon = ''; 259 if ($this->get_option('show_accepted_auth') == 'yes') { 260 if (is_array($this->authorizenet_cardtypes)) { 261 foreach ($this->authorizenet_cardtypes as $card_type) { 262 263 if ($url = $this->get_payment_method_image_url($card_type)) { 264 265 $icon .= '<img src="' . esc_url($url) . '" alt="' . esc_attr(strtolower($card_type)) . '" />'; 266 } 267 } 268 } 269 } else { 270 $icon = ""; 271 } 272 return apply_filters('woocommerce_gateway_icon', $icon, $this->id); 273 } 274 275 /** 276 * 277 * @param type $type 278 * @return type 279 */ 280 public function get_payment_method_image_url($type) { 281 282 $image_type = strtolower($type); 283 return WC_HTTPS::force_https_url(plugins_url('images/' . $image_type . '.jpg', __FILE__)); 284 } 285 286 /** 287 * 288 * @param type $number 289 * @return string 290 */ 291 public function get_card_type($number) { 292 293 $number = preg_replace('/[^\d]/', '', $number); 294 if (preg_match('/^3[47][0-9]{13}$/', $number)) { 295 return 'amex'; 296 } elseif (preg_match('/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/', $number)) { 297 return 'dinersclub'; 298 } elseif (preg_match('/^6(?:011|5[0-9][0-9])[0-9]{12}$/', $number)) { 299 return 'discover'; 300 } elseif (preg_match('/^(?:2131|1800|35\d{3})\d{11}$/', $number)) { 301 return 'jcb'; 302 } elseif (preg_match('/^5[1-5][0-9]{14}$/', $number)) { 303 return 'mastercard'; 304 } elseif (preg_match('/^4[0-9]{12}(?:[0-9]{3})?$/', $number)) { 305 return 'visa'; 306 } else { 307 return 'unknown card'; 308 } 309 } 310 311 /** 312 * 313 * @return string 314 */ 315 public function get_client_ip() { 316 $ipaddress = ''; 317 if (getenv('HTTP_CLIENT_IP')) 318 $ipaddress = getenv('HTTP_CLIENT_IP'); 319 else if (getenv('HTTP_X_FORWARDED_FOR')) 320 $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); 321 else if (getenv('HTTP_X_FORWARDED')) 322 $ipaddress = getenv('HTTP_X_FORWARDED'); 323 else if (getenv('HTTP_FORWARDED_FOR')) 324 $ipaddress = getenv('HTTP_FORWARDED_FOR'); 325 else if (getenv('HTTP_FORWARDED')) 326 $ipaddress = getenv('HTTP_FORWARDED'); 327 else if (getenv('REMOTE_ADDR')) 328 $ipaddress = getenv('REMOTE_ADDR'); 329 else 330 $ipaddress = '0.0.0.0'; 331 return $ipaddress; 332 } 333 334 /** 335 * 336 * @global type $woocommerce 337 * @param type $order_id 338 * @return boolean 339 */ 340 public function process_payment($order_id) { 341 global $woocommerce; 342 $wc_order = new WC_Order($order_id); 343 $user_id = get_current_user_id(); 344 345 $customer_profile_id = get_user_meta($user_id, 'customer_profile_id', true); 346 $payment_profile_id = get_user_meta($user_id, 'payment_profile_id', true); 347 348 if (!empty($customer_profile_id) && !empty($payment_profile_id)) { 349 350 $price = $woocommerce->cart->total; 351 $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); 352 $merchantAuthentication->setName($this->authorizenet_apilogin); 353 $merchantAuthentication->setTransactionKey($this->authorizenet_transactionkey); 354 $refId = 'ref' . time(); 355 $profileToCharge = new AnetAPI\CustomerProfilePaymentType(); 356 $profileToCharge->setCustomerProfileId($customer_profile_id); 357 $paymentProfile = new AnetAPI\PaymentProfileType(); 358 $paymentProfile->setPaymentProfileId($payment_profile_id); 359 $profileToCharge->setPaymentProfile($paymentProfile); 360 361 $transactionRequestType = new AnetAPI\TransactionRequestType(); 362 363 $transactionRequestType->setTransactionType("authCaptureTransaction"); 364 $transactionRequestType->setAmount($price); 365 $transactionRequestType->setProfile($profileToCharge); 366 $request = new AnetAPI\CreateTransactionRequest(); 367 $request->setMerchantAuthentication($merchantAuthentication); 368 $request->setRefId($refId); 369 $request->setTransactionRequest($transactionRequestType); 370 $controller = new AnetController\CreateTransactionController($request); 371 $response = $controller->executeWithApiResponse($this->authlink); 372 if ($response != null) { 373 if ($response->getMessages()->getResultCode() == 'Ok') { 374 $tresponse = $response->getTransactionResponse(); 375 if ($tresponse != null && $tresponse->getMessages() != null) { 376 $wc_order->add_order_note(__("Order Successfully Done With Transaction ID : " . $tresponse->getTransId() . "\n")); 377 $wc_order->payment_complete($response->transaction_id); 378 WC()->cart->empty_cart(); 379 add_post_meta($order_id, '_transaction_id', $tresponse->getTransId(), true); 380 return array( 381 'result' => 'success', 382 'redirect' => $this->get_return_url($wc_order), 383 ); 384 } else { 385 $wc_order->add_order_note(__("Transaction Failed \n")); 386 return false; 387 } 388 } else { 389 $wc_order->add_order_note(__("Transaction Failed \n")); 390 return false; 391 } 392 } else { 393 $wc_order->add_order_note(__("No response returned \n")); 394 return false; 395 } 396 } else { 397 398 $cardtype = $this->get_card_type(sanitize_text_field(str_replace(' ', '', $_POST['authorizenet-card-number']))); 399 if ($this->get_option('show_accepted_auth') == 'no') { 400 wc_add_notice('Show Accepted Card is not Properly Define', $notice_type = 'error'); 401 return array( 402 'result' => 'success', 403 'redirect' => wc_get_checkout_url(), 404 ); 405 die; 406 } 407 if (!in_array($cardtype, $this->authorizenet_cardtypes)) { 408 wc_add_notice('Merchant do not support accepting in ' . $cardtype, $notice_type = 'error'); 409 return array( 410 'result' => 'success', 411 'redirect' => wc_get_checkout_url(), 412 ); 413 die; 414 } 415 416 $card_num = sanitize_text_field(str_replace(' ', '', $_POST['authorizenet-card-number'])); 417 $exp_date = explode("/", sanitize_text_field($_POST['authorizenet-card-expiry'])); 418 $exp_month = str_replace(' ', '', $exp_date[0]); 419 $exp_year = str_replace(' ', '', $exp_date[1]); 420 $price = $woocommerce->cart->total; 421 if (strlen($exp_year) == 2) { 422 $exp_year += 2000; 423 } 424 $cvc = sanitize_text_field($_POST['authorizenet-card-cvc']); 425 426 $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); 427 $merchantAuthentication->setName($this->authorizenet_apilogin); 428 $merchantAuthentication->setTransactionKey($this->authorizenet_transactionkey); 429 $refId = 'ref' . time(); 430 431 $creditCard = new AnetAPI\CreditCardType(); 432 $creditCard->setCardNumber($card_num); 433 $creditCard->setExpirationDate($exp_year . "-" . $exp_month); 434 435 $paymentCreditCard = new AnetAPI\PaymentType(); 436 $paymentCreditCard->setCreditCard($creditCard); 437 $expiration_date = $exp_year . "-" . $exp_month; 438 439 if ($user_id == '') { 440 441 $order = new AnetAPI\OrderType(); 442 $order->setDescription("New Item"); 443 444 $transactionRequestType = new AnetAPI\TransactionRequestType(); 445 $transactionRequestType->setTransactionType("authCaptureTransaction"); 446 $transactionRequestType->setAmount($price); 447 $transactionRequestType->setOrder($order); 448 $transactionRequestType->setPayment($paymentCreditCard); 449 450 $request = new AnetAPI\CreateTransactionRequest(); 451 $request->setMerchantAuthentication($merchantAuthentication); 452 $request->setRefId($refId); 453 $request->setTransactionRequest($transactionRequestType); 454 $controller = new AnetController\CreateTransactionController($request); 455 $response = $controller->executeWithApiResponse($this->authlink); 456 if ($response != null) { 457 if ($response->getMessages()->getResultCode() == 'Ok') { 458 $tresponse = $response->getTransactionResponse(); 459 if ($tresponse != null && $tresponse->getMessages() != null) { 460 $wc_order->add_order_note(__("Order Successfully Done With Transaction ID : " . $tresponse->getTransId() . "\n")); 461 $wc_order->payment_complete($response->transaction_id); 462 WC()->cart->empty_cart(); 463 add_post_meta($order_id, '_transaction_id', $tresponse->getTransId(), true); 464 return array( 465 'result' => 'success', 466 'redirect' => $this->get_return_url($wc_order), 467 ); 468 } else { 469 $wc_order->add_order_note(__("Transaction Failed \n")); 470 return false; 471 } 472 } else { 473 $wc_order->add_order_note(__("Transaction Failed \n")); 474 return false; 475 } 476 } else { 477 $wc_order->add_order_note(__("Transaction Failed \n")); 478 return false; 479 } 480 } else { 481 482 $billto = new AnetAPI\CustomerAddressType(); 483 $billto->setFirstName($wc_order->billing_first_name); 484 $billto->setLastName($wc_order->billing_last_name); 485 $billto->setCompany($wc_order->billing_company); 486 $billto->setAddress($wc_order->billing_address_1 . ' ' . $wc_order->billing_address_2); 487 $billto->setCity($wc_order->billing_city); 488 $billto->setState($wc_order->billing_state); 489 $billto->setZip($wc_order->billing_postcode); 490 $billto->setCountry($wc_order->billing_country); 491 492 $shippto = new AnetAPI\CustomerAddressType(); 493 $shippto->setFirstName($wc_order->shipping_first_name); 494 $shippto->setLastName($wc_order->shipping_last_name); 495 $shippto->setCompany($wc_order->shipping_company); 496 $shippto->setAddress($wc_order->shipping_address_1 . ' ' . $wc_order->shipping_address_2); 497 $shippto->setCity($wc_order->shipping_city); 498 $shippto->setState($wc_order->shipping_state); 499 $shippto->setZip($wc_order->shipping_postcode); 500 $shippto->setCountry($wc_order->shipping_country); 501 502 $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); 503 504 $paymentprofile->setCustomerType('individual'); 505 $paymentprofile->setBillTo($billto); 506 $paymentprofile->setPayment($paymentCreditCard); 507 $paymentprofiles[] = $paymentprofile; 508 $customerprofile = new AnetAPI\CustomerProfileType(); 509 $customerprofile->setDescription("Product Purchase"); 510 511 $customerprofile->setMerchantCustomerId($wc_order->billing_first_name); 512 $customerprofile->setEmail($wc_order->billing_email); 513 $customerprofile->setPaymentProfiles($paymentprofiles); 514 515 $request = new AnetAPI\CreateCustomerProfileRequest(); 516 $request->setMerchantAuthentication($merchantAuthentication); 517 $request->setRefId($refId); 518 $request->setProfile($customerprofile); 519 $controller = new AnetController\CreateCustomerProfileController($request); 520 $response = $controller->executeWithApiResponse($this->authlink); 521 522 if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { 523 $request2 = new AnetAPI\CreateCustomerShippingAddressRequest(); 524 $request2->setMerchantAuthentication($merchantAuthentication); 525 $request2->setCustomerProfileId($response->getCustomerProfileId()); 526 $request2->setAddress($shippto); 527 528 $controller2 = new AnetController\CreateCustomerShippingAddressController($request2); 529 $response2 = $controller2->executeWithApiResponse($this->authlink); 530 531 if (($response2 != null) && ($response2->getMessages()->getResultCode() == "Ok")) { 532 $profileToCharge = new AnetAPI\CustomerProfilePaymentType(); 533 $profileToCharge->setCustomerProfileId($response->getCustomerProfileId()); 534 add_user_meta($user_id, 'customer_profile_id', $response->getCustomerProfileId()); 535 $paymentProfile1 = new AnetAPI\PaymentProfileType(); 536 $paymentProfile1->setPaymentProfileId($response->getCustomerPaymentProfileIdList()[0]); 537 add_user_meta($user_id, 'payment_profile_id', $response->getCustomerPaymentProfileIdList()[0]); 538 $profileToCharge->setPaymentProfile($paymentProfile1); 539 540 $transactionRequestType = new AnetAPI\TransactionRequestType(); 541 $transactionRequestType->setTransactionType("authCaptureTransaction"); 542 $transactionRequestType->setAmount($price); 543 $transactionRequestType->setProfile($profileToCharge); 544 545 $request = new AnetAPI\CreateTransactionRequest(); 546 $request->setMerchantAuthentication($merchantAuthentication); 547 $request->setRefId($refId); 548 $request->setTransactionRequest($transactionRequestType); 549 $controller = new AnetController\CreateTransactionController($request); 550 $response = $controller->executeWithApiResponse($this->authlink); 551 552 if ($response != null) { 553 $tresponse = $response->getTransactionResponse(); 554 555 if (($tresponse != null) && ($tresponse->getResponseCode() == 1)) { 556 $wc_order->add_order_note(__("Order Successfully Done With Transaction ID : " . $tresponse->getTransId() . "\n")); 557 $wc_order->payment_complete($response->transaction_id); 558 WC()->cart->empty_cart(); 559 add_post_meta($order_id, '_transaction_id', $tresponse->getTransId(), true); 560 return array( 561 'result' => 'success', 562 'redirect' => $this->get_return_url($wc_order), 563 ); 564 } 565 } else { 566 return false; 567 } 568 } 569 } else { 570 wc_add_notice("ERROR : " . $response->getMessages()->getMessage()[0]->getText()); 571 return array( 572 'result' => 'success', 573 'redirect' => wc_get_checkout_url(), 574 ); 575 die; 576 } 577 } 578 } 579 } 580 581 /** 582 * 583 * @param type $order_id 584 * @param type $amount 585 * @param type $reason 586 * @return boolean 587 */ 588 public function process_refund($order_id, $amount = NULL, $reason = '') { 589 if ($amount > 0) { 590 $wc_order = new WC_Order($order_id); 591 $transaction_id = get_post_meta($order_id, '_transaction_id', true); 592 $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); 593 $merchantAuthentication->setName($this->authorizenet_apilogin); 594 $merchantAuthentication->setTransactionKey($this->authorizenet_transactionkey); 595 596 $refId = 'ref' . time(); 597 $request = new AnetAPI\GetTransactionDetailsRequest(); 598 $request->setMerchantAuthentication($merchantAuthentication); 599 $request->setTransId($transaction_id); 600 601 $controller = new AnetController\GetTransactionDetailsController($request); 602 $response = $controller->executeWithApiResponse($this->authlink); 603 604 if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { 605 $cardnum = $response->getTransaction()->getPayment()->getCreditCard()->getCardNumber(); 606 $last_card_num = substr($cardnum, -4); 607 $expirationdate = $response->getTransaction()->getPayment()->getCreditCard()->getExpirationDate(); 608 $transaction_status = $response->getTransaction()->getTransactionStatus(); 609 if ($transaction_status == 'settledSuccessfully') { 610 $creditCard = new AnetAPI\CreditCardType(); 611 $creditCard->setCardNumber($last_card_num); 612 $creditCard->setExpirationDate($expirationdate); 613 $paymentOne = new AnetAPI\PaymentType(); 614 $paymentOne->setCreditCard($creditCard); 615 616 $transactionRequest = new AnetAPI\TransactionRequestType(); 617 $transactionRequest->setTransactionType("refundTransaction"); 618 $transactionRequest->setAmount($amount); 619 $transactionRequest->setPayment($paymentOne); 620 $transactionRequest->setRefTransId($transaction_id); 621 622 $request2 = new AnetAPI\CreateTransactionRequest(); 623 $request2->setMerchantAuthentication($merchantAuthentication); 624 $request2->setRefId($refId); 625 $request2->setTransactionRequest($transactionRequest); 626 $controller2 = new AnetController\CreateTransactionController($request2); 627 $response2 = $controller2->executeWithApiResponse($this->authlink); 628 if ($response2 != null) { 629 if ($response2->getMessages()->getResultCode() == "Ok") { 630 $new_transactionId = $response2->getTransactionResponse()->getTransId(); 631 $rtimestamp = date('Y-m-d H:i:s e'); 632 $wc_order->add_order_note(__('Authorizenet Refund completed at ' . $rtimestamp . ' with Refund ID : ' . $new_transactionId, 'woocommerce')); 633 return true; 634 } else { 635 $wc_order->add_order_note(__('Payment is not refunded,error is' . $response2->getMessages()->getResultCode())); 636 return false; 637 } 638 } else { 639 $wc_order->add_order_note(__('Please try after some time')); 640 return false; 641 } 642 } else { 643 $wc_order->add_order_note(__('Payment is not settled,Please Try After 24 hours after payment')); 644 return false; 645 } 646 } else { 647 $wc_order->add_order_note(__('Cannot get the transcation details from authorize.Net,error is' . $response2->getMessages()->getResultCode())); 648 return false; 649 } 650 } else { 651 $wc_order = new WC_Order($order_id); 652 $transaction_id = get_post_meta($order_id, '_transaction_id', true); 653 $order_total = get_post_meta($order_id, '_order_total', true); 654 655 $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); 656 $merchantAuthentication->setName($this->authorizenet_apilogin); 657 $merchantAuthentication->setTransactionKey($this->authorizenet_transactionkey); 658 659 $refId = 'ref' . time(); 660 $request = new AnetAPI\GetTransactionDetailsRequest(); 661 $request->setMerchantAuthentication($merchantAuthentication); 662 $request->setTransId($transaction_id); 663 664 $controller = new AnetController\GetTransactionDetailsController($request); 665 $response = $controller->executeWithApiResponse($this->authlink); 666 667 if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { 668 $cardnum = $response->getTransaction()->getPayment()->getCreditCard()->getCardNumber(); 669 $last_card_num = substr($cardnum, -4); 670 $expirationdate = $response->getTransaction()->getPayment()->getCreditCard()->getExpirationDate(); 671 $transaction_status = $response->getTransaction()->getTransactionStatus(); 672 if ($transaction_status == 'settledSuccessfully') { 673 $creditCard = new AnetAPI\CreditCardType(); 674 $creditCard->setCardNumber($last_card_num); 675 $creditCard->setExpirationDate($expirationdate); 676 $paymentOne = new AnetAPI\PaymentType(); 677 $paymentOne->setCreditCard($creditCard); 678 679 $transactionRequest = new AnetAPI\TransactionRequestType(); 680 $transactionRequest->setTransactionType("refundTransaction"); 681 $transactionRequest->setAmount($order_total); 682 $transactionRequest->setPayment($paymentOne); 683 $transactionRequest->setRefTransId($transaction_id); 684 685 $request2 = new AnetAPI\CreateTransactionRequest(); 686 $request2->setMerchantAuthentication($merchantAuthentication); 687 $request2->setRefId($refId); 688 $request2->setTransactionRequest($transactionRequest); 689 $controller2 = new AnetController\CreateTransactionController($request2); 690 $response2 = $controller2->executeWithApiResponse($this->authlink); 691 if ($response2 != null) { 692 if ($response2->getMessages()->getResultCode() == "Ok") { 693 $new_transactionId = $response2->getTransactionResponse()->getTransId(); 694 $rtimestamp = date('Y-m-d H:i:s e'); 695 $wc_order->add_order_note(__('Authorizenet Refund completed at ' . $rtimestamp . ' with Refund ID : ' . $new_transactionId, 'woocommerce')); 696 return true; 697 } else { 698 $wc_order->add_order_note(__('Payment is not refunded,error is' . $response2->getMessages()->getResultCode())); 699 return false; 700 } 701 } else { 702 $wc_order->add_order_note(__('Please try after some time')); 703 return false; 704 } 705 } else { 706 $wc_order->add_order_note(__('Payment is not settled,Please Try After 24 hours after payment')); 707 return false; 708 } 709 } else { 710 $wc_order->add_order_note(__('Cannot get the transcation details from authorize.Net,error is' . $response2->getMessages()->getResultCode())); 711 return false; 712 } 713 } 714 } 715 716 /** 717 * sslerror_authorize 718 */ 719 public function wane_sslerror_authorize() { 720 $html = '<div class="error">'; 721 $html .= '<p>'; 722 $html .= __('Please use <b>ssl</b> and activate Force secure checkout to use this plugin'); 723 $html .= '</p>'; 724 $html .= '</div>'; 725 echo $html; 726 } 727 728 } 729 730 } else { 731 if (!class_exists('WC_Payment_Gateway')) { 732 add_action('admin_notices', 'wane_activate_error_auth'); 733 } 734 deactivate_plugins(plugin_basename(__FILE__)); 735 return FALSE; 68 if( ! function_exists( 'woo_wcauthnet_install_woocommerce_admin_notice' ) ) { 69 function woo_wcauthnet_install_woocommerce_admin_notice() { 70 ?> 71 <div class="error"> 72 <p><?php echo sprintf( __( '%s is enabled but not effective. It requires WooCommerce in order to work.', 'woo-woocommerce-authorizenet-payment-gateway' ), 'WOO WooCommerce Authorize.net Payment Gateway' ); ?></p> 73 </div> 74 <?php 736 75 } 737 76 } 738 77 739 /** 740 * activate_error_auth 741 */ 742 function wane_activate_error_auth() { 743 $html = '<div class="error">'; 744 $html .= '<p>'; 745 $html .= __('Please activate <b>Woocommerce</b> Plugin to use this plugin'); 746 $html .= '</p>'; 747 $html .= '</div>'; 748 echo $html; 749 } 78 add_action( 'plugins_loaded', 'wc_offline_gateway_init', 11 ); 750 79 751 add_action('plugins_loaded', 'authorizenet_init'); 752 753 /** 754 * authorizenet_woocommerce_addon_activate755 */756 function wane_authorizenet_woocommerce_addon_activate() { 757 758 if (!function_exists('curl_exec')) {759 wp_die('<pre>This plugin requires PHP CURL library installled in order to be activated </pre>');80 if( ! function_exists( 'wc_offline_gateway_init' ) ) { 81 function wc_offline_gateway_init() 82 { 83 require_once( WOO_WCAUTHNET_DIR . 'includes/class-woo-wcauthnet-credit-card-gateway.php' ); 84 require_once( WOO_WCAUTHNET_DIR . 'includes/class-woo-wcauthnet-credit-card-gateway-premium.php' ); 85 require_once( WOO_WCAUTHNET_DIR . 'includes/class-woo-wcauthnet-cim-api.php' ); 86 require_once( WOO_WCAUTHNET_DIR . 'includes/class-woo-wcauthnet-premium.php' ); 87 require_once( WOO_WCAUTHNET_DIR . 'includes/class-woo-wcauthnet.php' ); 88 require_once( WOO_WCAUTHNET_DIR . 'includes/waa-woocommerce-compatibility.php' ); 760 89 } 761 90 } 762 91 763 register_activation_hook(__FILE__, 'wane_authorizenet_woocommerce_addon_activate'); 764 765 /* Plugin Settings Link */ 92 if( ! function_exists( 'wc_offline_add_to_gateways' ) ) { 93 function wc_offline_add_to_gateways($gateways) 94 { 95 $gateways[] = 'WOO_WCAUTHNET_Credit_Card_Gateway'; 96 return $gateways; 97 } 98 } 99 add_filter( 'woocommerce_payment_gateways', 'wc_offline_add_to_gateways' ); 766 100 767 101 /** 768 * 102 * 769 103 * @param type $links 770 104 * @return type 771 105 */ 772 function wane_authorizenet_woocommerce_settings_link($links) {773 $settings_link = '<a href="admin.php?page=wc-settings&tab=checkout§ion=w c_authorizenet_gateway">' . __('Settings') . '</a>';106 function authorizenet_woocommerce_settings_link($links) { 107 $settings_link = '<a href="admin.php?page=wc-settings&tab=checkout§ion=woo_wcauthnet_credit_card_gateway">' . __('Settings') . '</a>'; 774 108 array_push($links, $settings_link); 775 109 return $links; 776 110 } 777 778 111 $plugin = plugin_basename(__FILE__); 779 add_filter("plugin_action_links_$plugin", 'wane_authorizenet_woocommerce_settings_link'); 780 781 /** 782 * add_custom_js_auth 783 */ 784 function wane_add_custom_js_auth() { 785 wp_enqueue_script('jquery-cc-authorizenet', plugin_dir_url(__FILE__) . 'js/cc.custom_auth.js', array('jquery'), '1.0', True); 786 wp_enqueue_style('authorizenet-css', plugin_dir_url(__FILE__) . 'css/style.css'); 787 } 788 789 add_action('wp_enqueue_scripts', 'wane_add_custom_js_auth'); 790 /* $Class1 = new WC_Authorizenet_Gateway; */ 791 $woo_authorize_settings = get_option('woocommerce_authorize_settings'); 792 if (!empty($woo_authorize_settings)) { 793 if ($woo_authorize_settings['enabled'] == 'yes' && $woo_authorize_settings['mode'] == 'live' && !is_ssl()) { 794 add_action('admin_notices', array('WC_Authorizenet_Gateway', 'wane_sslerror_authorize')); 795 } else { 796 remove_action('admin_notices', array('WC_Authorizenet_Gateway', 'wane_sslerror_authorize')); 797 } 798 } 112 add_filter("plugin_action_links_$plugin", 'authorizenet_woocommerce_settings_link');
Note: See TracChangeset
for help on using the changeset viewer.