Skip to content

Commit 58f829b

Browse files
committed
feat: add ability to replace UnacceptedTransactionException with 'false' on insufficient wallet
1 parent 4580637 commit 58f829b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ $user->wallet->forceWithdraw(500);
103103
$user->wallet->balance; // -24.8990
104104
```
105105

106+
> If you don't want [UnacceptedTransactionException] you can change the `wallet.disable_insufficient_exception` config value to disable the exception or set `WALLET_DISABLE_INSUFFICIENT_EXCEPTION` to `true` on your `.env`
107+
106108
## Advanced Usage
107109

108110
You can easily add meta information to the transactions to suit your needs. For example:

config/config.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,18 @@
4646
|
4747
*/
4848
'auto_recalculate_balance' => env('WALLET_AUTO_RECALCULATE_BALANCE', false),
49+
50+
/*
51+
|--------------------------------------------------------------------------
52+
| Throwing Exception for Insufficient Balance
53+
|--------------------------------------------------------------------------
54+
|
55+
| This value is to disable exception handling when the request withdraw
56+
| amount is greater than current user balance on his wallet, if you
57+
| disabled the exception handling, the withdraw process will not proceeded
58+
| and the return will be false the balance will stay as is. default value
59+
| is false.
60+
|
61+
*/
62+
'disable_insufficient_exception' => env('WALLET_DISABLE_INSUFFICIENT_EXCEPTION', false),
4963
];

src/Models/Wallet.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ public function withdraw($amount, $meta = [], $type = 'withdraw', $shouldAccept
132132
]);
133133

134134
if (!$accepted) {
135-
throw new UnacceptedTransactionException($transaction, 'Withdrawal not accepted due to insufficient funds!');
135+
return config('wallet.disable_insufficient_exception')
136+
? false
137+
: throw new UnacceptedTransactionException(
138+
$transaction, 'Withdrawal not accepted due to insufficient funds!'
139+
);
136140
}
137141
$this->refresh();
138142
return $transaction;

0 commit comments

Comments
 (0)