Test Failed
Push — main ( 28b955...362ef3 )
by Reüel
14:17 queued 10s
created

Transaction::get_descriptor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Transaction
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
/**
14
 * Transaction
15
 *
16
 * @author  Remco Tolsma
17
 * @version 1.1.0
18
 * @since   1.0.0
19
 */
20
class Transaction implements \JsonSerializable {
21
	/**
22
	 * Store ID.
23
	 *
24
	 * @var string
25
	 */
26
	private $store_id;
27
28
	/**
29
	 * Amount.
30
	 *
31
	 * @var string|float
32
	 */
33
	private $amount;
34
35
	/**
36
	 * Currency code.
37
	 *
38
	 * @var string
39
	 */
40
	private $currency_code;
41
42
	/**
43
	 * Tracking code.
44
	 *
45
	 * @var TrackingCode
46
	 */
47
	private $tracking_code;
48
49
	/**
50
	 * Brand ID.
51
	 *
52
	 * Identifies the transaction payment brand. Mandatory for all transactions, except for card transactions when your configuration allows the presence of the card block to be enough. See brand list.
53
	 *
54
	 * @var string|null
55
	 */
56
	private $brand_id;
57
58
	/**
59
	 * Purchase ID.
60
	 *
61
	 * @var string|null
62
	 */
63
	private $purchase_id;
64
65
	/**
66
	 * Return URL.
67
	 *
68
	 * @var string|null
69
	 */
70
	private $return_url;
71
72
	/**
73
	 * Decriptor.
74
	 *
75
	 * @var string|null
76
	 */
77
	private $descriptor;
78
79
	/**
80
	 * Construct and initialize request header.
81
	 *
82
	 * @param string       $store_id      Store ID.
83
	 * @param string|float $amount        Amount.
84
	 * @param string       $currency_code Currency code.
85
	 * @param TrackingCode $tracking_code Tracking code.
86
	 */
87 3 View Code Duplication
	public function __construct( $store_id, $amount, $currency_code, $tracking_code ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88 3
		$this->store_id      = $store_id;
89 3
		$this->amount        = $amount;
90 3
		$this->currency_code = $currency_code;
91 3
		$this->tracking_code = $tracking_code;
92 3
	}
93
94
	/**
95
	 * Get brand ID.
96
	 *
97
	 * @return string|null
98
	 */
99 2
	public function get_brand_id() {
100 2
		return $this->brand_id;
101
	}
102
103
	/**
104
	 * Set brand ID.
105
	 *
106
	 * @param string|null $brand_id Brand ID.
107
	 * @return void
108
	 */
109 2
	public function set_brand_id( $brand_id ) {
110 2
		$this->brand_id = $brand_id;
111 2
	}
112
113
	/**
114
	 * Set purchase ID.
115
	 *
116
	 * @param string|null $purchase_id Purchase ID.
117
	 * @return void
118
	 */
119 2
	public function set_purchase_id( $purchase_id ) {
120 2
		$this->purchase_id = $purchase_id;
121 2
	}
122
123
	/**
124
	 * Set return URL.
125
	 *
126
	 * @param string|null $return_url Return URL.
127
	 * @return void
128
	 */
129 2
	public function set_return_url( $return_url ) {
130 2
		$this->return_url = $return_url;
131 2
	}
132
133
	/**
134
	 * Get descriptor.
135
	 *
136
	 * @return string|null
137
	 */
138
	public function get_descriptor() {
139
		return $this->descriptor;
140
	}
141
142
	/**
143
	 * Set descriptor.
144
	 *
145
	 * @param string|null $descriptor Descriptor.
146
	 * @return void
147
	 */
148 1
	public function set_descriptor( $descriptor ) {
149 1
		$this->descriptor = $descriptor;
150 1
	}
151
152
	/**
153
	 * JSON serialize.
154
	 *
155
	 * @return object
156
	 */
157 3
	public function jsonSerialize() {
158
		$data = array(
159 3
			'storeId'      => $this->store_id,
160 3
			'amount'       => $this->amount,
161 3
			'currencyCode' => $this->currency_code,
162 3
			'trackingCode' => $this->tracking_code,
163
		);
164
165 3
		if ( null !== $this->brand_id ) {
166 1
			$data['brandId'] = $this->brand_id;
167
		}
168
169 3
		if ( null !== $this->purchase_id ) {
170 2
			$data['purchaseId'] = $this->purchase_id;
171
		}
172
173 3
		if ( null !== $this->return_url ) {
174 2
			$data['returnUrl'] = $this->return_url;
175
		}
176
177 3
		if ( null !== $this->descriptor ) {
178 1
			$data['descriptor'] = $this->descriptor;
179
		}
180
181 3
		return (object) $data;
182
	}
183
}
184