|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Goodoneuz\PayUz\Http\Classes\Payme; |
|
4
|
|
|
|
|
5
|
|
|
use Goodoneuz\PayUz\Http\Classes\PaymentException; |
|
6
|
|
|
|
|
7
|
|
|
class Response |
|
8
|
|
|
{ |
|
9
|
|
|
const ERROR_INTERNAL_SYSTEM = -32400; |
|
10
|
|
|
const ERROR_INSUFFICIENT_PRIVILEGE = -32504; |
|
11
|
|
|
const ERROR_INVALID_JSON_RPC_OBJECT = -32600; |
|
12
|
|
|
const ERROR_METHOD_NOT_FOUND = -32601; |
|
13
|
|
|
const ERROR_INVALID_AMOUNT = -31001; |
|
14
|
|
|
const ERROR_TRANSACTION_NOT_FOUND = -31003; |
|
15
|
|
|
const ERROR_INVALID_ACCOUNT = -31050; |
|
16
|
|
|
const ERROR_INVALID_TRANSACTION = -31051; |
|
17
|
|
|
const ERROR_COULD_NOT_CANCEL = -31007; |
|
18
|
|
|
const ERROR_COULD_NOT_PERFORM = -31008; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
public $response; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Response constructor. |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->response = []; |
|
32
|
|
|
$this->response['jsonrpc'] = '2.0'; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* |
|
38
|
|
|
*/ |
|
39
|
|
|
public function send() |
|
40
|
|
|
{ |
|
41
|
|
|
if(env('APP_ENV') != 'testing') |
|
42
|
|
|
header('Content-Type: application/json; charset=UTF-8'); |
|
43
|
|
|
echo json_encode($this->response); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param $code |
|
48
|
|
|
* @param null $message |
|
49
|
|
|
* @param null $data |
|
50
|
|
|
* @throws PaymentException |
|
51
|
|
|
*/ |
|
52
|
|
|
public function error($code, $message = null, $data = null) |
|
53
|
|
|
{ |
|
54
|
|
|
// prepare error data |
|
55
|
|
|
$error = ['code' => $code]; |
|
56
|
|
|
|
|
57
|
|
|
if ($message) |
|
58
|
|
|
$error['message'] = $message; |
|
59
|
|
|
|
|
60
|
|
|
if ($data) |
|
61
|
|
|
$error['data'] = $data; |
|
62
|
|
|
|
|
63
|
|
|
$this->response['result'] = null; |
|
64
|
|
|
$this->response['error'] = $error; |
|
65
|
|
|
throw new PaymentException($this); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param $result |
|
70
|
|
|
* @throws PaymentException |
|
71
|
|
|
*/ |
|
72
|
|
|
public function success($result){ |
|
73
|
|
|
$this->response['result'] = $result; |
|
74
|
|
|
$this->response['error'] = null; |
|
75
|
|
|
throw new PaymentException($this); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param $ru |
|
80
|
|
|
* @param string $uz |
|
81
|
|
|
* @param string $en |
|
82
|
|
|
* @return array |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function message($ru, $uz = '', $en = '') |
|
85
|
|
|
{ |
|
86
|
|
|
return ['ru' => $ru, 'uz' => $uz, 'en' => $en]; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param $request |
|
91
|
|
|
*/ |
|
92
|
|
|
public function setRequest($request) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->response['id'] = $request->id; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|