1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LPTracker\models; |
4
|
|
|
|
5
|
|
|
use LPTracker\exceptions\LPTrackerSDKException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Payment |
9
|
|
|
* @package LPTracker\models |
10
|
|
|
*/ |
11
|
|
|
class Payment extends Model |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $category; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $purpose; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var float |
26
|
|
|
*/ |
27
|
|
|
protected $sum; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Payment constructor. |
32
|
|
|
* |
33
|
|
|
* @param array $paymentData |
34
|
|
|
*/ |
35
|
|
|
public function __construct(array $paymentData = []) |
36
|
|
|
{ |
37
|
|
|
if ( ! empty($paymentData['category'])) { |
38
|
|
|
$this->category = $paymentData['category']; |
39
|
|
|
} |
40
|
|
|
if ( ! empty($paymentData['purpose'])) { |
41
|
|
|
$this->purpose = $paymentData['purpose']; |
42
|
|
|
} |
43
|
|
|
if ( ! empty($paymentData['sum'])) { |
44
|
|
|
$this->sum = $paymentData['sum']; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* |
51
|
|
|
*/ |
52
|
|
|
public function toArray() |
53
|
|
|
{ |
54
|
|
|
$result = []; |
55
|
|
|
|
56
|
|
|
if ( ! empty($this->category)) { |
57
|
|
|
$result['category'] = $this->getCategory(); |
58
|
|
|
} |
59
|
|
|
if ( ! empty($this->purpose)) { |
60
|
|
|
$result['purpose'] = $this->getPurpose(); |
61
|
|
|
} |
62
|
|
|
if ( ! empty($this->sum)) { |
63
|
|
|
$result['sum'] = $this->getSum(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return bool |
70
|
|
|
* @throws LPTrackerSDKException |
71
|
|
|
*/ |
72
|
|
|
public function validate() |
73
|
|
|
{ |
74
|
|
|
if (empty($this->category)) { |
75
|
|
|
throw new LPTrackerSDKException('Payment category is required'); |
76
|
|
|
} |
77
|
|
|
if (empty($this->purpose)) { |
78
|
|
|
throw new LPTrackerSDKException('Payment purpose is required'); |
79
|
|
|
} |
80
|
|
|
if ( ! isset($this->sum)) { |
81
|
|
|
throw new LPTrackerSDKException('Payment sum is required'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return true; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getCategory() |
92
|
|
|
{ |
93
|
|
|
return $this->category; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $category |
99
|
|
|
* |
100
|
|
|
* @return $this |
101
|
|
|
*/ |
102
|
|
|
public function setCategory($category) |
103
|
|
|
{ |
104
|
|
|
$this->category = $category; |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function getPurpose() |
114
|
|
|
{ |
115
|
|
|
return $this->purpose; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param string $purpose |
121
|
|
|
* |
122
|
|
|
* @return $this |
123
|
|
|
*/ |
124
|
|
|
public function setPurpose($purpose) |
125
|
|
|
{ |
126
|
|
|
$this->purpose = $purpose; |
127
|
|
|
|
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return float |
134
|
|
|
*/ |
135
|
|
|
public function getSum() |
136
|
|
|
{ |
137
|
|
|
return $this->sum; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param float $sum |
143
|
|
|
* |
144
|
|
|
* @return $this |
145
|
|
|
*/ |
146
|
|
|
public function setSum($sum) |
147
|
|
|
{ |
148
|
|
|
$this->sum = $sum; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
} |