-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathklarnaaddr.php
609 lines (540 loc) · 11.9 KB
/
klarnaaddr.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
<?php
/**
* KlarnaAddr
*
* PHP Version 5.3
*
* @category Payment
* @package KlarnaAPI
* @author MS Dev <[email protected]>
* @copyright 2012 Klarna AB (http://klarna.com)
* @license http://opensource.org/licenses/BSD-2-Clause BSD-2
* @link https://developers.klarna.com/
*/
/**
* KlarnaAddr is an object of convenience, to parse and create addresses.
*
* @category Payment
* @package KlarnaAPI
* @author MS Dev <[email protected]>
* @copyright 2012 Klarna AB (http://klarna.com)
* @license http://opensource.org/licenses/BSD-2-Clause BSD-2
* @link https://developers.klarna.com/
*/
class KlarnaAddr
{
/**
* Email address.
*
* @var string
*/
protected $email;
/**
* Phone number.
*
* @var string
*/
protected $telno;
/**
* Cellphone number.
*
* @var string
*/
protected $cellno;
/**
* First name.
*
* @var string
*/
protected $fname;
/**
* Last name.
*
* @var string
*/
protected $lname;
/**
* Company name.
*
* @var string
*/
protected $company;
/**
* Care of, C/O.
*
* @var string
*/
protected $careof;
/**
* Street address.
*
* @var string
*/
protected $street;
/**
* Zip code.
*
* @var string
*/
protected $zip;
/**
* City.
*
* @var string
*/
protected $city;
/**
* KlarnaCountry constant
*
* @var int
*/
protected $country;
/**
* House number.
* Only for NL and DE!
*
* @var string
*/
protected $houseNo;
/**
* House extension.
* Only for NL!
*
* @var string
*/
protected $houseExt;
/**
* When using {@link Klarna::getAddresses()} this might be guessed
* depending on type used.
*
* Signifies if address is for a company or a private person.
* If isCompany is null, then it is unknown and will be assumed to
* be a private person.
*
* <b>Note</b>:<br>
* This has no effect on transmitted data.
*
* @var bool|null
*/
public $isCompany = null;
/**
* Class constructor.
*
* Calls the set methods for all arguments.
*
* @param string $email Email address.
* @param string $telno Phone number.
* @param string $cellno Cellphone number.
* @param string $fname First name.
* @param string $lname Last name.
* @param string $careof Care of, C/O.
* @param string $street Street address.
* @param string $zip Zip code.
* @param string $city City.
* @param string|int $country KlarnaCountry constant or two letter code.
* @param string $houseNo House number, only used in DE and NL.
* @param string $houseExt House extension, only used in NL.
*
* @throws KlarnaException
*/
public function __construct(
$email = null, $telno = null, $cellno = null, $fname = null,
$lname = null, $careof = "", $street = null, $zip = null,
$city = null, $country = null, $houseNo = "", $houseExt = ""
) {
//Set all string values to ""
$this->company = "";
$this->telno = "";
$this->careof = "";
$this->cellno = "";
$this->city = "";
$this->email = "";
$this->fname = "";
$this->lname = "";
$this->zip = "";
if ($email !== null) {
$this->setEmail($email);
}
if ($telno !== null) {
$this->setTelno($telno);
}
if ($cellno !== null) {
$this->setCellno($cellno);
}
if ($fname !== null) {
$this->setFirstName($fname);
}
if ($lname !== null) {
$this->setLastName($lname);
}
$this->setCareof($careof);
if ($street !== null) {
$this->setStreet($street);
}
if ($zip !== null) {
$this->setZipCode($zip);
}
if ($city !== null) {
$this->setCity($city);
}
if ($country !== null) {
$this->setCountry($country);
}
$this->setHouseNumber($houseNo);
$this->setHouseExt($houseExt);
}
/**
* Returns the email address.
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Sets the email address.
*
* @param string $email email address
*
* @return void
*/
public function setEmail($email)
{
if (!is_string($email)) {
$email = strval($email);
}
$this->email = $email;
}
/**
* Returns the phone number.
*
* @return string
*/
public function getTelno()
{
return $this->telno;
}
/**
* Sets the phone number.
*
* @param string $telno telno
*
* @return void
*/
public function setTelno($telno)
{
if (!is_string($telno)) {
$telno = strval($telno);
}
$this->telno = $telno;
}
/**
* Returns the cellphone number.
*
* @return string
*/
public function getCellno()
{
return $this->cellno;
}
/**
* Sets the cellphone number.
*
* @param string $cellno mobile number
*
* @return void
*/
public function setCellno($cellno)
{
if (!is_string($cellno)) {
$cellno = strval($cellno);
}
$this->cellno = $cellno;
}
/**
* Returns the first name.
*
* @return string
*/
public function getFirstName()
{
return $this->fname;
}
/**
* Sets the first name.
*
* @param string $fname firstname
*
* @return void
*/
public function setFirstName($fname)
{
if (!is_string($fname)) {
$fname = strval($fname);
}
$this->fname = $fname;
}
/**
* Returns the last name.
*
* @return string
*/
public function getLastName()
{
return $this->lname;
}
/**
* Sets the last name.
*
* @param string $lname lastname
*
* @return void
*/
public function setLastName($lname)
{
if (!is_string($lname)) {
$lname = strval($lname);
}
$this->lname = $lname;
}
/**
* Returns the company name.
*
* @return string
*/
public function getCompanyName()
{
return $this->company;
}
/**
* Sets the company name.
* If the purchase results in a company purchase,
* reference person will be used from first and last name,
* or the value set with {@link Klarna::setReference()}.
*
* @param string $company company name
*
* @see Klarna::setReference
* @return void
*/
public function setCompanyName($company)
{
if (!is_string($company)) {
$company = strval($company);
}
$this->company = $company;
}
/**
* Returns the care of, C/O.
*
* @return string
*/
public function getCareof()
{
return $this->careof;
}
/**
* Sets the care of, C/O.
*
* @param string $careof care of address
*
* @return void
*/
public function setCareof($careof)
{
if (!is_string($careof)) {
$careof = strval($careof);
}
$this->careof = $careof;
}
/**
* Returns the street address.
*
* @return string
*/
public function getStreet()
{
return $this->street;
}
/**
* Sets the street address.
*
* @param string $street street address
*
* @return void
*/
public function setStreet($street)
{
if (!is_string($street)) {
$street = strval($street);
}
$this->street = $street;
}
/**
* Returns the zip code.
*
* @return string
*/
public function getZipCode()
{
return $this->zip;
}
/**
* Sets the zip code.
*
* @param string $zip zip code
*
* @return void
*/
public function setZipCode($zip)
{
if (!is_string($zip)) {
$zip = strval($zip);
}
$zip = str_replace(' ', '', $zip); //remove spaces
$this->zip = $zip;
}
/**
* Returns the city.
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Sets the city.
*
* @param string $city city
*
* @return void
*/
public function setCity($city)
{
if (!is_string($city)) {
$city = strval($city);
}
$this->city = $city;
}
/**
* Returns the country as a integer constant.
*
* @return int {@link KlarnaCountry}
*/
public function getCountry()
{
return $this->country;
}
/**
* Returns the country as a two letter representation.
*
* @throws KlarnaException
* @return string E.g. 'de', 'dk', ...
*/
public function getCountryCode()
{
return KlarnaCountry::getCode($this->country);
}
/**
* Sets the country, use either a two letter representation or the integer
* constant.
*
* @param int $country {@link KlarnaCountry}
*
* @throws KlarnaException
* @return void
*/
public function setCountry($country)
{
if ($country === null) {
throw new Klarna_ArgumentNotSetException('Country');
}
if (is_numeric($country)) {
if (!is_int($country)) {
$country = intval($country);
}
$this->country = $country;
return;
}
if (strlen($country) == 2 || strlen($country) == 3) {
$this->setCountry(KlarnaCountry::fromCode($country));
return;
}
throw new KlarnaException("Failed to set country! ($country)");
}
/**
* Returns the house number.<br>
* Only used in Germany and Netherlands.<br>
*
* @return string
*/
public function getHouseNumber()
{
return $this->houseNo;
}
/**
* Sets the house number.<br>
* Only used in Germany and Netherlands.<br>
*
* @param string $houseNo house number
*
* @return void
*/
public function setHouseNumber($houseNo)
{
if (!is_string($houseNo)) {
$houseNo = strval($houseNo);
}
$this->houseNo = $houseNo;
}
/**
* Returns the house extension.<br>
* Only used in Netherlands.<br>
*
* @return string
*/
public function getHouseExt()
{
return $this->houseExt;
}
/**
* Sets the house extension.<br>
* Only used in Netherlands.<br>
*
* @param string $houseExt house extension
*
* @return void
*/
public function setHouseExt($houseExt)
{
if (!is_string($houseExt)) {
$houseExt = strval($houseExt);
}
$this->houseExt = $houseExt;
}
/**
* Returns an associative array representing this object.
*
* @return array
*/
public function toArray()
{
return array(
'email' => $this->getEmail(),
'telno' => $this->getTelno(),
'cellno' => $this->getCellno(),
'fname' => $this->getFirstName(),
'lname' => $this->getLastName(),
'company' => $this->getCompanyName(),
'careof' => $this->getCareof(),
'street' => $this->getStreet(),
'house_number' => $this->getHouseNumber(),
'house_extension' => $this->getHouseExt(),
'zip' => $this->getZipCode(),
'city' => $this->getCity(),
'country' => $this->getCountry(),
);
}
}