Test Failed
Push — master ( 417a33...505c40 )
by Reüel
16:46 queued 03:16
created

PaymentRequest::get_metadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Mollie payment request.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 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-2020 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 wehook 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 3
176 3
	/**
177 3
	 * Create Mollie payment request object.
178 3
	 *
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
	public function __construct( $amount, $description ) {
183
		$this->amount      = $amount;
184
		$this->description = $description;
185 3
	}
186 3
187
	/**
188
	 * Get due date.
189
	 *
190
	 * @return null|\DateTimeInterface
191
	 */
192
	public function get_due_date() {
193
		return $this->due_date;
194
	}
195 1
196 1
	/**
197 1
	 * Set due date.
198
	 *
199
	 * @param null|\DateTimeInterface $due_date Due date.
200
	 * @return void
201
	 */
202
	public function set_due_date( $due_date ) {
203
		$this->due_date = $due_date;
204
	}
205 1
206 1
	/**
207
	 * Get billing email.
208
	 *
209
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
210
	 * @return string|null
211
	 */
212
	public function get_billing_email() {
213
		return $this->billing_email;
214
	}
215
216 1
	/**
217 1
	 * Set billing email.
218 1
	 *
219
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
220
	 * @param string|null $email Billing email.
221
	 * @return void
222
	 */
223
	public function set_billing_email( $email = null ) {
224
		$this->billing_email = $email;
225 3
	}
226
227 3
	/**
228
	 * Get sequence type.
229 3
	 *
230 1
	 * @return string|null
231
	 */
232
	public function get_sequence_type() {
233
		return $this->sequence_type;
234 3
	}
235 3
236 3
	/**
237 3
	 * Set sequence type.
238 3
	 *
239 3
	 * @param string|null $sequence_type Sequence type.
240 3
	 * @return void
241 3
	 */
242 3
	public function set_sequence_type( $sequence_type = null ) {
243 3
		$this->sequence_type = $sequence_type;
244 3
	}
245 3
246 3
	/**
247 3
	 * Get mandate ID.
248 3
	 *
249
	 * When creating recurring payments, the ID of a specific Mandate may be
250
	 * supplied to indicate which of the consumer’s accounts should be
251
	 * credited.
252
	 *
253
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment#:~:text=mandateId
254 3
	 * @link https://docs.mollie.com/reference/v2/payments-api/get-payment#:~:text=mandateId
255
	 * @return string|null
256 3
	 */
257
	public function get_mandate_id() {
258
		return $this->mandate_id;
259
	}
260
261
	/**
262
	 * Set mandate ID.
263
	 *
264
	 * When creating recurring payments, the ID of a specific Mandate may be
265
	 * supplied to indicate which of the consumer’s accounts should be
266
	 * credited.
267
	 *
268
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment#:~:text=mandateId
269
	 * @link https://docs.mollie.com/reference/v2/payments-api/get-payment#:~:text=mandateId
270
	 * @param string|null $mandate_id Mandate ID.
271
	 * @return void
272
	 */
273
	public function set_mandate_id( $mandate_id = null ) {
274
		$this->mandate_id = $mandate_id;
275
	}
276
277
	/**
278
	 * Get metadata.
279
	 *
280
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
281
	 * @link https://en.wikipedia.org/wiki/Metadata
282
	 * @return mixed
283
	 */
284
	public function get_metadata() {
285
		return $this->metadata;
286
	}
287
288
	/**
289
	 * Set metadata.
290
	 *
291
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
292
	 * @link https://en.wikipedia.org/wiki/Metadata
293
	 * @param mixed $metadata Metadata.
294
	 * @return void
295
	 */
296
	public function set_metadata( $metadata = null ) {
297
		$this->metadata = $metadata;
298
	}
299
300
	/**
301
	 * Get array of this Mollie payment request object.
302
	 *
303
	 * @return array<string,object>
304
	 */
305
	public function get_array() {
306
		// Due date.
307
		$due_date = $this->get_due_date();
308
309
		if ( null !== $due_date ) {
310
			$due_date = $due_date->format( 'Y-m-d' );
311
		}
312
313
		$array = array(
314
			'amount'          => $this->amount->get_json(),
315
			'description'     => $this->description,
316
			'method'          => $this->method,
317
			'redirectUrl'     => $this->redirect_url,
318
			'metadata'        => $this->metadata,
319
			'locale'          => $this->locale,
320
			'webhookUrl'      => $this->webhook_url,
321
			'consumerName'    => $this->consumer_name,
322
			'consumerAccount' => $this->consumer_account,
323
			'issuer'          => $this->issuer,
324
			'billingEmail'    => $this->billing_email,
325
			'dueDate'         => $due_date,
326
			'sequenceType'    => $this->sequence_type,
327
			'customerId'      => $this->customer_id,
328
			'mandateId'       => $this->mandate_id,
329
		);
330
331
		/*
332
		 * Array filter will remove values NULL, FALSE and empty strings ('')
333
		 */
334
		$array = array_filter( $array );
335
336
		return $array;
337
	}
338
}
339