-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasePaymentMethod.php
79 lines (66 loc) · 1.84 KB
/
BasePaymentMethod.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace App\PaymentMethods;
use App\Models\User;
use App\WithdrawalUser;
use Carbon\CarbonInterface;
use Money\Money;
use Str;
abstract class BasePaymentMethod
{
const NAME = null;
protected $min_payout;
protected $disabled = false;
const PAYMENT_METHODS = [
BitcoinPaymentMethod::NAME,
EpaymentsPaymentMethod::NAME,
PaxumPaymentMethod::NAME,
WebmoneyPaymentMethod::NAME,
WireTransferPaymentMethod::NAME,
];
public function __construct(Money $min_payout)
{
$this->min_payout = $min_payout;
}
abstract public function calculateFee(Money $money): Money;
public function availableForPayout(WithdrawalUser $user)
{
if ($this->min_payout->isZero() && $user->getBalance()->lessThanOrEqual($this->min_payout)) {
return false;
}
if ($user->getBalance()->lessThan($this->min_payout)) {
return false;
}
return true;
}
public function getName()
{
return static::NAME;
}
// returns QueryBuilder
public function users()
{
return User::where([
['payment_method_name', $this->getName()]
]);
}
public function getUsersForPayout(CarbonInterface $timestamp = null)
{
return $this->users()->where('banned', false)->get()
->map(function ($user) use ($timestamp) {
return new WithdrawalUser($user, $timestamp);
})
->filter(function ($user) {
return $this->availableForPayout($user);
});
}
public static function resolveByName($name)
{
$pm = Str::studly($name);
$class_name = "App\PaymentMethods\\{$pm}PaymentMethod";
return resolve($class_name);
}
public function isDisabled()
{
return $this->disabled;
}
}