1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mollie customer. |
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
|
|
|
* Mollie customer |
15
|
|
|
* |
16
|
|
|
* @link https://docs.mollie.com/reference/v2/customers-api/create-customer |
17
|
|
|
* @author Remco Tolsma |
18
|
|
|
* @version 2.1.0 |
19
|
|
|
* @since 2.1.0 |
20
|
|
|
*/ |
21
|
|
|
class Customer { |
22
|
|
|
/** |
23
|
|
|
* ID. |
24
|
|
|
* |
25
|
|
|
* @var string|null |
26
|
|
|
*/ |
27
|
|
|
private $id; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Mode. |
31
|
|
|
* |
32
|
|
|
* @var string|null |
33
|
|
|
*/ |
34
|
|
|
private $mode; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Name. |
38
|
|
|
* |
39
|
|
|
* @var string|null |
40
|
|
|
*/ |
41
|
|
|
private $name; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Email. |
45
|
|
|
* |
46
|
|
|
* @var string|null |
47
|
|
|
*/ |
48
|
|
|
private $email; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Locale. |
52
|
|
|
* |
53
|
|
|
* @var string|null |
54
|
|
|
*/ |
55
|
|
|
public $locale; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Construct Mollie customer. |
59
|
|
|
* |
60
|
|
|
* @param string|null $id Mollie customer ID. |
61
|
|
|
*/ |
62
|
3 |
|
public function __construct( $id = null ) { |
63
|
3 |
|
$this->set_id( $id ); |
64
|
3 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get ID. |
68
|
|
|
* |
69
|
|
|
* @return string|null |
70
|
|
|
*/ |
71
|
3 |
|
public function get_id() { |
72
|
3 |
|
return $this->id; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set ID. |
77
|
|
|
* |
78
|
|
|
* @param string|null $id ID. |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
3 |
|
public function set_id( $id ) { |
82
|
3 |
|
$this->id = $id; |
83
|
3 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get mode. |
87
|
|
|
* |
88
|
|
|
* @return string|null |
89
|
|
|
*/ |
90
|
3 |
|
public function get_mode() { |
91
|
3 |
|
return $this->mode; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set mode. |
96
|
|
|
* |
97
|
|
|
* @param string|null $mode Mode. |
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
1 |
|
public function set_mode( $mode ) { |
101
|
1 |
|
$this->mode = $mode; |
102
|
1 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get name. |
106
|
|
|
* |
107
|
|
|
* @return string|null |
108
|
|
|
*/ |
109
|
1 |
|
public function get_name() { |
110
|
1 |
|
return $this->name; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Set name. |
115
|
|
|
* |
116
|
|
|
* @param string|null $name Name. |
117
|
|
|
* @return void |
118
|
|
|
*/ |
119
|
1 |
|
public function set_name( $name ) { |
120
|
1 |
|
$this->name = $name; |
121
|
1 |
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get email. |
125
|
|
|
* |
126
|
|
|
* @return string|null |
127
|
|
|
*/ |
128
|
3 |
|
public function get_email() { |
129
|
3 |
|
return $this->email; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Set email. |
134
|
|
|
* |
135
|
|
|
* @param string|null $email Email. |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
1 |
|
public function set_email( $email ) { |
139
|
1 |
|
$this->email = $email; |
140
|
1 |
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get locale. |
144
|
|
|
* |
145
|
|
|
* @return string|null |
146
|
|
|
*/ |
147
|
1 |
|
public function get_locale() { |
148
|
1 |
|
return $this->locale; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Set locale. |
153
|
|
|
* |
154
|
|
|
* @param string|null $locale Locale. |
155
|
|
|
* @return void |
156
|
|
|
*/ |
157
|
1 |
|
public function set_locale( $locale ) { |
158
|
1 |
|
$this->locale = $locale; |
159
|
1 |
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Get array. |
163
|
|
|
* |
164
|
|
|
* @return array<string> |
165
|
|
|
*/ |
166
|
|
|
public function get_array() { |
167
|
|
|
$array = array( |
168
|
|
|
'name' => $this->get_name(), |
169
|
|
|
'email' => $this->get_email(), |
170
|
|
|
'locale' => $this->get_locale(), |
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
/* |
174
|
|
|
* Array filter will remove values NULL, FALSE and empty strings ('') |
175
|
|
|
*/ |
176
|
|
|
$array = array_filter( $array ); |
177
|
|
|
|
178
|
|
|
return $array; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Create customer from object. |
183
|
|
|
* |
184
|
|
|
* @param object $object Object. |
185
|
|
|
* @return Customer |
186
|
|
|
*/ |
187
|
|
|
public static function from_object( $object ) { |
188
|
|
|
$customer = new self(); |
189
|
|
|
|
190
|
|
|
if ( property_exists( $object, 'id' ) ) { |
191
|
|
|
$customer->set_id( $object->id ); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
if ( property_exists( $object, 'mode' ) ) { |
195
|
|
|
$customer->set_mode( $object->mode ); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
if ( property_exists( $object, 'name' ) ) { |
199
|
|
|
$customer->set_name( $object->name ); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
if ( property_exists( $object, 'email' ) ) { |
203
|
|
|
$customer->set_email( $object->email ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
if ( property_exists( $object, 'locale' ) ) { |
207
|
|
|
$customer->set_locale( $object->locale ); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
return $customer; |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|