3
3
namespace HPWebdeveloper \LaravelPayPocket \Traits ;
4
4
5
5
use HPWebdeveloper \LaravelPayPocket \Models \WalletsLog ;
6
+ use Illuminate \Support \Facades \DB ;
6
7
use InvalidArgumentException ;
7
8
8
9
trait BalanceOperation
@@ -22,17 +23,21 @@ public function hasBalance(): bool
22
23
*/
23
24
public function decrementAndCreateLog (int |float $ value , ?string $ notes = null ): void
24
25
{
25
- $ this ->createLog ('dec ' , $ value , $ notes );
26
- $ this ->decrement ('balance ' , $ value );
26
+ DB ::transaction (function () use ($ value , $ notes ) {
27
+ $ this ->createLog ('dec ' , $ value , $ notes );
28
+ $ this ->decrement ('balance ' , $ value );
29
+ });
27
30
}
28
31
29
32
/**
30
33
* Increment Balance and create a log entry.
31
34
*/
32
35
public function incrementAndCreateLog (int |float $ value , ?string $ notes = null ): void
33
36
{
34
- $ this ->createLog ('inc ' , $ value , $ notes );
35
- $ this ->increment ('balance ' , $ value );
37
+ DB ::transaction (function () use ($ value , $ notes ) {
38
+ $ this ->createLog ('inc ' , $ value , $ notes );
39
+ $ this ->increment ('balance ' , $ value );
40
+ });
36
41
}
37
42
38
43
/**
0 commit comments