1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\AcquiroPay\Message; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Purchase Request. |
7
|
|
|
* |
8
|
|
|
* @method Response send() |
9
|
|
|
*/ |
10
|
|
|
class PurchaseRequest extends AuthorizeRequest |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Get phone. |
14
|
|
|
* |
15
|
|
|
* @return string |
16
|
|
|
*/ |
17
|
30 |
|
public function getPhone() |
18
|
|
|
{ |
19
|
30 |
|
return $this->getParameter('phone'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Set phone. |
24
|
|
|
* |
25
|
|
|
* @param string $value |
26
|
|
|
* |
27
|
|
|
* @return static|\Omnipay\Common\Message\AbstractRequest |
28
|
|
|
*/ |
29
|
9 |
|
public function setPhone($value) |
30
|
|
|
{ |
31
|
9 |
|
return $this->setParameter('phone', $value); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get custom field 2. |
36
|
|
|
* |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
18 |
|
public function getCf2() |
40
|
|
|
{ |
41
|
18 |
|
return $this->getParameter('cf2'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Set custom field 2. |
46
|
|
|
* |
47
|
|
|
* @param string $value |
48
|
|
|
* |
49
|
|
|
* @return static|\Omnipay\Common\Message\AbstractRequest |
50
|
|
|
*/ |
51
|
9 |
|
public function setCf2($value) |
52
|
|
|
{ |
53
|
9 |
|
return $this->setParameter('cf2', $value); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get custom field 3. |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
18 |
|
public function getCf3() |
62
|
|
|
{ |
63
|
18 |
|
return $this->getParameter('cf3'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Set custom field 3. |
68
|
|
|
* |
69
|
|
|
* @param string $value |
70
|
|
|
* |
71
|
|
|
* @return static|\Omnipay\Common\Message\AbstractRequest |
72
|
|
|
*/ |
73
|
9 |
|
public function setCf3($value) |
74
|
|
|
{ |
75
|
9 |
|
return $this->setParameter('cf3', $value); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get callback URL. |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
18 |
|
public function getCallbackUrl() |
84
|
|
|
{ |
85
|
18 |
|
return $this->getParameter('callbackUrl'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Set callback URL. |
90
|
|
|
* |
91
|
|
|
* @param string $value |
92
|
|
|
* |
93
|
|
|
* @return static|\Omnipay\Common\Message\AbstractRequest |
94
|
|
|
*/ |
95
|
9 |
|
public function setCallbackUrl($value) |
96
|
|
|
{ |
97
|
9 |
|
return $this->setParameter('callbackUrl', $value); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get apple reference. |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
18 |
|
public function getAppleReference() |
106
|
|
|
{ |
107
|
18 |
|
return $this->getParameter('appleReference'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Set apple reference. |
112
|
|
|
* |
113
|
|
|
* @param string $value |
114
|
|
|
* |
115
|
|
|
* @return static|\Omnipay\Common\Message\AbstractRequest |
116
|
|
|
*/ |
117
|
3 |
|
public function setAppleReference($value) |
118
|
|
|
{ |
119
|
3 |
|
return $this->setParameter('appleReference', $value); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get the raw data array for this message. The format of this varies from gateway to |
124
|
|
|
* gateway, but will usually be either an associative array, or a SimpleXMLElement. |
125
|
|
|
* |
126
|
|
|
* @return array |
127
|
|
|
*/ |
128
|
18 |
|
public function getData() |
129
|
|
|
{ |
130
|
18 |
|
if ($this->getAppleReference() !== null) { |
131
|
3 |
|
$this->validate('amount', 'appleReference'); |
132
|
|
|
|
133
|
|
|
$data = [ |
134
|
3 |
|
'opcode' => 4, |
135
|
3 |
|
'product_id' => $this->getProductId(), |
136
|
3 |
|
'apple_token' => urlencode(base64_encode(json_encode($this->getAppleReference()))), |
137
|
3 |
|
'token' => $this->getRequestToken(), |
138
|
3 |
|
]; |
139
|
18 |
|
} elseif ($this->getCardReference() !== null) { |
140
|
3 |
|
$this->validate( |
141
|
3 |
|
'amount', |
142
|
3 |
|
'card', |
143
|
3 |
|
'cardReference', |
144
|
3 |
|
'transactionId', |
145
|
3 |
|
'clientIp', |
146
|
|
|
'returnUrl' |
147
|
3 |
|
); |
148
|
|
|
|
149
|
|
|
$data = [ |
150
|
3 |
|
'opcode' => 21, |
151
|
3 |
|
'product_id' => $this->getProductId(), |
152
|
3 |
|
'payment_id' => $this->getCardReference(), |
153
|
3 |
|
'amount' => $this->getAmount(), |
154
|
3 |
|
'cf' => $this->getTransactionId(), |
155
|
3 |
|
'ip_address' => $this->getClientIp(), |
156
|
3 |
|
'cvv' => $this->getCard()->getCvv(), |
157
|
3 |
|
'pp_identity' => 'card', |
158
|
3 |
|
'token' => $this->getRequestToken(), |
159
|
3 |
|
]; |
160
|
3 |
|
} else { |
161
|
12 |
|
$this->validate( |
162
|
12 |
|
'amount', |
163
|
12 |
|
'card', |
164
|
12 |
|
'transactionId', |
165
|
12 |
|
'clientIp', |
166
|
|
|
'returnUrl' |
167
|
12 |
|
); |
168
|
|
|
|
169
|
12 |
|
$card = $this->getCard(); |
170
|
|
|
|
171
|
12 |
|
$card->validate(); |
172
|
|
|
|
173
|
|
|
$data = [ |
174
|
12 |
|
'opcode' => 0, |
175
|
12 |
|
'product_id' => $this->getProductId(), |
176
|
12 |
|
'amount' => $this->getAmount(), |
177
|
12 |
|
'cf' => $this->getTransactionId(), |
178
|
12 |
|
'ip_address' => $this->getClientIp(), |
179
|
12 |
|
'pan' => $card->getNumber(), |
180
|
12 |
|
'cardholder' => $card->getName(), |
181
|
12 |
|
'exp_month' => $card->getExpiryMonth(), |
182
|
12 |
|
'exp_year' => $card->getExpiryYear(), |
183
|
12 |
|
'cvv' => $card->getCvv(), |
184
|
12 |
|
'pp_identity' => 'card', |
185
|
12 |
|
'token' => $this->getRequestToken(), |
186
|
12 |
|
]; |
187
|
|
|
} |
188
|
|
|
|
189
|
18 |
|
if ($this->getPhone()) { |
190
|
9 |
|
$data['phone'] = $this->getPhone(); |
191
|
9 |
|
} |
192
|
18 |
|
if ($this->getCf2()) { |
193
|
9 |
|
$data['cf2'] = $this->getCf2(); |
194
|
9 |
|
} |
195
|
18 |
|
if ($this->getCf3()) { |
196
|
9 |
|
$data['cf3'] = $this->getCf3(); |
197
|
9 |
|
} |
198
|
18 |
|
if ($this->getCallbackUrl()) { |
199
|
9 |
|
$data['cb_url'] = $this->getCallbackUrl(); |
200
|
9 |
|
} |
201
|
|
|
|
202
|
18 |
|
return $data; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Get a request token. |
207
|
|
|
* |
208
|
|
|
* @return string |
209
|
|
|
*/ |
210
|
30 |
|
public function getRequestToken() |
211
|
|
|
{ |
212
|
30 |
|
return md5($this->getMerchantId().$this->getProductId().$this->getAmount().$this->getTransactionId().$this->getPhone().$this->getSecretWord()); |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|