You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: changelog.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
7
7
## [Unreleased]
8
8
9
+
### Added
10
+
- Transaction support.
11
+
- Now, within the transaction, the wallet has its own balance state.
12
+
13
+
### Updated
14
+
- Due to the state within transactions, I was able to speed up the computation up to 25 times for complex transfers.
15
+
16
+
### Removed
17
+
- class `WalletServiceLegacy`
18
+
9
19
## [7.0.0] - 2021-11-25
10
20
### Updated
11
21
- Optimization of the `payFreeCart` and `payFree` request. Now the package does not update the repository. But there is no point in updating it, because the client does not pay anything.
Previously, there was a vacuum package, but now it is a part of the core. You just need to configure the lock service and the cache service in the package configuration `wallet.php`.
11
+
12
+
```php
13
+
/**
14
+
* A system for dealing with race conditions.
15
+
*/
16
+
'lock' => [
17
+
'driver' => 'array',
18
+
'seconds' => 1,
19
+
],
20
+
```
21
+
22
+
To enable the fight against race conditions, you need to select a provider that supports work with locks. I recommend `redis`.
23
+
24
+
There is a setting for storing the state of the wallet, I recommend choosing `redis` here too.
25
+
26
+
```php
27
+
/**
28
+
* Storage of the state of the balance of wallets.
29
+
*/
30
+
'cache' => ['driver' => 'array'],
31
+
```
32
+
33
+
You need `redis-server` and `php-redis`.
34
+
35
+
Redis is recommended but not required. You can choose whatever the [framework](https://laravel.com/docs/8.x/cache#introduction) offers you.
Sometimes you need to execute many simple queries. You want to keep the data atomic. To do this, you need `laravel-wallet` v7.1+.
4
+
5
+
It is necessary to write off the amount from the balance and raise the ad in the search. What happens if the service for raising an ad fails? We wrote off the money, but did not raise the ad. Received reputational losses. We can imagine the opposite situation, we first raise the ad in the search, but it does not work to write off the money. There are not enough funds. This functionality will help to solve all this. We monitor ONLY the state of the wallet, the rest falls on the developer. Let's take an unsuccessful lift, for example.
6
+
7
+
```php
8
+
use Bavix\Wallet\Internal\Service\DatabaseServiceInterface;
9
+
10
+
/** @var object $businessLogicService */
11
+
/** @var \Bavix\Wallet\Models\Wallet $payer */
12
+
$payer->balanceInt; // 9999
13
+
app(DatabaseServiceInterface::class)->transaction(statuc function () use ($payer) {
14
+
$payer->withdraw(1000); // 8999
15
+
$businessLogicService->doingMagic($payer); // throws an exception
16
+
}); // rollback payer balance
17
+
18
+
$payer->balanceInt; // 9999
19
+
```
20
+
21
+
Now let's look at the successful raising of the ad.
22
+
23
+
```php
24
+
use Bavix\Wallet\Internal\Service\DatabaseServiceInterface;
25
+
26
+
/** @var object $businessLogicService */
27
+
/** @var \Bavix\Wallet\Models\Wallet $payer */
28
+
$payer->balanceInt; // 9999
29
+
app(DatabaseServiceInterface::class)->transaction(statuc function () use ($payer) {
0 commit comments