Skip to content

Commit

Permalink
Merge master into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
a1383n committed Sep 27, 2024
1 parent 0e54b4b commit 8aeaa7e
Show file tree
Hide file tree
Showing 36 changed files with 390 additions and 247 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
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
# Laravel Moadian API Driver
# Laravel Moadian API Driver (API Only)

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]
> 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 and private key 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.key
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');
> [!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();

// Get token
$info = Moadian::getToken();

// Get fiscal info
$fiscalInfo = Moadian::getFiscalInfo();

// Get economic code information
$info = Moadian::getEconomicCodeInformation('10840096498');

// Inquiry by reference numbers
$info = Moadian::inquiryByReferenceNumbers(["a45aa663-6888-4025-a89d-86fc789672a0"]);
$info = Moadian::inquiryByReferenceNumbers('a45aa663-6888-4025-a89d-86fc789672a0');
```

### Send Invoice

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 @@ -118,19 +120,13 @@ public function sendInvoice($invoiceId = '') {
}
}

if($invoice->referenceNumber) {
$moadianInvoice->retry = true;
}

$info = Moadian::sendInvoice($moadianInvoice);
$info = $info->getBody();
$info = $info[0];
$info = $info['result'][0];

$invoice->taxID = $header->taxid;
$invoice->uid = $info['uid'] ?? '';
$invoice->referenceNumber = $info['referenceNumber'] ?? '';
$invoice->errorCode = $info['errorCode'] ?? '';
$invoice->errorDetail = $info['errorDetail'] ?? '';
$invoice->taxResult = 'send';

$invoice->save();
Expand All @@ -139,11 +135,17 @@ public function sendInvoice($invoiceId = '') {

Note that you need to have a valid Moadian account and credentials to use this plugin.

There are other types of invoices (Cancellation, corrective, Sales return) that you can send with this package. For more information about different types of invoices and how to send them, please refer to the official document.

## Useful Links

* [The regulation of store terminals](https://www.intamedia.ir/The-regulation-of-store-terminals)
* [Guide to extract public key from digital signature](https://www.intamedia.ir/The-regulation-of-store-terminals/ID/15879/%D8%B1%D8%A7%D9%87%D9%86%D9%85%D8%A7%DB%8C-%D8%A7%D8%B3%D8%AA%D8%AE%D8%B1%D8%A7%D8%AC-%DA%A9%D9%84%DB%8C%D8%AF-%D8%B9%D9%85%D9%88%D9%85%DB%8C-%D8%A7%D8%B2-%D8%A7%D9%85%D8%B6%D8%A7%DB%8C-%D8%AF%DB%8C%D8%AC%DB%8C%D8%AA%D8%A7%D9%84%D9%85%D9%87%D8%B1%D8%B3%D8%A7%D8%B2%D9%85%D8%A7%D9%86%DB%8C-%D9%88-%D8%A8%D8%A7%D8%B1%DA%AF%D8%B0%D8%A7%D8%B1%DB%8C-%D8%A2%D9%86-%D8%AF%D8%B1-%DA%A9%D8%A7%D8%B1%D9%BE%D9%88%D8%B4%D9%87-%D8%B3%D8%A7%D9%85%D8%A7%D9%86%D9%87-%D9%85%D9%88%D8%AF%DB%8C%D8%A7%D9%86)

## 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).
Loading

0 comments on commit 8aeaa7e

Please sign in to comment.