Passed
Push — master ( 56512a...7231d9 )
by mahdi
03:12
created

Invoice::detail()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 4
nop 2
dl 0
loc 9
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
     * transactions ref id
27
     *
28
     * @var string
29
     */
30
    protected $refId;
31
32
    /**
33
     * Payment details
34
     *
35
     * @var string
36
     */
37
    protected $details = [];
38
39
    /**
40
     * @var string
41
     */
42
    protected $driver;
43
44
    /**
45
     * Invoice constructor.
46
     *
47
     * @throws \Exception
48
     */
49
    public function __construct()
50
    {
51
        $this->uuid();
52
    }
53
54
    /**
55
     * Set invoice uuid
56
     *
57
     * @param $uuid |null
0 ignored issues
show
Documentation Bug introduced by
The doc comment |null at position 0 could not be parsed: Unknown type name '|' at position 0 in |null.
Loading history...
58
     * @throws \Exception
59
     */
60
    public function uuid($uuid = null)
61
    {
62
        if (empty($uuid)) {
63
            $uuid = Uuid::uuid4()->toString();
64
        }
65
66
        $this->uuid = $uuid;
67
    }
68
69
    /**
70
     * Get invoice uuid
71
     *
72
     * @return string
73
     */
74
    public function getUuid()
75
    {
76
        return $this->uuid;
77
    }
78
79
    /**
80
     * Set a piece of data to the details.
81
     *
82
     * @param $key
83
     * @param $value |null
0 ignored issues
show
Documentation Bug introduced by
The doc comment |null at position 0 could not be parsed: Unknown type name '|' at position 0 in |null.
Loading history...
84
     * @return $this
85
     */
86
    public function detail($key, $value = null)
87
    {
88
        $key = is_array($key) ? $key : [$key => $value];
89
90
        foreach ($key as $k => $v) {
91
            $this->details[$k] = $v;
92
        }
93
94
        return $this;
95
    }
96
97
    /**
98
     * Get the value of details
99
     */
100
    public function getDetails()
101
    {
102
        return $this->details;
103
    }
104
105
    /**
106
     * Set the amount of invoice
107
     *
108
     * @param $amount
109
     * @return $this
110
     * @throws \Exception
111
     */
112
    public function amount($amount)
113
    {
114
        if (!is_int($amount)) {
115
            throw new \Exception('Amount value should be an integer.');
116
        }
117
        $this->amount = $amount;
118
119
        return $this;
120
    }
121
122
    /**
123
     * Get the value of invoice
124
     *
125
     * @return int
126
     */
127
    public function getAmount()
128
    {
129
        return $this->amount;
130
    }
131
132
    /**
133
     * set transaction id
134
     *
135
     * @param $id
136
     * @return $this
137
     */
138
    public function transactionId($id)
139
    {
140
        $this->transactionId = $id;
141
142
        return $this;
143
    }
144
145
    /**
146
     * Get the value of transaction's id
147
     *
148
     * @return string
149
     */
150
    public function getTransactionId()
151
    {
152
        return $this->transactionId;
153
    }
154
155
    /**
156
     * set ref id
157
     *
158
     * @param $id
159
     * @return $this
160
     */
161
    public function refId($id)
162
    {
163
        $this->refId = $id;
164
165
        return $this;
166
    }
167
168
    /**
169
     * Get the value of transaction's ref id
170
     *
171
     * @return string
172
     */
173
    public function getRefId()
174
    {
175
        return $this->refId;
176
    }
177
178
    /**
179
     * Set the value of driver
180
     *
181
     * @param $driver
182
     * @return $this
183
     */
184
    public function via($driver)
185
    {
186
        $this->driver = $driver;
187
188
        return $this;
189
    }
190
191
    /**
192
     * Get the value of driver
193
     *
194
     * @return string
195
     */
196
    public function getDriver()
197
    {
198
        return $this->driver;
199
    }
200
}
201