Failed Conditions
Push — main ( e106fe...b61967 )
by Remco
09:42 queued 16s
created

Config   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 87.88%

Importance

Changes 0
Metric Value
dl 0
loc 144
ccs 29
cts 33
cp 0.8788
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A get_business_id() 0 3 1
A get_username() 0 3 1
A get_password() 0 3 1
A get_store_id() 0 3 1
A get_endpoint_url() 0 7 2
A get_purchase_id() 0 3 1
A set_purchase_id() 0 3 1
A jsonSerialize() 0 15 2
1
<?php
2
/**
3
 * Config
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2021 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Payvision
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Payvision;
12
13
use Pronamic\WordPress\Pay\Core\GatewayConfig;
14
15
/**
16
 * Config
17
 *
18
 * @author  Remco Tolsma
19
 * @version 1.1.0
20
 * @since   1.0.0
21
 */
22
class Config extends GatewayConfig implements \JsonSerializable {
23
	/**
24
	 * Business Id.
25
	 *
26
	 * @var string
27
	 */
28
	private $business_id;
29
30
	/**
31
	 * User.
32
	 *
33
	 * @var string
34
	 */
35
	private $username;
36
37
	/**
38
	 * Password.
39
	 *
40
	 * @var string
41
	 */
42
	private $password;
43
44
	/**
45
	 * Store ID.
46
	 *
47
	 * @var string
48
	 */
49
	private $store_id;
50
51
	/**
52
	 * Purchase ID.
53
	 *
54
	 * @var string|null
55
	 */
56
	private $purchase_id;
57
58
	/**
59
	 * Construct config object.
60
	 *
61
	 * @param string $mode        Mode.
62
	 * @param string $business_id Business Id.
63
	 * @param string $username    Username.
64
	 * @param string $password    Password.
65
	 * @param string $store_id    Store ID.
66
	 */
67 11
	public function __construct( $mode, $business_id, $username, $password, $store_id ) {
68 11
		$this->mode        = $mode;
69 11
		$this->business_id = $business_id;
70 11
		$this->username    = $username;
71 11
		$this->password    = $password;
72 11
		$this->store_id    = $store_id;
73 11
	}
74
75
	/**
76
	 * Get business ID.
77
	 *
78
	 * @return string
79
	 */
80 3
	public function get_business_id() {
81 3
		return $this->business_id;
82
	}
83
84
	/**
85
	 * Get username.
86
	 *
87
	 * @return string
88
	 */
89 6
	public function get_username() {
90 6
		return $this->username;
91
	}
92
93
	/**
94
	 * Get password.
95
	 *
96
	 * @return string
97
	 */
98 6
	public function get_password() {
99 6
		return $this->password;
100
	}
101
102
	/**
103
	 * Get store ID.
104
	 *
105
	 * @return string
106
	 */
107 3
	public function get_store_id() {
108 3
		return $this->store_id;
109
	}
110
111
	/**
112
	 * Get endpoint URL.
113
	 *
114
	 * @link https://developers.acehubpaymentservices.com/docs/service-endpoints-and-headers
115
	 * @param string $path Path.
116
	 * @return string
117
	 */
118 8
	public function get_endpoint_url( $path ) {
119 8
		if ( Gateway::MODE_TEST === $this->mode ) {
120 7
			return SystemAddress::STAGING_SYSTEM . $path;
121
		}
122
123 1
		return SystemAddress::LIVE_SYSTEM . $path;
124
	}
125
126
	/**
127
	 * Get purchase ID.
128
	 *
129
	 * @return string|null
130
	 */
131 1
	public function get_purchase_id() {
132 1
		return $this->purchase_id;
133
	}
134
135
	/**
136
	 * Set purchase ID.
137
	 *
138
	 * @param string|null $purchase_id Purchase ID.
139
	 * @return void
140
	 */
141
	public function set_purchase_id( $purchase_id ) {
142
		$this->purchase_id = $purchase_id;
143
	}
144
145
	/**
146
	 * JSON serialize.
147
	 *
148
	 * @return object
149
	 */
150 2
	public function jsonSerialize() {
151
		$data = array(
152 2
			'mode'        => $this->mode,
153 2
			'business_id' => $this->business_id,
154 2
			'username'    => $this->username,
155 2
			'password'    => $this->password,
156 2
			'store_id'    => $this->store_id,
157
		);
158
159 2
		if ( null !== $this->purchase_id ) {
160
			$data['purchase_id'] = $this->purchase_id;
161
		}
162
163 2
		return (object) $data;
164
	}
165
}
166