@@ -56,28 +56,28 @@ public function deposit(int $amount, string $description)
56
56
});
57
57
}
58
58
59
- public function withdraw (int $ amount , string $ description , bool $ force = false )
59
+ public function withdraw (int $ amount , string $ description , bool $ force = false , $ bypass_withdrawable_limit = false )
60
60
{
61
61
if ($ amount < 1 ) {
62
62
throw new Exception ("Withdrawl amount must not be less than 1, $ amount given. " );
63
63
}
64
64
65
- return DB ::transaction (function () use ($ amount , $ description , $ force ) {
65
+ return DB ::transaction (function () use ($ amount , $ description , $ force, $ bypass_withdrawable_limit ) {
66
66
$ wallet = $ this ->lockForUpdate ()->find ($ this ->id );
67
67
68
68
$ transaction ['ob ' ] = $ wallet ->balance ;
69
69
70
- if ($ wallet ->balance < $ amount && ! $ force ) {
70
+ if ($ wallet ->balance < $ amount && !$ force ) {
71
71
throw new Exception ("To withdraw more than wallet balance you need to use force mode. " );
72
72
}
73
73
74
- if ($ wallet ->withdrawable_balance < $ amount ) {
74
+ if ($ wallet ->withdrawable_balance < $ amount && ! $ bypass_withdrawable_limit ) {
75
75
throw new Exception ("Withdrawable balance exceeds! Max withdrawable limit is set to {$ wallet ->withdrawable_balance }. " );
76
76
}
77
77
78
78
$ this ->update ([
79
79
'balance ' => $ wallet ->balance - $ amount ,
80
- 'withdrawable_balance ' => $ wallet ->withdrawable_balance - $ amount ,
80
+ 'withdrawable_balance ' => $ bypass_withdrawable_limit ? $ wallet -> withdrawable_balance : $ wallet ->withdrawable_balance - $ amount ,
81
81
]);
82
82
83
83
return $ this ->transactions ()->create ([
0 commit comments