From bfe4872bccc49ceba551ab065437276ef09f0194 Mon Sep 17 00:00:00 2001 From: Simon Depelchin Date: Thu, 22 Feb 2018 18:10:58 +0100 Subject: [PATCH] A deposit can fail --- src/HasWallet.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/HasWallet.php b/src/HasWallet.php index 7bcf9d3..5ff8655 100644 --- a/src/HasWallet.php +++ b/src/HasWallet.php @@ -44,21 +44,34 @@ public function canWithdraw($amount) * @param string $type * @param array $meta */ - public function deposit($amount, $type = 'deposit', $meta = []) + public function deposit($amount, $type = 'deposit', $meta = [], $accepted = true) { - $this->wallet->balance += $amount; - $this->wallet->save(); + if ($accepted) { + $this->wallet->balance += $amount; + $this->wallet->save(); + } $this->wallet->transactions() ->create([ 'amount' => $amount, 'hash' => uniqid('lwch_'), 'type' => $type, - 'accepted' => true, + 'accepted' => $accepted, 'meta' => $meta ]); } + /** + * Fail to move credits to this account + * @param integer $amount + * @param string $type + * @param array $meta + */ + public function failDeposit($amount, $type = 'deposit', $meta = []) + { + $this->deposit($amount, $type, $meta, false); + } + /** * Attempt to move credits from this account * @param integer $amount