|
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
|
|
|
|