1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Larium\Pay\Transaction; |
4
|
|
|
|
5
|
|
|
use Larium\Pay\ParamsBag; |
6
|
|
|
use Larium\Pay\Transaction\Sale; |
7
|
|
|
use Larium\CreditCard\CreditCard; |
8
|
|
|
|
9
|
|
|
abstract class SaleTransaction implements Sale |
10
|
|
|
{ |
11
|
|
|
use Commit; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var int |
15
|
|
|
*/ |
16
|
|
|
private $amount = 0; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $currency = ''; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var CreditCard |
25
|
|
|
*/ |
26
|
|
|
private $card; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ParamsBag |
30
|
|
|
*/ |
31
|
|
|
private $address; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $merchantReference; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $clientIp; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
private $description; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
private $customerEmail; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var ParamsBag |
55
|
|
|
*/ |
56
|
|
|
private $extraOptions; |
57
|
|
|
|
58
|
8 |
|
public function __construct( |
59
|
|
|
$amount, |
60
|
|
|
CreditCard $card, |
61
|
|
|
array $extraOptions = [] |
62
|
|
|
) { |
63
|
8 |
|
$this->amount = $amount; |
64
|
8 |
|
$this->card = $card; |
65
|
8 |
|
$this->extraOptions = new ParamsBag($extraOptions); |
66
|
8 |
|
$this->address = new ParamsBag(); |
67
|
8 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
1 |
|
public function getCard() |
73
|
|
|
{ |
74
|
1 |
|
return $this->card; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
1 |
|
public function getAmount() |
81
|
|
|
{ |
82
|
1 |
|
return $this->amount; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
1 |
|
public function getAddress() |
89
|
|
|
{ |
90
|
1 |
|
return $this->address; |
91
|
|
|
} |
92
|
|
|
|
93
|
1 |
|
public function setAddress(array $address) |
94
|
|
|
{ |
95
|
1 |
|
$this->allowChanges(); |
96
|
1 |
|
$this->address = new ParamsBag($address); |
97
|
1 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
*/ |
102
|
|
|
public function getMerchantReference() |
103
|
|
|
{ |
104
|
|
|
return $this->merchantReference; |
105
|
|
|
} |
106
|
|
|
|
107
|
1 |
|
public function setMerchantReference($merchantReference) |
108
|
|
|
{ |
109
|
1 |
|
$this->allowChanges(); |
110
|
1 |
|
$this->merchantReference = $merchantReference; |
111
|
1 |
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
1 |
|
public function getClientIp() |
117
|
|
|
{ |
118
|
1 |
|
return $this->clientIp; |
119
|
|
|
} |
120
|
|
|
|
121
|
1 |
|
public function setClientIp($clientIp) |
122
|
|
|
{ |
123
|
1 |
|
$this->allowChanges(); |
124
|
1 |
|
$this->clientIp = $clientIp; |
125
|
1 |
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* {@inheritdoc} |
129
|
|
|
*/ |
130
|
1 |
|
public function getDescription() |
131
|
|
|
{ |
132
|
1 |
|
return $this->description; |
133
|
|
|
} |
134
|
|
|
|
135
|
2 |
|
public function setDescription($description) |
136
|
|
|
{ |
137
|
2 |
|
$this->allowChanges(); |
138
|
1 |
|
$this->description = $description; |
139
|
1 |
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* {@inheritdoc} |
143
|
|
|
*/ |
144
|
1 |
|
public function getCustomerEmail() |
145
|
|
|
{ |
146
|
1 |
|
return $this->customerEmail; |
147
|
|
|
} |
148
|
|
|
|
149
|
1 |
|
public function setCustomerEmail($customerEmail) |
150
|
|
|
{ |
151
|
1 |
|
$this->allowChanges(); |
152
|
1 |
|
$this->customerEmail = $customerEmail; |
153
|
1 |
|
} |
154
|
|
|
|
155
|
6 |
|
public function canCommit() |
156
|
|
|
{ |
157
|
6 |
|
return $this->card instanceof CreditCard |
158
|
6 |
|
&& $this->amount > 0; |
159
|
|
|
} |
160
|
|
|
|
161
|
1 |
|
public function getExtraOptions() |
162
|
|
|
{ |
163
|
1 |
|
return $this->extraOptions; |
164
|
|
|
} |
165
|
|
|
|
166
|
1 |
|
public function setCurrency($currency) |
167
|
|
|
{ |
168
|
1 |
|
$this->allowChanges(); |
169
|
1 |
|
$this->currency = $currency; |
170
|
1 |
|
} |
171
|
|
|
|
172
|
1 |
|
public function getCurrency() |
173
|
|
|
{ |
174
|
1 |
|
return $this->currency; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|