1 | <?php |
||
2 | /** |
||
3 | * Name |
||
4 | * |
||
5 | * @author Pronamic <[email protected]> |
||
6 | * @copyright 2005-2019 Pronamic |
||
7 | * @license GPL-3.0-or-later |
||
8 | * @package Pronamic\WordPress\Pay\Gateways\OmniKassa2 |
||
9 | */ |
||
10 | |||
11 | namespace Pronamic\WordPress\Pay\Gateways\Adyen; |
||
12 | |||
13 | /** |
||
14 | * Name |
||
15 | * |
||
16 | * @link https://docs.adyen.com/developers/api-reference/common-api/name |
||
17 | * |
||
18 | * @author Remco Tolsma |
||
19 | * @version 2.1.0 |
||
20 | * @since 2.0.2 |
||
21 | */ |
||
22 | class Name { |
||
23 | /** |
||
24 | * First name. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | private $first_name; |
||
29 | |||
30 | /** |
||
31 | * Gender. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | private $gender; |
||
36 | |||
37 | /** |
||
38 | * The name's infix, if applicable. |
||
39 | * |
||
40 | * @var string|null |
||
41 | */ |
||
42 | private $infix; |
||
43 | |||
44 | /** |
||
45 | * Last name. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private $last_name; |
||
50 | |||
51 | /** |
||
52 | * Construct shopper name. |
||
53 | * |
||
54 | * @param string $first_name First name. |
||
55 | * @param string $last_name Last name. |
||
56 | * @param string $gender Gender. |
||
57 | */ |
||
58 | 2 | public function __construct( $first_name, $last_name, $gender ) { |
|
59 | 2 | $this->set_first_name( $first_name ); |
|
60 | 2 | $this->set_last_name( $last_name ); |
|
61 | 2 | $this->set_gender( $gender ); |
|
62 | 2 | } |
|
63 | |||
64 | /** |
||
65 | * Get first name. |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | 2 | public function get_first_name() { |
|
70 | 2 | return $this->first_name; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Set first name. |
||
75 | * |
||
76 | * @param string $first_name First name. |
||
77 | */ |
||
78 | 2 | public function set_first_name( $first_name ) { |
|
79 | 2 | $this->first_name = $first_name; |
|
80 | 2 | } |
|
81 | |||
82 | /** |
||
83 | * Get gender. |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | 2 | public function get_gender() { |
|
88 | 2 | return $this->gender; |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * Set gender. |
||
93 | * |
||
94 | * @param string $gender Gender. |
||
95 | */ |
||
96 | 2 | public function set_gender( $gender ) { |
|
97 | 2 | $this->gender = $gender; |
|
98 | 2 | } |
|
99 | |||
100 | /** |
||
101 | * Get infix. |
||
102 | * |
||
103 | * @return string|null |
||
104 | */ |
||
105 | 2 | public function get_infix() { |
|
106 | 2 | return $this->infix; |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * Set infix. |
||
111 | * |
||
112 | * @param string|null $infix Infix. |
||
113 | */ |
||
114 | 1 | public function set_infix( $infix ) { |
|
115 | 1 | if ( null !== $infix && mb_strlen( $infix ) > 20 ) { |
|
116 | throw new InvalidArgumentException( |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
117 | sprintf( |
||
118 | 'Given infix `%s` is longer then 20 characters.', |
||
119 | $infix |
||
120 | ) |
||
121 | ); |
||
122 | } |
||
123 | |||
124 | 1 | $this->infix = $infix; |
|
125 | 1 | } |
|
126 | |||
127 | /** |
||
128 | * Get last name. |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | 2 | public function get_last_name() { |
|
133 | 2 | return $this->last_name; |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * Set last name. |
||
138 | * |
||
139 | * @param string $last_name Last name. |
||
140 | */ |
||
141 | 2 | public function set_last_name( $last_name ) { |
|
142 | 2 | $this->last_name = $last_name; |
|
143 | 2 | } |
|
144 | |||
145 | /** |
||
146 | * Get JSON. |
||
147 | * |
||
148 | * @return object |
||
149 | */ |
||
150 | 1 | public function get_json() { |
|
151 | 1 | $object = (object) array(); |
|
152 | |||
153 | // First name. |
||
154 | 1 | $object->firstName = $this->get_first_name(); |
|
155 | |||
156 | // Gender. |
||
157 | 1 | $object->gender = $this->get_gender(); |
|
158 | |||
159 | // Infix. |
||
160 | 1 | $infix = $this->get_infix(); |
|
161 | |||
162 | 1 | if ( null !== $infix ) { |
|
163 | $object->infix = $infix; |
||
164 | } |
||
165 | |||
166 | // Last name. |
||
167 | 1 | $object->lastName = $this->get_last_name(); |
|
168 | |||
169 | // Return object. |
||
170 | 1 | return $object; |
|
171 | } |
||
172 | } |
||
173 |