PluginProbe
Bookit — Booking & Appointment Calendar / 2.6.0.5
Bookit — Booking & Appointment Calendar v2.6.0.5
2.6.0.5 2.6.0.4 2.6.0.3 2.6.0.2 2.6.0.1 2.6.0 trunk 1.2 1.2.2 1.2.3 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 All 62 releases
bookit / src / Bookit / Gateways / Traits / Has_Mode.php

Has_Mode.php in Bookit — Booking & Appointment Calendar 2.6.0.5, at src/Bookit/Gateways/Traits/Has_Mode.php

80 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Bookit\Gateways\Traits;
4
5 /**
6 * Trait Has_Mode.
7 *
8 * @since 2.5.0
9 *
10 * @package Bookit\Gateways\Traits
11 */
12 trait Has_Mode {
13
14 /**
15 * The current working mode: live or sandbox.
16 *
17 * @since 2.5.0
18 *
19 * @var string
20 */
21 protected $mode;
22
23 /**
24 * Valid modes.
25 *
26 * @since 2.5.0
27 *
28 * @var array
29 */
30 protected $valid_modes = [
31 'sandbox', // Default.
32 'live',
33 ];
34
35 /**
36 * Sets the mode for the Merchant for handling operations.
37 *
38 * @since 2.5.0
39 *
40 * @param string $mode
41 *
42 * @return $this
43 */
44 public function set_mode( $mode ) {
45 if ( ! in_array( $mode, $this->valid_modes, true ) ) {
46 $mode = reset( $this->valid_modes );
47 }
48
49 $this->mode = $mode;
50
51 return $this;
52 }
53
54 /**
55 * Gets the mode for Merchant for handling operations.
56 *
57 * @since 2.5.0
58 *
59 * @return string Which mode we are using the Merchant.
60 */
61 public function get_mode() {
62 if ( null === $this->mode ) {
63 $this->set_mode( bookit_is_sandbox_mode( static::$option_sandbox ) ? 'sandbox' : 'live' );
64 }
65
66 return $this->mode;
67 }
68
69 /**
70 * Determines if we are using sandbox mode.
71 *
72 * @since 2.5.0
73 *
74 * @return bool
75 */
76 public function is_sandbox() {
77 return 'sandbox' === $this->get_mode();
78 }
79 }
80