Failed Conditions
Push — master ( a58383...417a33 )
by Reüel
10:40 queued 04:17
created

PaymentRequest::get_billing_email()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
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.3
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
	 * @var mixed|null
79
	 */
80
	public $meta_data;
81
82
	/**
83
	 * Allow you to preset the language to be used in the payment screens shown to the consumer.
84
	 * When this parameter is not provided, the browser language will be used instead (which is
85
	 * usually more accurate).
86
	 *
87
	 * @link https://www.mollie.com/nl/docs/reference/payments/create
88
	 * @var string|null
89
	 */
90
	public $locale;
91
92
	/**
93
	 * Payment method specific parameters
94
	 */
95
96
	/**
97
	 * An iDEAL issuer ID, for example ideal_INGNL2A. The returned payment URL will deep-link into
98
	 * the specific banking website (ING Bank, in this example). For a list of issuers, refer to the
99
	 * Issuers API.
100
	 *
101
	 * @link https://www.mollie.com/nl/docs/reference/payments/create
102
	 * @var string|null
103
	 */
104
	public $issuer;
105
106
	/**
107
	 * Billing email.
108
	 *
109
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
110
	 * @var string|null
111
	 */
112
	private $billing_email;
113
114
	/**
115
	 * The date the payment should expire, in YYYY-MM-DD format. Please note: the minimum date
116
	 * is tomorrow and the maximum date is 100 days after tomorrow.
117
	 *
118
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
119
	 * @var \DateTimeInterface|null
120
	 */
121
	private $due_date;
122
123
	/**
124
	 * Customer ID for Mollie checkout.
125
	 *
126
	 * @link https://www.mollie.com/nl/docs/checkout
127
	 * @var string|null
128
	 */
129
	public $customer_id;
130
131
	/**
132
	 * Sequence type for Mollie Recurring.
133
	 *
134
	 * @link https://www.mollie.com/nl/docs/recurring
135
	 * @since 1.1.9
136
	 * @var string|null
137
	 */
138
	public $sequence_type;
139
140
	/**
141
	 * Mandate ID.
142
	 *
143
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
144
	 * @since unreleased
145
	 * @var string|null
146
	 */
147
	public $mandate_id;
148
149
	/**
150
	 * Consumer name for SEPA Direct Debit.
151
	 *
152
	 * Beneficiary name of the account holder. Only available if one-off payments are enabled
153
	 * on your account. Will pre-fill the beneficiary name in the checkout screen if present.
154
	 *
155
	 * @var string|null
156
	 */
157
	public $consumer_name;
158
159
	/**
160
	 * Consumer account for SEPA Direct Debit.
161
	 *
162
	 * IBAN of the account holder. Only available if one-off payments are enabled on your account.
163
	 * Will pre-fill the IBAN in the checkout screen if present.
164
	 *
165
	 * @var string|null
166
	 */
167
	public $consumer_account;
168
169
	/**
170
	 * Create Mollie payment request object.
171
	 *
172
	 * @param Amount $amount      The amount that you want to charge.
173
	 * @param string $description The description of the payment you’re creating.
174
	 */
175 3
	public function __construct( $amount, $description ) {
176 3
		$this->amount      = $amount;
177 3
		$this->description = $description;
178 3
	}
179
180
	/**
181
	 * Get due date.
182
	 *
183
	 * @return null|\DateTimeInterface
184
	 */
185 3
	public function get_due_date() {
186 3
		return $this->due_date;
187
	}
188
189
	/**
190
	 * Set due date.
191
	 *
192
	 * @param null|\DateTimeInterface $due_date Due date.
193
	 * @return void
194
	 */
195 1
	public function set_due_date( $due_date ) {
196 1
		$this->due_date = $due_date;
197 1
	}
198
199
	/**
200
	 * Get billing email.
201
	 *
202
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
203
	 * @return string|null
204
	 */
205 1
	public function get_billing_email() {
206 1
		return $this->billing_email;
207
	}
208
209
	/**
210
	 * Set billing email.
211
	 *
212
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
213
	 * @param string|null $email Billing email.
214
	 * @return void
215
	 */
216 1
	public function set_billing_email( $email = null ) {
217 1
		$this->billing_email = $email;
218 1
	}
219
220
	/**
221
	 * Get array of this Mollie payment request object.
222
	 *
223
	 * @return array<string,object>
224
	 */
225 3
	public function get_array() {
226
		// Due date.
227 3
		$due_date = $this->get_due_date();
228
229 3
		if ( null !== $due_date ) {
230 1
			$due_date = $due_date->format( 'Y-m-d' );
231
		}
232
233
		$array = array(
234 3
			'amount'          => $this->amount->get_json(),
235 3
			'description'     => $this->description,
236 3
			'method'          => $this->method,
237 3
			'redirectUrl'     => $this->redirect_url,
238 3
			'metadata'        => $this->meta_data,
239 3
			'locale'          => $this->locale,
240 3
			'webhookUrl'      => $this->webhook_url,
241 3
			'consumerName'    => $this->consumer_name,
242 3
			'consumerAccount' => $this->consumer_account,
243 3
			'issuer'          => $this->issuer,
244 3
			'billingEmail'    => $this->billing_email,
245 3
			'dueDate'         => $due_date,
246 3
			'sequenceType'    => $this->sequence_type,
247 3
			'customerId'      => $this->customer_id,
248 3
			'mandateId'       => $this->mandate_id,
249
		);
250
251
		/*
252
		 * Array filter will remove values NULL, FALSE and empty strings ('')
253
		 */
254 3
		$array = array_filter( $array );
255
256 3
		return $array;
257
	}
258
}
259