Failed Conditions
Push — master ( b549f2...090668 )
by Remco
10:21 queued 03:46
created

PaymentRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
ccs 3
cts 3
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.0.9
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
	 * The date the payment should expire, in YYYY-MM-DD format. Please note: the minimum date
108
	 * is tomorrow and the maximum date is 100 days after tomorrow.
109
	 *
110
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
111
	 * @var \DateTimeInterface|null
112
	 */
113
	private $due_date;
114
115
	/**
116
	 * Customer ID for Mollie checkout.
117
	 *
118
	 * @link https://www.mollie.com/nl/docs/checkout
119
	 * @var string|null
120
	 */
121
	public $customer_id;
122
123
	/**
124
	 * Sequence type for Mollie Recurring.
125
	 *
126
	 * @link https://www.mollie.com/nl/docs/recurring
127
	 * @since 1.1.9
128
	 * @var string|null
129
	 */
130
	public $sequence_type;
131
132
	/**
133
	 * Mandate ID.
134
	 *
135
	 * @link https://docs.mollie.com/reference/v2/payments-api/create-payment
136
	 * @since unreleased
137
	 * @var string|null
138
	 */
139
	public $mandate_id;
140
141
	/**
142
	 * Consumer name for SEPA Direct Debit.
143
	 *
144
	 * Beneficiary name of the account holder. Only available if one-off payments are enabled
145
	 * on your account. Will pre-fill the beneficiary name in the checkout screen if present.
146
	 *
147
	 * @var string|null
148
	 */
149
	public $consumer_name;
150
151
	/**
152
	 * Consumer account for SEPA Direct Debit.
153
	 *
154
	 * IBAN of the account holder. Only available if one-off payments are enabled on your account.
155
	 * Will pre-fill the IBAN in the checkout screen if present.
156
	 *
157
	 * @var string|null
158
	 */
159
	public $consumer_account;
160
161
	/**
162
	 * Create Mollie payment request object.
163
	 *
164
	 * @param Amount $amount      The amount that you want to charge.
165
	 * @param string $description The description of the payment you’re creating.
166
	 */
167 2
	public function __construct( $amount, $description ) {
168 2
		$this->amount      = $amount;
169 2
		$this->description = $description;
170 2
	}
171
172
	/**
173
	 * Get due date.
174
	 *
175
	 * @return null|\DateTimeInterface
176
	 */
177 2
	public function get_due_date() {
178 2
		return $this->due_date;
179
	}
180
181
	/**
182
	 * Set due date.
183
	 *
184
	 * @param null|\DateTimeInterface $due_date Due date.
185
	 * @return void
186
	 */
187 1
	public function set_due_date( $due_date ) {
188 1
		$this->due_date = $due_date;
189 1
	}
190
191
	/**
192
	 * Get array of this Mollie payment request object.
193
	 *
194
	 * @return array<string,object>
195
	 */
196 2
	public function get_array() {
197
		// Due date.
198 2
		$due_date = $this->get_due_date();
199
200 2
		if ( null !== $due_date ) {
201 1
			$due_date = $due_date->format( 'Y-m-d' );
202
		}
203
204
		$array = array(
205 2
			'amount'          => $this->amount->get_json(),
206 2
			'description'     => $this->description,
207 2
			'method'          => $this->method,
208 2
			'redirectUrl'     => $this->redirect_url,
209 2
			'metadata'        => $this->meta_data,
210 2
			'locale'          => $this->locale,
211 2
			'webhookUrl'      => $this->webhook_url,
212 2
			'consumerName'    => $this->consumer_name,
213 2
			'consumerAccount' => $this->consumer_account,
214 2
			'issuer'          => $this->issuer,
215 2
			'dueDate'         => $due_date,
216 2
			'sequenceType'    => $this->sequence_type,
217 2
			'customerId'      => $this->customer_id,
218 2
			'mandateId'       => $this->mandate_id,
219
		);
220
221
		/*
222
		 * Array filter will remove values NULL, FALSE and empty strings ('')
223
		 */
224 2
		$array = array_filter( $array );
225
226 2
		return $array;
227
	}
228
}
229