id = WC_Aplazame::METHOD_ID; $this->method_title = WC_Aplazame::METHOD_TITLE; $this->has_fields = true; # Settings $this->init_form_fields(); $this->init_settings(); $this->title = $this->method_title; $this->enabled = $this->settings['enabled']; $this->icon = plugins_url('assets/img/icon.png', dirname(__FILE__)); $this->supports = array( 'products', 'refunds' ); 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('admin_notices', array($this, 'checks')); } public function is_available() { if (($this->enabled === 'no') || (get_woocommerce_currency() !== 'EUR') || (!$this->settings['public_api_key']) || (!$this->settings['private_api_key'])) { return false; } return true; } public function payment_fields() { Aplazame_Helpers::render_to_template('gateway/payment-fields.php'); } public function process_payment($order_id) { $url = get_permalink(Aplazame_Redirect::get_the_ID()); WC()->session->redirect_order_id = $order_id; return array( 'result' => 'success', 'redirect' => add_query_arg(array('order_id' => $order_id), $url) ); } public function process_refund($order_id, $amount=null, $reason='') { if ($amount) { global $aplazame; try { $aplazame->get_client()->refund( $order_id, Aplazame_Filters::decimals($amount), $reason); $aplazame->add_order_note($order_id, sprintf( __('%s has successfully returned %d %s of the order #%s.', 'aplazame'), $this->method_title, $amount, get_woocommerce_currency(), $order_id)); return true; } catch (Aplazame_Exception $e) { return new WP_Error('aplazame_refund_error', sprintf( __('%s Error: "%s"', 'aplazame'), $this->method_title, $e->get_field_error('amount'))); } } return false; } public function checks() { if (!$this->enabled) { return; } $_render_to_notice = function($msg) { echo '
' . $msg . '