|
1
|
|
|
<?php |
|
2
|
|
|
namespace Omnipay\Gtpay\Message; |
|
3
|
|
|
|
|
4
|
|
|
use Omnipay\Common\Exception\InvalidRequestException; |
|
5
|
|
|
use Omnipay\Common\Exception\InvalidResponseException; |
|
6
|
|
|
|
|
7
|
|
|
class CompletePurchaseRequest extends AbstractRequest |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
11 |
|
public function getData() |
|
11
|
|
|
{ |
|
12
|
11 |
|
$data = $this->httpRequest->request->all(); |
|
13
|
|
|
|
|
14
|
11 |
|
if (empty($data)) { |
|
15
|
1 |
|
throw new InvalidRequestException('No Request Body Found'); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
10 |
|
return $this->mergeResponse($this->queryGateway(), $data); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
10 |
|
public function sendData($data) |
|
22
|
|
|
{ |
|
23
|
10 |
|
return new CompletePurchaseResponse($this, $data); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
10 |
|
public function queryGateway() |
|
28
|
|
|
{ |
|
29
|
|
|
$param = [ |
|
30
|
10 |
|
'tranxid' => $this->getTransactionId(), |
|
31
|
10 |
|
'amount' => $this->getAmountInteger(), |
|
32
|
10 |
|
'mertid' => $this->getMerchantId(), |
|
33
|
10 |
|
'hash'=>$this->getVerificationHash() |
|
34
|
|
|
]; |
|
35
|
10 |
|
$response = $this->httpClient->get( |
|
36
|
10 |
|
$this->getWebserviceUrl(), |
|
37
|
10 |
|
null, |
|
38
|
10 |
|
['query'=>$param,'read_timeout'=>60] |
|
39
|
10 |
|
)->send(); |
|
40
|
|
|
|
|
41
|
10 |
|
if ($response->getStatusCode() !== 200) { |
|
42
|
|
|
throw new InvalidResponseException(); |
|
43
|
|
|
} |
|
44
|
10 |
|
$body = (string) $response->getBody(); |
|
45
|
10 |
|
return json_decode($body, true); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
10 |
|
private function getVerificationHash() |
|
49
|
|
|
{ |
|
50
|
10 |
|
$hashString = $this->getMerchantId() . $this->getTransactionId() . $this->getHashKey(); |
|
51
|
10 |
|
return hash('sha512', $hashString); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
10 |
|
private function mergeResponse($newResponse, $data) |
|
55
|
|
|
{ |
|
56
|
10 |
|
if (empty($data)) { |
|
57
|
|
|
return $newResponse; |
|
58
|
|
|
} |
|
59
|
10 |
|
return array_merge($data, $newResponse); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|