Passed
Push — main ( 061772...28b955 )
by Remco
07:49 queued 12s
created

Transaction::get_brand_id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Transaction
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 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.0.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
	 * Construct and initialize request header.
74
	 *
75
	 * @param string       $store_id      Store ID.
76
	 * @param string|float $amount        Amount.
77
	 * @param string       $currency_code Currency code.
78
	 * @param TrackingCode $tracking_code Tracking code.
79
	 */
80 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...
81 3
		$this->store_id      = $store_id;
82 3
		$this->amount        = $amount;
83 3
		$this->currency_code = $currency_code;
84 3
		$this->tracking_code = $tracking_code;
85 3
	}
86
87
	/**
88
	 * Get brand ID.
89
	 *
90
	 * @return string|null
91
	 */
92 2
	public function get_brand_id() {
93 2
		return $this->brand_id;
94
	}
95
96
	/**
97
	 * Set brand ID.
98
	 *
99
	 * @param string|null $brand_id Brand ID.
100
	 * @return void
101
	 */
102 2
	public function set_brand_id( $brand_id ) {
103 2
		$this->brand_id = $brand_id;
104 2
	}
105
106
	/**
107
	 * Set purchase ID.
108
	 *
109
	 * @param string|null $purchase_id Purchase ID.
110
	 * @return void
111
	 */
112 2
	public function set_purchase_id( $purchase_id ) {
113 2
		$this->purchase_id = $purchase_id;
114 2
	}
115
116
	/**
117
	 * Set return URL.
118
	 *
119
	 * @param string|null $return_url Return URL.
120
	 * @return void
121
	 */
122 2
	public function set_return_url( $return_url ) {
123 2
		$this->return_url = $return_url;
124 2
	}
125
126
	/**
127
	 * JSON serialize.
128
	 *
129
	 * @return object
130
	 */
131 3
	public function jsonSerialize() {
132
		$data = array(
133 3
			'storeId'      => $this->store_id,
134 3
			'amount'       => $this->amount,
135 3
			'currencyCode' => $this->currency_code,
136 3
			'trackingCode' => $this->tracking_code,
137
		);
138
139 3
		if ( null !== $this->brand_id ) {
140 1
			$data['brandId'] = $this->brand_id;
141
		}
142
143 3
		if ( null !== $this->purchase_id ) {
144 2
			$data['purchaseId'] = $this->purchase_id;
145
		}
146
147 3
		if ( null !== $this->return_url ) {
148 2
			$data['returnUrl'] = $this->return_url;
149
		}
150
151 3
		return (object) $data;
152
	}
153
}
154