File "abstract-wc-payment-gateway.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-payment-gateway.php
File size: 8.26 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

use Automattic\Jetpack\Constants;
if (!defined('ABSPATH')) {
    exit;
}
abstract class WC_Payment_Gateway extends WC_Settings_API
{
    public $order_button_text;
    public $enabled = 'yes';
    public $title;
    public $description;
    public $chosen;
    public $method_title = '';
    public $method_description = '';
    public $has_fields;
    public $countries;
    public $availability;
    public $icon;
    public $supports = array('products');
    public $max_amount = 0;
    public $view_transaction_url = '';
    public $new_method_label = '';
    public $pay_button_id = '';
    protected $tokens = array();
    public function get_tokens()
    {
        if (count($this->tokens) > 0) {
            return $this->tokens;
        }
        if (is_user_logged_in() && $this->supports('tokenization')) {
            $this->tokens = WC_Payment_Tokens::get_customer_tokens(get_current_user_id(), $this->id);
        }
        return $this->tokens;
    }
    public function get_method_title()
    {
        return apply_filters('woocommerce_gateway_method_title', $this->method_title, $this);
    }
    public function get_method_description()
    {
        return apply_filters('woocommerce_gateway_method_description', $this->method_description, $this);
    }
    public function admin_options()
    {
        echo '<h2>' . esc_html($this->get_method_title());
        wc_back_link(__('Return to payments', 'woocommerce'), admin_url('admin.php?page=wc-settings&tab=checkout'));
        echo '</h2>';
        echo wp_kses_post(wpautop($this->get_method_description()));
        parent::admin_options();
    }
    public function init_settings()
    {
        parent::init_settings();
        $this->enabled = !empty($this->settings['enabled']) && 'yes' === $this->settings['enabled'] ? 'yes' : 'no';
    }
    public function needs_setup()
    {
        return false;
    }
    public function get_return_url($order = null)
    {
        if ($order) {
            $return_url = $order->get_checkout_order_received_url();
        } else {
            $return_url = wc_get_endpoint_url('order-received', '', wc_get_checkout_url());
        }
        return apply_filters('woocommerce_get_return_url', $return_url, $order);
    }
    public function get_transaction_url($order)
    {
        $return_url = '';
        $transaction_id = $order->get_transaction_id();
        if (!empty($this->view_transaction_url) && !empty($transaction_id)) {
            $return_url = sprintf($this->view_transaction_url, $transaction_id);
        }
        return apply_filters('woocommerce_get_transaction_url', $return_url, $order, $this);
    }
    protected function get_order_total()
    {
        $total = 0;
        $order_id = absint(get_query_var('order-pay'));
        if (0 < $order_id) {
            $order = wc_get_order($order_id);
            if ($order) {
                $total = (float) $order->get_total();
            }
        } elseif (0 < WC()->cart->total) {
            $total = (float) WC()->cart->total;
        }
        return $total;
    }
    public function is_available()
    {
        $is_available = 'yes' === $this->enabled;
        if (WC()->cart && 0 < $this->get_order_total() && 0 < $this->max_amount && $this->max_amount < $this->get_order_total()) {
            $is_available = false;
        }
        return $is_available;
    }
    public function has_fields()
    {
        return (bool) $this->has_fields;
    }
    public function get_title()
    {
        return apply_filters('woocommerce_gateway_title', $this->title, $this->id);
    }
    public function get_description()
    {
        return apply_filters('woocommerce_gateway_description', $this->description, $this->id);
    }
    public function get_icon()
    {
        $icon = $this->icon ? '<img src="' . WC_HTTPS::force_https_url($this->icon) . '" alt="' . esc_attr($this->get_title()) . '" />' : '';
        return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
    }
    public function get_pay_button_id()
    {
        return sanitize_html_class($this->pay_button_id);
    }
    public function set_current()
    {
        $this->chosen = true;
    }
    public function process_payment($order_id)
    {
        return array();
    }
    public function process_refund($order_id, $amount = null, $reason = '')
    {
        return false;
    }
    public function validate_fields()
    {
        return true;
    }
    public function payment_fields()
    {
        $description = $this->get_description();
        if ($description) {
            echo wpautop(wptexturize($description));
        }
        if ($this->supports('default_credit_card_form')) {
            $this->credit_card_form();
        }
    }
    public function supports($feature)
    {
        return apply_filters('woocommerce_payment_gateway_supports', in_array($feature, $this->supports), $feature, $this);
    }
    public function can_refund_order($order)
    {
        return $order && $this->supports('refunds');
    }
    public function credit_card_form($args = array(), $fields = array())
    {
        wc_deprecated_function('credit_card_form', '2.6', 'WC_Payment_Gateway_CC->form');
        $cc_form = new WC_Payment_Gateway_CC();
        $cc_form->id = $this->id;
        $cc_form->supports = $this->supports;
        $cc_form->form();
    }
    public function tokenization_script()
    {
        wp_enqueue_script('woocommerce-tokenization-form', plugins_url('/assets/js/frontend/tokenization-form' . (Constants::is_true('SCRIPT_DEBUG') ? '' : '.min') . '.js', WC_PLUGIN_FILE), array('jquery'), WC()->version);
        wp_localize_script('woocommerce-tokenization-form', 'wc_tokenization_form_params', array('is_registration_required' => WC()->checkout()->is_registration_required(), 'is_logged_in' => is_user_logged_in()));
    }
    public function saved_payment_methods()
    {
        $html = '<ul class="woocommerce-SavedPaymentMethods wc-saved-payment-methods" data-count="' . esc_attr(count($this->get_tokens())) . '">';
        foreach ($this->get_tokens() as $token) {
            $html .= $this->get_saved_payment_method_option_html($token);
        }
        $html .= $this->get_new_payment_method_option_html();
        $html .= '</ul>';
        echo apply_filters('wc_payment_gateway_form_saved_payment_methods_html', $html, $this);
    }
    public function get_saved_payment_method_option_html($token)
    {
        $html = sprintf('<li class="woocommerce-SavedPaymentMethods-token">
				<input id="wc-%1$s-payment-token-%2$s" type="radio" name="wc-%1$s-payment-token" value="%2$s" style="width:auto;" class="woocommerce-SavedPaymentMethods-tokenInput" %4$s />
				<label for="wc-%1$s-payment-token-%2$s">%3$s</label>
			</li>', esc_attr($this->id), esc_attr($token->get_id()), esc_html($token->get_display_name()), checked($token->is_default(), true, false));
        return apply_filters('woocommerce_payment_gateway_get_saved_payment_method_option_html', $html, $token, $this);
    }
    public function get_new_payment_method_option_html()
    {
        $label = apply_filters('woocommerce_payment_gateway_get_new_payment_method_option_html_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'woocommerce'), $this);
        $html = sprintf('<li class="woocommerce-SavedPaymentMethods-new">
				<input id="wc-%1$s-payment-token-new" type="radio" name="wc-%1$s-payment-token" value="new" style="width:auto;" class="woocommerce-SavedPaymentMethods-tokenInput" />
				<label for="wc-%1$s-payment-token-new">%2$s</label>
			</li>', esc_attr($this->id), esc_html($label));
        return apply_filters('woocommerce_payment_gateway_get_new_payment_method_option_html', $html, $this);
    }
    public function save_payment_method_checkbox()
    {
        $html = sprintf('<p class="form-row woocommerce-SavedPaymentMethods-saveNew">
				<input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" />
				<label for="wc-%1$s-new-payment-method" style="display:inline;">%2$s</label>
			</p>', esc_attr($this->id), esc_html__('Save to account', 'woocommerce'));
        echo apply_filters('woocommerce_payment_gateway_save_new_payment_method_option_html', $html, $this);
    }
    public function add_payment_method()
    {
        return array('result' => 'failure', 'redirect' => wc_get_endpoint_url('payment-methods'));
    }
}