diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 7fefe35..3761563 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,7 +13,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.2, 8.1] + php: [8.3, 8.2, 8.1] laravel: [10.*] stability: [prefer-lowest, prefer-stable] include: diff --git a/src/Exceptions/InsufficientBalanceException.php b/src/Exceptions/InsufficientBalanceException.php index e7332f1..1e87b6f 100644 --- a/src/Exceptions/InsufficientBalanceException.php +++ b/src/Exceptions/InsufficientBalanceException.php @@ -12,7 +12,7 @@ class InsufficientBalanceException extends Exception * @param string $message * @param int $code */ - public function __construct($message = 'Insufficient balance to cover the order', $code = 0, \Throwable $previous = null) + public function __construct($message = 'Insufficient balance to cover the order', $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Exceptions/InvalidDepositException.php b/src/Exceptions/InvalidDepositException.php index da644ba..937011e 100644 --- a/src/Exceptions/InvalidDepositException.php +++ b/src/Exceptions/InvalidDepositException.php @@ -12,7 +12,7 @@ class InvalidDepositException extends Exception * @param string $message * @param int $code */ - public function __construct($message = 'Invalid deposit operation', $code = 0, \Throwable $previous = null) + public function __construct($message = 'Invalid deposit operation', $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Exceptions/InvalidValueException.php b/src/Exceptions/InvalidValueException.php index 36a6d7e..7c351db 100644 --- a/src/Exceptions/InvalidValueException.php +++ b/src/Exceptions/InvalidValueException.php @@ -12,7 +12,7 @@ class InvalidValueException extends Exception * @param string $message * @param int $code */ - public function __construct($message = 'Invalie value to deposit', $code = 0, \Throwable $previous = null) + public function __construct($message = 'Invalie value to deposit', $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Exceptions/InvalidWalletTypeException.php b/src/Exceptions/InvalidWalletTypeException.php index cfae06d..5f35ef9 100644 --- a/src/Exceptions/InvalidWalletTypeException.php +++ b/src/Exceptions/InvalidWalletTypeException.php @@ -6,7 +6,7 @@ class InvalidWalletTypeException extends Exception { - public function __construct($message = 'Invalid wallet type', $code = 0, \Throwable $previous = null) + public function __construct($message = 'Invalid wallet type', $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Exceptions/WalletNotFoundException.php b/src/Exceptions/WalletNotFoundException.php index ee62fde..4b314a6 100644 --- a/src/Exceptions/WalletNotFoundException.php +++ b/src/Exceptions/WalletNotFoundException.php @@ -6,7 +6,7 @@ class WalletNotFoundException extends Exception { - public function __construct($message = 'Wallet not found', $code = 0, \Throwable $previous = null) + public function __construct($message = 'Wallet not found', $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index 3e07524..73d6813 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -13,7 +13,7 @@ * HPWebdeveloper\LaravelPayPocket\Models\Wallet * * @property mixed $balance - * @property HPWebdeveloper\LaravelPayPocket\Enums\WalletEnums $type + * @property WalletEnums $type */ class Wallet extends Model { diff --git a/src/Traits/HandlesPayment.php b/src/Traits/HandlesPayment.php index b673372..2e31745 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,10 @@ trait HandlesPayment /** * Pay the order value from the user's wallets. * - * @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 +22,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(); + $walletsInOrder = $this->wallets()->whereIn('type', $this->walletsInOrder())->get(); + foreach ($walletsInOrder as $wallet) { if (! $wallet || ! $wallet->hasBalance()) { continue; }