Request   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 26
c 1
b 0
f 1
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addParam() 0 5 1
A __construct() 0 13 2
A url() 0 17 2
1
<?php
2
3
namespace DeveloperH\Knet\SDK;
4
5
use Config;
6
use DeveloperH\Knet\Exceptions\KnetExceptions;
7
8
class Request extends Client
9
{
10
    public $params = '';
11
12
    public function __construct()
13
    {
14
        if (!Config::get('knet.resource_key', null)) {
15
            throw new KnetExceptions('No Resource Key');
16
        }
17
        $this
18
            ->addParam('id', Config::get('knet.transport_id'))
19
            ->addParam('password', Config::get('knet.transport_password'))
20
            ->addParam('action', Config::get('knet.action_code'))
21
            ->addParam('langid', Config::get('knet.language'))
22
            ->addParam('currencycode', Config::get('knet.currency'))
23
            ->addParam('responseURL', Config::get('knet.response_url'))
24
            ->addParam('errorURL', Config::get('knet.error_url'));
25
    }
26
27
    public function addParam($key, $value)
28
    {
29
        $this->params .= "&{$key}={$value}";
30
31
        return $this;
32
    }
33
34
    public function url()
35
    {
36
        $url = Config::get('knet.development_url');
37
38
        if (strtolower(Config::get('app.env')) == 'production') {
39
            $url = Config::get('knet.production_url');
40
        }
41
        $encrypt = $this->encryptAES(substr($this->params, 1), Config::get('knet.resource_key'));
42
        $this->params = '';
43
        $this
44
            ->addParam('param', 'paymentInit')
45
            ->addParam('trandata', $encrypt)
46
            ->addParam('tranportalId', Config::get('knet.transport_id'))
47
            ->addParam('responseURL', Config::get('knet.response_url'))
48
            ->addParam('errorURL', Config::get('knet.error_url'));
49
50
        return $url.'?'.substr($this->params, 1);
51
    }
52
}
53