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.
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
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..a5e0f7f 100644
--- a/.github/workflows/run-tests.yml
+++ b/.github/workflows/run-tests.yml
@@ -14,21 +14,18 @@ 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 }}
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
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
diff --git a/README.md b/README.md
index d829a3c..18f98f3 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,9 @@
-You can find instructions for submitting a new package proposal in [this repo](https://github.com/ageekdev/packages).
+
Geek Credit
-# A skeleton repo for contributions
-
-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 +16,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 +60,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
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
+}
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 4ad754b..5dbd72a 100644
--- a/src/Services/CreditService.php
+++ b/src/Services/CreditService.php
@@ -85,7 +85,7 @@ public function addNonExpiringCredit(
float $amount,
$meta = null,
): Credit {
- $credit = $this->creditModel->query()
+ $credit = $this->creditModel
->whereNull('expires_at')
->isHolder($holder)
->lockForUpdate()
@@ -200,13 +200,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()