1
|
|
|
<?php |
2
|
|
|
namespace PHPSC\PagSeguro\Purchases; |
3
|
|
|
|
4
|
|
|
use DateTime; |
5
|
|
|
use PHPSC\PagSeguro\Customer\Address; |
6
|
|
|
use PHPSC\PagSeguro\Customer\Customer; |
7
|
|
|
use PHPSC\PagSeguro\Customer\Phone; |
8
|
|
|
use SimpleXMLElement; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
abstract class Decoder |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param SimpleXMLElement $obj |
17
|
|
|
* |
18
|
|
|
* @return Details |
19
|
|
|
*/ |
20
|
2 |
|
protected function createDetails(SimpleXMLElement $obj) |
21
|
|
|
{ |
22
|
2 |
|
return new Details( |
23
|
2 |
|
(string) $obj->code, |
24
|
2 |
|
isset($obj->reference) ? (string) $obj->reference : null, |
25
|
2 |
|
(string) $obj->status, |
26
|
2 |
|
new DateTime((string) $obj->date), |
27
|
2 |
|
new DateTime((string) $obj->lastEventDate), |
28
|
2 |
|
$this->createCustomer($obj->sender) |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param SimpleXMLElement $address |
34
|
|
|
* |
35
|
|
|
* @return Address |
36
|
|
|
*/ |
37
|
2 |
|
protected function createAddress(SimpleXMLElement $address) |
38
|
|
|
{ |
39
|
2 |
|
return new Address( |
40
|
2 |
|
(string) $address->state, |
41
|
2 |
|
(string) $address->city, |
42
|
2 |
|
(string) $address->postalCode, |
43
|
2 |
|
(string) $address->district, |
44
|
2 |
|
(string) $address->street, |
45
|
2 |
|
(string) $address->number, |
46
|
2 |
|
(string) $address->complement |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param SimpleXMLElement $customer |
52
|
|
|
* |
53
|
|
|
* @return Customer |
54
|
|
|
*/ |
55
|
2 |
|
protected function createCustomer(SimpleXMLElement $customer) |
56
|
|
|
{ |
57
|
2 |
|
$phone = null; |
58
|
|
|
|
59
|
2 |
|
if (isset($customer->phone)) { |
60
|
2 |
|
$phone = new Phone( |
61
|
2 |
|
(string) $customer->phone->areaCode, |
62
|
2 |
|
(string) $customer->phone->number |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
2 |
|
return new Customer( |
67
|
2 |
|
(string) $customer->email, |
68
|
2 |
|
isset($customer->name) ? (string) $customer->name : null, |
69
|
|
|
$phone, |
70
|
2 |
|
isset($customer->address) ? $this->createAddress($customer->address) : null |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|