Passed
Pull Request — master (#72)
by
unknown
03:01 queued 19s
created

Receipt::getTransactionId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Shetabit\Payment\Abstracts;
4
5
use Carbon\Carbon;
6
use Shetabit\Payment\Contracts\ReceiptInterface;
7
use Shetabit\Payment\Exceptions\NoTransactionIdException;
8
9
abstract class Receipt implements ReceiptInterface
10
{
11
    /**
12
     * A unique ID which is given to the customer whenever the payment is done successfully.
13
     * This ID can be used for financial follow up.
14
     *
15
     * @var string
16
     */
17
    protected $referenceId;
18
19
    /**
20
     * The transaction ID that was created when initiating the payment.
21
     * This ID can be used to track transaction's state inside database.
22
     *
23
     * @var string|null
24
     */
25
    protected $transactionId;
26
27
    /**
28
     * payment driver's name.
29
     *
30
     * @var string
31
     */
32
    protected $driver;
33
34
    /**
35
     * payment date
36
     *
37
     * @var Carbon
38
     */
39
    protected $date;
40
41
    /**
42
     * Receipt constructor.
43
     *
44
     * @param $driver
45
     * @param $referenceId
46
     * @param string|null $transactionId
47
     */
48
    public function __construct($driver, $referenceId, $transactionId = null)
49
    {
50
        $this->driver = $driver;
51
        $this->referenceId = $referenceId;
52
        $this->transactionId = $transactionId;
53
        $this->date = now();
54
    }
55
56
    /**
57
     * Retrieve driver's name
58
     *
59
     * @return string
60
     */
61
    public function getDriver() : string
62
    {
63
        return $this->driver;
64
    }
65
66
    /**
67
     * Retrieve payment reference code.
68
     *
69
     * @return string
70
     */
71
    public function getReferenceId() : string
72
    {
73
        return (string) $this->referenceId;
74
    }
75
76
    /**
77
     * Retrieve transaction's ID.
78
     *
79
     * @return string
80
     * @throws NoTransactionIdException
81
     */
82
    public function getTransactionId() : string
83
    {
84
        // Developer may be relaying on this, so instead of returning null
85
        // we'll throw an exception to let them know something's wrong
86
        if (empty($this->transactionId)) {
87
            throw new NoTransactionIdException();
88
        }
89
        return (string) $this->transactionId;
90
    }
91
92
    /**
93
     * Retrieve payment date
94
     *
95
     * @return Carbon|\Illuminate\Support\Carbon
96
     */
97
    public function getDate() : Carbon
98
    {
99
        return $this->date;
100
    }
101
}
102