From d78df0cf18c72dc2b6cc36ffcd32a646d9c3c0cf Mon Sep 17 00:00:00 2001 From: Tint Naing Win Date: Fri, 12 Jan 2024 16:55:47 +0700 Subject: [PATCH 1/8] chore:update email --- .github/SECURITY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/SECURITY.md b/.github/SECURITY.md index 23a44c8..f884a81 100644 --- a/.github/SECURITY.md +++ b/.github/SECURITY.md @@ -1,3 +1,3 @@ # Security Policy -If you discover any security related issues, please email <:author_email> instead of using the issue tracker. +If you discover any security related issues, please email amigo.k8@gmail.com instead of using the issue tracker. From 8aef6d18de51cdf7573fad692c1b9431e04a9a32 Mon Sep 17 00:00:00 2001 From: Tint Naing Win Date: Fri, 12 Jan 2024 16:56:09 +0700 Subject: [PATCH 2/8] chore:update --- LICENSE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index cf72c99..0b92669 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) :author_name <:author_email> +Copyright (c) AgeekDev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From fc129c959ca407d144ce76bbec0e2d87a55c48d2 Mon Sep 17 00:00:00 2001 From: Tint Naing Win Date: Fri, 12 Jan 2024 16:56:44 +0700 Subject: [PATCH 3/8] chore:update --- ...2023_12_31_153356_create_credits_table.php | 0 ...53426_create_credit_transactions_table.php | 0 ...reate_credit_transaction_details_table.php | 0 src/Enums/CreditTransactionType.php | 6 +-- src/Facades/GeekCredit.php | 2 +- src/GeekCreditServiceProvider.php | 40 +++++++++++++------ src/Models/Credit.php | 11 +++++ src/Models/CreditTransaction.php | 9 +++++ src/Models/CreditTransactionDetail.php | 16 ++++---- src/Services/CreditService.php | 7 ++-- 10 files changed, 63 insertions(+), 28 deletions(-) rename database/{ => migrations}/2023_12_31_153356_create_credits_table.php (100%) rename database/{ => migrations}/2023_12_31_153426_create_credit_transactions_table.php (100%) rename database/{ => migrations}/2023_12_31_161849_create_credit_transaction_details_table.php (100%) diff --git a/database/2023_12_31_153356_create_credits_table.php b/database/migrations/2023_12_31_153356_create_credits_table.php similarity index 100% rename from database/2023_12_31_153356_create_credits_table.php rename to database/migrations/2023_12_31_153356_create_credits_table.php diff --git a/database/2023_12_31_153426_create_credit_transactions_table.php b/database/migrations/2023_12_31_153426_create_credit_transactions_table.php similarity index 100% rename from database/2023_12_31_153426_create_credit_transactions_table.php rename to database/migrations/2023_12_31_153426_create_credit_transactions_table.php diff --git a/database/2023_12_31_161849_create_credit_transaction_details_table.php b/database/migrations/2023_12_31_161849_create_credit_transaction_details_table.php similarity index 100% rename from database/2023_12_31_161849_create_credit_transaction_details_table.php rename to database/migrations/2023_12_31_161849_create_credit_transaction_details_table.php diff --git a/src/Enums/CreditTransactionType.php b/src/Enums/CreditTransactionType.php index 0c796e8..e5526e6 100644 --- a/src/Enums/CreditTransactionType.php +++ b/src/Enums/CreditTransactionType.php @@ -9,7 +9,7 @@ enum CreditTransactionType: int public function text(): string { - return match ($this->value) { + return match ($this) { self::In => 'In', self::Out => 'Out', }; @@ -17,11 +17,11 @@ public function text(): string public function isOut(): bool { - return $this->value === self::Out; + return $this === self::Out; } public function isIn(): bool { - return $this->value === self::In; + return $this === self::In; } } diff --git a/src/Facades/GeekCredit.php b/src/Facades/GeekCredit.php index e565b1d..9b6a3a0 100644 --- a/src/Facades/GeekCredit.php +++ b/src/Facades/GeekCredit.php @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Facade; /** - * @see \Ageekdev\GeekCredit\geek-credit + * @see \Ageekdev\GeekCredit\GeekCredit */ class GeekCredit extends Facade { diff --git a/src/GeekCreditServiceProvider.php b/src/GeekCreditServiceProvider.php index 3588e83..514f5f8 100644 --- a/src/GeekCreditServiceProvider.php +++ b/src/GeekCreditServiceProvider.php @@ -11,15 +11,7 @@ class GeekCreditServiceProvider extends ServiceProvider */ public function register(): void { - $this->loadMigrationsFrom([ - dirname(__DIR__).'/database', - ]); - - $this->mergeConfigFrom(__DIR__.'/../config/geek-credit.php', 'geek-credit'); - - $this->app->singleton('geek-credit', function () { - return new GeekCredit(); - }); + $this->configure(); } /** @@ -27,8 +19,32 @@ public function register(): void */ public function boot(): void { - $this->publishes([ - __DIR__.'/../config/geek-credit.php' => config_path('geek-credit.php'), - ], 'config'); + $this->registerPublishing(); + } + + /** + * Setup the configuration. + */ + protected function configure(): void + { + $this->mergeConfigFrom( + __DIR__.'/../config/geek-credit.php', 'geek-credit' + ); + } + + /** + * Register the package's publishable resources. + */ + protected function registerPublishing(): void + { + if ($this->app->runningInConsole()) { + $this->publishes([ + __DIR__.'/../config/geek-credit.php' => $this->app->configPath('geek-credit.php'), + ], 'geek-credit-config'); + + $this->publishes([ + __DIR__.'/../database/migrations' => $this->app->databasePath('migrations'), + ], 'geek-credit-migrations'); + } } } diff --git a/src/Models/Credit.php b/src/Models/Credit.php index ef407e1..b88d22f 100644 --- a/src/Models/Credit.php +++ b/src/Models/Credit.php @@ -6,6 +6,17 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; +/** + * @property int $id + * @property string $holder_type + * @property string|int $holder_id + * @property float $initial_balance + * @property float $remaining_balance + * @property array $meta + * @property ?\Illuminate\Support\Carbon $expires_at + * @property-read ?\Illuminate\Support\Carbon $created_at + * @property-read ?\Illuminate\Support\Carbon $updated_at + */ class Credit extends Model { protected $fillable = [ diff --git a/src/Models/CreditTransaction.php b/src/Models/CreditTransaction.php index f7f7d3e..088eec9 100644 --- a/src/Models/CreditTransaction.php +++ b/src/Models/CreditTransaction.php @@ -10,7 +10,16 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; /** + * @property int $id + * @property string $holder_type + * @property string|int $holder_id + * @property float $amount * @property CreditTransactionType $type + * @property string $name + * @property string $description + * @property array $meta + * @property-read ?\Illuminate\Support\Carbon $created_at + * @property-read ?\Illuminate\Support\Carbon $updated_at */ class CreditTransaction extends Model { diff --git a/src/Models/CreditTransactionDetail.php b/src/Models/CreditTransactionDetail.php index a75c30d..e9065fc 100644 --- a/src/Models/CreditTransactionDetail.php +++ b/src/Models/CreditTransactionDetail.php @@ -2,19 +2,19 @@ namespace Ageekdev\GeekCredit\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +/** + * @property int $id + * @property int $credit_transaction_id + * @property int $credit_id + * @property float $amount + * @property-read ?\Illuminate\Support\Carbon $created_at + * @property-read ?\Illuminate\Support\Carbon $updated_at + */ class CreditTransactionDetail extends Model { - use HasFactory; - - /** - * Indicates if the model should be timestamped. - * - * @var bool - */ public $timestamps = false; protected $fillable = [ diff --git a/src/Services/CreditService.php b/src/Services/CreditService.php index 19810ed..dd38689 100644 --- a/src/Services/CreditService.php +++ b/src/Services/CreditService.php @@ -81,7 +81,7 @@ public function addNonExpiringCredit( Model $holder, float $amount, ): Credit { - $credit = $this->creditModel->query() + $credit = $this->creditModel ->whereNull('expires_at') ->isHolder($holder) ->lockForUpdate() @@ -193,13 +193,12 @@ public function useCreditFromHolder( } /** - * @return \Illuminate\Support\Collection + * @return \Illuminate\Support\Collection */ public function getRemainingCreditFromHolderForUpdate( Model $holder, - ): Collection { + ) { return $this->creditModel - ->query() ->isHolder($holder) ->notExpired() ->hasRemainingBalance() From 234d2a6ca5967e74c9c908176afdad49fecf85ea Mon Sep 17 00:00:00 2001 From: Tint Naing Win Date: Fri, 12 Jan 2024 16:56:52 +0700 Subject: [PATCH 4/8] chore:update desc --- composer.json | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index fc61d53..b63e1b5 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "ageekdev/geek-credit", - "description": ":package_description", + "description": "To simplify credit management and in-app purchases in Laravel apps.", "keywords": [ "laravel", "geek-credit" @@ -9,8 +9,7 @@ "license": "MIT", "authors": [ { - "name": ":author_name", - "email": ":author_email", + "name": "eidolex", "role": "Developer" } ], @@ -22,11 +21,11 @@ }, "require-dev": { "laravel/pint": "^1.10", - "nunomaduro/collision": "^6.0|^7.0", + "nunomaduro/collision": "^7.0", "nunomaduro/larastan": "^2.0", - "orchestra/testbench": "^7.0|^8.0", - "pestphp/pest": "^1.0|^2.0", - "pestphp/pest-plugin-laravel": "^1.4|^2.0", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.0", + "pestphp/pest-plugin-laravel": "^2.0", "phpstan/extension-installer": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.0", @@ -67,4 +66,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} \ No newline at end of file +} From 859e18d911de0bbf14e47b1c56edbde32e20ba12 Mon Sep 17 00:00:00 2001 From: Tint Naing Win Date: Fri, 12 Jan 2024 16:57:07 +0700 Subject: [PATCH 5/8] chore:add dependabot --- .github/dependabot.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..30c8a49 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + labels: + - "dependencies" \ No newline at end of file From abea23370266c67be456c303b409da40e999d07a Mon Sep 17 00:00:00 2001 From: Tint Naing Win Date: Fri, 12 Jan 2024 16:57:19 +0700 Subject: [PATCH 6/8] chore:improve docs blocks --- README.md | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d829a3c..ee2bf7e 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,10 @@ -You can find instructions for submitting a new package proposal in [this repo](https://github.com/ageekdev/packages). - -# A skeleton repo for contributions - -

geek-credit

+

Geek Credit

[![Laravel 9.x](https://img.shields.io/badge/Laravel-9.x-red.svg?style=flat-square)](https://laravel.com/docs/9.x) [![Laravel 10.x](https://img.shields.io/badge/Laravel-10.x-red.svg?style=flat-square)](http://laravel.com/docs/10.x) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/ageekdev/geek-credit/run-tests.yml?label=tests&style=flat-square)](https://github.com/ageekdev/geek-credit/actions/workflows/run-tests.yml) -Note: Replace GeekCredit :author_name :author_username :author_email geek-credit :package_description with their correct values in README.md, CHANGELOG.md, CONTRIBUTING.md, LICENSE.md, composer.json and other files, then delete this line. Tip: Use "Find in Path/Files" in your code editor to find these keywords within the package directory and replace all occurrences with your specified term. - -This is where your description should go. Add a little code example so build can understand real quick how the package can be used. Try and limit it to a paragraph or two. +The Geek Credit Package simplifies credit management and in-app purchases in Laravel apps. With transaction history and customizable features, it's ideal for implementing credit-based systems. ## Installation @@ -23,12 +17,29 @@ composer require ageekdev/geek-credit You can publish the config file with: ```bash -php artisan vendor:publish --tag="geek-credit-config" +php artisan vendor:publish --provider="Ageekdev\GeekCredit\GeekCreditServiceProvider" --tag="geek-credit-config" ``` +You can publish the migration with: -## Usage +```bash +php artisan vendor:publish --provider="Ageekdev\GeekCredit\GeekCreditServiceProvider" --tag="geek-credit-migrations" +``` +## Using Credit +Add the HasCredit trait on App\User model or any model who acts as user in your app. + +```php +use Illuminate\Database\Eloquent\Model; +use Ageekdev\GeekCredit\Traits\HasCredit; + +class UserModel extends Model +{ + use HasCredit; + + ... +} +``` ## Testing @@ -50,7 +61,6 @@ Please review [our security policy](../../security/policy) on how to report secu ## Credits -- [:author_name](https://github.com/:author_username) - [All Contributors](../../contributors) ## License From b27677ab64340ecb20d4549611f7e94ede135fcc Mon Sep 17 00:00:00 2001 From: Tint Naing Win Date: Fri, 12 Jan 2024 16:57:43 +0700 Subject: [PATCH 7/8] chore:bump actions --- .github/workflows/fix-php-code-style-issues.yml | 2 +- .github/workflows/phpstan.yml | 2 +- .github/workflows/run-tests.yml | 2 +- .github/workflows/update-changelog.yml | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 9336b28..972a956 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Dependencies run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 0a2b17a..9fc582e 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -7,7 +7,7 @@ jobs: name: phpstan runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e6f42db..a6ca20a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -28,7 +28,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml index 12d91cc..7437524 100644 --- a/.github/workflows/update-changelog.yml +++ b/.github/workflows/update-changelog.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: main @@ -21,8 +21,8 @@ jobs: release-notes: ${{ github.event.release.body }} - name: Commit updated CHANGELOG - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: branch: main commit_message: Update CHANGELOG - file_pattern: CHANGELOG.md \ No newline at end of file + file_pattern: CHANGELOG.md From 7a5a4abdd6c1823b85f31d9da9fa1a414bb78f85 Mon Sep 17 00:00:00 2001 From: Tint Naing Win Date: Fri, 12 Jan 2024 16:59:58 +0700 Subject: [PATCH 8/8] chore:update --- .github/workflows/run-tests.yml | 5 +---- README.md | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a6ca20a..a5e0f7f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,15 +14,12 @@ jobs: matrix: os: [ubuntu-latest] php: [8.1, 8.2] - laravel: [10.*, 9.*] + laravel: [10.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* testbench: 8.* larastan: 2.4.* - - laravel: 9.* - testbench: 7.* - larastan: 2.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/README.md b/README.md index ee2bf7e..18f98f3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@

Geek Credit

-[![Laravel 9.x](https://img.shields.io/badge/Laravel-9.x-red.svg?style=flat-square)](https://laravel.com/docs/9.x) [![Laravel 10.x](https://img.shields.io/badge/Laravel-10.x-red.svg?style=flat-square)](http://laravel.com/docs/10.x) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/ageekdev/geek-credit/run-tests.yml?label=tests&style=flat-square)](https://github.com/ageekdev/geek-credit/actions/workflows/run-tests.yml)