From d8c640ca5c6d982937e5bca9a678d00f74d1d939 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeely Date: Tue, 12 Dec 2023 16:30:33 +0100 Subject: [PATCH] add return type, update docblock, get all wallets in a single go --- src/Traits/HandlesPayment.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Traits/HandlesPayment.php b/src/Traits/HandlesPayment.php index b673372..63f8a33 100644 --- a/src/Traits/HandlesPayment.php +++ b/src/Traits/HandlesPayment.php @@ -2,7 +2,6 @@ namespace HPWebdeveloper\LaravelPayPocket\Traits; -use App\Enums\WalletEnums; use HPWebdeveloper\LaravelPayPocket\Exceptions\InsufficientBalanceException; use Illuminate\Support\Facades\DB; @@ -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.'); @@ -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; }