1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BPCI\SumUp\Customer; |
4
|
|
|
|
5
|
|
|
class Customer implements CustomerInterface |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Customer SumUp ID |
9
|
|
|
* |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
protected $customerId; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Customer Name |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $name; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Customer phone |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $phone; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Cusomter address |
30
|
|
|
* |
31
|
|
|
* @var AddressInterface |
32
|
|
|
*/ |
33
|
|
|
protected $address; |
34
|
|
|
|
35
|
|
|
function __construct(?array $data = []) |
36
|
|
|
{ |
37
|
|
|
$this->setCustomerId($data['customer_id']??null); |
38
|
|
|
$personal_details = $data['personal_details']??$data; |
39
|
|
|
$this->setName($personal_details['name']??null); |
40
|
|
|
$this->setPhone($personal_details['phone']??null); |
41
|
|
|
$this->setAddress(new Address($personal_details['address']??null)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get customer SumUp ID |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function getCustomerId(): ?string |
50
|
|
|
{ |
51
|
|
|
return $this->customerId; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set customer SumUp ID |
56
|
|
|
* |
57
|
|
|
* @param string $customerId Customer SumUp ID |
58
|
|
|
* @return CustomerInterface |
59
|
|
|
*/ |
60
|
|
|
public function setCustomerId(?string $customerId): CustomerInterface |
61
|
|
|
{ |
62
|
|
|
$this->customerId = $customerId; |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get customer Name |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public function getName(): ?string |
73
|
|
|
{ |
74
|
|
|
return $this->name; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Set customer Name |
79
|
|
|
* |
80
|
|
|
* @param string $name Customer Name |
81
|
|
|
* |
82
|
|
|
* @return self |
83
|
|
|
*/ |
84
|
|
|
public function setName(?string $name): CustomerInterface |
85
|
|
|
{ |
86
|
|
|
$this->name = $name; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get customer phone |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function getPhone(): ?string |
97
|
|
|
{ |
98
|
|
|
return $this->phone; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Set customer phone |
103
|
|
|
* |
104
|
|
|
* @param string $phone Customer phone |
105
|
|
|
* |
106
|
|
|
* @return self |
107
|
|
|
*/ |
108
|
|
|
public function setPhone(?string $phone): CustomerInterface |
109
|
|
|
{ |
110
|
|
|
$this->phone = $phone; |
111
|
|
|
|
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get cusomter address |
117
|
|
|
* |
118
|
|
|
* @return AddressInterface |
119
|
|
|
*/ |
120
|
|
|
public function getAddress(): AddressInterface |
121
|
|
|
{ |
122
|
|
|
return $this->address; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set cusomter address |
127
|
|
|
* |
128
|
|
|
* @param AddressInterface $address |
129
|
|
|
* @return Customer|CustomerInterface |
130
|
|
|
*/ |
131
|
|
|
public function setAddress(AddressInterface $address): CustomerInterface |
132
|
|
|
{ |
133
|
|
|
$this->address = $address; |
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return bool |
139
|
|
|
*/ |
140
|
|
|
function isValid():bool |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
return $this->getCustomerId()!==null; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.