1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tzsk\Payu\Verifiers; |
4
|
|
|
|
5
|
|
|
class MoneyVerifier extends AbstractVerifier |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @return object |
9
|
|
|
*/ |
10
|
|
View Code Duplication |
public function verify() |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
try { |
13
|
|
|
$response = $this->client->request('POST', $this->url(), [ |
|
|
|
|
14
|
|
|
'headers' => [ |
15
|
|
|
'Authorization' => $this->config->getAuth() |
16
|
|
|
], |
17
|
|
|
]); |
18
|
|
|
|
19
|
|
|
return $this->makeResponse(json_decode($response->getBody())); |
|
|
|
|
20
|
|
|
} catch (\Exception $e) { |
21
|
|
|
return (object) ['status' => false, 'message' => $e->getMessage()]; |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
protected function url() |
29
|
|
|
{ |
30
|
|
|
$src = "https://www.payumoney.com/{$this->prefix()}payment/op/getPaymentResponse?"; |
31
|
|
|
|
32
|
|
|
return $src . http_build_query($this->fields()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
protected function fields() |
39
|
|
|
{ |
40
|
|
|
return [ |
41
|
|
|
'merchantKey' => $this->config->getKey(), |
42
|
|
|
'merchantTransactionIds' => implode("|", $this->txnIds) |
43
|
|
|
]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
protected function prefix() |
50
|
|
|
{ |
51
|
|
|
$env = $this->config->getEnv(); |
52
|
|
|
|
53
|
|
|
return ($env == 'test') ? 'sandbox/' : ''; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param object $data |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
protected function makeResponse($data) |
61
|
|
|
{ |
62
|
|
|
if (!empty($data->errorCode)) { |
63
|
|
|
return (object) ['status' => false, 'data' => [], 'message' => $data->message]; |
64
|
|
|
} |
65
|
|
|
$response = ['status' => true, 'data' => [], 'message' => '']; |
66
|
|
|
$collection = collect($data->result)->pluck('postBackParam', 'merchantTransactionId'); |
67
|
|
|
|
68
|
|
|
foreach($this->txnIds as $id) { |
69
|
|
|
if (! empty($collection[$id])) { |
70
|
|
|
$response['data'][$id] = $this->getInstance($collection[$id]); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return (object) $response; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.