Skip to content

Commit 6926242

Browse files
committed
Return a collection of all related WalletLog for successfull call to the pay() method.
2 parents ef127e9 + 02d948b commit 6926242

10 files changed

+67
-35
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@
22

33
All notable changes to `laravel-pay-pocket` will be documented in this file.
44

5+
## 2.2.0 - 2024-06-27
6+
7+
### What's Changed
8+
9+
* Update: Change log_reference_length to log_reference_params by @3m1n3nc3 in https://github.com/HPWebdeveloper/laravel-pay-pocket/pull/34
10+
* Modify comments by @HPWebdeveloper in https://github.com/HPWebdeveloper/laravel-pay-pocket/pull/36
11+
12+
**Full Changelog**: https://github.com/HPWebdeveloper/laravel-pay-pocket/compare/2.1.0...2.2.0
13+
14+
## 2.1.0 - 2024-06-27
15+
16+
### What's Changed
17+
18+
* Bump aglipanci/laravel-pint-action from 2.3.1 to 2.4 by @dependabot in https://github.com/HPWebdeveloper/laravel-pay-pocket/pull/26
19+
* Bump dependabot/fetch-metadata from 2.0.0 to 2.1.0 by @dependabot in https://github.com/HPWebdeveloper/laravel-pay-pocket/pull/27
20+
* Add check Laravel 11 compatibility by @HPWebdeveloper in https://github.com/HPWebdeveloper/laravel-pay-pocket/pull/28
21+
* Test over the correct php version by @HPWebdeveloper in https://github.com/HPWebdeveloper/laravel-pay-pocket/pull/29
22+
* Support Laravel 11 by @samehdoush in https://github.com/HPWebdeveloper/laravel-pay-pocket/pull/25
23+
24+
### New Contributors
25+
26+
* @samehdoush made their first contribution in https://github.com/HPWebdeveloper/laravel-pay-pocket/pull/25
27+
28+
**Full Changelog**: https://github.com/HPWebdeveloper/laravel-pay-pocket/compare/2.0.3...2.1.0
29+
530
## 2.0.3 - 2024-04-12
631

732
### What's Changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,34 @@
99

1010
**Laravel Pay Pocket** is a package designed for Laravel applications, offering the flexibility to manage multiple wallet types within two dedicated database tables, `wallets` and `wallets_logs`.
1111

12-
**Demo** https://github.com/HPWebdeveloper/demo-pay-pocket
12+
**Demo:** https://github.com/HPWebdeveloper/demo-pay-pocket
13+
14+
**Videos:**
15+
16+
- [Laravel Pay Pocket Package: Virtual Wallets in Your Project](https://www.youtube.com/watch?v=KoQyURiwsA4)
17+
18+
- [Laravel Exceptions: Why and How to Use? Practical Example.](https://www.youtube.com/watch?v=-Sr18w91v8Q)
19+
20+
- [PHP Enums in Laravel: Practical Example from Package](https://www.youtube.com/watch?v=iUOb-3HQtK8)
21+
1322

1423
**Note:** This package does not handle payments from payment platforms, but instead offers the concept of virtual money, deposit, and withdrawal.
1524

1625
- **Author**: Hamed Panjeh
1726
- **Vendor**: hpwebdeveloper
1827
- **Package**: laravel-pay-pocket
1928
- **Alias name**: Laravel PPP (Laravel Pay Pocket Package)
20-
- **Version**: `1.x`
29+
- **Version**: `2.x`
2130
- **PHP Version**: 8.1+
22-
- **Laravel Version**: `10.x`
31+
- **Laravel Version**: `10.x`, `11.x`
2332
- **[Composer](https://getcomposer.org/):** `composer require hpwebdeveloper/laravel-pay-pocket`
2433

2534
### Support Policy
2635

27-
| Version | Laravel | PHP | Release date | End of improvements | End of support |
28-
| ------- | ------- | ------------- | ------------ | ------------------- | -------------- |
29-
| 1.x | ^10.0 | 8.1, 8.2, 8.3 | Nov 30, 2023 | Mar 1, 2024 | |
30-
| x.x | | | | | |
36+
| Version | Laravel | PHP | Release date | End of improvements | End of support |
37+
|---------|--------------|-------------|---------------|---------------------| -------------- |
38+
| 1.x | ^10.0 | 8.1, 8.2, 8.3 | Nov 30, 2023 | Mar 1, 2024 | |
39+
| 2.x | ^10.0, ^11.0 |8.2, 8.3| June 27, 2024 | January 30, 2025 | |
3140

3241
## Installation:
3342

@@ -199,7 +208,7 @@ you will discover a variety of exceptions tailored to address each scenario of i
199208
### Log
200209

201210
A typical `wallets_logs` table.
202-
![Laravel Pay Pocket Log](https://github.com/HPWebdeveloper/laravel-pay-pocket/assets/16323354/a242d335-8bd2-4af1-aa38-4e95b8870941)
211+
![Laravel Pay Pocket Log](https://github.com/HPWebdeveloper/laravel-pay-pocket/assets/16323354/0d7f2237-88e1-4ac0-a4f2-ac200bad9273)
203212

204213
## Testing
205214

config/pay-pocket.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
| This configuration allows you to customize the generation of log reference strings
1313
| within the LaravelPayPocket package.
1414
|
15-
| - [array] log_reference_params: The parameters to pass to the log reference generator.
16-
| - [string] log_reference_prefix: The prefix for the generated reference string.
17-
| - [class-string] log_reference_generator_class: The fully qualified name of the class containing static methods for generation.
18-
| - [string] log_reference_generator_method: The name of the static method available in the generator class.
15+
| - [array] log_reference_params: An array of parameters to pass to the log_reference_generator_method.
16+
| - [string] log_reference_prefix: Prefix for the generated reference string.
17+
| - [class-string] log_reference_generator_class: Fully qualified name of the class containing static methods for generation.
18+
| - [string] log_reference_generator_method: Name of the static method available in the generator class.
1919
|
20-
| This is how it works by default in the code:
20+
| By default, the following generator is set up:
2121
| Illuminate\Support\Str::random(12)
2222
|
2323
*/

src/Facades/LaravelPayPocket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ protected static function getFacadeAccessor(): string
1919
{
2020
return \HPWebdeveloper\LaravelPayPocket\Services\PocketServices::class;
2121
}
22-
}
22+
}

src/Interfaces/WalletOperations.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ public function hasSufficientBalance(int|float $value): bool;
2424
/**
2525
* Pay the order value from the user's wallets.
2626
*
27-
* @param int|float $orderValue
28-
* @param ?string $notes
27+
* @param ?string $notes
28+
* @return \Illuminate\Support\Collection<TKey,WalletsLog>
2929
*
3030
* @throws InsufficientBalanceException
31-
* @return \Illuminate\Support\Collection<TKey,WalletsLog>
3231
*/
3332
public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\Support\Collection;
3433

@@ -41,4 +40,4 @@ public function deposit(string $type, int|float $amount, ?string $notes = null):
4140
* Get user's wallet balance.
4241
*/
4342
public function getWalletBalance(): int|float;
44-
}
43+
}

src/Services/PocketServices.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ public function deposit(WalletOperations $user, string $type, int|float $amount,
1818
/**
1919
* Pay the order value from the user's wallets.
2020
*
21-
* @param WalletOperations $user
22-
* @param int|float $orderValue
23-
* @param ?string $notes
21+
* @param ?string $notes
22+
* @return \Illuminate\Support\Collection<TKey,WalletsLog>
2423
*
2524
* @throws InsufficientBalanceException
26-
* @return \Illuminate\Support\Collection<TKey,WalletsLog>
2725
*/
2826
public function pay(WalletOperations $user, int|float $orderValue, ?string $notes = null): \Illuminate\Support\Collection
2927
{
@@ -45,4 +43,4 @@ public function walletBalanceByType(WalletOperations $user, string $type): int|f
4543
{
4644
return $user->getWalletBalanceByType($type);
4745
}
48-
}
46+
}

src/Traits/BalanceOperation.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function decrementAndCreateLog(int|float $value, ?string $notes = null):
2424
{
2525
$this->createLog('dec', $value, $notes);
2626
$this->decrement('balance', $value);
27+
2728
return $this->createdLog;
2829
}
2930

@@ -34,6 +35,7 @@ public function incrementAndCreateLog(int|float $value, ?string $notes = null):
3435
{
3536
$this->createLog('inc', $value, $notes);
3637
$this->increment('balance', $value);
38+
3739
return $this->createdLog;
3840
}
3941

@@ -67,15 +69,15 @@ protected function generateReference(): string
6769
{
6870
$className = config('pay-pocket.log_reference_generator_class');
6971
$methodName = config('pay-pocket.log_reference_generator_method');
70-
$params = (array)config('pay-pocket.log_reference_params', [12]);
72+
$params = (array) config('pay-pocket.log_reference_params', [12]);
7173
$prefix = config('pay-pocket.log_reference_prefix');
7274

73-
if (!is_callable([$className, $methodName])) {
75+
if (! is_callable([$className, $methodName])) {
7476
throw new InvalidArgumentException('Invalid configuration: The combination of log_reference_generator_class and log_reference_generator_method is not callable.');
7577
}
7678

7779
$reference = call_user_func([$className, $methodName], ...$params);
7880

79-
return $prefix . $reference;
81+
return $prefix.$reference;
8082
}
81-
}
83+
}

src/Traits/HandlesPayment.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ trait HandlesPayment
1111
/**
1212
* Pay the order value from the user's wallets.
1313
*
14-
* @param int|float $orderValue
15-
* @param ?string $notes
14+
* @param ?string $notes
15+
* @return \Illuminate\Support\Collection<TKey,WalletsLog>
1616
*
1717
* @throws InsufficientBalanceException
18-
* @return \Illuminate\Support\Collection<TKey,WalletsLog>
1918
*/
2019
public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\Database\Eloquent\Collection
2120
{
22-
if (!$this->hasSufficientBalance($orderValue)) {
21+
if (! $this->hasSufficientBalance($orderValue)) {
2322
throw new InsufficientBalanceException('Insufficient balance to cover the order.');
2423
}
2524

@@ -34,7 +33,7 @@ public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\D
3433
$logs = (new WalletsLog())->newCollection();
3534

3635
foreach ($walletsInOrder as $wallet) {
37-
if (!$wallet || !$wallet->hasBalance()) {
36+
if (! $wallet || ! $wallet->hasBalance()) {
3837
continue;
3938
}
4039

@@ -54,4 +53,4 @@ public function pay(int|float $orderValue, ?string $notes = null): \Illuminate\D
5453
return $logs;
5554
});
5655
}
57-
}
56+
}

tests/OperationsWithFacadeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@
140140
$log = LaravelPayPocket::pay($user, 100.16);
141141

142142
expect($log->sum('value'))->toBe(100.16);
143-
});
143+
});

tests/OperationsWithoutFacadeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@
141141
$log = $user->pay(100.16);
142142

143143
expect($log->sum('value'))->toBe(100.16);
144-
});
144+
});

0 commit comments

Comments
 (0)