|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tzsk\Payu\Concerns; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Validator; |
|
6
|
|
|
use Illuminate\Validation\ValidationException; |
|
7
|
|
|
use Tzsk\Payu\Contracts\HasFormParams; |
|
8
|
|
|
|
|
9
|
|
|
class Customer implements HasFormParams |
|
10
|
|
|
{ |
|
11
|
|
|
public ?string $firstName = null; |
|
|
|
|
|
|
12
|
|
|
public ?string $lastName = null; |
|
13
|
|
|
public ?string $email = null; |
|
14
|
|
|
public ?string $phone = null; |
|
15
|
|
|
public ?string $addressOne = null; |
|
16
|
|
|
public ?string $addressTwo = null; |
|
17
|
|
|
public ?string $city = null; |
|
18
|
|
|
public ?string $state = null; |
|
19
|
|
|
public ?string $country = null; |
|
20
|
|
|
public ?string $zipCode = null; |
|
21
|
|
|
|
|
22
|
|
|
public static function make(): self |
|
23
|
|
|
{ |
|
24
|
|
|
return new self(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function firstName(string $firstName): self |
|
28
|
|
|
{ |
|
29
|
|
|
$this->firstName = $firstName; |
|
30
|
|
|
|
|
31
|
|
|
return $this; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function lastName(string $lastName): self |
|
35
|
|
|
{ |
|
36
|
|
|
$this->lastName = $lastName; |
|
37
|
|
|
|
|
38
|
|
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function email(string $email): self |
|
42
|
|
|
{ |
|
43
|
|
|
$this->email = $email; |
|
44
|
|
|
|
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function phone(string $phone): self |
|
49
|
|
|
{ |
|
50
|
|
|
$this->phone = $phone; |
|
51
|
|
|
|
|
52
|
|
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function addressOne(string $addressOne): self |
|
56
|
|
|
{ |
|
57
|
|
|
$this->addressOne = $addressOne; |
|
58
|
|
|
|
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function addressTwo(string $addressTwo): self |
|
63
|
|
|
{ |
|
64
|
|
|
$this->addressTwo = $addressTwo; |
|
65
|
|
|
|
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function city(string $city): self |
|
70
|
|
|
{ |
|
71
|
|
|
$this->city = $city; |
|
72
|
|
|
|
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function state(string $state): self |
|
77
|
|
|
{ |
|
78
|
|
|
$this->state = $state; |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function country(string $country): self |
|
84
|
|
|
{ |
|
85
|
|
|
$this->country = $country; |
|
86
|
|
|
|
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function zipCode(string $zipCode): self |
|
91
|
|
|
{ |
|
92
|
|
|
$this->zipCode = $zipCode; |
|
93
|
|
|
|
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function toArray(): array |
|
98
|
|
|
{ |
|
99
|
|
|
return [ |
|
100
|
|
|
'firstname' => $this->firstName, |
|
101
|
|
|
'lastname' => $this->lastName, |
|
102
|
|
|
'email' => $this->email, |
|
103
|
|
|
'phone' => $this->phone, |
|
104
|
|
|
'address1' => $this->addressOne, |
|
105
|
|
|
'address2' => $this->addressTwo, |
|
106
|
|
|
'city' => $this->city, |
|
107
|
|
|
'state' => $this->state, |
|
108
|
|
|
'country' => $this->country, |
|
109
|
|
|
'zipcode' => $this->zipCode, |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @throws ValidationException |
|
115
|
|
|
*/ |
|
116
|
|
|
public function validate(): array |
|
117
|
|
|
{ |
|
118
|
|
|
return Validator::make($this->toArray(), [ |
|
119
|
|
|
'firstname' => 'required|string', |
|
120
|
|
|
'lastname' => 'nullable|string', |
|
121
|
|
|
'email' => 'required|email', |
|
122
|
|
|
'phone' => 'nullable|string', |
|
123
|
|
|
'address1' => 'nullable|string', |
|
124
|
|
|
'address2' => 'nullable|string', |
|
125
|
|
|
'city' => 'nullable|string', |
|
126
|
|
|
'state' => 'nullable|string', |
|
127
|
|
|
'country' => 'nullable|string', |
|
128
|
|
|
'zipcode' => 'nullable|string', |
|
129
|
|
|
])->validate(); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function fields(): array |
|
133
|
|
|
{ |
|
134
|
|
|
return array_filter($this->toArray()); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|