Completed
Branch master (1f9cd3)
by mahdi
03:09 queued 51s
created

Invoice::getDriver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Shetabit\Payment;
4
5
use Ramsey\Uuid\Uuid;
6
7
class Invoice
8
{
9
    protected $uuid;
10
11
    /**
12
     * Amount
13
     *
14
     * @var int
15
     */
16
    protected $amount = 0;
17
18
    /**
19
     * invoice's transaction id
20
     *
21
     * @var string
22
     */
23
    protected $transactionId;
24
25
    /**
26
     * Payment details
27
     *
28
     * @var string
29
     */
30
    protected $details = [];
31
32
    /**
33
     * @var string
34
     */
35
    protected $driver;
36
37
    /**
38
     * Invoice constructor.
39
     *
40
     * @throws \Exception
41
     */
42
    public function __construct()
43
    {
44
        $this->uuid();
45
    }
46
47
    /**
48
     * Set invoice uuid
49
     *
50
     * @param $uuid|null
51
     * @throws \Exception
52
     */
53
    public function uuid($uuid = null)
54
    {
55
        if (empty($uuid)) {
56
            $uuid = Uuid::uuid4()->toString();
57
        }
58
59
        $this->uuid = $uuid;
60
    }
61
62
    /**
63
     * Get invoice uuid
64
     *
65
     * @return string
66
     */
67
    public function getUuid() {
68
        return $this->uuid;
69
    }
70
71
    /**
72
     * Set a piece of data to the details.
73
     *
74
     * @param $key
75
     * @param $value|null
76
     * @return $this
77
     */
78
    public function detail($key, $value = null)
79
    {
80
        $key = is_array($key) ? $key : [$key => $value];
81
82
        foreach ($key as $k => $v) {
83
            $this->details[$k] = $v;
84
        }
85
86
        return $this;
87
    }
88
89
    /**
90
     * Get the value of details
91
     */
92
    public function getDetails()
93
    {
94
        return $this->details;
95
    }
96
97
    /**
98
     * Set the amount of invoice
99
     *
100
     * @param $amount
101
     * @return $this
102
     * @throws \Exception
103
     */
104
    public function amount($amount)
105
    {
106
        if (!is_int($amount)) {
107
            throw new \Exception('Amount value should be an integer.');
108
        }
109
        $this->amount = $amount;
110
111
        return $this;
112
    }
113
114
    /**
115
     * Get the value of invoice
116
     *
117
     * @return int
118
     */
119
    public function getAmount()
120
    {
121
        return $this->amount;
122
    }
123
124
    /**
125
     * set transaction id
126
     *
127
     * @param $id
128
     * @return $this
129
     */
130
    public function transactionId($id)
131
    {
132
        $this->transactionId = $id;
133
134
        return $this;
135
    }
136
137
    /**
138
     * Get the value of transaction's id
139
     *
140
     * @return string
141
     */
142
    public function getTransactionId()
143
    {
144
        return $this->transactionId;
145
    }
146
147
    /**
148
     * Set the value of driver
149
     *
150
     * @param $driver
151
     * @return $this
152
     */
153
    public function via($driver)
154
    {
155
        $this->driver = $driver;
156
157
        return $this;
158
    }
159
160
    /**
161
     * Get the value of driver
162
     *
163
     * @return string
164
     */
165
    public function getDriver()
166
    {
167
        return $this->driver;
168
    }
169
}
170