|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Rafał Muszyński <[email protected]> |
|
5
|
|
|
* @copyright 2015 Sourcefabric z.ú. |
|
6
|
|
|
* @license http://www.gnu.org/licenses/gpl-3.0.txt |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace Newscoop\PaywallBundle\Entity; |
|
9
|
|
|
|
|
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Payment entity. |
|
14
|
|
|
* |
|
15
|
|
|
* @ORM\Entity(repositoryClass="Newscoop\PaywallBundle\Entity\Repository\PaymentRepository") |
|
16
|
|
|
* @ORM\Table(name="plugin_paywall_payments") |
|
17
|
|
|
*/ |
|
18
|
|
|
class Payment implements PaymentInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @ORM\Id |
|
22
|
|
|
* @ORM\GeneratedValue |
|
23
|
|
|
* @ORM\Column(type="integer", name="id") |
|
24
|
|
|
* |
|
25
|
|
|
* @var int |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $id; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @ORM\ManyToOne(targetEntity="Order", inversedBy="payments") |
|
31
|
|
|
* @ORM\JoinColumn(name="order_id", referencedColumnName="id", nullable=false) |
|
32
|
|
|
* |
|
33
|
|
|
* @var OrderInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $order; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @ORM\Column(type="string", name="method") |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $method; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @ORM\Column(type="string", name="currency", length=3) |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $currency; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @ORM\Column(type="integer", name="total") |
|
53
|
|
|
* |
|
54
|
|
|
* @var int |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $amount = 0; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @ORM\Column(type="string", name="state") |
|
60
|
|
|
* |
|
61
|
|
|
* @var string |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $state = PaymentInterface::STATE_NEW; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @ORM\Column(type="datetime", name="created_at") |
|
67
|
|
|
* |
|
68
|
|
|
* @var \DateTime |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $createdAt; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @ORM\Column(type="datetime", name="updated_at") |
|
74
|
|
|
* |
|
75
|
|
|
* @var \DateTime |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $updatedAt; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @ORM\Column(type="json_array", name="details") |
|
81
|
|
|
* |
|
82
|
|
|
* @var array |
|
83
|
|
|
*/ |
|
84
|
|
|
protected $details = array(); |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Constructor. |
|
88
|
|
|
*/ |
|
89
|
|
|
public function __construct() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->createdAt = new \DateTime(); |
|
92
|
|
|
$this->updatedAt = new \DateTime(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* {@inheritdoc} |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getId() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->id; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* {@inheritdoc} |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getMethod() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->method; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* {@inheritdoc} |
|
113
|
|
|
*/ |
|
114
|
|
|
public function setMethod($method = null) |
|
115
|
|
|
{ |
|
116
|
|
|
$this->method = $method; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* {@inheritdoc} |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getCurrency() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->currency; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* {@inheritdoc} |
|
129
|
|
|
*/ |
|
130
|
|
|
public function setCurrency($currency) |
|
131
|
|
|
{ |
|
132
|
|
|
$this->currency = $currency; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* {@inheritdoc} |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getAmount() |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->amount / 100; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* {@inheritdoc} |
|
145
|
|
|
*/ |
|
146
|
|
|
public function setAmount($amount) |
|
147
|
|
|
{ |
|
148
|
|
|
$this->amount = $amount * 100; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* {@inheritdoc} |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getState() |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->state; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* {@inheritdoc} |
|
161
|
|
|
*/ |
|
162
|
|
|
public function setState($state) |
|
163
|
|
|
{ |
|
164
|
|
|
$this->state = $state; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* {@inheritdoc} |
|
169
|
|
|
*/ |
|
170
|
|
|
public function getCreatedAt() |
|
171
|
|
|
{ |
|
172
|
|
|
return $this->createdAt; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* {@inheritdoc} |
|
177
|
|
|
*/ |
|
178
|
|
|
public function setCreatedAt(\DateTime $createdAt) |
|
179
|
|
|
{ |
|
180
|
|
|
$this->createdAt = $createdAt; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* {@inheritdoc} |
|
185
|
|
|
*/ |
|
186
|
|
|
public function getUpdatedAt() |
|
187
|
|
|
{ |
|
188
|
|
|
return $this->updatedAt; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* {@inheritdoc} |
|
193
|
|
|
*/ |
|
194
|
|
|
public function setUpdatedAt(\DateTime $updatedAt) |
|
195
|
|
|
{ |
|
196
|
|
|
$this->updatedAt = $updatedAt; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* {@inheritdoc} |
|
201
|
|
|
*/ |
|
202
|
|
|
public function setDetails($details) |
|
203
|
|
|
{ |
|
204
|
|
|
if ($details instanceof \Traversable) { |
|
205
|
|
|
$details = iterator_to_array($details); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
if (!is_array($details)) { |
|
209
|
|
|
throw new \InvalidArgumentException($details.' is not an array'); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
$this->details = $details; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* {@inheritdoc} |
|
217
|
|
|
*/ |
|
218
|
|
|
public function getDetails() |
|
219
|
|
|
{ |
|
220
|
|
|
return $this->details; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Gets the order. |
|
225
|
|
|
* |
|
226
|
|
|
* @return OrderInterface Order |
|
227
|
|
|
*/ |
|
228
|
|
|
public function getOrder() |
|
229
|
|
|
{ |
|
230
|
|
|
return $this->order; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Sets the order. |
|
235
|
|
|
* |
|
236
|
|
|
* @param OrderInterface Order |
|
237
|
|
|
*/ |
|
238
|
|
|
public function setOrder(OrderInterface $order) |
|
239
|
|
|
{ |
|
240
|
|
|
$this->order = $order; |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|