diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 19d16f2..cc14ad4 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -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, ]; diff --git a/src/Models/WalletsLog.php b/src/Models/WalletsLog.php index e278404..b7a4130 100644 --- a/src/Models/WalletsLog.php +++ b/src/Models/WalletsLog.php @@ -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 diff --git a/src/Traits/BalanceOperation.php b/src/Traits/BalanceOperation.php index cf6ceb2..adc3783 100644 --- a/src/Traits/BalanceOperation.php +++ b/src/Traits/BalanceOperation.php @@ -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] ?? []) diff --git a/tests/OperationsWithFacadeTest.php b/tests/OperationsWithFacadeTest.php index 6a44c9e..2421416 100644 --- a/tests/OperationsWithFacadeTest.php +++ b/tests/OperationsWithFacadeTest.php @@ -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); +}); diff --git a/tests/OperationsWithoutFacadeTest.php b/tests/OperationsWithoutFacadeTest.php index 6a9f3d8..e64143f 100644 --- a/tests/OperationsWithoutFacadeTest.php +++ b/tests/OperationsWithoutFacadeTest.php @@ -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); +});