1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Classes; |
4
|
|
|
|
5
|
|
|
use App\Order; |
6
|
|
|
use App\Transaction; |
7
|
|
|
use Goodoneuz\PayUz\Classes\DataFormat; |
8
|
|
|
use Goodoneuz\PayUz\Classes\Oson\Merchant; |
9
|
|
|
use Goodoneuz\PayUz\Classes\Paycom\Request; |
10
|
|
|
use Goodoneuz\PayUz\Http\Classes\BaseGateway; |
11
|
|
|
use Goodoneuz\PayUz\Classes\Oson\OsonException; |
12
|
|
|
|
13
|
|
|
class Oson extends BaseGateway |
14
|
|
|
{ |
15
|
|
|
public $config; |
16
|
|
|
public $request; |
17
|
|
|
public $merchant; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* OsonController constructor. |
21
|
|
|
* @param $request |
22
|
|
|
*/ |
23
|
|
|
public function __construct($request) |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
$this->config = [ |
27
|
|
|
'login' => env('OSON_LOGIN',null), |
28
|
|
|
'password' => env('OSON_PASSWORD',null), |
29
|
|
|
]; |
30
|
|
|
$this->request = new Request(); |
31
|
|
|
$this->merchant = new Merchant($this->config,$request['params']['acc']); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
*/ |
37
|
|
|
public function run(){ |
38
|
|
|
try { |
39
|
|
|
$this->merchant->checkAuth(); |
40
|
|
|
switch ($this->request['method']) { |
41
|
|
|
case 'user.check': |
42
|
|
|
$this->CheckTransaction(); |
43
|
|
|
break; |
44
|
|
|
case 'transaction.perform': |
45
|
|
|
$this->PayTransaction(); |
46
|
|
|
break; |
47
|
|
|
default: |
48
|
|
|
throw new OsonException(OsonException::ERROR_UNKNOWN,[]); |
49
|
|
|
|
50
|
|
|
} |
51
|
|
|
}catch (OsonException $exception){ |
|
|
|
|
52
|
|
|
$exception->send(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
public function CheckTransaction(){ |
56
|
|
|
if (!isset($this->request['params']) || !isset($this->request['params']['info'])) |
57
|
|
|
throw new OsonException(OsonException::ERROR_INVALID_AMOUNT,[]); |
58
|
|
|
|
59
|
|
|
$order = Order::where('id', $this->request['params']['info']['login'])->first(); //todo login may change in feature |
60
|
|
|
if ($order) |
61
|
|
|
{ |
62
|
|
|
if($order->state == Order::STATE_PAY_ACCEPTED) |
63
|
|
|
throw new OsonException(OsonException::ERROR_ALREADY_PAID,[]); |
64
|
|
|
if ($order->state != Order::STATE_AVAILABLE) |
65
|
|
|
throw new OsonException(OsonException::ERROR_ORDER_NOT_AVAILABLE,[]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
throw new OsonException(OsonException::SUCCESS,['exist' => true]); |
69
|
|
|
} |
70
|
|
|
public function PayTransaction(){ |
71
|
|
|
try { |
72
|
|
|
$this->CheckTransaction(); |
73
|
|
|
} catch (OsonException $e) { |
|
|
|
|
74
|
|
|
if ($e->status != OsonException::SUCCESS) |
75
|
|
|
$e->send(); |
76
|
|
|
} |
77
|
|
|
if (is_null($this->request['params']['trans']) || is_null($this->request['params']['trans']['time']) |
78
|
|
|
|| is_null($this->request['params']['trans']['transID'])) |
79
|
|
|
throw new OsonException(OsonException::ERROR_INSUFFICIENT_PRIVILEGE,[]); |
80
|
|
|
$order = Order::find($this->request['params']['trans']['login']); //todo login may change in feature |
81
|
|
|
|
82
|
|
|
if ($order){ |
83
|
|
|
if ($order->state == Order::STATE_PAY_ACCEPTED) |
84
|
|
|
throw new OsonException(OsonException::ERROR_ALREADY_PAID, []); |
85
|
|
|
if ($order->state != Order::STATE_WAITING_PAY) |
86
|
|
|
throw new OsonException(OsonException::ERROR_ALREADY_PAID, []); |
87
|
|
|
if ($order->price != $this->request['params']['trans']['amount']) |
88
|
|
|
throw new OsonException(OsonException::ERROR_INVALID_AMOUNT, ['prividerTrnId' => $this->request['params']['trans']['transID'], 'ts' => $this->request['params']['trans']['time']]); |
89
|
|
|
$order->changeState(Order::STATE_PAY_ACCEPTED); |
90
|
|
|
} |
91
|
|
|
$create_time = DataFormat::timestamp(true); |
92
|
|
|
$transaction = new Transaction(); |
93
|
|
|
$transaction->payment_system = Transaction::OSON; |
94
|
|
|
$transaction->system_transaction_id = $this->request['params']['trans']['transID']; |
95
|
|
|
$transaction->system_time = DataFormat::datetime2timestamp($this->request['params']['trans']['time']); |
96
|
|
|
$transaction->system_time_datetime = $this->request['params']['trans']['time']; |
97
|
|
|
$transaction->create_time = DataFormat::timestamp2datetime($create_time); |
98
|
|
|
$transaction->state = Transaction::STATE_COMPLETED; |
99
|
|
|
$transaction->amount = $this->request['params']['trans']['amount']; |
100
|
|
|
$transaction->currency_code = Transaction::CODE_UZS; |
101
|
|
|
$transaction->order_id = $this->request['params']['trans']['login']; |
102
|
|
|
$transaction->save(); |
103
|
|
|
|
104
|
|
|
throw new OsonException(OsonException::SUCCESS,['prividerTrnId'=>$this->request['params']['trans']['transID'],'ts'=>$this->request['params']['trans']['time'],'order_state'=>Order::STATE_PAY_ACCEPTED]); |
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
public static function getRedirectParams($order) |
108
|
|
|
{ |
109
|
|
|
return [ |
110
|
|
|
'merchant' => env('OSON_MERCHANT_ID'), |
111
|
|
|
'amount' => $order->price, |
112
|
|
|
'account' => $order->id, |
113
|
|
|
'description' => 'Kafolat Sug\'urta kompaniyasi', |
114
|
|
|
'callback' => route('payment.handle.result',['payment'=>'oson', 'type' => 'accept', 'order_id' => $order->id, 'state' => 'ok']) |
115
|
|
|
]; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.