|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Customer information. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2021 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Pay\Gateways\OmniKassa2 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; |
|
12
|
|
|
|
|
13
|
|
|
use DateTimeInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Customer information. |
|
17
|
|
|
* |
|
18
|
|
|
* @author Remco Tolsma |
|
19
|
|
|
* @version 2.2.4 |
|
20
|
|
|
* @since 2.0.2 |
|
21
|
|
|
*/ |
|
22
|
|
|
class CustomerInformation implements \JsonSerializable { |
|
23
|
|
|
/** |
|
24
|
|
|
* The e-mailadress of the consumer. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string|null |
|
27
|
|
|
*/ |
|
28
|
|
|
private $email_address; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The date of birth of the consumer. |
|
32
|
|
|
* |
|
33
|
|
|
* @var DateTimeInterface|null |
|
34
|
|
|
*/ |
|
35
|
|
|
private $date_of_birth; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The gender of the consumer. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string|null |
|
41
|
|
|
*/ |
|
42
|
|
|
private $gender; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The initials of the consumer. |
|
46
|
|
|
* |
|
47
|
|
|
* @var string|null |
|
48
|
|
|
*/ |
|
49
|
|
|
private $initials; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* The consumer's telephone number. |
|
53
|
|
|
* |
|
54
|
|
|
* @var string|null |
|
55
|
|
|
*/ |
|
56
|
|
|
private $telephone_number; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Set the e-mailadress of the consumer. |
|
60
|
|
|
* |
|
61
|
|
|
* @param string|null $email_address E-mailadress of the consumer. |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function set_email_address( $email_address ) { |
|
65
|
1 |
|
$this->email_address = $email_address; |
|
66
|
1 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Set date of birth. |
|
70
|
|
|
* |
|
71
|
|
|
* @param DateTimeInterface|null $date_of_birth Date of birth. |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function set_date_of_birth( DateTimeInterface $date_of_birth = null ) { |
|
75
|
1 |
|
$this->date_of_birth = $date_of_birth; |
|
76
|
1 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Set gender. |
|
80
|
|
|
* |
|
81
|
|
|
* @param string|null $gender Gender. |
|
82
|
|
|
* @return void |
|
83
|
|
|
* @throws \InvalidArgumentException Throws invalid argument exception when gender is not null, 'F' or 'M'. |
|
84
|
|
|
*/ |
|
85
|
1 |
|
public function set_gender( $gender ) { |
|
86
|
1 |
|
if ( ! \in_array( $gender, array( null, 'F', 'M' ), true ) ) { |
|
87
|
|
|
throw new \InvalidArgumentException( |
|
88
|
|
|
\sprintf( |
|
89
|
|
|
'Gender "%s" must be equal to `null`, "F" or "M".', |
|
90
|
|
|
(string) $gender |
|
91
|
|
|
) |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
1 |
|
$this->gender = $gender; |
|
96
|
1 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Set initials. |
|
100
|
|
|
* |
|
101
|
|
|
* @param string|null $initials Initials. |
|
102
|
|
|
* @return void |
|
103
|
|
|
*/ |
|
104
|
1 |
|
public function set_initials( $initials ) { |
|
105
|
1 |
|
$this->initials = $initials; |
|
106
|
1 |
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Set telephone number. |
|
110
|
|
|
* |
|
111
|
|
|
* @param string|null $telephone_number Telephone number. |
|
112
|
|
|
* @return void |
|
113
|
|
|
*/ |
|
114
|
1 |
|
public function set_telephone_number( $telephone_number ) { |
|
115
|
1 |
|
$this->telephone_number = $telephone_number; |
|
116
|
1 |
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Get JSON. |
|
120
|
|
|
* |
|
121
|
|
|
* @return object |
|
122
|
|
|
*/ |
|
123
|
|
|
public function jsonSerialize() { |
|
124
|
|
|
$object = (object) array(); |
|
125
|
|
|
|
|
126
|
|
|
if ( null !== $this->email_address ) { |
|
127
|
|
|
$object->emailAddress = $this->email_address; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
if ( null !== $this->date_of_birth ) { |
|
131
|
|
|
$object->dateOfBirth = $this->date_of_birth->format( 'd-m-Y' ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
if ( null !== $this->gender ) { |
|
135
|
|
|
$object->gender = $this->gender; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
if ( null !== $this->initials ) { |
|
139
|
|
|
$object->initials = $this->initials; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
if ( null !== $this->telephone_number ) { |
|
143
|
|
|
$object->telephoneNumber = $this->telephone_number; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return $object; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Get signature fields. |
|
151
|
|
|
* |
|
152
|
|
|
* @param array<string> $fields Fields. |
|
153
|
|
|
* @return array<string> |
|
154
|
|
|
*/ |
|
155
|
1 |
|
public function get_signature_fields( $fields = array() ) { |
|
156
|
1 |
|
$fields[] = (string) $this->email_address; |
|
157
|
1 |
|
$fields[] = ( null === $this->date_of_birth ) ? '' : $this->date_of_birth->format( 'd-m-Y' ); |
|
158
|
1 |
|
$fields[] = (string) $this->gender; |
|
159
|
1 |
|
$fields[] = (string) $this->initials; |
|
160
|
1 |
|
$fields[] = (string) $this->telephone_number; |
|
161
|
|
|
|
|
162
|
1 |
|
return $fields; |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|