Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Jooyeshgar/moadian
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: V0.5
Choose a base ref
...
head repository: Jooyeshgar/moadian
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on May 14, 2023

  1. Copy the full SHA
    a1643dd View commit details
  2. update read me

    hbhossein committed May 14, 2023
    Copy the full SHA
    4766f6e View commit details

Commits on May 15, 2023

  1. taxID validation fixed

    hadi60 committed May 15, 2023
    Copy the full SHA
    f39429f View commit details

Commits on May 21, 2023

  1. update readme

    hbhossein committed May 21, 2023
    Copy the full SHA
    6d58c56 View commit details

Commits on May 28, 2023

  1. new InvoiceHeader fields

    hbhossein committed May 28, 2023
    Copy the full SHA
    354572d View commit details
  2. new InvoiceItem fields

    hbhossein committed May 28, 2023
    Copy the full SHA
    e6d4504 View commit details
  3. New Payment fields

    hbhossein committed May 28, 2023
    Copy the full SHA
    ca8a8ae View commit details

Commits on Jun 18, 2023

  1. Send CyberDepot's codes

    hadi60 committed Jun 18, 2023
    Copy the full SHA
    5fcafb5 View commit details

Commits on Jun 20, 2023

  1. add retry to code

    hadi60 committed Jun 20, 2023
    Copy the full SHA
    70e38b9 View commit details
  2. Merge pull request #9 from Jooyeshgar/7-update-27-3-1402

    Update for compatibility with Moadian API V6.4 27-3-1402
    hadi60 authored Jun 20, 2023
    Copy the full SHA
    0ae69b3 View commit details

Commits on Jun 26, 2023

  1. bug fix

    hbhossein committed Jun 26, 2023
    Copy the full SHA
    0e54b4b View commit details

Commits on Aug 16, 2023

  1. fix normalizer

    hbhossein committed Aug 16, 2023
    Copy the full SHA
    2fcc563 View commit details

Commits on Oct 2, 2023

  1. Copy the full SHA
    5242adc View commit details
  2. create Token traits

    hbhossein committed Oct 2, 2023
    Copy the full SHA
    b811d6b View commit details
  3. new request implementation

    hbhossein committed Oct 2, 2023
    Copy the full SHA
    793e6b0 View commit details

Commits on Oct 4, 2023

  1. add certificate

    hbhossein committed Oct 4, 2023
    Copy the full SHA
    1ffe66c View commit details
  2. Copy the full SHA
    0684a3a View commit details

Commits on Oct 9, 2023

  1. new signature service

    hbhossein committed Oct 9, 2023
    Copy the full SHA
    f377d09 View commit details
  2. new encryption service

    hbhossein committed Oct 9, 2023
    Copy the full SHA
    e55d196 View commit details
  3. send invoice request

    hbhossein committed Oct 9, 2023
    Copy the full SHA
    e6ab189 View commit details
  4. Copy the full SHA
    bafb39a View commit details
  5. inquiry by uid request

    hbhossein committed Oct 9, 2023
    Copy the full SHA
    76d7f81 View commit details
  6. remove ApiClient

    hbhossein committed Oct 9, 2023
    Copy the full SHA
    46f7b35 View commit details
  7. change response template

    hbhossein committed Oct 9, 2023
    Copy the full SHA
    99ef4af View commit details

Commits on Oct 18, 2023

  1. bug fix

    hbhossein committed Oct 18, 2023
    Copy the full SHA
    8e6607b View commit details

Commits on Dec 31, 2023

  1. add baseUri to env

    hbhossein committed Dec 31, 2023
    Copy the full SHA
    51112ee View commit details
  2. update readme

    hbhossein committed Dec 31, 2023
    Copy the full SHA
    1b09056 View commit details

Commits on Feb 18, 2024

  1. Update InvoiceHeader.php

    check if not defined 'CHARACTER_TO_NUMBER_CODING' 
    when use multi instance
    hosseinjarrahi authored Feb 18, 2024
    Copy the full SHA
    d1641c1 View commit details

Commits on Mar 26, 2024

  1. update readme

    hadi60 committed Mar 26, 2024
    Copy the full SHA
    66c0f1a View commit details

Commits on May 30, 2024

  1. Update README.md

    hadi60 authored May 30, 2024
    Copy the full SHA
    bb47731 View commit details
  2. Merge pull request #30 from hosseinjarrahi/patch-1

    Update InvoiceHeader.php
    hadi60 authored May 30, 2024
    Copy the full SHA
    76f2e8c View commit details

Commits on Sep 10, 2024

  1. prevent wrong content on GET requests

    bandi committed Sep 10, 2024
    Copy the full SHA
    9ab07c1 View commit details

Commits on Feb 8, 2025

  1. Copy the full SHA
    d0d58ce View commit details

Commits on Feb 13, 2025

  1. Merge pull request #39 from amizayi/main

    Fix validation for economic code length
    hbhossein authored Feb 13, 2025
    Copy the full SHA
    15444ba View commit details
115 changes: 62 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# 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 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

## 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.
@@ -14,14 +20,15 @@ composer require jooyeshgar/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. 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');
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:

@@ -31,17 +38,14 @@ use Jooyeshgar\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
@@ -64,68 +68,67 @@ public function sendInvoice($invoiceId = '') {

$timestamp = Carbon::parse($invoice->date)->timestamp * 1000;

$Header = new InvoiceHeader(env('MOADIAN_USERNAME'));
$Header->setTaxID(Carbon::parse($invoice->date), $invoice->number);
$Header->indati2m = $timestamp;
$Header->indatim = $timestamp;
$Header->inty = 1; //invoice type
$Header->inno = $invoiceId;
$Header->irtaxid = null; // invoice reference tax ID
$Header->inp = $invoice->inp; //invoice pattern
$Header->ins = 1;
$Header->tins = env('TAXID');
$Header->tob = 2;
$Header->bid = $invoice->nationalnum;
$Header->tinb = $invoice->nationalnum;
$Header->bpc = $invoice->postal;
$header = new InvoiceHeader(env('MOADIAN_USERNAME'));
$header->setTaxID(Carbon::parse($invoice->date), $invoice->number);
$header->indati2m = $timestamp;
$header->indatim = $timestamp;
$header->inty = 1; //invoice type
$header->inno = $invoiceId;
$header->irtaxid = null; // invoice reference tax ID
$header->inp = $invoice->inp; //invoice pattern
$header->ins = 1;
$header->tins = env('TAXID');
$header->tob = 2;
$header->bid = $invoice->nationalnum;
$header->tinb = $invoice->nationalnum;
$header->bpc = $invoice->postal;

$amount = $invoice->items->sum('amount');
$discount = $invoice->items->sum('discount');
$vat = $invoice->items->sum('vat');
$Header->tprdis = $amount;
$Header->tdis = $discount;
$Header->tadis = $amount - $discount;
$Header->tvam = $vat;
$Header->tbill = $amount - $discount + $vat;
$Header->setm = $invoice->setm;
$Header->cap = $amount - $discount + $vat;
$header->tprdis = $amount;
$header->tdis = $discount;
$header->tadis = $amount - $discount;
$header->tvam = $vat;
$header->todam = 0;
$header->tbill = $amount - $discount + $vat;
$header->setm = $invoice->setm;
$header->cap = $amount - $discount + $vat;

$moadianInvoice = new MoadianInvoice($Header);
$moadianInvoice = new MoadianInvoice($header);

foreach ($invoice->items as $item) {
$Body = new InvoiceItem();
$Body->sstid = $item->seals->sstid;
$Body->sstt = $item->desc;
$Body->am = '1';
$Body->mu = 1627;
$Body->fee = $item->amount;
$Body->prdis = $item->amount;
$Body->dis = $item->discount;
$Body->adis = $item->amount - $item->discount;
$Body->vra = '0.09';
$Body->vam = $item->vat;
$Body->tsstam = $item->amount - $item->discount + $item->vat;
$moadianInvoice->addItem($Body);
$body = new InvoiceItem();
$body->sstid = $item->seals->sstid;
$body->sstt = $item->desc;
$body->am = '1';
$body->mu = 1627;
$body->fee = $item->amount;
$body->prdis = $item->amount;
$body->dis = $item->discount;
$body->adis = $item->amount - $item->discount;
$body->vra = 9;
$body->vam = $item->vat; // or directly calculate here like floor($body->adis * $body->vra / 100)
$body->tsstam = $item->amount - $item->discount + $item->vat;
$moadianInvoice->addItem($body);
}

foreach ($invoice->cashes as $cashe) {
if ($cashe->active == 1) {
$Payment = new Payment();
$Payment->trn = $cashe->code;
$Payment->pdt = Carbon::parse($cashe->date)->timestamp * 1000;
$moadianInvoice->addPayment($Payment);
$payment = new Payment();
$payment->trn = $cashe->code;
$payment->pdt = Carbon::parse($cashe->date)->timestamp * 1000;
$moadianInvoice->addPayment($payment);
}
}

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

$invoice->taxID = $Header->taxid;
$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();
@@ -134,11 +137,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).

## 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](https://opensource.org/licenses/GPL-3.0).
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@
"guzzlehttp/guzzle": "^7.0",
"ramsey/uuid": "^4.2",
"symfony/cache": "^5.3|^6.0",
"phpseclib/phpseclib": "^3.0"
"phpseclib/phpseclib": "^3.0",
"firebase/php-jwt": "^6.9"
},
"autoload": {
"psr-4": {
14 changes: 13 additions & 1 deletion src/Facades/Moadian.php
Original file line number Diff line number Diff line change
@@ -2,6 +2,18 @@

namespace Jooyeshgar\Moadian\Facades;

/**
* @method static string getNonce(int $validity = 30)
* @method static Jooyeshgar\Moadian\Http\Response getServerInfo()
* @method static Jooyeshgar\Moadian\Http\Response getFiscalInfo()
* @method static Jooyeshgar\Moadian\Http\Response inquiryByUid(string $uid, string $start = '', string $end = '')
* @method static Jooyeshgar\Moadian\Http\Response inquiryByReferenceNumbers(string $referenceId, string $start = '', string $end = '')
* @method static Jooyeshgar\Moadian\Http\Response getEconomicCodeInformation(string $taxID)
* @method static Jooyeshgar\Moadian\Http\Response sendInvoice(Invoice $invoice)
*
* @see \Jooyeshgar\Moadian\Moadian
*/

use Illuminate\Support\Facades\Facade;

class Moadian extends Facade
@@ -10,4 +22,4 @@ protected static function getFacadeAccessor()
{
return 'Jooyeshgar\Moadian\Moadian';
}
}
}
21 changes: 14 additions & 7 deletions src/Http/EconomicCodeInformation.php
Original file line number Diff line number Diff line change
@@ -2,17 +2,24 @@

namespace Jooyeshgar\Moadian\Http;

class EconomicCodeInformation extends Packet
use Jooyeshgar\Moadian\Services\EncryptionService;
use Jooyeshgar\Moadian\Services\SignatureService;
use Jooyeshgar\Moadian\Traits\HasToken;

class EconomicCodeInformation extends Request
{
use HasToken;

public function __construct(string $taxId)
{
parent::__construct();

$this->path = 'req/api/self-tsp/sync/GET_ECONOMIC_CODE_INFORMATION';
$this->packetType = 'GET_ECONOMIC_CODE_INFORMATION';

$this->data = [
'economicCode' => $taxId,
];
$this->path = 'taxpayer';
$this->params['economicCode'] = $taxId;
}

public function prepare(SignatureService $signer, EncryptionService $encryptor)
{
$this->addToken($signer);
}
}
25 changes: 25 additions & 0 deletions src/Http/FiscalInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Jooyeshgar\Moadian\Http;

use Jooyeshgar\Moadian\Services\EncryptionService;
use Jooyeshgar\Moadian\Services\SignatureService;
use Jooyeshgar\Moadian\Traits\HasToken;

class FiscalInfo extends Request
{
use HasToken;

public function __construct()
{
parent::__construct();

$this->path = 'fiscal-information';
$this->params['memoryId'] = config('moadian.username');
}

public function prepare(SignatureService $signer, EncryptionService $encryptor)
{
$this->addToken($signer);
}
}
15 changes: 0 additions & 15 deletions src/Http/FiscalInfoPacket.php

This file was deleted.

22 changes: 22 additions & 0 deletions src/Http/GetNonce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Jooyeshgar\Moadian\Http;

use Jooyeshgar\Moadian\Services\SignatureService;
use Jooyeshgar\Moadian\Services\EncryptionService;

class GetNonce extends Request
{
/**
* @param int $validity Optional. Validity period of string in seconds.
*/
public function __construct(int $validity = 30)
{
parent::__construct();

$this->path = 'nonce';
$this->params['timeToLive'] = $validity;
}

public function prepare(SignatureService $signer, EncryptionService $encryptor) {}
}
19 changes: 0 additions & 19 deletions src/Http/GetTokenPacket.php

This file was deleted.

30 changes: 21 additions & 9 deletions src/Http/InquiryByReferenceNumber.php
Original file line number Diff line number Diff line change
@@ -2,19 +2,31 @@

namespace Jooyeshgar\Moadian\Http;

class InquiryByReferenceNumber extends Packet
use Jooyeshgar\Moadian\Services\EncryptionService;
use Jooyeshgar\Moadian\Services\SignatureService;
use Jooyeshgar\Moadian\Traits\HasToken;

class InquiryByReferenceNumber extends Request
{
public function __construct(array $refNums, string $username)
use HasToken;

public function __construct(string $referenceId, string $start = '', string $end = '')
{
parent::__construct();

$this->path = 'req/api/self-tsp/sync/INQUIRY_BY_REFERENCE_NUMBER';
$this->packetType = 'INQUIRY_BY_REFERENCE_NUMBER';
$this->fiscalId = $username;
$this->needToken = true;
$this->path = 'inquiry-by-reference-id';
$this->params['referenceIds'] = $referenceId;

$this->data = [
'referenceNumber' => $refNums,
];
if (!empty($start)) {
$this->params['start'] = $start;
}
if (!empty($end)) {
$this->params['end'] = $end;
}
}

public function prepare(SignatureService $signer, EncryptionService $encryptor)
{
$this->addToken($signer);
}
}
Loading