Skip to content

Commit 317e555

Browse files
committed
rebase and add notes/description feature
1 parent 8110c2e commit 317e555

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

database/migrations/update_wallets_logs_table.php.stub

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ return new class extends Migration
1212
public function up(): void
1313
{
1414
Schema::table('wallets_logs', function (Blueprint $table) {
15-
if (!Schema::hasColumn('wallets_logs', 'detail')) {
16-
$table->string('detail')->nullable()->after('status');
15+
if (!Schema::hasColumn('wallets_logs', 'notes')) {
16+
$table->string('notes')->nullable()->after('status');
1717
}
1818
if (!Schema::hasColumn('wallets_logs', 'reference')) {
1919
$table->string('reference')->nullable()->after('ip');
@@ -27,8 +27,8 @@ return new class extends Migration
2727
public function down(): void
2828
{
2929
Schema::table('wallets_logs', function (Blueprint $table) {
30-
if (Schema::hasColumn('wallets_logs', 'detail')) {
31-
$table->dropColumn('detail');
30+
if (Schema::hasColumn('wallets_logs', 'notes')) {
31+
$table->dropColumn('notes');
3232
}
3333
if (Schema::hasColumn('wallets_logs', 'reference')) {
3434
$table->dropColumn('reference');

src/Traits/BalanceOperation.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ public function hasBalance(): bool
1919
/**
2020
* Decrement Balance and create a log entry.
2121
*/
22-
public function decrementAndCreateLog($value, $detail = null): void
22+
public function decrementAndCreateLog($value, $notes = null): void
2323
{
24-
$this->createLog('dec', $value, $detail);
24+
$this->createLog('dec', $value, $notes);
2525
$this->decrement('balance', $value);
2626
}
2727

2828
/**
2929
* Increment Balance and create a log entry.
3030
*/
31-
public function incrementAndCreateLog($value, $detail = null): void
31+
public function incrementAndCreateLog($value, $notes = null): void
3232
{
33-
$this->createLog('inc', $value, $detail);
33+
$this->createLog('inc', $value, $notes);
3434
$this->increment('balance', $value);
3535
}
3636

3737
/**
3838
* Create a new log record
3939
*/
40-
protected function createLog($logType, $value, $detail = null): void
40+
protected function createLog($logType, $value, $notes = null): void
4141
{
4242
$currentBalance = $this->balance ?? 0;
4343

@@ -56,10 +56,10 @@ protected function createLog($logType, $value, $detail = null): void
5656
'type' => $logType,
5757
'ip' => \Request::ip(),
5858
'value' => $value,
59-
'detail' => $detail,
59+
'notes' => $notes,
6060
'reference' => $reference
6161
]);
6262

6363
$this->createdLog->changeStatus('Done');
6464
}
65-
}
65+
}

src/Traits/HandlesDeposit.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait HandlesDeposit
1515
/**
1616
* Deposit an amount to the user's wallet of a specific type.
1717
*/
18-
public function deposit(string $type, int|float $amount, $detail = null): bool
18+
public function deposit(string $type, int|float $amount, $notes = null): bool
1919
{
2020
$depositable = $this->getDepositableTypes();
2121

@@ -27,10 +27,10 @@ public function deposit(string $type, int|float $amount, $detail = null): bool
2727
throw new InvalidValueException();
2828
}
2929

30-
DB::transaction(function () use ($type, $amount, $detail) {
30+
DB::transaction(function () use ($type, $amount, $notes) {
3131
$type = WalletEnums::tryFrom($type);
3232
$wallet = $this->wallets()->firstOrCreate(['type' => $type]);
33-
$wallet->incrementAndCreateLog($amount, $detail);
33+
$wallet->incrementAndCreateLog($amount, $notes);
3434
});
3535

3636
return true;
@@ -63,4 +63,4 @@ private function isRequestValid($type, array $depositable)
6363

6464
return true;
6565
}
66-
}
66+
}

src/Traits/HandlesPayment.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ trait HandlesPayment
1313
*
1414
* @throws InsufficientBalanceException
1515
*/
16-
public function pay(int|float $orderValue, $detail = null): void
16+
public function pay(int|float $orderValue, $notes = null): void
1717
{
1818
if (! $this->hasSufficientBalance($orderValue)) {
1919
throw new InsufficientBalanceException('Insufficient balance to cover the order.');
2020
}
2121

22-
DB::transaction(function () use ($orderValue, $detail) {
22+
DB::transaction(function () use ($orderValue, $notes) {
2323
$remainingOrderValue = $orderValue;
2424

2525
$walletsInOrder = $this->wallets()->whereIn('type', $this->walletsInOrder())->get();
@@ -30,7 +30,7 @@ public function pay(int|float $orderValue, $detail = null): void
3030
}
3131

3232
$amountToDeduct = min($wallet->balance, $remainingOrderValue);
33-
$wallet->decrementAndCreateLog($amountToDeduct, $detail);
33+
$wallet->decrementAndCreateLog($amountToDeduct, $notes);
3434
$remainingOrderValue -= $amountToDeduct;
3535

3636
if ($remainingOrderValue <= 0) {
@@ -43,4 +43,4 @@ public function pay(int|float $orderValue, $detail = null): void
4343
}
4444
});
4545
}
46-
}
46+
}

0 commit comments

Comments
 (0)