Skip to content

Commit

Permalink
Merge branch 'main' into features
Browse files Browse the repository at this point in the history
  • Loading branch information
3m1n3nc3 authored Jan 4, 2024
2 parents 9cbf132 + 208efc8 commit d3295ea
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 29 deletions.
9 changes: 2 additions & 7 deletions src/Exceptions/InsufficientBalanceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
namespace HPWebdeveloper\LaravelPayPocket\Exceptions;

use Exception;
use Throwable;

class InsufficientBalanceException extends Exception
{
/**
* Construct the 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(string $message = 'Insufficient balance to cover the order', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
9 changes: 2 additions & 7 deletions src/Exceptions/InvalidDepositException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
namespace HPWebdeveloper\LaravelPayPocket\Exceptions;

use Exception;
use Throwable;

class InvalidDepositException extends Exception
{
/**
* Construct the exception.
*
* @param string $message
* @param int $code
*/
public function __construct($message = 'Invalid deposit operation', $code = 0, ?\Throwable $previous = null)
public function __construct(string $message = 'Invalid deposit operation', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
9 changes: 2 additions & 7 deletions src/Exceptions/InvalidValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
namespace HPWebdeveloper\LaravelPayPocket\Exceptions;

use Exception;
use Throwable;

class InvalidValueException extends Exception
{
/**
* Construct the exception.
*
* @param string $message
* @param int $code
*/
public function __construct($message = 'Invalie value to deposit', $code = 0, ?\Throwable $previous = null)
public function __construct(string $message = 'Invalid value to deposit', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Exceptions/InvalidWalletTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace HPWebdeveloper\LaravelPayPocket\Exceptions;

use Exception;
use Throwable;

class InvalidWalletTypeException extends Exception
{
public function __construct($message = 'Invalid wallet type', $code = 0, ?\Throwable $previous = null)
public function __construct(string $message = 'Invalid wallet type', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Exceptions/WalletNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace HPWebdeveloper\LaravelPayPocket\Exceptions;

use Exception;
use Throwable;

class WalletNotFoundException extends Exception
{
public function __construct($message = 'Wallet not found', $code = 0, ?\Throwable $previous = null)
public function __construct(string $message = 'Wallet not found', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
10 changes: 6 additions & 4 deletions src/Services/PocketServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace HPWebdeveloper\LaravelPayPocket\Services;

use Illuminate\Database\Eloquent\Model;

class PocketServices
{
/**
Expand All @@ -14,7 +16,7 @@ class PocketServices
*
* @return bool
*/
public function deposit($user, string $type, int|float $amount, ?string $notes = null): bool
public function deposit(Model $user, string $type, int|float $amount, ?string $notes = null): bool
{
return $user->deposit($type, $amount, $notes);
}
Expand All @@ -30,7 +32,7 @@ public function deposit($user, string $type, int|float $amount, ?string $notes =
* @return void
* @throws InsufficientBalanceException
*/
public function pay($user, $orderValue, array $allowedWallets = [], ?string $notes = null): void
public function pay(Model $user, $orderValue, array $allowedWallets = [], ?string $notes = null): void
{
$user->pay($orderValue, $allowedWallets, $notes);
}
Expand All @@ -43,7 +45,7 @@ public function pay($user, $orderValue, array $allowedWallets = [], ?string $not
*
* @return float|int
*/
public function checkBalance($user): float|int
public function checkBalance(Model $user): int|float
{
return $user->walletBalance;
}
Expand All @@ -57,7 +59,7 @@ public function checkBalance($user): float|int
*
* @return float|int
*/
public function walletBalanceByType($user, string $type): float|int
public function walletBalanceByType(Model $user, string $type): float|int
{
return $user->getWalletBalanceByType($type);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Traits/HandlesDeposit.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ trait HandlesDeposit
* @param ?string $notes
*
* @return bool
* @throws InvalidDepositException|InvalidValueException|InvalidWalletTypeException
*/
public function deposit(string $type, int|float $amount, ?string $notes = null): bool
{
Expand Down Expand Up @@ -58,14 +59,15 @@ private function getDepositableTypes(): array
}

/**
* Check if the given tyep is valid.
* Check if the given type is valid.
*
* @var string $type
* @var array $depositable
*
* @return bool
* @throws InvalidWalletTypeException
*/
private function isRequestValid($type, array $depositable)
private function isRequestValid($type, array $depositable): bool
{
if (! array_key_exists($type, $depositable)) {
throw new InvalidWalletTypeException('Invalid deposit type.');
Expand Down

0 comments on commit d3295ea

Please sign in to comment.