1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Good One Sales |
5
|
|
|
* Date: 9/3/2018 |
6
|
|
|
* Time: 5:01 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Goodoneuz\PayUz\Http\Classes\Paynet; |
10
|
|
|
|
11
|
|
|
class Request |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
public $method; |
15
|
|
|
|
16
|
|
|
const ARGUMENTS_PerformTransaction = 'PerformTransactionArguments'; |
17
|
|
|
const ARGUMENTS_CheckTransaction = 'CheckTransactionArguments'; |
18
|
|
|
const ARGUMENTS_GetStatement = 'GetStatementArguments'; |
19
|
|
|
const ARGUMENTS_CancelTransaction = 'CancelTransactionArguments'; |
20
|
|
|
const ARGUMENTS_GetInformation = 'GetInformationArguments'; |
21
|
|
|
|
22
|
|
|
const METHOD_PerformTransaction = 'PerformTransaction'; |
23
|
|
|
const METHOD_CheckTransaction = 'CheckTransaction'; |
24
|
|
|
const METHOD_GetStatement = 'GetStatement'; |
25
|
|
|
const METHOD_CancelTransaction = 'CancelTransaction'; |
26
|
|
|
const METHOD_GetInformation = 'GetInformation'; |
27
|
|
|
|
28
|
|
|
public $params; |
29
|
|
|
private $response; |
30
|
|
|
|
31
|
|
|
public function __construct($response) |
32
|
|
|
{ |
33
|
|
|
$this->response = $response; |
34
|
|
|
$this->params = []; |
35
|
|
|
$arr_params = $this->getRequestArray(); |
36
|
|
|
$this->loadAccount($arr_params); |
37
|
|
|
|
38
|
|
|
foreach ($arr_params as $key => $value){ |
39
|
|
|
switch ($key){ |
40
|
|
|
case self::ARGUMENTS_PerformTransaction: |
41
|
|
|
$this->paramsPerformTransaction($arr_params[self::ARGUMENTS_PerformTransaction]); |
42
|
|
|
break; |
43
|
|
|
case self::ARGUMENTS_CheckTransaction: |
44
|
|
|
$this->paramsCheckTransaction($arr_params[self::ARGUMENTS_CheckTransaction]); |
45
|
|
|
break; |
46
|
|
|
case self::ARGUMENTS_GetStatement: |
47
|
|
|
$this->paramsStament($arr_params[self::ARGUMENTS_GetStatement]); |
48
|
|
|
break; |
49
|
|
|
case self::ARGUMENTS_CancelTransaction: |
50
|
|
|
$this->paramsCancel($arr_params[self::ARGUMENTS_CancelTransaction]); |
51
|
|
|
break; |
52
|
|
|
case self::ARGUMENTS_GetInformation: |
53
|
|
|
$this->paramsInformation($arr_params[self::ARGUMENTS_GetInformation]); |
54
|
|
|
break; |
55
|
|
|
default: |
56
|
|
|
$this->response->response($this,'Error in request', Response::ERROR_METHOD_NOT_FOUND); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
public function loadAccount($arr_params){ |
61
|
|
|
$arr_params = array_values($arr_params)[0]; |
62
|
|
|
|
63
|
|
|
$this->params['account'] = [ |
64
|
|
|
'login' => $arr_params['username'], |
65
|
|
|
'password' => $arr_params['password'] |
66
|
|
|
]; |
67
|
|
|
$this->params['serviceId'] = $arr_params['serviceId']; |
68
|
|
|
} |
69
|
|
|
public function getRequestArray(){ |
70
|
|
|
$request_body = file_get_contents('php://input'); |
71
|
|
|
$clean_xml = str_ireplace(['soapenv:', 'soap:','xmlns:','xsi:','ns1:'], '', $request_body); |
72
|
|
|
$xml = simplexml_load_string($clean_xml); |
73
|
|
|
$body = null; |
74
|
|
|
if ($xml) |
75
|
|
|
$body = $xml->Body; |
|
|
|
|
76
|
|
|
else |
77
|
|
|
$this->response->response($this,'Error in request', Response::ERROR_INVALID_JSON_RPC_OBJECT); |
78
|
|
|
|
79
|
|
|
return json_decode(json_encode($body),1); |
80
|
|
|
} |
81
|
|
|
public function paramsPerformTransaction($par){ |
82
|
|
|
$res = [ |
83
|
|
|
'method' => self::METHOD_PerformTransaction, |
84
|
|
|
'amount' => $par['amount'], |
85
|
|
|
'transactionId' => $par['transactionId'], |
86
|
|
|
'transactionTime' => $par['transactionTime'], |
87
|
|
|
'key' => $par['parameters']['paramValue'] |
88
|
|
|
]; |
89
|
|
|
$this->params = array_merge($this->params, $res); |
90
|
|
|
} |
91
|
|
View Code Duplication |
public function paramsCheckTransaction($par){ |
|
|
|
|
92
|
|
|
$res = [ |
93
|
|
|
'method' => self::METHOD_CheckTransaction, |
94
|
|
|
'transactionId' => $par['transactionId'], |
95
|
|
|
'transactionTime' => $par['transactionTime'], |
96
|
|
|
]; |
97
|
|
|
$this->params = array_merge($this->params, $res); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
private function paramsStament($par) |
101
|
|
|
{ |
102
|
|
|
$res = [ |
103
|
|
|
'method' => self::METHOD_GetStatement, |
104
|
|
|
'dateFrom' => $par['dateFrom'], |
105
|
|
|
'dateTo' => $par['dateTo'] |
106
|
|
|
]; |
107
|
|
|
$this->params = array_merge($this->params, $res); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
View Code Duplication |
private function paramsCancel($par) |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
$res = [ |
113
|
|
|
'method' => self::METHOD_CancelTransaction, |
114
|
|
|
'transactionId' => $par['transactionId'], |
115
|
|
|
'transactionTime' => $par['transactionTime'] |
116
|
|
|
]; |
117
|
|
|
$this->params = array_merge($this->params, $res); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
private function paramsInformation($par) |
121
|
|
|
{ |
122
|
|
|
$res = [ |
123
|
|
|
'method' => self::METHOD_GetInformation, |
124
|
|
|
'key' => $par['parameters']['paramValue'] |
125
|
|
|
]; |
126
|
|
|
$this->params = array_merge($this->params, $res); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.