|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Goodoneuz\PayUz\Http\Classes\Click; |
|
4
|
|
|
|
|
5
|
|
|
use Goodoneuz\PayUz\Models\PaymentSystem; |
|
6
|
|
|
use Goodoneuz\PayUz\Http\Classes\PaymentException; |
|
7
|
|
|
use Goodoneuz\PayUz\Services\PaymentSystemService; |
|
8
|
|
|
|
|
9
|
|
|
class Merchant{ |
|
10
|
|
|
private $config; |
|
11
|
|
|
private $response; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
public function __construct($response) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->config = PaymentSystemService::getPaymentSystemParamsCollect(PaymentSystem::CLICK); |
|
17
|
|
|
$this->response = $response; |
|
18
|
|
|
} |
|
19
|
|
|
public function validateRequest($request){ |
|
20
|
|
|
$result = false; |
|
21
|
|
|
switch($request['action']){ |
|
22
|
|
|
case Click::REQUEST_PREPARE: |
|
23
|
|
|
$result = $this->validatePrepareRequest($request); |
|
24
|
|
|
break; |
|
25
|
|
|
case Click::REQUEST_COMPLATE: |
|
26
|
|
|
$result = $this->validateCompleteRequest($request); |
|
27
|
|
|
break; |
|
28
|
|
|
} |
|
29
|
|
|
if($request['service_id'] != $this->config['service_id'] || !$result){ |
|
30
|
|
|
echo $result; |
|
31
|
|
|
$this->response->setResult(Response::ERROR_SIGN_CHECK); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
View Code Duplication |
public function validatePrepareRequest($request) |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$sign = md5($request['click_trans_id'] . |
|
37
|
|
|
$request['service_id'] . $this->config['secret_key'] . |
|
38
|
|
|
$request['merchant_trans_id'] . $request['amount'] . |
|
39
|
|
|
$request['action'] . $request['sign_time']); |
|
40
|
|
|
// echo $sign .'/'. $request['sign_string']; |
|
41
|
|
|
return $sign == $request['sign_string']; |
|
42
|
|
|
} |
|
43
|
|
View Code Duplication |
public function validateCompleteRequest($request) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
$sign = md5( |
|
46
|
|
|
$request['click_trans_id'] . $request['service_id'] . |
|
47
|
|
|
$this->config['secret_key'] . $request['merchant_trans_id'] . |
|
48
|
|
|
$request['merchant_prepare_id'] . $request['amount'] . |
|
49
|
|
|
$request['action'] . $request['sign_time']); |
|
50
|
|
|
// echo $sign; |
|
51
|
|
|
return $sign == $request['sign_string']; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
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.