Skip to content

Commit 3d92254

Browse files
committed
add transaction for creation of log and actual inc/dec
1 parent d661d59 commit 3d92254

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Traits/BalanceOperation.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace HPWebdeveloper\LaravelPayPocket\Traits;
44

55
use HPWebdeveloper\LaravelPayPocket\Models\WalletsLog;
6+
use Illuminate\Support\Facades\DB;
67
use InvalidArgumentException;
78

89
trait BalanceOperation
@@ -22,17 +23,21 @@ public function hasBalance(): bool
2223
*/
2324
public function decrementAndCreateLog(int|float $value, ?string $notes = null): void
2425
{
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+
});
2730
}
2831

2932
/**
3033
* Increment Balance and create a log entry.
3134
*/
3235
public function incrementAndCreateLog(int|float $value, ?string $notes = null): void
3336
{
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+
});
3641
}
3742

3843
/**

0 commit comments

Comments
 (0)