|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Mollie payment request. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2022 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Pay |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Mollie; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Title: Mollie payment request |
|
15
|
|
|
* Description: |
|
16
|
|
|
* Copyright: 2005-2022 Pronamic |
|
17
|
|
|
* Company: Pronamic |
|
18
|
|
|
* |
|
19
|
|
|
* @author Remco Tolsma |
|
20
|
|
|
* @version 2.1.4 |
|
21
|
|
|
* @since 1.0.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class PaymentRequest { |
|
24
|
|
|
/** |
|
25
|
|
|
* The amount in EURO that you want to charge, e.g. `{"currency":"EUR", "value":"100.00"}` |
|
26
|
|
|
* if you would want to charge € 100,00. |
|
27
|
|
|
* |
|
28
|
|
|
* @link https://www.mollie.com/nl/docs/reference/payments/create |
|
29
|
|
|
* @var Amount |
|
30
|
|
|
*/ |
|
31
|
|
|
public $amount; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The description of the payment you're creating. This will be shown to the consumer on their |
|
35
|
|
|
* card or bank statement when possible. |
|
36
|
|
|
* |
|
37
|
|
|
* @link https://www.mollie.com/nl/docs/reference/payments/create |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
public $description; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The URL the consumer will be redirected to after the payment process. It could make sense |
|
44
|
|
|
* for the redirectURL to contain a unique identifier – like your order ID – so you can show |
|
45
|
|
|
* the right page referencing the order when the consumer returns. |
|
46
|
|
|
* |
|
47
|
|
|
* @link https://www.mollie.com/nl/docs/reference/payments/create |
|
48
|
|
|
* @var string|null |
|
49
|
|
|
*/ |
|
50
|
|
|
public $redirect_url; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Use this parameter to set a webhook URL for this payment only. Mollie will ignore any webhook |
|
54
|
|
|
* set in your website profile for this payment. |
|
55
|
|
|
* |
|
56
|
|
|
* @link https://www.mollie.com/nl/docs/reference/payments/create |
|
57
|
|
|
* @var string|null |
|
58
|
|
|
*/ |
|
59
|
|
|
public $webhook_url; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Normally, a payment method selection screen is shown. However, when using this parameter, |
|
63
|
|
|
* your customer will skip the selection screen and will be sent directly to the chosen payment |
|
64
|
|
|
* method. The parameter enables you to fully integrate the payment method selection into your |
|
65
|
|
|
* website, however note Mollie's country based conversion optimization is lost. |
|
66
|
|
|
* |
|
67
|
|
|
* @link https://www.mollie.com/nl/docs/reference/payments/create |
|
68
|
|
|
* @var string|null |
|
69
|
|
|
*/ |
|
70
|
|
|
public $method; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Provide any data you like in JSON notation, and we will save the data alongside the payment. |
|
74
|
|
|
* Whenever you fetch the payment with our API, we'll also include the metadata. You can use up |
|
75
|
|
|
* to 1kB of JSON. |
|
76
|
|
|
* |
|
77
|
|
|
* @link https://www.mollie.com/nl/docs/reference/payments/create |
|
78
|
|
|
* @link https://en.wikipedia.org/wiki/Metadata |
|
79
|
|
|
* @var mixed|null |
|
80
|
|
|
*/ |
|
81
|
|
|
private $metadata; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Allow you to preset the language to be used in the payment screens shown to the consumer. |
|
85
|
|
|
* When this parameter is not provided, the browser language will be used instead (which is |
|
86
|
|
|
* usually more accurate). |
|
87
|
|
|
* |
|
88
|
|
|
* @link https://www.mollie.com/nl/docs/reference/payments/create |
|
89
|
|
|
* @var string|null |
|
90
|
|
|
*/ |
|
91
|
|
|
public $locale; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Payment method specific parameters |
|
95
|
|
|
*/ |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* An iDEAL issuer ID, for example ideal_INGNL2A. The returned payment URL will deep-link into |
|
99
|
|
|
* the specific banking website (ING Bank, in this example). For a list of issuers, refer to the |
|
100
|
|
|
* Issuers API. |
|
101
|
|
|
* |
|
102
|
|
|
* @link https://www.mollie.com/nl/docs/reference/payments/create |
|
103
|
|
|
* @var string|null |
|
104
|
|
|
*/ |
|
105
|
|
|
public $issuer; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Billing email. |
|
109
|
|
|
* |
|
110
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/create-payment |
|
111
|
|
|
* @var string|null |
|
112
|
|
|
*/ |
|
113
|
|
|
private $billing_email; |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* The date the payment should expire, in YYYY-MM-DD format. Please note: the minimum date |
|
117
|
|
|
* is tomorrow and the maximum date is 100 days after tomorrow. |
|
118
|
|
|
* |
|
119
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/create-payment |
|
120
|
|
|
* @var \DateTimeInterface|null |
|
121
|
|
|
*/ |
|
122
|
|
|
private $due_date; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Customer ID for Mollie checkout. |
|
126
|
|
|
* |
|
127
|
|
|
* @link https://www.mollie.com/nl/docs/checkout |
|
128
|
|
|
* @var string|null |
|
129
|
|
|
*/ |
|
130
|
|
|
public $customer_id; |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Sequence type for Mollie Recurring. |
|
134
|
|
|
* |
|
135
|
|
|
* @link https://docs.mollie.com/payments/recurring#:~:text=sequenceType |
|
136
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/create-payment#:~:text=sequenceType |
|
137
|
|
|
* @since 1.1.9 |
|
138
|
|
|
* @var string|null |
|
139
|
|
|
*/ |
|
140
|
|
|
public $sequence_type; |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Mandate ID. |
|
144
|
|
|
* |
|
145
|
|
|
* When creating recurring payments, the ID of a specific Mandate may be |
|
146
|
|
|
* supplied to indicate which of the consumer’s accounts should be |
|
147
|
|
|
* credited. |
|
148
|
|
|
* |
|
149
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/create-payment#:~:text=mandateId |
|
150
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/get-payment#:~:text=mandateId |
|
151
|
|
|
* @since unreleased |
|
152
|
|
|
* @var string|null |
|
153
|
|
|
*/ |
|
154
|
|
|
public $mandate_id; |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Consumer name for SEPA Direct Debit. |
|
158
|
|
|
* |
|
159
|
|
|
* Beneficiary name of the account holder. Only available if one-off payments are enabled |
|
160
|
|
|
* on your account. Will pre-fill the beneficiary name in the checkout screen if present. |
|
161
|
|
|
* |
|
162
|
|
|
* @var string|null |
|
163
|
|
|
*/ |
|
164
|
|
|
public $consumer_name; |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Consumer account for SEPA Direct Debit. |
|
168
|
|
|
* |
|
169
|
|
|
* IBAN of the account holder. Only available if one-off payments are enabled on your account. |
|
170
|
|
|
* Will pre-fill the IBAN in the checkout screen if present. |
|
171
|
|
|
* |
|
172
|
|
|
* @var string|null |
|
173
|
|
|
*/ |
|
174
|
|
|
public $consumer_account; |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Create Mollie payment request object. |
|
178
|
|
|
* |
|
179
|
|
|
* @param Amount $amount The amount that you want to charge. |
|
180
|
|
|
* @param string $description The description of the payment you’re creating. |
|
181
|
|
|
*/ |
|
182
|
5 |
|
public function __construct( $amount, $description ) { |
|
183
|
5 |
|
$this->amount = $amount; |
|
184
|
5 |
|
$this->description = $description; |
|
185
|
5 |
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Get method. |
|
189
|
|
|
* |
|
190
|
|
|
* @return null|string |
|
191
|
|
|
*/ |
|
192
|
|
|
public function get_method() { |
|
193
|
|
|
return $this->method; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Set method. |
|
198
|
|
|
* |
|
199
|
|
|
* @param null|string $method Method. |
|
200
|
|
|
* @return void |
|
201
|
|
|
*/ |
|
202
|
|
|
public function set_method( $method ) { |
|
203
|
|
|
$this->method = $method; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Get due date. |
|
208
|
|
|
* |
|
209
|
|
|
* @return null|\DateTimeInterface |
|
210
|
|
|
*/ |
|
211
|
4 |
|
public function get_due_date() { |
|
212
|
4 |
|
return $this->due_date; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Set due date. |
|
217
|
|
|
* |
|
218
|
|
|
* @param null|\DateTimeInterface $due_date Due date. |
|
219
|
|
|
* @return void |
|
220
|
|
|
*/ |
|
221
|
1 |
|
public function set_due_date( $due_date ) { |
|
222
|
1 |
|
$this->due_date = $due_date; |
|
223
|
1 |
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Get billing email. |
|
227
|
|
|
* |
|
228
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/create-payment |
|
229
|
|
|
* @return string|null |
|
230
|
|
|
*/ |
|
231
|
1 |
|
public function get_billing_email() { |
|
232
|
1 |
|
return $this->billing_email; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Set billing email. |
|
237
|
|
|
* |
|
238
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/create-payment |
|
239
|
|
|
* @param string|null $email Billing email. |
|
240
|
|
|
* @return void |
|
241
|
|
|
*/ |
|
242
|
1 |
|
public function set_billing_email( $email = null ) { |
|
243
|
1 |
|
$this->billing_email = $email; |
|
244
|
1 |
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* Get sequence type. |
|
248
|
|
|
* |
|
249
|
|
|
* @return string|null |
|
250
|
|
|
*/ |
|
251
|
1 |
|
public function get_sequence_type() { |
|
252
|
1 |
|
return $this->sequence_type; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Set sequence type. |
|
257
|
|
|
* |
|
258
|
|
|
* @param string|null $sequence_type Sequence type. |
|
259
|
|
|
* @return void |
|
260
|
|
|
*/ |
|
261
|
1 |
|
public function set_sequence_type( $sequence_type = null ) { |
|
262
|
1 |
|
$this->sequence_type = $sequence_type; |
|
263
|
1 |
|
} |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* Get mandate ID. |
|
267
|
|
|
* |
|
268
|
|
|
* When creating recurring payments, the ID of a specific Mandate may be |
|
269
|
|
|
* supplied to indicate which of the consumer’s accounts should be |
|
270
|
|
|
* credited. |
|
271
|
|
|
* |
|
272
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/create-payment#:~:text=mandateId |
|
273
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/get-payment#:~:text=mandateId |
|
274
|
|
|
* @return string|null |
|
275
|
|
|
*/ |
|
276
|
1 |
|
public function get_mandate_id() { |
|
277
|
1 |
|
return $this->mandate_id; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* Set mandate ID. |
|
282
|
|
|
* |
|
283
|
|
|
* When creating recurring payments, the ID of a specific Mandate may be |
|
284
|
|
|
* supplied to indicate which of the consumer’s accounts should be |
|
285
|
|
|
* credited. |
|
286
|
|
|
* |
|
287
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/create-payment#:~:text=mandateId |
|
288
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/get-payment#:~:text=mandateId |
|
289
|
|
|
* @param string|null $mandate_id Mandate ID. |
|
290
|
|
|
* @return void |
|
291
|
|
|
*/ |
|
292
|
1 |
|
public function set_mandate_id( $mandate_id = null ) { |
|
293
|
1 |
|
$this->mandate_id = $mandate_id; |
|
294
|
1 |
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Get metadata. |
|
298
|
|
|
* |
|
299
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/create-payment |
|
300
|
|
|
* @link https://en.wikipedia.org/wiki/Metadata |
|
301
|
|
|
* @return mixed |
|
302
|
|
|
*/ |
|
303
|
1 |
|
public function get_metadata() { |
|
304
|
1 |
|
return $this->metadata; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* Set metadata. |
|
309
|
|
|
* |
|
310
|
|
|
* @link https://docs.mollie.com/reference/v2/payments-api/create-payment |
|
311
|
|
|
* @link https://en.wikipedia.org/wiki/Metadata |
|
312
|
|
|
* @param mixed $metadata Metadata. |
|
313
|
|
|
* @return void |
|
314
|
|
|
*/ |
|
315
|
5 |
|
public function set_metadata( $metadata = null ) { |
|
316
|
5 |
|
$this->metadata = $metadata; |
|
317
|
5 |
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
|
|
* Get array of this Mollie payment request object. |
|
321
|
|
|
* |
|
322
|
|
|
* @return array<string,null|string|object> |
|
323
|
|
|
*/ |
|
324
|
4 |
|
public function get_array() { |
|
325
|
|
|
// Due date. |
|
326
|
4 |
|
$due_date = $this->get_due_date(); |
|
327
|
|
|
|
|
328
|
4 |
|
if ( null !== $due_date ) { |
|
329
|
1 |
|
$due_date = $due_date->format( 'Y-m-d' ); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
$array = array( |
|
333
|
4 |
|
'amount' => $this->amount->get_json(), |
|
334
|
4 |
|
'description' => $this->description, |
|
335
|
4 |
|
'method' => $this->method, |
|
336
|
4 |
|
'redirectUrl' => $this->redirect_url, |
|
337
|
4 |
|
'metadata' => $this->metadata, |
|
338
|
4 |
|
'locale' => $this->locale, |
|
339
|
4 |
|
'webhookUrl' => $this->webhook_url, |
|
340
|
4 |
|
'consumerName' => $this->consumer_name, |
|
341
|
4 |
|
'consumerAccount' => $this->consumer_account, |
|
342
|
4 |
|
'issuer' => $this->issuer, |
|
343
|
4 |
|
'billingEmail' => $this->billing_email, |
|
344
|
4 |
|
'dueDate' => $due_date, |
|
345
|
4 |
|
'sequenceType' => $this->sequence_type, |
|
346
|
4 |
|
'customerId' => $this->customer_id, |
|
347
|
4 |
|
'mandateId' => $this->mandate_id, |
|
348
|
|
|
); |
|
349
|
|
|
|
|
350
|
|
|
/* |
|
351
|
|
|
* Array filter will remove values NULL, FALSE and empty strings ('') |
|
352
|
|
|
*/ |
|
353
|
4 |
|
$array = array_filter( $array ); |
|
354
|
|
|
|
|
355
|
4 |
|
return $array; |
|
356
|
|
|
} |
|
357
|
|
|
} |
|
358
|
|
|
|