1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Transaction Response |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2022 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 Response |
15
|
|
|
* |
16
|
|
|
* @author Remco Tolsma |
17
|
|
|
* @version 1.1.0 |
18
|
|
|
* @since 1.0.0 |
19
|
|
|
*/ |
20
|
|
|
class TransactionResponse { |
21
|
|
|
/** |
22
|
|
|
* Unique transaction ID given to each transaction. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
public $id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Action. |
30
|
|
|
* |
31
|
|
|
* Actual action performed. In case a separate capture is NOT possible, the transaction will be interpreted and performed as a payment transaction and cannot be cancelled, but can be refunded and with result=0 considered as a “successful payment". |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $action; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Your unique transaction reference. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $tracking_code; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Amount of the transaction. |
46
|
|
|
* |
47
|
|
|
* @var string|float|int |
48
|
|
|
*/ |
49
|
|
|
private $amount; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Currency code of the amount of the transaction. |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
private $currency_code; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Construct and initialize transaction response. |
60
|
|
|
* |
61
|
|
|
* @param string $action Action. |
62
|
|
|
* @param string $id ID. |
63
|
|
|
* @param string $tracking_code Tracking code. |
64
|
|
|
* @param string|float|int $amount Amount. |
65
|
|
|
* @param string $currency_code Currency code. |
66
|
|
|
*/ |
67
|
4 |
|
public function __construct( $action, $id, $tracking_code, $amount, $currency_code ) { |
68
|
4 |
|
$this->action = $action; |
69
|
4 |
|
$this->id = $id; |
70
|
4 |
|
$this->tracking_code = $tracking_code; |
71
|
4 |
|
$this->amount = $amount; |
72
|
4 |
|
$this->currency_code = $currency_code; |
73
|
4 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* From JSON. |
77
|
|
|
* |
78
|
|
|
* @link https://github.com/WordPress/wp-notify/blob/develop/includes/JsonUnserializable.php |
79
|
|
|
* @param object $object Object. |
80
|
|
|
* @return self |
81
|
|
|
* @throws \JsonSchema\Exception\ValidationException Throws exception when JSON is not valid. |
82
|
|
|
*/ |
83
|
3 |
|
public static function from_json( $object ) { |
84
|
3 |
|
$validator = new \JsonSchema\Validator(); |
85
|
|
|
|
86
|
3 |
|
$validator->validate( |
87
|
3 |
|
$object, |
88
|
|
|
(object) array( |
89
|
3 |
|
'$ref' => 'file://' . \realpath( __DIR__ . '/../json-schemas/transaction-response.json' ), |
90
|
|
|
), |
91
|
3 |
|
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */ |
95
|
3 |
|
return new self( $object->action, $object->id, $object->trackingCode, $object->amount, $object->currencyCode ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get action. |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
1 |
|
public function get_action() { |
104
|
1 |
|
return $this->action; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get id. |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
1 |
|
public function get_id() { |
113
|
1 |
|
return $this->id; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get tracking code. |
118
|
|
|
* |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
1 |
|
public function get_tracking_code() { |
122
|
1 |
|
return $this->tracking_code; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get amount. |
127
|
|
|
* |
128
|
|
|
* @return string|float|int |
129
|
|
|
*/ |
130
|
1 |
|
public function get_amount() { |
131
|
1 |
|
return $this->amount; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Get currency code. |
136
|
|
|
* |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
1 |
|
public function get_currency_code() { |
140
|
1 |
|
return $this->currency_code; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|