1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bavix\Wallet\Objects; |
4
|
|
|
|
5
|
|
|
use Bavix\Wallet\Interfaces\Wallet; |
6
|
|
|
use Bavix\Wallet\Models\Transaction; |
7
|
|
|
use Bavix\Wallet\Models\Transfer; |
8
|
|
|
use Ramsey\Uuid\Uuid; |
9
|
|
|
|
10
|
|
|
class Bring |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $status; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Wallet |
20
|
|
|
*/ |
21
|
|
|
protected $from; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Wallet |
25
|
|
|
*/ |
26
|
|
|
protected $to; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Transaction |
30
|
|
|
*/ |
31
|
|
|
protected $deposit; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var Transaction |
35
|
|
|
*/ |
36
|
|
|
protected $withdraw; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
18 |
|
public function getStatus(): string |
42
|
|
|
{ |
43
|
18 |
|
return $this->status; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $status |
48
|
|
|
* @return static |
49
|
|
|
*/ |
50
|
18 |
|
public function setStatus(string $status): self |
51
|
|
|
{ |
52
|
18 |
|
$this->status = $status; |
53
|
18 |
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return Wallet |
58
|
|
|
*/ |
59
|
18 |
|
public function getFrom(): Wallet |
60
|
|
|
{ |
61
|
18 |
|
return $this->from; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param Wallet $from |
66
|
|
|
* @return static |
67
|
|
|
*/ |
68
|
18 |
|
public function setFrom(Wallet $from): self |
69
|
|
|
{ |
70
|
18 |
|
$this->from = $from; |
71
|
18 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return Wallet |
76
|
|
|
*/ |
77
|
18 |
|
public function getTo(): Wallet |
78
|
|
|
{ |
79
|
18 |
|
return $this->to; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param Wallet $to |
84
|
|
|
* @return static |
85
|
|
|
*/ |
86
|
18 |
|
public function setTo(Wallet $to): self |
87
|
|
|
{ |
88
|
18 |
|
$this->to = $to; |
89
|
18 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return Transaction |
94
|
|
|
*/ |
95
|
18 |
|
public function getDeposit(): Transaction |
96
|
|
|
{ |
97
|
18 |
|
return $this->deposit; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param Transaction $deposit |
102
|
|
|
* @return static |
103
|
|
|
*/ |
104
|
18 |
|
public function setDeposit(Transaction $deposit): self |
105
|
|
|
{ |
106
|
18 |
|
$this->deposit = $deposit; |
107
|
18 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return Transaction |
112
|
|
|
*/ |
113
|
18 |
|
public function getWithdraw(): Transaction |
114
|
|
|
{ |
115
|
18 |
|
return $this->withdraw; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param Transaction $withdraw |
120
|
|
|
* @return static |
121
|
|
|
*/ |
122
|
18 |
|
public function setWithdraw(Transaction $withdraw): self |
123
|
|
|
{ |
124
|
18 |
|
$this->withdraw = $withdraw; |
125
|
18 |
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return Transfer |
130
|
|
|
* @throws |
131
|
|
|
*/ |
132
|
18 |
|
public function create(): Transfer |
133
|
|
|
{ |
134
|
18 |
|
return app(Transfer::class)->create([ |
135
|
18 |
|
'status' => $this->getStatus(), |
136
|
18 |
|
'deposit_id' => $this->getDeposit()->getKey(), |
137
|
18 |
|
'withdraw_id' => $this->getWithdraw()->getKey(), |
138
|
18 |
|
'from_type' => $this->getFrom()->getMorphClass(), |
|
|
|
|
139
|
18 |
|
'from_id' => $this->getFrom()->getKey(), |
|
|
|
|
140
|
18 |
|
'to_type' => $this->getTo()->getMorphClass(), |
141
|
18 |
|
'to_id' => $this->getTo()->getKey(), |
142
|
18 |
|
'fee' => \abs($this->getWithdraw()->amount) - \abs($this->getDeposit()->amount), |
143
|
18 |
|
'uuid' => Uuid::uuid4()->toString(), |
144
|
|
|
]); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
} |
148
|
|
|
|