From 3d92254d38e9f2e5b81dc0278ebb2864e7cbd24f Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Mon, 15 Jan 2024 21:18:41 +0100 Subject: [PATCH 01/21] add transaction for creation of log and actual inc/dec --- src/Traits/BalanceOperation.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Traits/BalanceOperation.php b/src/Traits/BalanceOperation.php index c0ec100..9cac04f 100644 --- a/src/Traits/BalanceOperation.php +++ b/src/Traits/BalanceOperation.php @@ -3,6 +3,7 @@ namespace HPWebdeveloper\LaravelPayPocket\Traits; use HPWebdeveloper\LaravelPayPocket\Models\WalletsLog; +use Illuminate\Support\Facades\DB; use InvalidArgumentException; trait BalanceOperation @@ -22,8 +23,10 @@ public function hasBalance(): bool */ public function decrementAndCreateLog(int|float $value, ?string $notes = null): void { - $this->createLog('dec', $value, $notes); - $this->decrement('balance', $value); + DB::transaction(function () use ($value, $notes) { + $this->createLog('dec', $value, $notes); + $this->decrement('balance', $value); + }); } /** @@ -31,8 +34,10 @@ public function decrementAndCreateLog(int|float $value, ?string $notes = null): */ public function incrementAndCreateLog(int|float $value, ?string $notes = null): void { - $this->createLog('inc', $value, $notes); - $this->increment('balance', $value); + DB::transaction(function () use ($value, $notes) { + $this->createLog('inc', $value, $notes); + $this->increment('balance', $value); + }); } /** From 170d4f4563d6f0078d4750ab7ee19c59d7045d20 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Mon, 15 Jan 2024 21:22:18 +0100 Subject: [PATCH 02/21] log creation in a single query --- src/Traits/BalanceOperation.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Traits/BalanceOperation.php b/src/Traits/BalanceOperation.php index 9cac04f..311e528 100644 --- a/src/Traits/BalanceOperation.php +++ b/src/Traits/BalanceOperation.php @@ -49,7 +49,7 @@ protected function createLog(string $logType, int|float $value, ?string $notes = $newBalance = $logType === 'dec' ? $currentBalance - $value : $currentBalance + $value; - $this->createdLog = $this->logs()->create([ + $walletLog = (new WalletsLog())->fill([ 'wallet_name' => $this->type->value, 'from' => $currentBalance, 'to' => $newBalance, @@ -60,7 +60,9 @@ protected function createLog(string $logType, int|float $value, ?string $notes = 'reference' => $this->generateReference(), ]); - $this->createdLog->changeStatus('Done'); + $walletLog->status = 'Done'; + + $this->createdLog = $this->logs()->save($walletLog); } /** From 23155feb4070375b5b4bcf78b84c91c6c36b8a35 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 22:00:31 +0200 Subject: [PATCH 03/21] fix comment of config file --- config/pay-pocket.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 9dd0dbe..1f01255 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -3,14 +3,15 @@ // config for HPWebdeveloper/LaravelPayPocket /** - * The 'log_reference_generator' should be a numeric array with three elements: - * - The first element should be the fully qualified name of a class that contains static methods. - * This includes the namespace of the class. - * - The second element should be the name of a static method available in the specified class. - * - The third element should be an array of optional parameters to pass to the static method. - * For example, the default generator is configured as follows: - * [\Illuminate\Support\Str::class, 'random', [12]], which uses the 'random' static method - * from the \Illuminate\Support\Str class with 12 as a parameter. + * Configuration for generating log reference strings. + * + * @param int $log_reference_length The length of the generated string. + * @param string $log_reference_prefix The prefix for the generated string. + * @param string $log_reference_generator_class The fully qualified name of the class containing static methods for generation. + * @param string $log_reference_generator_method The name of the static method available in the generator class. + * + * This is how it works in the code: + * Illuminate\Support\Str::random(12) */ return [ 'log_reference_length' => 12, From c56b512f4a10e1f51ea76eefe94a3fc4837e59d1 Mon Sep 17 00:00:00 2001 From: SSEsmaeeli Date: Fri, 12 Apr 2024 20:00:58 +0000 Subject: [PATCH 04/21] Fix styling --- config/pay-pocket.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 1f01255..762dabb 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -5,10 +5,10 @@ /** * Configuration for generating log reference strings. * - * @param int $log_reference_length The length of the generated string. - * @param string $log_reference_prefix The prefix for the generated string. - * @param string $log_reference_generator_class The fully qualified name of the class containing static methods for generation. - * @param string $log_reference_generator_method The name of the static method available in the generator class. + * @param int $log_reference_length The length of the generated string. + * @param string $log_reference_prefix The prefix for the generated string. + * @param string $log_reference_generator_class The fully qualified name of the class containing static methods for generation. + * @param string $log_reference_generator_method The name of the static method available in the generator class. * * This is how it works in the code: * Illuminate\Support\Str::random(12) From b4c682999345bdf32af98a92393cacc1b60823c1 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 22:08:57 +0200 Subject: [PATCH 05/21] update docblock --- config/pay-pocket.php | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 1f01255..9f87b6d 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -2,20 +2,29 @@ // config for HPWebdeveloper/LaravelPayPocket -/** - * Configuration for generating log reference strings. - * - * @param int $log_reference_length The length of the generated string. - * @param string $log_reference_prefix The prefix for the generated string. - * @param string $log_reference_generator_class The fully qualified name of the class containing static methods for generation. - * @param string $log_reference_generator_method The name of the static method available in the generator class. - * - * This is how it works in the code: - * Illuminate\Support\Str::random(12) - */ return [ + + /* + |-------------------------------------------------------------------------- + | Reference Generator Configuration + |-------------------------------------------------------------------------- + | + | This configuration allows you to customize the generation of log reference strings + | within the LaravelPayPocket package. + | + | - log_reference_length: The length of the generated string. + | - log_reference_prefix: The prefix for the generated string. + | - log_reference_generator_class: The fully qualified name of the class containing static methods for generation. + | - log_reference_generator_method: The name of the static method available in the generator class. + | + | This is how it works in the code: + | Illuminate\Support\Str::random(12) + | + */ + 'log_reference_length' => 12, 'log_reference_prefix' => '', 'log_reference_generator_class' => Illuminate\Support\Str::class, 'log_reference_generator_method' => 'random', + ]; From 3ae48144001e12c1c407a70a2e85077ab4a9b38d Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 22:14:17 +0200 Subject: [PATCH 06/21] remove comment --- config/pay-pocket.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 9f87b6d..9c84e76 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -1,7 +1,5 @@ Date: Fri, 12 Apr 2024 22:16:18 +0200 Subject: [PATCH 07/21] test for pipeline --- config/pay-pocket.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 9c84e76..32417e0 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -1,8 +1,8 @@ 12, 'log_reference_prefix' => '', 'log_reference_generator_class' => Illuminate\Support\Str::class, 'log_reference_generator_method' => 'random', - ]; From 7d1c40de1d542a7e670c902fa019e4210438a0a5 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 22:17:29 +0200 Subject: [PATCH 08/21] test --- config/pay-pocket.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 32417e0..84af11e 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -1,24 +1,5 @@ 12, 'log_reference_prefix' => '', From 55e72f0a3ba7364c3e83448ab58c2f0976f12280 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 22:19:28 +0200 Subject: [PATCH 09/21] bring back comment --- config/pay-pocket.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 84af11e..d2f262f 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -1,6 +1,27 @@ 12, 'log_reference_prefix' => '', 'log_reference_generator_class' => Illuminate\Support\Str::class, From 3fe41a6ed7f6234ac809733bdd3bca587ab31ea2 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 23:06:29 +0200 Subject: [PATCH 10/21] bring back original --- config/pay-pocket.php | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index d2f262f..9dd0dbe 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -2,26 +2,17 @@ // config for HPWebdeveloper/LaravelPayPocket +/** + * The 'log_reference_generator' should be a numeric array with three elements: + * - The first element should be the fully qualified name of a class that contains static methods. + * This includes the namespace of the class. + * - The second element should be the name of a static method available in the specified class. + * - The third element should be an array of optional parameters to pass to the static method. + * For example, the default generator is configured as follows: + * [\Illuminate\Support\Str::class, 'random', [12]], which uses the 'random' static method + * from the \Illuminate\Support\Str class with 12 as a parameter. + */ return [ - - /* - |-------------------------------------------------------------------------- - | Reference Generator Configuration - |-------------------------------------------------------------------------- - | - | This configuration allows you to customize the generation of log reference strings - | within the LaravelPayPocket package. - | - | - log_reference_length: The length of the generated string. - | - log_reference_prefix: The prefix for the generated string. - | - log_reference_generator_class: The fully qualified name of the class containing static methods for generation. - | - log_reference_generator_method: The name of the static method available in the generator class. - | - | This is how it works in the code: - | Illuminate\Support\Str::random(12) - | - */ - 'log_reference_length' => 12, 'log_reference_prefix' => '', 'log_reference_generator_class' => Illuminate\Support\Str::class, From 79f42f5833f1770b0479f8c893d3a80b6592d165 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 23:09:38 +0200 Subject: [PATCH 11/21] add docblock for config --- config/pay-pocket.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 9dd0dbe..d2f262f 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -2,17 +2,26 @@ // config for HPWebdeveloper/LaravelPayPocket -/** - * The 'log_reference_generator' should be a numeric array with three elements: - * - The first element should be the fully qualified name of a class that contains static methods. - * This includes the namespace of the class. - * - The second element should be the name of a static method available in the specified class. - * - The third element should be an array of optional parameters to pass to the static method. - * For example, the default generator is configured as follows: - * [\Illuminate\Support\Str::class, 'random', [12]], which uses the 'random' static method - * from the \Illuminate\Support\Str class with 12 as a parameter. - */ return [ + + /* + |-------------------------------------------------------------------------- + | Reference Generator Configuration + |-------------------------------------------------------------------------- + | + | This configuration allows you to customize the generation of log reference strings + | within the LaravelPayPocket package. + | + | - log_reference_length: The length of the generated string. + | - log_reference_prefix: The prefix for the generated string. + | - log_reference_generator_class: The fully qualified name of the class containing static methods for generation. + | - log_reference_generator_method: The name of the static method available in the generator class. + | + | This is how it works in the code: + | Illuminate\Support\Str::random(12) + | + */ + 'log_reference_length' => 12, 'log_reference_prefix' => '', 'log_reference_generator_class' => Illuminate\Support\Str::class, From 8db3f8bd18b3e218dc9499882d8f0a39167391bc Mon Sep 17 00:00:00 2001 From: Hamed Panjeh Date: Tue, 25 Jun 2024 22:46:45 -0300 Subject: [PATCH 12/21] Modify comment --- config/pay-pocket.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index d2f262f..bc74b57 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -12,12 +12,12 @@ | This configuration allows you to customize the generation of log reference strings | within the LaravelPayPocket package. | - | - log_reference_length: The length of the generated string. - | - log_reference_prefix: The prefix for the generated string. + | - log_reference_length: The length of the generated reference string. + | - log_reference_prefix: The prefix for the generated reference string. | - log_reference_generator_class: The fully qualified name of the class containing static methods for generation. | - log_reference_generator_method: The name of the static method available in the generator class. | - | This is how it works in the code: + | This is how it works by default in the code: | Illuminate\Support\Str::random(12) | */ From f06409aa77ff7db0ede8becb95f8ae050ace772e Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 22:14:17 +0200 Subject: [PATCH 13/21] remove comment --- config/pay-pocket.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index bc74b57..157760e 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -1,7 +1,5 @@ Date: Fri, 12 Apr 2024 22:16:18 +0200 Subject: [PATCH 14/21] test for pipeline --- config/pay-pocket.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 157760e..a57709e 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -1,8 +1,8 @@ 12, 'log_reference_prefix' => '', 'log_reference_generator_class' => Illuminate\Support\Str::class, From 43c442951850d72e449c82ebfdc0f9d6ec884fce Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 22:19:28 +0200 Subject: [PATCH 15/21] bring back comment --- config/pay-pocket.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index a57709e..6764663 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -20,6 +20,25 @@ | */ return [ + + /* + |-------------------------------------------------------------------------- + | Reference Generator Configuration + |-------------------------------------------------------------------------- + | + | This configuration allows you to customize the generation of log reference strings + | within the LaravelPayPocket package. + | + | - log_reference_length: The length of the generated string. + | - log_reference_prefix: The prefix for the generated string. + | - log_reference_generator_class: The fully qualified name of the class containing static methods for generation. + | - log_reference_generator_method: The name of the static method available in the generator class. + | + | This is how it works in the code: + | Illuminate\Support\Str::random(12) + | + */ + 'log_reference_length' => 12, 'log_reference_prefix' => '', 'log_reference_generator_class' => Illuminate\Support\Str::class, From e4dc1a597eb1a677e7120c9afdffdbd641c32634 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 23:06:29 +0200 Subject: [PATCH 16/21] bring back original --- config/pay-pocket.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index 6764663..a57709e 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -20,25 +20,6 @@ | */ return [ - - /* - |-------------------------------------------------------------------------- - | Reference Generator Configuration - |-------------------------------------------------------------------------- - | - | This configuration allows you to customize the generation of log reference strings - | within the LaravelPayPocket package. - | - | - log_reference_length: The length of the generated string. - | - log_reference_prefix: The prefix for the generated string. - | - log_reference_generator_class: The fully qualified name of the class containing static methods for generation. - | - log_reference_generator_method: The name of the static method available in the generator class. - | - | This is how it works in the code: - | Illuminate\Support\Str::random(12) - | - */ - 'log_reference_length' => 12, 'log_reference_prefix' => '', 'log_reference_generator_class' => Illuminate\Support\Str::class, From cfbc359a69fbed7e3632369a7d6a07193e61b34d Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Fri, 12 Apr 2024 23:09:38 +0200 Subject: [PATCH 17/21] add docblock for config --- config/pay-pocket.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index a57709e..d2f262f 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -2,7 +2,9 @@ // config for HPWebdeveloper/LaravelPayPocket -/* +return [ + + /* |-------------------------------------------------------------------------- | Reference Generator Configuration |-------------------------------------------------------------------------- @@ -10,16 +12,16 @@ | This configuration allows you to customize the generation of log reference strings | within the LaravelPayPocket package. | - | - log_reference_length: The length of the generated reference string. - | - log_reference_prefix: The prefix for the generated reference string. + | - log_reference_length: The length of the generated string. + | - log_reference_prefix: The prefix for the generated string. | - log_reference_generator_class: The fully qualified name of the class containing static methods for generation. | - log_reference_generator_method: The name of the static method available in the generator class. | - | This is how it works by default in the code: + | This is how it works in the code: | Illuminate\Support\Str::random(12) | -*/ -return [ + */ + 'log_reference_length' => 12, 'log_reference_prefix' => '', 'log_reference_generator_class' => Illuminate\Support\Str::class, From 394b3068595893a97ba9764c2521da449cc45152 Mon Sep 17 00:00:00 2001 From: Hamed Panjeh Date: Tue, 25 Jun 2024 22:46:45 -0300 Subject: [PATCH 18/21] Modify comment --- config/pay-pocket.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/pay-pocket.php b/config/pay-pocket.php index d2f262f..bc74b57 100644 --- a/config/pay-pocket.php +++ b/config/pay-pocket.php @@ -12,12 +12,12 @@ | This configuration allows you to customize the generation of log reference strings | within the LaravelPayPocket package. | - | - log_reference_length: The length of the generated string. - | - log_reference_prefix: The prefix for the generated string. + | - log_reference_length: The length of the generated reference string. + | - log_reference_prefix: The prefix for the generated reference string. | - log_reference_generator_class: The fully qualified name of the class containing static methods for generation. | - log_reference_generator_method: The name of the static method available in the generator class. | - | This is how it works in the code: + | This is how it works by default in the code: | Illuminate\Support\Str::random(12) | */ From 7fcbc24ee89ea461c412ecee68b17710f7738e24 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Sat, 6 Jul 2024 21:03:47 +0200 Subject: [PATCH 19/21] fix workflow --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index fa8c4ad..f5fe893 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -20,7 +20,7 @@ jobs: - laravel: 10.* testbench: 8.* carbon: ^2.63 - php: 8.1 + php: 8.2 - laravel: 11.* testbench: 9.* carbon: ^3.0 From 5867d1a39a8c23b2d286f9787b2117f137522fce Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Sat, 6 Jul 2024 21:10:24 +0200 Subject: [PATCH 20/21] fix --- .github/workflows/run-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index f5fe893..2249479 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,14 +13,14 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.2, 8.3] + php: [8.1, 8.2, 8.3] laravel: [10.*, 11.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* testbench: 8.* carbon: ^2.63 - php: 8.2 + php: 8.1 - laravel: 11.* testbench: 9.* carbon: ^3.0 From 3b5d25c70251c2a6e6a094a1e182b9de0850cb75 Mon Sep 17 00:00:00 2001 From: Sajjad Esmaeeli Date: Sat, 6 Jul 2024 21:12:08 +0200 Subject: [PATCH 21/21] bring back workflow changes --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 2249479..fa8c4ad 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,7 +13,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.1, 8.2, 8.3] + php: [8.2, 8.3] laravel: [10.*, 11.*] stability: [prefer-lowest, prefer-stable] include: