1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace WC_POS\Admin\Settings;
13
14 use WC_Payment_Gateways;
15
16 class Checkout extends Page {
17
18 protected static $instance;
19
20 21 22
23 public function __construct() {
24 $this->id = 'checkout';
25
26 $this->label = __( 'Checkout', 'woocommerce' );
27
28 $this->defaults = array(
29 'order_status' => 'wc-completed',
30 'default_gateway' => 'pos_cash',
31 'enabled' => array(
32 'pos_cash' => true,
33 'pos_card' => true,
34 'paypal' => true
35 )
36 );
37 }
38
39 40 41
42 public function load_gateways() {
43 $gateways = WC_Payment_Gateways::instance()->payment_gateways;
44 $order = $this->get('gateway_order');
45
46
47
48 if( ! in_array( 'WC_POS\Gateways\Cash', array_map( 'get_class', $gateways ) ) ){
49 WC_Payment_Gateways::instance()->init();
50 $gateways = WC_Payment_Gateways::instance()->payment_gateways;
51 }
52
53
54 $i = count($gateways);
55 foreach( $gateways as $gateway ) {
56 if( isset( $order[$gateway->id] ) ) {
57 $ordered_gateways[ $order[$gateway->id] ] = $gateway;
58 } else {
59 $ordered_gateways[ ++$i ] = $gateway;
60 }
61 $settings = new Gateways($gateway->id);
62 $settings->merge_settings($gateway);
63 }
64
65 ksort( $ordered_gateways, SORT_NUMERIC );
66 return apply_filters( 'woocommerce_pos_load_gateways', $ordered_gateways );
67 }
68
69 70 71
72 public function load_enabled_gateways() {
73 $gateways = $this->load_gateways();
74 $enabled = $this->get_enabled_gateway_ids();
75 $default = $this->get( 'default_gateway' );
76 $enabled_gateways = array();
77
78 if ( $gateways ): foreach ( $gateways as $gateway ):
79 $id = $gateway->id;
80 if ( in_array( $id, $enabled ) && isset( $gateway->pos ) && $gateway->pos ) {
81 $gateway->default = $id == $default;
82
83 $enabled_gateways[ $id ] = $gateway;
84 }
85 endforeach; endif;
86
87 return apply_filters( 'woocommerce_pos_load_enabled_gateways', $enabled_gateways );
88 }
89
90 91 92 93
94 public function get_enabled_gateway_ids(){
95 return array_keys( (array) $this->get('enabled'), true);
96 }
97
98 }
99