1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Refund |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2022 Pronamic |
7
|
|
|
* @license GPL-3.0-or-later |
8
|
|
|
* @package Pronamic\WordPress\Pay\Gateways\Mollie |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Mollie; |
12
|
|
|
|
13
|
|
|
use DateTimeInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Refund |
17
|
|
|
* |
18
|
|
|
* @author Reüel van der Steege |
19
|
|
|
* @version 2.3.0 |
20
|
|
|
* @since 2.3.0 |
21
|
|
|
*/ |
22
|
|
|
class Refund extends BaseResource { |
23
|
|
|
/** |
24
|
|
|
* The amount refunded to your customer with this refund. |
25
|
|
|
* |
26
|
|
|
* @var Amount |
27
|
|
|
*/ |
28
|
|
|
private $amount; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The description of the refund that may be shown to your customer, |
32
|
|
|
* depending on the payment method used. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $description; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The optional metadata you provided upon refund creation. Metadata can for |
40
|
|
|
* example be used to link an bookkeeping ID to a refund. |
41
|
|
|
* |
42
|
|
|
* @var mixed |
43
|
|
|
*/ |
44
|
|
|
private $metadata; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Since refunds may not be instant for certain payment methods, |
48
|
|
|
* the refund carries a status field. |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
private $status; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* The unique identifier of the payment this refund was created for. |
56
|
|
|
* For example: tr_7UhSN1zuXS. |
57
|
|
|
* |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
private $payment_id; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* The date and time the refund was issued. |
64
|
|
|
* |
65
|
|
|
* @var DateTimeInterface |
66
|
|
|
*/ |
67
|
|
|
private $created_at; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Construct chargeback. |
71
|
|
|
* |
72
|
|
|
* @param string $id Identifier. |
73
|
|
|
* @param Amount $amount Amount. |
74
|
|
|
* @param string $description Description. |
75
|
|
|
* @param string $status Status. |
76
|
|
|
* @param string $payment_id Mollie payment ID. |
77
|
|
|
* @param DateTimeInterface $created_at Created at. |
78
|
|
|
*/ |
79
|
|
|
public function __construct( $id, Amount $amount, $description, $status, $payment_id, DateTimeInterface $created_at ) { |
80
|
|
|
parent::__construct( $id ); |
81
|
|
|
|
82
|
|
|
$this->amount = $amount; |
83
|
|
|
$this->description = $description; |
84
|
|
|
$this->status = $status; |
85
|
|
|
$this->payment_id = $payment_id; |
86
|
|
|
$this->created_at = $created_at; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get amount. |
91
|
|
|
* |
92
|
|
|
* @return Amount |
93
|
|
|
*/ |
94
|
|
|
public function get_amount() { |
95
|
|
|
return $this->amount; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get description. |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function get_description() { |
104
|
|
|
return $this->description; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get metadata. |
109
|
|
|
* |
110
|
|
|
* @return mixed |
111
|
|
|
*/ |
112
|
|
|
public function get_metadata() { |
113
|
|
|
return $this->metadata; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get status. |
118
|
|
|
* |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
|
|
public function get_status() { |
122
|
|
|
return $this->status; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get Mollie payment ID. |
127
|
|
|
* |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function get_payment_id() { |
131
|
|
|
return $this->payment_id; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Get created at. |
136
|
|
|
* |
137
|
|
|
* @return DateTimeInterface |
138
|
|
|
*/ |
139
|
|
|
public function get_created_at() { |
140
|
|
|
return $this->created_at; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Create chargeback from JSON. |
145
|
|
|
* |
146
|
|
|
* @link https://docs.mollie.com/reference/v2/refunds-api/get-refund |
147
|
|
|
* @param object $json JSON object. |
148
|
|
|
* @return Refund |
149
|
|
|
* @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid. |
150
|
|
|
*/ |
151
|
|
|
public static function from_json( $json ) { |
152
|
|
|
$validator = new \JsonSchema\Validator(); |
153
|
|
|
|
154
|
|
|
$validator->validate( |
155
|
|
|
$json, |
156
|
|
|
(object) array( |
157
|
|
|
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/refund.json' ), |
158
|
|
|
), |
159
|
|
|
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS |
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Mollie JSON object. |
163
|
|
|
|
164
|
|
|
$refund = new Refund( |
165
|
|
|
$json->id, |
166
|
|
|
Amount::from_json( $json->amount ), |
167
|
|
|
$json->description, |
168
|
|
|
$json->status, |
169
|
|
|
$json->paymentId, |
170
|
|
|
new \DateTimeImmutable( $json->createdAt ) |
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
174
|
|
|
|
175
|
|
|
return $refund; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|