Skip to content

Commit

Permalink
Major changes and improvements (#4)
Browse files Browse the repository at this point in the history
* refactor: preparing

* ci: workflows were added

* style: improve code formatting and fix styling

* analysis: fix issues

* Update InvoiceHeader.php

* Update lint.yml

* Update workflows
  • Loading branch information
a1383n authored Sep 24, 2024
1 parent 9ab07c1 commit 07b2283
Show file tree
Hide file tree
Showing 36 changed files with 416 additions and 280 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
20 changes: 20 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
* text=auto eol=lf

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
CHANGELOG-* export-ignore
CODE_OF_CONDUCT.md export-ignore
CONTRIBUTING.md export-ignore
phpstan.src.neon.dist export-ignore
phpstan.types.neon.dist export-ignore
phpunit.xml.dist export-ignore
RELEASE.md export-ignore
66 changes: 66 additions & 0 deletions .github/workflows/code_analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Code Analyse

on:
push:
branches:
- main
- develop
pull_request:

permissions:
contents: read

jobs:
tests:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [ 7.4, 8.0, 8.1, 8.2, 8.3 ]

name: PHP ${{ matrix.php }}
env:
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
key: php_${{ matrix.php }}_cache_v1
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup cache environment
id: ext_cache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v4
with:
path: ${{ steps.ext_cache.outputs.dir }}
key: ${{ steps.ext_cache.outputs.key }}
restore-keys: ${{ steps.ext_cache.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ env.key }}-${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ env.key }}-${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction --no-progress

- name: Execute Analyze
run: ./vendor/bin/phpstan analyse ./src --level 5 -n --no-progress --no-ansi
59 changes: 59 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Fix Code Style

on:
push:
branches:
- main
- develop
pull_request:

permissions:
contents: write

jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [8.2]

env:
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
key: php_${{ matrix.php }}_cache_v1
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup cache environment
id: ext_cache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v4
with:
path: ${{ steps.ext_cache.outputs.dir }}
key: ${{ steps.ext_cache.outputs.key }}
restore-keys: ${{ steps.ext_cache.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json, dom, curl, libxml, mbstring
coverage: none

- name: Install Pint
run: composer global require laravel/pint

- name: Run Pint
run: pint --preset psr12

- name: Commit linted files
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "style: improve code formatting and fix styling"
63 changes: 63 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Tests

on:
push:
branches:
- main
- develop
pull_request:

jobs:
tests:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [ 7.4, 8.0, 8.1, 8.2, 8.3 ]

name: PHP ${{ matrix.php }}
env:
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
key: php_${{ matrix.php }}_cache_v1
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup cache environment
id: ext_cache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v4
with:
path: ${{ steps.ext_cache.outputs.dir }}
key: ${{ steps.ext_cache.outputs.key }}
restore-keys: ${{ steps.ext_cache.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ env.key }}-${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ env.key }}-${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit
13 changes: 10 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
vendor/*
/.phpunit.cache
/vendor
composer.phar
composer.lock
.phpunit.*
tests/Feature/private.pem
.DS_Store
Thumbs.db
/phpunit.xml
/.idea
/.fleet
/.vscode
.phpunit.result.cache
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,36 @@

This Laravel package provides a convenient way to interact with the API of the "Moadian system" (سامانه مودیان) offered by intamedia.ir. With this package, you can easily make requests to the Moadian API and handle the responses in your Laravel application.

**Important Notice:** This package provides access to the Moadian system API and is not intended for direct user interaction. It's designed for developers integrating Moadian functionality into their applications.

For a user-friendly accounting software experience, we recommend checking out our FreeAmin project (under **development**):

* Link: https://github.com/Jooyeshgar/FreeAmir
> [!IMPORTANT]
> This package provides access to the Moadian system API and is not intended for direct user interaction. It's designed for developers integrating Moadian functionality into their applications.
## Requirements

This package requires Laravel 8 or higher. It has been tested with Laravel 8 and PHP 7.4, as well as with Laravel 10 and PHP 8.1.
This package requires Laravel 8 and PHP 7.4 or higher.

## Installation

To install this package, simply run the following command:
```bash
composer require jooyeshgar/moadian
composer require novaday-co/moadian
```
## Usage

To use this package, you will need to obtain a username, private key and certificate from intamedia.ir. Once you have your credentials, you can configure the package in your Laravel application's `.env` file:
To use this package, you will need to obtain a username, private key and certificate from [intamedia.ir](https://intamedia.ir). Once you have your credentials, you can configure the package in your Laravel application's `.env` file:

```
MOADIAN_USERNAME=your-username-here
MOADIAN_PRIVATE_KEY_PATH=/path/to/private.pem
MOADIAN_CERTIFICATE_PATH=/path/to/certificate.crt
```
The default location to store the private key is: storage_path('app/keys/private.pem');\
The default location to store the certificate is: storage_path('app/keys/certificate.crt');
> [!NOTE]
> The default location to store the private key is: storage_path('app/keys/private.pem');\
> The default location to store the certificate is: storage_path('app/keys/certificate.crt');
You can then use the `Moadian` facade to interact with the Moadian API. Here are some examples:

```php
use Jooyeshgar\Moadian\Facades\Moadian;
use Novaday\Moadian\Facades\Moadian;

// Get server info
$info = Moadian::getServerInfo();
Expand All @@ -53,10 +51,10 @@ $info = Moadian::inquiryByReferenceNumbers('a45aa663-6888-4025-a89d-86fc789672a0
To send an invoice to Moadian, you can use the sendInvoice() method provided by the plugin. Here's an example of how to use it:

```php
use Jooyeshgar\Moadian\Invoice as MoadianInvoice;
use Jooyeshgar\Moadian\InvoiceHeader;
use Jooyeshgar\Moadian\InvoiceItem;
use Jooyeshgar\Moadian\Payment;
use Novaday\Moadian\Invoice as MoadianInvoice;
use Novaday\Moadian\InvoiceHeader;
use Novaday\Moadian\InvoiceItem;
use Novaday\Moadian\Payment;

public function sendInvoice($invoiceId = '') {
$invoiceId = intval($invoiceId);
Expand Down Expand Up @@ -146,8 +144,8 @@ There are other types of invoices (Cancellation, corrective, Sales return) that

## Contributing

If you find a bug or would like to contribute to this package, please feel free to [submit an issue](https://github.com/Jooyeshgar/moadian/issues) or [create a pull request](https://github.com/Jooyeshgar/moadian/pulls).
If you find a bug or would like to contribute to this package, please feel free to [submit an issue](https://github.com/novaday-co/moadian/issues) or [create a pull request](https://github.com/novaday-co/moadian/pulls).

## License

This package is open source software licensed under the [GPL-3.0 license](https://opensource.org/licenses/GPL-3.0).
This package is open source software licensed under the [GPL-3.0 license](./LICENSE).
35 changes: 21 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
{
"name": "jooyeshgar/moadian",
"name": "novaday-co/moadian",
"description": "Laravel package for interacting with the Moadian API of intamedia.ir",
"type": "library",
"keywords": ["laravel", "moadian", "intamedia"],
"homepage": "https://github.com/Jooyeshgar/moadian",
"keywords": [
"laravel",
"moadian",
"intamedia"
],
"homepage": "https://github.com/novaday-co/moadian",
"license": "GPL-3.0",
"authors": [
{
"name": "Hadi Aminzadeh",
"email": "hadi60@gmail.com"
"name": "Amirsobhan Nafariyeh",
"email": "amirsobhan1553@gmail.com"
}
],
"require": {
"php": "^7.4|^8.0",
"ext-openssl": "*",
"guzzlehttp/guzzle": "^7.0",
"ramsey/uuid": "^4.2",
"symfony/cache": "^5.3|^6.0",
"ext-json": "*",
"ext-curl": "*",
"firebase/php-jwt": "^6.10",
"guzzlehttp/guzzle": "^7.4",
"laravel/framework": "^8.37|^9.0|^10.0|^11.0",
"phpseclib/phpseclib": "^3.0",
"firebase/php-jwt": "^6.9"
"ramsey/uuid": "^4.2"
},
"autoload": {
"psr-4": {
"Jooyeshgar\\Moadian\\": "src/",
"Jooyeshgar\\Moadian\\Tests\\": "tests/"
"Novaday\\Moadian\\": "src/",
"Novaday\\Moadian\\Tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^9.0 || ^10.0",
"mockery/mockery": "^1.5"
"phpunit/phpunit": "^9.0 || ^10.0 || ^11.0",
"mockery/mockery": "^1.5",
"phpstan/phpstan": "^1.12"
},
"extra": {
"laravel": {
"providers": [
"Jooyeshgar\\Moadian\\MoadianServiceProvider"
"Novaday\\Moadian\\MoadianServiceProvider"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/moadian.php → config/moadian.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
'private_key_path' => env('MOADIAN_PRIVATE_KEY_PATH'),
'certificate_path' => env('MOADIAN_CERTIFICATE_PATH'),
'base_uri' => env('MOADIAN_BASE_URI'),
];
];
File renamed without changes.
Loading

0 comments on commit 07b2283

Please sign in to comment.