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