Skip to content

Commit

Permalink
add return type, update docblock, get all wallets in a single go
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjad Esmaeely committed Dec 12, 2023
1 parent 1d9e185 commit d8c640c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Traits/HandlesPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace HPWebdeveloper\LaravelPayPocket\Traits;

use App\Enums\WalletEnums;
use HPWebdeveloper\LaravelPayPocket\Exceptions\InsufficientBalanceException;
use Illuminate\Support\Facades\DB;

Expand All @@ -11,11 +10,12 @@ trait HandlesPayment
/**
* Pay the order value from the user's wallets.
*
* @param int|float $orderValue
* @return void
*
* @throws InsufficientBalanceException
*/
public function pay(int|float $orderValue)
public function pay(int|float $orderValue): void
{
if (! $this->hasSufficientBalance($orderValue)) {
throw new InsufficientBalanceException('Insufficient balance to cover the order.');
Expand All @@ -24,10 +24,9 @@ public function pay(int|float $orderValue)
DB::transaction(function () use ($orderValue) {
$remainingOrderValue = $orderValue;

foreach ($this->walletsInOrder() as $walletInOrder) {
$walletEnumType = WalletEnums::tryFrom($walletInOrder);
$wallet = $this->wallets()->where('type', $walletEnumType)->first();
$wallets = $this->wallets()->whereIn('type', $this->walletsInOrder())->get();

foreach ($wallets as $wallet) {
if (! $wallet || ! $wallet->hasBalance()) {
continue;
}
Expand Down

0 comments on commit d8c640c

Please sign in to comment.