PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.9.15
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.9.15
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / Gateways.php

Gateways.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.15, at includes/Gateways.php

110 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Loads the POS Payment Gateways.
4 *
5 * @author Paul Kilmurray <paul@kilbot.com>
6 *
7 * @see https://wcpos.com
8 * @package WCPOS\WooCommercePOS
9 */
10
11 namespace WCPOS\WooCommercePOS;
12
13 /**
14 * Gateways class.
15 */
16 class Gateways {
17 /**
18 * Constructor.
19 */
20 public function __construct() {
21 add_filter( 'woocommerce_payment_gateways', array( $this, 'payment_gateways' ) );
22 add_filter( 'woocommerce_available_payment_gateways', array( $this, 'available_payment_gateways' ), 99 );
23 }
24
25 /**
26 * Add POS gateways
27 * BEWARE: some gateways/themes/plugins call this very early on every page!!
28 * We cannot guarantee that $wp is set, so we cannot use woocommerce_pos_request.
29 *
30 * @param array $gateways The registered payment gateways.
31 *
32 * @return array
33 */
34 public function payment_gateways( array $gateways ) {
35 global $plugin_page;
36
37 // Early exit for WooCommerce settings, ie: don't show POS gateways.
38 if ( is_admin() && 'wc-settings' == $plugin_page ) {
39 return $gateways;
40 }
41
42 // All other cases, the default POS gateways are added.
43 return array_merge(
44 $gateways,
45 array(
46 'WCPOS\WooCommercePOS\Gateways\Cash',
47 'WCPOS\WooCommercePOS\Gateways\Card',
48 )
49 );
50 }
51
52 /**
53 * Get available payment POS gateways,
54 * - Order and set default order
55 * - Also going to remove icons from the gateways.
56 *
57 * - NOTE: lots of plugins/themes call this filter and I can't guarantee that $gateways is an array
58 *
59 * @param null|array $gateways The available payment gateways.
60 *
61 * @return null|array The available payment gateways.
62 */
63 public function available_payment_gateways( ?array $gateways ): ?array {
64 // early exit.
65 if ( ! woocommerce_pos_request() ) {
66 return $gateways;
67 }
68
69 // use POS settings.
70 $settings = woocommerce_pos_get_settings( 'payment_gateways' );
71
72 // Get all payment gateways.
73 $all_gateways = WC()->payment_gateways->payment_gateways;
74
75 $_available_gateways = array();
76
77 foreach ( $all_gateways as $gateway ) {
78 if ( isset( $settings['gateways'][ $gateway->id ] ) && $settings['gateways'][ $gateway->id ]['enabled'] ) {
79 if ( isset( $settings['gateways'][ $gateway->id ]['title'] ) ) {
80 $gateway->title = $settings['gateways'][ $gateway->id ]['title'];
81 }
82
83 /*
84 * There is an issue over-writing the description field because some gateways use this for info,
85 * eg: Account Funds uses it to show the current balance.
86 */
87 // if ( isset( $settings['gateways'][ $gateway->id ]['description'] ) ) {
88 // $gateway->description = $settings['gateways'][ $gateway->id ]['description'];
89 // }.
90
91 $gateway->icon = '';
92 $gateway->enabled = 'yes';
93 $gateway->chosen = $gateway->id === $settings['default_gateway'];
94
95 $_available_gateways[ $gateway->id ] = $gateway;
96 }
97 }
98
99 // Order the available gateways according to the settings.
100 uksort(
101 $_available_gateways,
102 function ( $a, $b ) use ( $settings ) {
103 return $settings['gateways'][ $a ]['order'] <=> $settings['gateways'][ $b ]['order'];
104 }
105 );
106
107 return $_available_gateways;
108 }
109 }
110