Skip to content

Commit

Permalink
Merge pull request #12 from eyounelson/main
Browse files Browse the repository at this point in the history
deposit and deduct from the wallet at the database level
  • Loading branch information
stephenjude authored Jan 9, 2023
2 parents 57cbff8 + ab66d45 commit 4ccc561
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/Traits/HasWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ public function deposit(int|float $amount): float|int
{
$this->throwExceptionIfAmountIsInvalid($amount);

$balance = $this->wallet_balance ?? 0;

$balance += $amount;
$this->increment('wallet_balance', $amount);

$this->forceFill(['wallet_balance' => $balance])->save();

return $balance;
return $this->wallet_balance;
}

public function withdraw(int|float $amount): float|int
Expand All @@ -27,11 +23,9 @@ public function withdraw(int|float $amount): float|int

$this->throwExceptionIfFundIsInsufficient($amount);

$balance = $this->wallet_balance - $amount;

$this->forceFill(['wallet_balance' => $balance])->save();
$this->decrement('wallet_balance', $amount);

return $balance;
return $this->wallet_balance;
}

public function canWithdraw(int|float $amount): bool
Expand Down

0 comments on commit 4ccc561

Please sign in to comment.