diff --git a/src/Facades/LaravelPayPocket.php b/src/Facades/LaravelPayPocket.php index 1c33b5f..6b53bb5 100644 --- a/src/Facades/LaravelPayPocket.php +++ b/src/Facades/LaravelPayPocket.php @@ -9,7 +9,7 @@ */ class LaravelPayPocket extends Facade { - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return \HPWebdeveloper\LaravelPayPocket\Services\PocketServices::class; } diff --git a/src/Interfaces/WalletOperations.php b/src/Interfaces/WalletOperations.php index 42742ef..6a46d99 100644 --- a/src/Interfaces/WalletOperations.php +++ b/src/Interfaces/WalletOperations.php @@ -6,11 +6,13 @@ interface WalletOperations { public function getWalletBalanceAttribute(); - public function getWalletBalanceByType(string $walletType); + public function getWalletBalanceByType(string $walletType): int|float; public function hasSufficientBalance($value): bool; - public function pay(int|float $orderValue); + public function pay(int|float $orderValue): void; public function deposit(string $type, int|float $amount): bool; + + public function getWalletBalance(): int|float; } diff --git a/src/Services/PocketServices.php b/src/Services/PocketServices.php index a52fa0d..3e38985 100644 --- a/src/Services/PocketServices.php +++ b/src/Services/PocketServices.php @@ -2,26 +2,26 @@ namespace HPWebdeveloper\LaravelPayPocket\Services; -use Illuminate\Database\Eloquent\Model; +use HPWebdeveloper\LaravelPayPocket\Interfaces\WalletOperations; class PocketServices { - public function deposit(Model $user, string $type, int|float $amount): bool + public function deposit(WalletOperations $user, string $type, int|float $amount): bool { return $user->deposit($type, $amount); } - public function pay(Model $user, int|float $orderValue): void + public function pay(WalletOperations $user, int|float $orderValue): void { $user->pay($orderValue); } - public function checkBalance(Model $user): int|float + public function checkBalance(WalletOperations $user): int|float { - return $user->walletBalance; + return $user->getWalletBalance(); } - public function walletBalanceByType(Model $user, string $type): int|float + public function walletBalanceByType(WalletOperations $user, string $type): int|float { return $user->getWalletBalanceByType($type); } diff --git a/src/Traits/GetWallets.php b/src/Traits/GetWallets.php index 4606dd4..7fdb9aa 100644 --- a/src/Traits/GetWallets.php +++ b/src/Traits/GetWallets.php @@ -6,12 +6,10 @@ trait GetWallets { - private function walletsInOrder() + private function walletsInOrder(): array { return array_map( - function ($enumCase) { - return $enumCase->value; - }, + fn($enumCase) => $enumCase->value, WalletEnums::cases() ); } diff --git a/src/Traits/HasWallet.php b/src/Traits/HasWallet.php index d30ca89..2b5b1df 100644 --- a/src/Traits/HasWallet.php +++ b/src/Traits/HasWallet.php @@ -26,7 +26,6 @@ public function wallets() */ public function getWalletBalanceAttribute() { - $totalBalance = 0; foreach ($this->walletsInOrder() as $walletInOrder) { @@ -39,7 +38,6 @@ public function getWalletBalanceAttribute() } return $totalBalance; - } /** @@ -53,9 +51,12 @@ public function hasSufficientBalance($value): bool /** * Get the balance of a specific wallet type. * - * @return float|int + * @param string $walletType + * @return int|float + * @throws InvalidWalletTypeException + * @throws WalletNotFoundException */ - public function getWalletBalanceByType(string $walletType) + public function getWalletBalanceByType(string $walletType): int|float { if (! WalletEnums::isValid($walletType)) { throw new InvalidWalletTypeException("Invalid wallet type '{$walletType}'."); @@ -69,4 +70,9 @@ public function getWalletBalanceByType(string $walletType) return $wallet->balance; } + + public function getWalletBalance(): int|float + { + return $this->walletBalance; + } }