PluginProbe
Easy Hotel – Powerful Hotel Booking / trunk
Easy Hotel – Powerful Hotel Booking vtrunk
2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.9.9 1.9.8 1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 All 110 releases
easy-hotel / admin / includes / native-checkout / gateways / class-gateway-manager.php

class-gateway-manager.php in Easy Hotel – Powerful Hotel Booking trunk, at admin/includes/native-checkout/gateways/class-gateway-manager.php

63 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gateway manager / loader.
4 *
5 * Holds a registry of payment gateways and lets the checkout class
6 * fetch enabled ones for the UI / processing. Other plugins can hook
7 * into 'eshb_native_checkout_gateways' to register more gateways
8 * without touching this plugin.
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) exit;
12
13 class ESHB_Native_Gateway_Manager {
14
15 private static $instance = null;
16
17 /** @var ESHB_Native_Abstract_Gateway[] */
18 private $gateways = [];
19
20 public static function instance() {
21 if ( is_null( self::$instance ) ) {
22 self::$instance = new self();
23 }
24 return self::$instance;
25 }
26
27 private function __construct() {
28 // Built-in gateways. Cash on Delivery is registered first so it
29 // is the natural fallback default when no online gateway is set up.
30 $this->register_gateway( new ESHB_Native_COD_Gateway() );
31 $this->register_gateway( new ESHB_Native_PayPal_Gateway() );
32
33 /**
34 * Filter the array of registered gateway instances. Third-party
35 * gateways should be appended here as ESHB_Native_Abstract_Gateway
36 * instances.
37 *
38 * @param ESHB_Native_Abstract_Gateway[] $gateways
39 */
40 $this->gateways = apply_filters( 'eshb_native_checkout_gateways', $this->gateways );
41 }
42
43 public function register_gateway( ESHB_Native_Abstract_Gateway $gateway ) {
44 $this->gateways[ $gateway->get_id() ] = $gateway;
45 }
46
47 /**
48 * @return ESHB_Native_Abstract_Gateway[]
49 */
50 public function get_gateways( $only_enabled = true ) {
51 if ( ! $only_enabled ) {
52 return $this->gateways;
53 }
54 return array_filter( $this->gateways, function ( $gw ) {
55 return $gw->is_enabled();
56 } );
57 }
58
59 public function get_gateway( $id ) {
60 return $this->gateways[ $id ] ?? null;
61 }
62 }
63