Skip to content

Commit 8096fd8

Browse files
committed
Add reference to WalletsLog fillable properties
1 parent b5a7974 commit 8096fd8

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

config/pay-pocket.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
'log_reference_length' => 12,
66
'log_reference_prefix' => null,
77
/**
8-
* The log reference generator should be static
9-
* The third array item should contain optional parameters to pass to the generator
8+
* The log reference generator should be a numeric array with 3 indexes
9+
* First item should be a static class
10+
* Second item sould be method availble in the static class
11+
* third item should be an array of optional parameters to pass to the method
12+
* The default generator looks like this: [\Illuminate\Support\Str::class, 'random', [12]]
1013
*/
11-
'log_reference_generator' => [\Illuminate\Support\Str::class, 'random', [15]],
14+
'log_reference_generator' => null,
1215
];

src/Models/WalletsLog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class WalletsLog extends Model
1616
use HasFactory;
1717

1818
protected $fillable = [
19-
'from', 'to', 'type', 'ip', 'value', 'wallet_name', 'notes',
19+
'from', 'to', 'type', 'ip', 'value', 'wallet_name', 'notes', 'reference',
2020
];
2121

2222
public function loggable(): MorphTo

src/Traits/BalanceOperation.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ protected function createLog($logType, $value, $notes = null): void
4343

4444
$newBalance = $logType === 'dec' ? $currentBalance - $value : $currentBalance + $value;
4545

46-
$refGen = config('pay-pocket.log_reference_generator', [Str::class, 'random', [12]]);
46+
$refGen = config('pay-pocket.log_reference_generator', [
47+
Str::class, 'random', [config('pay-pocket.log_reference_length', 12)]
48+
]);
4749
$reference = config('pay-pocket.reference_string_prefix', '');
4850
$reference .= isset($refGen[0], $refGen[1])
4951
? $refGen[0]::{$refGen[1]}(...$refGen[2] ?? [])

tests/OperationsWithFacadeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,13 @@
119119

120120
expect(WalletsLog::where('notes', $description)->exists())->toBe(true);
121121
});
122+
123+
test('transaction reference is added to wallet log', function () {
124+
$user = User::factory()->create();
125+
126+
$type = 'wallet_2';
127+
128+
LaravelPayPocket::deposit($user, $type, 234.56);
129+
130+
expect(WalletsLog::whereNotNull('reference')->exists())->toBe(true);
131+
});

tests/OperationsWithoutFacadeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,13 @@
120120

121121
expect(WalletsLog::where('notes', $description)->exists())->toBe(true);
122122
});
123+
124+
test('transaction reference is added to wallet log', function () {
125+
$user = User::factory()->create();
126+
127+
$type = 'wallet_2';
128+
129+
$user->deposit($type, 234.56);
130+
131+
expect(WalletsLog::whereNotNull('reference')->exists())->toBe(true);
132+
});

0 commit comments

Comments
 (0)