$user_mygate_title, 'enabled' => $user_mygate_enabled, 'testmode' => $user_mygate_testmode, 'description' => $user_mygate_description, 'merchantid' => $user_mygate_merchantid, 'appid' => $user_mygate_appid, ); $serialized_user_mygate_settings_array = serialize($user_mygate_settings_array); update_option('woocommerce_mygate_settings', $serialized_user_mygate_settings_array); } } add_action('plugins_loaded', 'woocommerce_mygate_init', 0); function woocommerce_mygate_init() { if (!class_exists('WC_Payment_Gateway')) { return; } class mygate extends WC_Payment_Gateway { public function __construct() { $this->id = 'mygate'; $this->method_title = __('MyGate'); $this->icon = WP_PLUGIN_URL . "/" . plugin_basename(dirname(__FILE__)) . '/a-mygate-plugin.png'; $this->has_fields = false; $this->init_form_fields(); $this->init_settings(); $serialized_mygate_settings = get_option('woocommerce_mygate_settings'); $this->settings = unserialize($serialized_mygate_settings); $this->title = esc_html($this->settings['title']); $this->description = esc_html($this->settings['description']); $this->merchantid = esc_html($this->settings['merchantid']); $this->appid = esc_html($this->settings['appid']); $this->testmode = esc_html($this->settings['testmode']); $this->liveurl = esc_url("https://www.mygate.co.za/virtual/8x0x0/dsp_ecommercepaymentparent.cfm"); add_action('init', array(&$this, 'successful_request')); add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options')); add_action('woocommerce_receipt_mygate', array(&$this, 'receipt_page')); } function init_form_fields() { $this->form_fields = array( 'noncename' => array( 'type' => 'hidden', 'label' => __('Mygatenonce.'), 'default' => wp_create_nonce(plugin_basename(__FILE__)), 'display_label' => false,), 'enabled' => array( 'title' => __('Enable/Disable'), 'type' => 'checkbox', 'label' => __('Enable MyGate Payment Module.'), 'default' => 'yes'), 'testmode' => array( 'title' => __('Enable MyGate SandBox', 'woothemes'), 'type' => 'checkbox', 'default' => 'yes'), 'title' => array( 'title' => __('Title'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.'), 'default' => __('MyGate')), 'description' => array( 'title' => __('Description'), 'type' => 'textarea', 'description' => __('This controls the description which the user sees during checkout.'), 'default' => __('Pay securely by Credit Card through MyGate Secure Servers.')), 'merchantid' => array( 'title' => __('MyGate Merchant ID'), 'type' => 'text', 'description' => __('Please enter your MyGate Merchant ID; this is needed in order to take payment!')), 'appid' => array( 'title' => __('MyGate Application ID'), 'type' => 'text', 'description' => __('Please enter your MyGate Application ID; this is needed in order to take payment!')), ); } /** * Admin Panel Options * - Options for bits like 'title' and availability on a country-by-country basis * */ public function admin_options() { echo '
' . __('MyGate works by sending the user to MyGate Secure Site to enter their payment information. Make sure you select store currency supported by MyGate.') . '
'; echo '' . __('Thank you for your order, please click the button below to pay with MyGate.') . '
'; echo $this->generate_mygate_form($order); } /** * Successful Payment! * */ function successful_request() { global $woocommerce; if (isset($_REQUEST['VARIABLE1'])) { $order_id = (int) $_SESSION['order_awaiting_payment']; if ($order_id > 0) { $order = wc_get_order($order_id); $provided_order_key = trim(esc_attr($_GET['t'])); if ($provided_order_key == $order->order_key) { $cancel_url = $order->get_cancel_order_url(); wp_redirect($cancel_url); } } } if (isset($_POST['VARIABLE1']) && is_numeric($_POST['VARIABLE1']) && isset($_POST['_RESULT'])) { $_POST = stripslashes_deep($_POST); if (!empty($_POST['VARIABLE1'])) { $order = wc_get_order($order_id); if ($order->status !== 'completed') { if ($_POST['_RESULT'] >= 0) { $order->add_order_note(__('MyGate payment completed', 'woothemes')); $order->payment_complete(); $woocommerce->cart->empty_cart(); } else { $order->update_status('failed', sprintf(__('MyGate payment failed!', 'woothemes'))); } } } } } } /** * Add the Gateway to WooCommerce * */ function add_mygate_gateway($methods) { $obj = new mygate; $title = get_the_title(); if ((!empty($title) && $obj->settings['enabled'] == 'yes') || empty($title)) $methods[] = 'mygate'; return $methods; } add_filter('woocommerce_payment_gateways', 'add_mygate_gateway'); }