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