GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 8bf793...f49fde )
by Shaxzodbek
01:23
created

WoywoController::getMAC()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Classes;
4
5
use App\Order;
6
use App\Transaction;
7
use Goodoneuz\PayUz\Http\Classes\Paycom\Format;
8
use Goodoneuz\PayUz\Http\Classes\Paycom\Request;
9
use Goodoneuz\PayUz\Http\Classes\Uzcard\Merchant;
10
use Goodoneuz\PayUz\Http\Classes\Uzcard\WoywoException;
11
use Goodoneuz\PayUz\Http\Classes\BaseGateway;
12
13
14
class WoywoController extends BaseGateway
15
{
16
    public $config;
17
    public $request;
18
    public $merchant;
19
20
    public function __construct($request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22
23
        $this->config   = [
24
            'merchant_id' => env('WOYWO_MERCHANT_ID',null),
25
            'key'     => env('WOYWO_KEY',null),
26
        ];
27
        $request_body  = file_get_contents('php://input');
28
        $this->request  = json_decode($request_body, true);
29
        $this->merchant = new Merchant($this->config);
30
    }
31
    public function run(){
32
        try {
33
            switch ($this->request['billType']) {
34
                case 'CHECK':
35
                    $this->CheckTransaction();
36
                    break;
37
                case 'PAY':
38
                    $this->PayTransaction();
39
                    break;
40
                default:
41
                    throw new WoywoException(WoywoException::ERROR_METHOD_NOT_FOUND);
42
43
            }
44
        }catch (WoywoException $exception){
0 ignored issues
show
Bug introduced by
The class Goodoneuz\PayUz\Http\Classes\Uzcard\WoywoException does not exist. Did you forget a USE statement, or did you not list all dependencies?

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.

Loading history...
45
            $exception->send();
46
        }
47
    }
48
    public function CheckTransaction(){
49
        if (!isset($this->request['order_id'])|| !isset($this->request['amount']))
50
            throw new WoywoException(WoywoException::ERROR_INSUFFICIENT_PRIVILEGE);
51
52
        $order = Order::find($this->request['order_id']);
53
        if ($order) {
54
            if (!$order)
55
                throw new WoywoException(WoywoException::ERROR_ORDER_NOT_FOUND);
56
            if ($order->state == Order::STATE_PAY_ACCEPTED)
57
                throw new WoywoException(WoywoException::ERROR_ALREADY_PAID);
58
            if ($order->state != Order::STATE_AVAILABLE)
59
                throw new WoywoException(WoywoException::ERROR_ORDER_NOT_AVAILABLE);
60
            if ($order->price != $this->request['amount'])
61
                throw new WoywoException(WoywoException::ERROR_INVALID_AMOUNT);
62
        }
63
        throw new WoywoException(WoywoException::SUCCESS);
64
    }
65
    public function PayTransaction(){
66
        try {
67
            $this->CheckTransaction();
68
        } catch (WoywoException $e) {
0 ignored issues
show
Bug introduced by
The class Goodoneuz\PayUz\Http\Classes\Uzcard\WoywoException does not exist. Did you forget a USE statement, or did you not list all dependencies?

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.

Loading history...
69
            if ($e->status != WoywoException::SUCCESS)
70
                $e->send();
71
        }
72
        if (is_null($this->request['mac']) || is_null($this->request['tran_date'])
73
            || is_null($this->request['tran_id']))
74
            throw new WoywoException(WoywoException::ERROR_INSUFFICIENT_PRIVILEGE);
75
76
        $mac = $this->getMAC();
77
        if ($this->request['mac'] != $mac)
78
            throw new WoywoException(WoywoException::ERROR_INSUFFICIENT_PRIVILEGE);
79
80
        $create_time                        = Format::timestamp(true);
81
        $transaction                        = new Transaction();
82
        $transaction->payment_system        = Transaction::WOYWO;
83
        $transaction->system_transaction_id = $this->request['tran_id'];
84
        $transaction->system_time           = $this->request['tran_date'];
85
        $transaction->system_time_datetime  = Format::timestamp2datetime($this->request['tran_date']);
86
        $transaction->create_time           = Format::timestamp2datetime($create_time);
87
        $transaction->state                 = Transaction::STATE_COMPLETED;
88
        $transaction->amount                = $this->request['amount'];
89
        $transaction->currency_code         = Transaction::CODE_UZS;
90
        $transaction->order_id              = $this->request['order_id'];
91
        $transaction->save(); // after save $transaction->id will be populated with the newly created transaction's id.
92
93
        $order = Order::find($this->request['order_id']);
94
        $str = "Pul o'tkazishi  muvofaqqiyatli yakunlandi ✅";
95
        if ($order) {
96
            $order->changeState(Order::STATE_PAY_ACCEPTED);
97
            $str = $str
98
                . "\n<b>Buyurtma raqami 📥</b>: " . $order->id
99
                . "\n<b>Sug'urtalanuvchi 👥</b>: " . $order->user->detail->name
100
                . " \n<b>Summasi 💰:</b>" . $order->price . " sum ."
101
                . "\n<b>To'lov tizimi:</b> Uzcard";
102
        }else{
103
            $str = $str
104
                . "\n<b>Buyurtma raqami 📥</b>: " . $this->request['order_id']
105
                . " \n<b>Summasi 💰:</b>" . $this->request['amount'] . " sum ."
106
                . "\n<b>To'lov tizimi:</b> Uzcard";;
107
        }
108
        TelegramController::send($str);
109
        // $temp = cURL::send_result($transaction);
110
111
        throw new WoywoException(WoywoException::SUCCESS);
112
113
    }
114
    public static function getRedirectParams($order)
115
    {
116
        $hash = base64_encode('m='.env('WOYWO_MERCHANT_ID').';ac.order_id='.$order->id.';a='.$order->price.';r='.urlencode(route('home')));
117
        return [
118
            'base64' => $hash
119
        ];
120
    }
121
    public function getMAC() {
122
        $str = $this->config['key'] . $this->config['merchant_id'] .
123
                $this->request['order_id'] . $this->request['tran_date'] . $this->request['amount'];
124
        return sha1($str);
125
    }
126
}
127