Response::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 23
rs 9.4888
cc 5
nc 5
nop 1
1
<?php
2
3
namespace DeveloperH\Knet\SDK;
4
5
use Config;
6
7
class Response extends Client
8
{
9
    /**
10
     * @var \Illuminate\Http\Request
11
     */
12
    private $request;
13
    private $result = [];
14
15
    /**
16
     * Response constructor.
17
     *
18
     * @param \Illuminate\Http\Request $request
19
     */
20
    public function __construct(\Illuminate\Http\Request $request)
21
    {
22
        $this->request = $request;
23
        $ResTranData = $request->get('trandata');
24
        if ($ResTranData) {
25
            $decryptedData = explode('&', $this->decrypt($ResTranData, Config::get('knet.resource_key')));
26
            foreach ($decryptedData as $datum) {
27
                $temp = explode('=', $datum);
28
                if (isset($temp[1])) {
29
                    if ($temp[0] == 'result') {
30
                        $temp[1] = implode(' ', explode('+', $temp[1]));
31
                        $this->result['paid'] = $temp[1] == 'CAPTURED';
32
                    }
33
34
                    $this->result[$temp[0]] = $temp[1];
35
                }
36
            }
37
38
            return true;
39
        }
40
        $this->result = explode('-', $this->request->get('ErrorText'));
41
42
        return false;
43
    }
44
45
    public function __toString()
46
    {
47
        return json_encode($this->result);
48
    }
49
50
    public function toArray()
51
    {
52
        return $this->result;
53
    }
54
}
55