TransactionManager   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 32
c 1
b 0
f 0
dl 0
loc 77
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 4 1
A pay() 0 4 1
A fireDriver() 0 4 1
A __construct() 0 3 1
A callbackUrl() 0 4 1
A amount() 0 4 1
A getDriver() 0 6 2
A orderId() 0 4 1
A detail() 0 4 1
A driver() 0 4 1
A request() 0 4 1
1
<?php
2
3
namespace Sinarajabpour1998\Gateway\Core;
4
5
class TransactionManager
6
{
7
    protected $driver;
8
    protected $amount;
9
    protected $orderId;
10
    protected $callbackUrl;
11
    protected $detail;
12
    protected $config;
13
    protected $transaction;
14
    protected $request;
15
16
    public function __construct()
17
    {
18
        $this->config = config('gateway');
19
    }
20
21
    public function pay()
22
    {
23
        $object = $this->fireDriver();
24
        return $object->init($this->amount, $this->orderId, $this->callbackUrl, $this->detail);
25
    }
26
27
    public function verify()
28
    {
29
        $object = $this->fireDriver();
30
        return $object->verify($this->request);
31
    }
32
33
    public function getDriver()
34
    {
35
        (is_null($this->driver))
36
            ? $driver = $this->config['default']
37
            : $driver = $this->driver;
38
        return $driver;
39
    }
40
41
    public function fireDriver()
42
    {
43
        $class = $this->config['drivers'][$this->getDriver()];
44
        return new $class($this->getDriver());
45
    }
46
47
    // Has parameter
48
    public function driver($driver = null)
49
    {
50
        $this->driver = $driver;
51
        return $this;
52
    }
53
54
    public function amount($amount)
55
    {
56
        $this->amount = (int) $amount;
57
        return $this;
58
    }
59
60
    public function orderId($orderId)
61
    {
62
        $this->orderId = $orderId;
63
        return $this;
64
    }
65
66
    public function callbackUrl($callbackUrl)
67
    {
68
        $this->callbackUrl = $callbackUrl;
69
        return $this;
70
    }
71
72
    public function request($request)
73
    {
74
        $this->request = $request;
75
        return $this;
76
    }
77
78
    public function detail($detail = [])
79
    {
80
        $this->detail = $detail;
81
        return $this;
82
    }
83
}
84