woocommerce/classes/gateways/class-wc-payment-gateways.php

94 lines
2.2 KiB
PHP
Raw Normal View History

2011-08-09 15:16:18 +00:00
<?php
/**
2011-08-10 17:11:11 +00:00
* WooCommerce Payment Gateways class
*
* Loads payment gateways via hooks for use in the store.
*
2012-01-27 16:38:39 +00:00
* @class WC_Payment_Gateways
2011-08-10 17:11:11 +00:00
* @package WooCommerce
* @category Payment Gateways
* @author WooThemes
*/
2012-01-27 16:38:39 +00:00
class WC_Payment_Gateways {
2011-08-09 15:16:18 +00:00
var $payment_gateways;
2011-08-09 15:16:18 +00:00
function init() {
2011-12-08 12:50:50 +00:00
2011-08-10 17:11:11 +00:00
$load_gateways = apply_filters('woocommerce_payment_gateways', array());
2011-08-09 15:16:18 +00:00
2011-12-06 16:45:08 +00:00
// Get order option
$ordering = (array) get_option('woocommerce_gateway_order');
$order_end = 999;
2011-08-09 15:16:18 +00:00
2011-12-06 16:45:08 +00:00
// Load gateways in order
foreach ($load_gateways as $gateway) :
2012-01-10 15:11:06 +00:00
$load_gateway = new $gateway();
2011-12-06 16:45:08 +00:00
if (isset($ordering[$load_gateway->id]) && is_numeric($ordering[$load_gateway->id])) :
// Add in position
$this->payment_gateways[$ordering[$load_gateway->id]] = $load_gateway;
else :
// Add to end of the array
$this->payment_gateways[$order_end] = $load_gateway;
$order_end++;
endif;
2011-08-09 15:16:18 +00:00
endforeach;
2011-12-06 16:45:08 +00:00
ksort($this->payment_gateways);
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
2011-08-09 15:16:18 +00:00
}
2011-08-09 15:16:18 +00:00
function payment_gateways() {
$_available_gateways = array();
if (sizeof($this->payment_gateways) > 0) :
foreach ( $this->payment_gateways as $gateway ) :
2011-08-09 15:16:18 +00:00
$_available_gateways[$gateway->id] = $gateway;
endforeach;
endif;
return $_available_gateways;
}
function get_available_payment_gateways() {
$_available_gateways = array();
foreach ( $this->payment_gateways as $gateway ) :
2011-08-09 15:16:18 +00:00
if ($gateway->is_available()) $_available_gateways[$gateway->id] = $gateway;
endforeach;
return $_available_gateways;
}
2011-12-06 16:45:08 +00:00
function process_admin_options() {
$default_gateway = (isset($_POST['default_gateway'])) ? esc_attr($_POST['default_gateway']) : '';
$gateway_order = (isset($_POST['gateway_order'])) ? $_POST['gateway_order'] : '';
$order = array();
if (is_array($gateway_order) && sizeof($gateway_order)>0) :
$loop = 0;
foreach ($gateway_order as $gateway_id) :
$order[$gateway_id] = $loop;
$loop++;
endforeach;
endif;
update_option( 'woocommerce_default_gateway', $default_gateway );
update_option( 'woocommerce_gateway_order', $order );
}
2011-08-09 15:16:18 +00:00
}