1 <?php
2 3 4 5 6 7 8 9 10 11 12
13 class WC_Payment_Gateways {
14
15
16 var $payment_gateways;
17
18 19 20 21
22 protected static $_instance = null;
23
24 25 26 27 28 29 30 31 32 33
34 public static function instance() {
35 if ( is_null( self::$_instance ) )
36 self::$_instance = new self();
37 return self::$_instance;
38 }
39
40 41 42 43 44
45 public function __clone() {
46 _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce' ), '2.1' );
47 }
48
49 50 51 52 53
54 public function __wakeup() {
55 _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce' ), '2.1' );
56 }
57
58 59 60 61 62 63
64 public function __construct() {
65 $this->init();
66 }
67
68 69 70 71 72 73
74 function init() {
75
76 $load_gateways = apply_filters( 'woocommerce_payment_gateways', array(
77 'WC_Gateway_BACS',
78 'WC_Gateway_Cheque',
79 'WC_Gateway_COD',
80 'WC_Gateway_Mijireh',
81 'WC_Gateway_Paypal'
82 ) );
83
84
85 $ordering = (array) get_option('woocommerce_gateway_order');
86 $order_end = 999;
87
88
89 foreach ($load_gateways as $gateway) :
90
91 $load_gateway = new $gateway();
92
93 if (isset($ordering[$load_gateway->id]) && is_numeric($ordering[$load_gateway->id])) :
94
95 $this->payment_gateways[$ordering[$load_gateway->id]] = $load_gateway;
96 else :
97
98 $this->payment_gateways[$order_end] = $load_gateway;
99 $order_end++;
100 endif;
101
102 endforeach;
103
104 ksort( $this->payment_gateways );
105 }
106
107
108 109 110 111 112 113
114 function payment_gateways() {
115
116 $_available_gateways = array();
117
118 if ( sizeof( $this->payment_gateways ) > 0 )
119 foreach ( $this->payment_gateways as $gateway )
120 $_available_gateways[ $gateway->id ] = $gateway;
121
122 return $_available_gateways;
123 }
124
125
126 127 128 129 130 131
132 function get_available_payment_gateways() {
133
134 $_available_gateways = array();
135
136 foreach ( $this->payment_gateways as $gateway ) :
137
138 if ( $gateway->is_available() ) {
139 if ( ! is_add_payment_method_page() )
140 $_available_gateways[$gateway->id] = $gateway;
141 elseif( $gateway->supports( 'add_payment_method' ) )
142 $_available_gateways[$gateway->id] = $gateway;
143 }
144
145 endforeach;
146
147 return apply_filters( 'woocommerce_available_payment_gateways', $_available_gateways );
148 }
149
150
151 152 153 154 155 156
157 function process_admin_options() {
158
159 $default_gateway = ( isset( $_POST['default_gateway'] ) ) ? esc_attr( $_POST['default_gateway'] ) : '';
160 $gateway_order = ( isset( $_POST['gateway_order'] ) ) ? $_POST['gateway_order'] : '';
161
162 $order = array();
163
164 if ( is_array( $gateway_order ) && sizeof( $gateway_order ) > 0 ) {
165 $loop = 0;
166 foreach ( $gateway_order as $gateway_id ) {
167 $order[ esc_attr( $gateway_id ) ] = $loop;
168 $loop++;
169 }
170 }
171
172 update_option( 'woocommerce_default_gateway', $default_gateway );
173 update_option( 'woocommerce_gateway_order', $order );
174 }
175 }