Skip to content

Commit

Permalink
Add reference to WalletsLog fillable properties
Browse files Browse the repository at this point in the history
  • Loading branch information
3m1n3nc3 committed Jan 11, 2024
1 parent b5a7974 commit 8096fd8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
9 changes: 6 additions & 3 deletions config/pay-pocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
'log_reference_length' => 12,
'log_reference_prefix' => null,
/**
* The log reference generator should be static
* The third array item should contain optional parameters to pass to the generator
* The log reference generator should be a numeric array with 3 indexes
* First item should be a static class
* Second item sould be method availble in the static class
* third item should be an array of optional parameters to pass to the method
* The default generator looks like this: [\Illuminate\Support\Str::class, 'random', [12]]
*/
'log_reference_generator' => [\Illuminate\Support\Str::class, 'random', [15]],
'log_reference_generator' => null,
];
2 changes: 1 addition & 1 deletion src/Models/WalletsLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WalletsLog extends Model
use HasFactory;

protected $fillable = [
'from', 'to', 'type', 'ip', 'value', 'wallet_name', 'notes',
'from', 'to', 'type', 'ip', 'value', 'wallet_name', 'notes', 'reference',
];

public function loggable(): MorphTo
Expand Down
4 changes: 3 additions & 1 deletion src/Traits/BalanceOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ protected function createLog($logType, $value, $notes = null): void

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

$refGen = config('pay-pocket.log_reference_generator', [Str::class, 'random', [12]]);
$refGen = config('pay-pocket.log_reference_generator', [
Str::class, 'random', [config('pay-pocket.log_reference_length', 12)]
]);
$reference = config('pay-pocket.reference_string_prefix', '');
$reference .= isset($refGen[0], $refGen[1])
? $refGen[0]::{$refGen[1]}(...$refGen[2] ?? [])
Expand Down
10 changes: 10 additions & 0 deletions tests/OperationsWithFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,13 @@

expect(WalletsLog::where('notes', $description)->exists())->toBe(true);
});

test('transaction reference is added to wallet log', function () {
$user = User::factory()->create();

$type = 'wallet_2';

LaravelPayPocket::deposit($user, $type, 234.56);

expect(WalletsLog::whereNotNull('reference')->exists())->toBe(true);
});
10 changes: 10 additions & 0 deletions tests/OperationsWithoutFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,13 @@

expect(WalletsLog::where('notes', $description)->exists())->toBe(true);
});

test('transaction reference is added to wallet log', function () {
$user = User::factory()->create();

$type = 'wallet_2';

$user->deposit($type, 234.56);

expect(WalletsLog::whereNotNull('reference')->exists())->toBe(true);
});

0 comments on commit 8096fd8

Please sign in to comment.