Skip to content

Commit

Permalink
A deposit can fail
Browse files Browse the repository at this point in the history
  • Loading branch information
depsimon committed Feb 22, 2018
1 parent 04d6890 commit bfe4872
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/HasWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bfe4872

Please sign in to comment.