From 4ea62934a4af941d51870bc51383ac8696c2680b Mon Sep 17 00:00:00 2001 From: Legacy <52163001+3m1n3nc3@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:08:20 +0100 Subject: [PATCH 1/9] Update: Change log_reference_length to log_reference_params to allow passing additional parameters to the log reference generator --- src/Traits/BalanceOperation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Traits/BalanceOperation.php b/src/Traits/BalanceOperation.php index 247fb26..16fde2d 100644 --- a/src/Traits/BalanceOperation.php +++ b/src/Traits/BalanceOperation.php @@ -65,7 +65,7 @@ protected function generateReference(): string { $className = config('pay-pocket.log_reference_generator_class'); $methodName = config('pay-pocket.log_reference_generator_method'); - $params = (array) config('pay-pocket.log_reference_params', [12]); + $params = (array)config('pay-pocket.log_reference_params', [12]); $prefix = config('pay-pocket.log_reference_prefix'); if (! is_callable([$className, $methodName])) { @@ -74,6 +74,6 @@ protected function generateReference(): string $reference = call_user_func([$className, $methodName], ...$params); - return $prefix.$reference; + return $prefix . $reference; } } From 84fa891a28b2be4ebe91f516f34e042d61d67fc9 Mon Sep 17 00:00:00 2001 From: Legacy <52163001+3m1n3nc3@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:09:12 +0100 Subject: [PATCH 2/9] Update: Change log_reference_length to log_reference_params to allow passing additional parameters to the log reference generator --- config/pay-pocket.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index a6a8124..c245102 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -12,10 +12,10 @@ | This configuration allows you to customize the generation of log reference strings | within the LaravelPayPocket package. | - | - [array] log_reference_params: An array of parameters to pass to the log_reference_generator_method. - | - [string] log_reference_prefix: Prefix for the generated reference string. - | - [class-string] log_reference_generator_class: Fully qualified name of the class containing static methods for generation. - | - [string] log_reference_generator_method: Name of the static method available in the generator class. + | - [array] log_reference_params: The parameters to pass to the log reference generator. + | - [string] log_reference_prefix: The prefix for the generated reference string. + | - [class-string] log_reference_generator_class: The fully qualified name of the class containing static methods for generation. + | - [string] log_reference_generator_method: The name of the static method available in the generator class. | | By default, the following generator is set up: | Illuminate\Support\Str::random(12) From 2398bae6b9c5aca36c2a30ccfeb60540289b039d Mon Sep 17 00:00:00 2001 From: 3m1n3nc3 Date: Sat, 29 Jun 2024 21:02:52 +0100 Subject: [PATCH 3/9] Return a collection of all related WalletLog for successfull call to the pay() method. --- src/Facades/LaravelPayPocket.php | 4 ++-- src/Interfaces/WalletOperations.php | 8 ++++++-- src/Services/PocketServices.php | 11 ++++++++--- src/Traits/BalanceOperation.php | 10 ++++++---- src/Traits/HandlesPayment.php | 21 +++++++++++++++------ tests/OperationsWithFacadeTest.php | 12 ++++++++++++ tests/OperationsWithoutFacadeTest.php | 12 ++++++++++++ 7 files changed, 61 insertions(+), 17 deletions(-) diff --git a/src/Facades/LaravelPayPocket.php b/src/Facades/LaravelPayPocket.php index 8d7092a..502c28c 100644 --- a/src/Facades/LaravelPayPocket.php +++ b/src/Facades/LaravelPayPocket.php @@ -8,7 +8,7 @@ /** * @see \HPWebdeveloper\LaravelPayPocket\Services\PocketServices * - * @method static void pay(WalletOperations $user, int|float $orderValue, ?string $notes = null) + * @method static \Illuminate\Support\Collection pay(WalletOperations $user, int|float $orderValue, ?string $notes = null) * @method static bool deposit(WalletOperations $user, string $type, int|float $amount, ?string $notes = null) * @method static int|float checkBalance(WalletOperations $user) * @method static int|float walletBalanceByType(WalletOperations $user, string $type) @@ -19,4 +19,4 @@ protected static function getFacadeAccessor(): string { return \HPWebdeveloper\LaravelPayPocket\Services\PocketServices::class; } -} +} \ No newline at end of file diff --git a/src/Interfaces/WalletOperations.php b/src/Interfaces/WalletOperations.php index 572bf82..b70134b 100644 --- a/src/Interfaces/WalletOperations.php +++ b/src/Interfaces/WalletOperations.php @@ -24,9 +24,13 @@ public function hasSufficientBalance(int|float $value): bool; /** * Pay the order value from the user's wallets. * + * @param int|float $orderValue + * @param ?string $notes + * * @throws InsufficientBalanceException + * @return \Illuminate\Support\Collection */ - public function pay(int|float $orderValue, ?string $notes = null): void; + public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\Support\Collection; /** * Deposit an amount to the user's wallet of a specific type. @@ -37,4 +41,4 @@ public function deposit(string $type, int|float $amount, ?string $notes = null): * Get user's wallet balance. */ public function getWalletBalance(): int|float; -} +} \ No newline at end of file diff --git a/src/Services/PocketServices.php b/src/Services/PocketServices.php index 71f5244..cc8a5cc 100644 --- a/src/Services/PocketServices.php +++ b/src/Services/PocketServices.php @@ -18,11 +18,16 @@ public function deposit(WalletOperations $user, string $type, int|float $amount, /** * Pay the order value from the user's wallets. * + * @param WalletOperations $user + * @param int|float $orderValue + * @param ?string $notes + * * @throws InsufficientBalanceException + * @return \Illuminate\Support\Collection */ - public function pay(WalletOperations $user, int|float $orderValue, ?string $notes = null): void + public function pay(WalletOperations $user, int|float $orderValue, ?string $notes = null): \Illuminate\Support\Collection { - $user->pay($orderValue, $notes); + return $user->pay($orderValue, $notes); } /** @@ -40,4 +45,4 @@ public function walletBalanceByType(WalletOperations $user, string $type): int|f { return $user->getWalletBalanceByType($type); } -} +} \ No newline at end of file diff --git a/src/Traits/BalanceOperation.php b/src/Traits/BalanceOperation.php index 16fde2d..678d6a3 100644 --- a/src/Traits/BalanceOperation.php +++ b/src/Traits/BalanceOperation.php @@ -20,19 +20,21 @@ public function hasBalance(): bool /** * Decrement Balance and create a log entry. */ - public function decrementAndCreateLog(int|float $value, ?string $notes = null): void + public function decrementAndCreateLog(int|float $value, ?string $notes = null): WalletsLog { $this->createLog('dec', $value, $notes); $this->decrement('balance', $value); + return $this->createdLog; } /** * Increment Balance and create a log entry. */ - public function incrementAndCreateLog(int|float $value, ?string $notes = null): void + public function incrementAndCreateLog(int|float $value, ?string $notes = null): WalletsLog { $this->createLog('inc', $value, $notes); $this->increment('balance', $value); + return $this->createdLog; } /** @@ -68,7 +70,7 @@ protected function generateReference(): string $params = (array)config('pay-pocket.log_reference_params', [12]); $prefix = config('pay-pocket.log_reference_prefix'); - if (! is_callable([$className, $methodName])) { + if (!is_callable([$className, $methodName])) { throw new InvalidArgumentException('Invalid configuration: The combination of log_reference_generator_class and log_reference_generator_method is not callable.'); } @@ -76,4 +78,4 @@ protected function generateReference(): string return $prefix . $reference; } -} +} \ No newline at end of file diff --git a/src/Traits/HandlesPayment.php b/src/Traits/HandlesPayment.php index 2ea0a44..5055c24 100644 --- a/src/Traits/HandlesPayment.php +++ b/src/Traits/HandlesPayment.php @@ -3,6 +3,7 @@ namespace HPWebdeveloper\LaravelPayPocket\Traits; use HPWebdeveloper\LaravelPayPocket\Exceptions\InsufficientBalanceException; +use HPWebdeveloper\LaravelPayPocket\Models\WalletsLog; use Illuminate\Support\Facades\DB; trait HandlesPayment @@ -10,15 +11,19 @@ trait HandlesPayment /** * Pay the order value from the user's wallets. * + * @param int|float $orderValue + * @param ?string $notes + * * @throws InsufficientBalanceException + * @return \Illuminate\Support\Collection */ - public function pay(int|float $orderValue, ?string $notes = null): void + public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\Database\Eloquent\Collection { - if (! $this->hasSufficientBalance($orderValue)) { + if (!$this->hasSufficientBalance($orderValue)) { throw new InsufficientBalanceException('Insufficient balance to cover the order.'); } - DB::transaction(function () use ($orderValue, $notes) { + return DB::transaction(function () use ($orderValue, $notes) { $remainingOrderValue = $orderValue; /** @@ -26,13 +31,15 @@ public function pay(int|float $orderValue, ?string $notes = null): void */ $walletsInOrder = $this->wallets()->whereIn('type', $this->walletsInOrder())->get(); + $logs = (new WalletsLog())->newCollection(); + foreach ($walletsInOrder as $wallet) { - if (! $wallet || ! $wallet->hasBalance()) { + if (!$wallet || !$wallet->hasBalance()) { continue; } $amountToDeduct = min($wallet->balance, $remainingOrderValue); - $wallet->decrementAndCreateLog($amountToDeduct, $notes); + $logs->push($wallet->decrementAndCreateLog($amountToDeduct, $notes)); $remainingOrderValue -= $amountToDeduct; if ($remainingOrderValue <= 0) { @@ -43,6 +50,8 @@ public function pay(int|float $orderValue, ?string $notes = null): void if ($remainingOrderValue > 0) { throw new InsufficientBalanceException('Insufficient total wallet balance to cover the order.'); } + + return $logs; }); } -} +} \ No newline at end of file diff --git a/tests/OperationsWithFacadeTest.php b/tests/OperationsWithFacadeTest.php index 2421416..33f2b9b 100644 --- a/tests/OperationsWithFacadeTest.php +++ b/tests/OperationsWithFacadeTest.php @@ -129,3 +129,15 @@ expect(WalletsLog::whereNotNull('reference')->exists())->toBe(true); }); + +test('Payment returns log', function () { + $user = User::factory()->create(); + + $type = 'wallet_2'; + + LaravelPayPocket::deposit($user, $type, 234.56); + + $log = LaravelPayPocket::pay($user, 100.16); + + expect($log->sum('value'))->toBe(100.16); +}); \ No newline at end of file diff --git a/tests/OperationsWithoutFacadeTest.php b/tests/OperationsWithoutFacadeTest.php index e64143f..dd71986 100644 --- a/tests/OperationsWithoutFacadeTest.php +++ b/tests/OperationsWithoutFacadeTest.php @@ -130,3 +130,15 @@ expect(WalletsLog::whereNotNull('reference')->exists())->toBe(true); }); + +test('Payment returns log', function () { + $user = User::factory()->create(); + + $type = 'wallet_2'; + + $user->deposit($type, 234.56); + + $log = $user->pay(100.16); + + expect($log->sum('value'))->toBe(100.16); +}); \ No newline at end of file From edca76a7fe5ee7b3583ec9be2e1e03dc7dc3499c Mon Sep 17 00:00:00 2001 From: 3m1n3nc3 Date: Sat, 29 Jun 2024 21:16:06 +0100 Subject: [PATCH 4/9] Fix missing class references --- src/Interfaces/WalletOperations.php | 1 + src/Services/PocketServices.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Interfaces/WalletOperations.php b/src/Interfaces/WalletOperations.php index b70134b..55e52f5 100644 --- a/src/Interfaces/WalletOperations.php +++ b/src/Interfaces/WalletOperations.php @@ -3,6 +3,7 @@ namespace HPWebdeveloper\LaravelPayPocket\Interfaces; use HPWebdeveloper\LaravelPayPocket\Exceptions\InsufficientBalanceException; +use HPWebdeveloper\LaravelPayPocket\Models\WalletsLog; interface WalletOperations { diff --git a/src/Services/PocketServices.php b/src/Services/PocketServices.php index cc8a5cc..e3a3902 100644 --- a/src/Services/PocketServices.php +++ b/src/Services/PocketServices.php @@ -4,6 +4,7 @@ use HPWebdeveloper\LaravelPayPocket\Exceptions\InsufficientBalanceException; use HPWebdeveloper\LaravelPayPocket\Interfaces\WalletOperations; +use HPWebdeveloper\LaravelPayPocket\Models\WalletsLog; class PocketServices { From 4805718e208aad3641a97d707d4b1921edea84e3 Mon Sep 17 00:00:00 2001 From: 3m1n3nc3 Date: Sat, 29 Jun 2024 21:21:21 +0100 Subject: [PATCH 5/9] Fix missing types --- src/Traits/HandlesDeposit.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Traits/HandlesDeposit.php b/src/Traits/HandlesDeposit.php index 87c817a..1c86d82 100644 --- a/src/Traits/HandlesDeposit.php +++ b/src/Traits/HandlesDeposit.php @@ -21,7 +21,7 @@ public function deposit(string $type, int|float $amount, ?string $notes = null): { $depositable = $this->getDepositableTypes(); - if (! $this->isRequestValid($type, $depositable)) { + if (!$this->isRequestValid($type, $depositable)) { throw new InvalidDepositException('Invalid deposit request.'); } @@ -58,10 +58,10 @@ private function getDepositableTypes(): array */ private function isRequestValid($type, array $depositable): bool { - if (! array_key_exists($type, $depositable)) { + if (!array_key_exists($type, $depositable)) { throw new InvalidWalletTypeException('Invalid deposit type.'); } return true; } -} +} \ No newline at end of file From 43d14bcb9cbe957045c1bc0878ad608b0a8a3e8b Mon Sep 17 00:00:00 2001 From: 3m1n3nc3 Date: Sat, 29 Jun 2024 21:22:23 +0100 Subject: [PATCH 6/9] Run pint --- src/Interfaces/WalletOperations.php | 7 +++---- src/Services/PocketServices.php | 8 +++----- src/Traits/HandlesDeposit.php | 6 +++--- src/Traits/HandlesPayment.php | 11 +++++------ 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Interfaces/WalletOperations.php b/src/Interfaces/WalletOperations.php index 55e52f5..4d16b60 100644 --- a/src/Interfaces/WalletOperations.php +++ b/src/Interfaces/WalletOperations.php @@ -25,11 +25,10 @@ public function hasSufficientBalance(int|float $value): bool; /** * Pay the order value from the user's wallets. * - * @param int|float $orderValue - * @param ?string $notes + * @param ?string $notes + * @return \Illuminate\Support\Collection * * @throws InsufficientBalanceException - * @return \Illuminate\Support\Collection */ public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\Support\Collection; @@ -42,4 +41,4 @@ public function deposit(string $type, int|float $amount, ?string $notes = null): * Get user's wallet balance. */ public function getWalletBalance(): int|float; -} \ No newline at end of file +} diff --git a/src/Services/PocketServices.php b/src/Services/PocketServices.php index e3a3902..bd2199e 100644 --- a/src/Services/PocketServices.php +++ b/src/Services/PocketServices.php @@ -19,12 +19,10 @@ public function deposit(WalletOperations $user, string $type, int|float $amount, /** * Pay the order value from the user's wallets. * - * @param WalletOperations $user - * @param int|float $orderValue - * @param ?string $notes + * @param ?string $notes + * @return \Illuminate\Support\Collection * * @throws InsufficientBalanceException - * @return \Illuminate\Support\Collection */ public function pay(WalletOperations $user, int|float $orderValue, ?string $notes = null): \Illuminate\Support\Collection { @@ -46,4 +44,4 @@ public function walletBalanceByType(WalletOperations $user, string $type): int|f { return $user->getWalletBalanceByType($type); } -} \ No newline at end of file +} diff --git a/src/Traits/HandlesDeposit.php b/src/Traits/HandlesDeposit.php index 1c86d82..87c817a 100644 --- a/src/Traits/HandlesDeposit.php +++ b/src/Traits/HandlesDeposit.php @@ -21,7 +21,7 @@ public function deposit(string $type, int|float $amount, ?string $notes = null): { $depositable = $this->getDepositableTypes(); - if (!$this->isRequestValid($type, $depositable)) { + if (! $this->isRequestValid($type, $depositable)) { throw new InvalidDepositException('Invalid deposit request.'); } @@ -58,10 +58,10 @@ private function getDepositableTypes(): array */ private function isRequestValid($type, array $depositable): bool { - if (!array_key_exists($type, $depositable)) { + if (! array_key_exists($type, $depositable)) { throw new InvalidWalletTypeException('Invalid deposit type.'); } return true; } -} \ No newline at end of file +} diff --git a/src/Traits/HandlesPayment.php b/src/Traits/HandlesPayment.php index 5055c24..51ea3c4 100644 --- a/src/Traits/HandlesPayment.php +++ b/src/Traits/HandlesPayment.php @@ -11,15 +11,14 @@ trait HandlesPayment /** * Pay the order value from the user's wallets. * - * @param int|float $orderValue - * @param ?string $notes + * @param ?string $notes + * @return \Illuminate\Support\Collection * * @throws InsufficientBalanceException - * @return \Illuminate\Support\Collection */ public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\Database\Eloquent\Collection { - if (!$this->hasSufficientBalance($orderValue)) { + if (! $this->hasSufficientBalance($orderValue)) { throw new InsufficientBalanceException('Insufficient balance to cover the order.'); } @@ -34,7 +33,7 @@ public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\D $logs = (new WalletsLog())->newCollection(); foreach ($walletsInOrder as $wallet) { - if (!$wallet || !$wallet->hasBalance()) { + if (! $wallet || ! $wallet->hasBalance()) { continue; } @@ -54,4 +53,4 @@ public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\D return $logs; }); } -} \ No newline at end of file +} From 6837b4d5eaed9539e2508760b2590da02658da00 Mon Sep 17 00:00:00 2001 From: 3m1n3nc3 Date: Sat, 29 Jun 2024 21:31:46 +0100 Subject: [PATCH 7/9] Run pint one more time --- src/Traits/HandlesDeposit.php | 1 + src/Traits/HandlesPayment.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Traits/HandlesDeposit.php b/src/Traits/HandlesDeposit.php index 87c817a..e95960f 100644 --- a/src/Traits/HandlesDeposit.php +++ b/src/Traits/HandlesDeposit.php @@ -13,6 +13,7 @@ trait HandlesDeposit /** * Deposit an amount to the user's wallet of a specific type. * + * * @throws InvalidDepositException * @throws InvalidValueException * @throws InvalidWalletTypeException diff --git a/src/Traits/HandlesPayment.php b/src/Traits/HandlesPayment.php index 51ea3c4..b5a513c 100644 --- a/src/Traits/HandlesPayment.php +++ b/src/Traits/HandlesPayment.php @@ -11,7 +11,7 @@ trait HandlesPayment /** * Pay the order value from the user's wallets. * - * @param ?string $notes + * * @return \Illuminate\Support\Collection * * @throws InsufficientBalanceException From 02acc084eea52d3085235122588af8e10c29de29 Mon Sep 17 00:00:00 2001 From: Hamed Panjeh Date: Wed, 3 Dec 2025 14:29:38 -0300 Subject: [PATCH 8/9] add new feature to readme --- README.md | 83 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cbc1c18..4515a0b 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,13 @@ **Demo:** https://github.com/HPWebdeveloper/demo-pay-pocket -**Videos:** +**Videos:** -- [Laravel Pay Pocket Package: Virtual Wallets in Your Project](https://www.youtube.com/watch?v=KoQyURiwsA4) +- [Laravel Pay Pocket Package: Virtual Wallets in Your Project](https://www.youtube.com/watch?v=KoQyURiwsA4) -- [Laravel Exceptions: Why and How to Use? Practical Example.](https://www.youtube.com/watch?v=-Sr18w91v8Q) - -- [PHP Enums in Laravel: Practical Example from Package](https://www.youtube.com/watch?v=iUOb-3HQtK8) +- [Laravel Exceptions: Why and How to Use? Practical Example.](https://www.youtube.com/watch?v=-Sr18w91v8Q) +- [PHP Enums in Laravel: Practical Example from Package](https://www.youtube.com/watch?v=iUOb-3HQtK8) **Note:** This package does not handle payments from payment platforms, but instead offers the concept of virtual money, deposit, and withdrawal. @@ -33,11 +32,10 @@ ### Support Policy -| Version | Laravel | PHP | Release date | End of improvements | End of support | -|-------------------------------------------------|--------------|-------------|---------------|---------------------| -------------- | -| 1.x | ^10.0 | 8.1, 8.2, 8.3 | Nov 30, 2023 | Mar 1, 2024 | | -| 2.x | ^10.0, ^11.0 |8.2, 8.3| June 27, 2024 | January 30, 2025 | | -| 3.x (atomic operations and restricted wallets) | ^11.0 |8.2, 8.3| comming soon | | | +| Version | Laravel | PHP | Release date | End of improvements | End of support | +| ------- | ------------ | ------------- | ------------- | ------------------- | -------------- | +| 1.x | ^10.0 | 8.1, 8.2, 8.3 | Nov 30, 2023 | Mar 1, 2024 | | +| 2.x | ^10.0, ^11.0 | 8.2, 8.3 | June 27, 2024 | January 30, 2025 | | ## Installation: @@ -178,6 +176,71 @@ $user = auth()->user(); LaravelPayPocket::pay($user, 12.34); ``` +#### Payment Transaction Logs + +The `pay()` method returns a collection of `WalletsLog` instances representing all wallet transactions that occurred during the payment. This enables you to track exactly which wallets were used and access detailed transaction information. + +**Return Value:** + +```php +@return \Illuminate\Database\Eloquent\Collection +``` + +**Basic Usage:** + +```php +$user = auth()->user(); +$logs = $user->pay(120.00, 'Order #1234'); + +// Access transaction details +foreach ($logs as $log) { + echo "Wallet: {$log->wallet_name}, Amount: {$log->value}"; +} +``` + +**Practical Examples:** + +```php +// Get the number of wallets used in the payment +$walletCount = $logs->count(); + +// Calculate total amount deducted (verification) +$totalDeducted = $logs->sum('value'); + +// Get all wallet names used in the transaction +$walletsUsed = $logs->pluck('wallet_name'); + +// Access specific log details +$firstLog = $logs->first(); +echo "From: {$firstLog->from}, To: {$firstLog->to}"; +echo "Reference: {$firstLog->reference}"; +``` + +**Use Cases:** + +- **Receipt Generation:** Display detailed payment breakdown showing amounts from each wallet +- **Audit Trail:** Maintain comprehensive records of payment sources +- **Transaction Verification:** Confirm the exact amount deducted from each wallet +- **Analytics:** Track wallet usage patterns across payments + +**Example: Multi-Wallet Payment** + +```php +$user = auth()->user(); + +// User has: wallet_1 = $100, wallet_2 = $50 +$logs = $user->pay(120.00, 'Premium subscription'); + +// Returns collection with 2 logs: +// Log 1: wallet_1 deducted $100 (100.00 -> 0.00) +// Log 2: wallet_2 deducted $20 (50.00 -> 30.00) + +echo "Payment completed using {$logs->count()} wallet(s)"; +// Output: Payment completed using 2 wallet(s) +``` + +**Note:** This feature is backward compatible. Existing code that doesn't capture the return value will continue to work without any modifications. + ### Balance - **Wallets** From 44e993cc335bb8db93bb54ae2e6a8299f147f0aa Mon Sep 17 00:00:00 2001 From: HPWebdeveloper <16323354+HPWebdeveloper@users.noreply.github.com> Date: Wed, 3 Dec 2025 17:37:05 +0000 Subject: [PATCH 9/9] Fix styling --- src/Facades/LaravelPayPocket.php | 2 +- src/Interfaces/WalletOperations.php | 1 - src/Services/PocketServices.php | 1 - src/Traits/BalanceOperation.php | 10 ++++++---- src/Traits/HandlesDeposit.php | 2 +- src/Traits/HandlesPayment.php | 2 +- tests/OperationsWithFacadeTest.php | 2 +- tests/OperationsWithoutFacadeTest.php | 2 +- tests/database/migrations/create_users_tables.php | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Facades/LaravelPayPocket.php b/src/Facades/LaravelPayPocket.php index 502c28c..897f3ca 100644 --- a/src/Facades/LaravelPayPocket.php +++ b/src/Facades/LaravelPayPocket.php @@ -19,4 +19,4 @@ protected static function getFacadeAccessor(): string { return \HPWebdeveloper\LaravelPayPocket\Services\PocketServices::class; } -} \ No newline at end of file +} diff --git a/src/Interfaces/WalletOperations.php b/src/Interfaces/WalletOperations.php index 4d16b60..4cff7ce 100644 --- a/src/Interfaces/WalletOperations.php +++ b/src/Interfaces/WalletOperations.php @@ -25,7 +25,6 @@ public function hasSufficientBalance(int|float $value): bool; /** * Pay the order value from the user's wallets. * - * @param ?string $notes * @return \Illuminate\Support\Collection * * @throws InsufficientBalanceException diff --git a/src/Services/PocketServices.php b/src/Services/PocketServices.php index bd2199e..0b9a78b 100644 --- a/src/Services/PocketServices.php +++ b/src/Services/PocketServices.php @@ -19,7 +19,6 @@ public function deposit(WalletOperations $user, string $type, int|float $amount, /** * Pay the order value from the user's wallets. * - * @param ?string $notes * @return \Illuminate\Support\Collection * * @throws InsufficientBalanceException diff --git a/src/Traits/BalanceOperation.php b/src/Traits/BalanceOperation.php index 678d6a3..fe3bbdf 100644 --- a/src/Traits/BalanceOperation.php +++ b/src/Traits/BalanceOperation.php @@ -24,6 +24,7 @@ public function decrementAndCreateLog(int|float $value, ?string $notes = null): { $this->createLog('dec', $value, $notes); $this->decrement('balance', $value); + return $this->createdLog; } @@ -34,6 +35,7 @@ public function incrementAndCreateLog(int|float $value, ?string $notes = null): { $this->createLog('inc', $value, $notes); $this->increment('balance', $value); + return $this->createdLog; } @@ -67,15 +69,15 @@ protected function generateReference(): string { $className = config('pay-pocket.log_reference_generator_class'); $methodName = config('pay-pocket.log_reference_generator_method'); - $params = (array)config('pay-pocket.log_reference_params', [12]); + $params = (array) config('pay-pocket.log_reference_params', [12]); $prefix = config('pay-pocket.log_reference_prefix'); - if (!is_callable([$className, $methodName])) { + if (! is_callable([$className, $methodName])) { throw new InvalidArgumentException('Invalid configuration: The combination of log_reference_generator_class and log_reference_generator_method is not callable.'); } $reference = call_user_func([$className, $methodName], ...$params); - return $prefix . $reference; + return $prefix.$reference; } -} \ No newline at end of file +} diff --git a/src/Traits/HandlesDeposit.php b/src/Traits/HandlesDeposit.php index e95960f..562b72d 100644 --- a/src/Traits/HandlesDeposit.php +++ b/src/Traits/HandlesDeposit.php @@ -27,7 +27,7 @@ public function deposit(string $type, int|float $amount, ?string $notes = null): } if ($amount <= 0) { - throw new InvalidValueException(); + throw new InvalidValueException; } DB::transaction(function () use ($type, $amount, $notes) { diff --git a/src/Traits/HandlesPayment.php b/src/Traits/HandlesPayment.php index b5a513c..5187e13 100644 --- a/src/Traits/HandlesPayment.php +++ b/src/Traits/HandlesPayment.php @@ -30,7 +30,7 @@ public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\D */ $walletsInOrder = $this->wallets()->whereIn('type', $this->walletsInOrder())->get(); - $logs = (new WalletsLog())->newCollection(); + $logs = (new WalletsLog)->newCollection(); foreach ($walletsInOrder as $wallet) { if (! $wallet || ! $wallet->hasBalance()) { diff --git a/tests/OperationsWithFacadeTest.php b/tests/OperationsWithFacadeTest.php index 33f2b9b..41c56b2 100644 --- a/tests/OperationsWithFacadeTest.php +++ b/tests/OperationsWithFacadeTest.php @@ -140,4 +140,4 @@ $log = LaravelPayPocket::pay($user, 100.16); expect($log->sum('value'))->toBe(100.16); -}); \ No newline at end of file +}); diff --git a/tests/OperationsWithoutFacadeTest.php b/tests/OperationsWithoutFacadeTest.php index dd71986..1b3fee0 100644 --- a/tests/OperationsWithoutFacadeTest.php +++ b/tests/OperationsWithoutFacadeTest.php @@ -141,4 +141,4 @@ $log = $user->pay(100.16); expect($log->sum('value'))->toBe(100.16); -}); \ No newline at end of file +}); diff --git a/tests/database/migrations/create_users_tables.php b/tests/database/migrations/create_users_tables.php index 2bf4180..8efafc6 100644 --- a/tests/database/migrations/create_users_tables.php +++ b/tests/database/migrations/create_users_tables.php @@ -4,7 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration +return new class extends Migration { public function up(): void {