id = 'authorize'; $this->method_title = __('Authorize.net', 'tech'); $this->icon = WP_PLUGIN_URL . "/" . plugin_basename(dirname(__FILE__)) . '/images/logo.gif'; $this->has_fields = false; $this->init_form_fields(); $this->init_settings(); $this->title = $this->settings['title']; $this->description = $this->settings['description']; $this->login = $this->settings['login_id']; $this->mode = $this->settings['working_mode']; $this->transaction_mode = $this->settings['transaction_mode']; $this->transaction_key = $this->settings['transaction_key']; $this->hash_key = $this->settings['hash_key']; $this->success_message = $this->settings['success_message']; $this->failed_message = $this->settings['failed_message']; $this->liveurl = 'https://secure2.authorize.net/gateway/transact.dll'; $this->testurl = 'https://test.authorize.net/gateway/transact.dll'; $this->powerpay = 'https://verifi.powerpay.biz/cart/ausi.php'; $this->msg['message'] = ""; $this->msg['class'] = ""; add_action('init', array(&$this, 'check_authorize_response')); //update for woocommerce >2.0 add_action( 'woocommerce_api_wc_tech_autho' , array( $this, 'check_authorize_response' ) ); add_action('valid-authorize-request', array(&$this, 'successful_request')); if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) { add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ) ); } else { add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) ); } add_action('woocommerce_receipt_authorize', array(&$this, 'receipt_page')); add_action('woocommerce_thankyou_authorize',array(&$this, 'thankyou_page')); if( function_exists('indatos_woo_auth_process_refund') ){ $this->supports = array( 'products', 'refunds' ); }else{ } } function process_refund($order_id, $amount = null, $reason = '') { return indatos_woo_auth_process_refund($order_id, $amount = null, $reason = ''); } function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __('Enable/Disable', 'tech'), 'type' => 'checkbox', 'label' => __('Enable Authorize.net Payment Module.', 'tech'), 'default' => 'no'), 'title' => array( 'title' => __('Title:', 'tech'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'tech'), 'default' => __('Authorize.net', 'tech')), 'description' => array( 'title' => __('Description:', 'tech'), 'type' => 'textarea', 'description' => __('This controls the description which the user sees during checkout.', 'tech'), 'default' => __('Pay securely by Credit or Debit Card through Authorize.net Secure Servers.', 'tech')), 'login_id' => array( 'title' => __('Login ID', 'tech'), 'type' => 'password', 'description' => __('This is API Login ID')), 'transaction_key' => array( 'title' => __('Transaction Key', 'tech'), 'type' => 'password', 'description' => __('API Transaction Key', 'tech')), 'hash_key' => array( 'title' => __('MD5 Hash Key', 'tech'), 'type' => 'password', 'description' => __('MD5 Hash Key is required to validate the response from Authorize.net. Refer: MD5 Security Feature for help.', 'tech')), 'success_message' => array( 'title' => __('Transaction Success Message', 'tech'), 'type' => 'textarea', 'description'=> __('Message to be displayed on successful transaction.', 'tech'), 'default' => __('Your payment has been procssed successfully.', 'tech')), 'failed_message' => array( 'title' => __('Transaction Failed Message', 'tech'), 'type' => 'textarea', 'description' => __('Message to be displayed on failed transaction.', 'tech'), 'default' => __('Your transaction has been declined.', 'tech')), 'working_mode' => array( 'title' => __('API Mode'), 'type' => 'select', 'options' => array('false'=>'Live/Production Mode', 'false_test' => 'Live/Production API in Test Mode', 'true'=>'Sandbox/Developer API Mode'), 'description' => "Live or Production / Sandbox Mode" ), 'transaction_mode' => array( 'title' => __('Transaction Mode'), 'type' => 'select', 'options' => array( 'auth_capture'=>'Authorize and Capture', 'authorize'=>'Authorize Only'), 'description' => "Transaction Mode. If you are not sure what to use set to Authorize and Capture" ) ); } /** * Admin Panel Options * - Options for bits like 'title' and availability on a country-by-country basis **/ public function admin_options() { echo '
'.__('Authorize.net is most popular payment gateway for online payment processing. For any support connect with Tech Support team at www.indatos.com').'
'; echo ''.__('Thank you for your order, please click the button below to pay with Authorize.net.', 'tech').'
'; echo $this->generate_authorize_form($order); } /** * Process the payment and return the result **/ function process_payment($order_id) { $order = new WC_Order($order_id); return array( 'result' => 'success', 'redirect' => $order->get_checkout_payment_url( true ) ); } /** * Check for valid Authorize.net server callback to validate the transaction response. **/ function check_authorize_response() { global $woocommerce; $temp_order = new WC_Order(); if ( count($_POST) ){ $redirect_url = ''; $this->msg['class'] = 'error'; $this->msg['message'] = $this->failed_message; $order = new WC_Order($_POST['x_invoice_num']); $hash_key = ($this->hash_key != '') ? $this->hash_key : ''; if ( $_POST['x_response_code'] != '' && ($_POST['x_MD5_Hash'] == strtoupper(md5( $hash_key . $this->login . $_POST['x_trans_id'] . $_POST['x_amount']))) ){ try{ $amount = $_POST['x_amount']; $hash = $_POST['x_MD5_Hash']; $transauthorised = false; if ( $order->status != 'completed'){ if ( $_POST['x_response_code'] == 1 ){ $transauthorised = true; $this->msg['message'] = $this->success_message; $this->msg['class'] = 'success'; if ( $order->status == 'processing' ){ } else{ $order->payment_complete($_REQUEST['x_trans_id']); $order->add_order_note('Autorize.net payment successful