File "class-wc-payment-gateways.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/includes/class-wc-payment-gateways.php
File
size: 4.21 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
defined('ABSPATH') || exit;
class WC_Payment_Gateways
{
public $payment_gateways = array();
protected static $_instance = null;
public static function instance()
{
if (is_null(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
public function __clone()
{
wc_doing_it_wrong(__FUNCTION__, __('Cloning is forbidden.', 'woocommerce'), '2.1');
}
public function __wakeup()
{
wc_doing_it_wrong(__FUNCTION__, __('Unserializing instances of this class is forbidden.', 'woocommerce'), '2.1');
}
public function __construct()
{
$this->init();
}
public function init()
{
$load_gateways = array('WC_Gateway_BACS', 'WC_Gateway_Cheque', 'WC_Gateway_COD');
if ($this->should_load_paypal_standard()) {
$load_gateways[] = 'WC_Gateway_Paypal';
}
$load_gateways = apply_filters('woocommerce_payment_gateways', $load_gateways);
$ordering = (array) get_option('woocommerce_gateway_order');
$order_end = 999;
foreach ($load_gateways as $gateway) {
if (is_string($gateway) && class_exists($gateway)) {
$gateway = new $gateway();
}
if (!is_a($gateway, 'WC_Payment_Gateway')) {
continue;
}
if (isset($ordering[$gateway->id]) && is_numeric($ordering[$gateway->id])) {
$this->payment_gateways[$ordering[$gateway->id]] = $gateway;
} else {
$this->payment_gateways[$order_end] = $gateway;
$order_end++;
}
}
ksort($this->payment_gateways);
}
public function payment_gateways()
{
$_available_gateways = array();
if (count($this->payment_gateways) > 0) {
foreach ($this->payment_gateways as $gateway) {
$_available_gateways[$gateway->id] = $gateway;
}
}
return $_available_gateways;
}
public function get_payment_gateway_ids()
{
return wp_list_pluck($this->payment_gateways, 'id');
}
public function get_available_payment_gateways()
{
$_available_gateways = array();
foreach ($this->payment_gateways as $gateway) {
if ($gateway->is_available()) {
if (!is_add_payment_method_page()) {
$_available_gateways[$gateway->id] = $gateway;
} elseif ($gateway->supports('add_payment_method') || $gateway->supports('tokenization')) {
$_available_gateways[$gateway->id] = $gateway;
}
}
}
return array_filter((array) apply_filters('woocommerce_available_payment_gateways', $_available_gateways), array($this, 'filter_valid_gateway_class'));
}
protected function filter_valid_gateway_class($gateway)
{
return $gateway && is_a($gateway, 'WC_Payment_Gateway');
}
public function set_current_gateway($gateways)
{
if (!is_array($gateways) || empty($gateways)) {
return;
}
$current_gateway = false;
if (WC()->session) {
$current = WC()->session->get('chosen_payment_method');
if ($current && isset($gateways[$current])) {
$current_gateway = $gateways[$current];
}
}
if (!$current_gateway) {
$current_gateway = current($gateways);
}
if ($current_gateway && is_callable(array($current_gateway, 'set_current'))) {
$current_gateway->set_current();
}
}
public function process_admin_options()
{
$gateway_order = isset($_POST['gateway_order']) ? wc_clean(wp_unslash($_POST['gateway_order'])) : '';
$order = array();
if (is_array($gateway_order) && count($gateway_order) > 0) {
$loop = 0;
foreach ($gateway_order as $gateway_id) {
$order[esc_attr($gateway_id)] = $loop;
$loop++;
}
}
update_option('woocommerce_gateway_order', $order);
}
protected function should_load_paypal_standard()
{
$paypal = new WC_Gateway_Paypal();
return $paypal->should_load();
}
}