8000 GitHub - BaseMax/moadian-api-laravel-example: A minimal Laravel example demonstrating integration with Iran's national tax system (سامانه مودیان) using the jooyeshgar/moadian PHP package.
[go: up one dir, main page]

Skip to content

A minimal Laravel example demonstrating integration with Iran's national tax system (سامانه مودیان) using the jooyeshgar/moadian PHP package.

License

Notifications You must be signed in to change notification settings

BaseMax/moadian-api-laravel-example

Repository files navigation

Moadian API Laravel Example

This is a simple example Laravel project demonstrating how to use the jooyeshgar/moadian PHP package for integrating with Iran's national tax system (سامانه مودیان).

⚠️ Note: This is a test project and should not be used in production without proper validation, error handling, and security hardening.

🔧 Features

  • Demonstrates basic usage of the jooyeshgar/moadian package
  • Retrieves:
    • A server nonce via the Moadian API
    • Server info
  • Basic error handling for API responses

📁 Project Structure

This example is built on top of a fresh Laravel installation and adds a sample route at /test-moadian that interacts with the سامانه مودیان.

🧪 How It Works

The /test-moadian route initializes the Moadian client using your private key, certificate, and base API URL. It then sends two test requests:

  1. getNonce(): Gets a unique one-time token from the tax system.
  2. getServerInfo(): Fetches server information.

The route returns both responses as JSON.

🛠️ Setup Instructions

  1. Clone the Repository

    git clone https://github.com/BaseMax/moadian-api-laravel-example.git
    cd moadian-api-laravel-example
  2. Install Dependencies

    composer install
  3. Generate Application Key

    php artisan key:generate
  4. Configure Environment

    Copy .env.example to .env and configure the following:

    MOADIAN_USERNAME=xxxxxxxxxxx
    TAXID=xxxxxxxxxxx

    Also ensure your private key and certificate files are placed in:

    storage/app/keys/private.pem
    storage/app/keys/certificate.crt
    
  5. Serve the Application

    php artisan serve
  6. Test the Endpoint

    Visit:

    http://localhost:8000/test-moadian
    

📄 Example Route

This is the key route defined in routes/web.php:

Route::get('/test-moadian', function () {
    try {
        $privateKey = file_get_contents(__DIR__.'/../storage/app/keys/private.pem');
        $certificate = file_get_contents(__DIR__.'/../storage/app/keys/certificate.crt');
        $base_url = 'https://tp.tax.gov.ir/requestsmanager/api/v2/';
        $moadian = new Moadian($privateKey, $certificate, $base_url);
        $nonce = $moadian->getNonce();
        $info = $moadian->getServerInfo();
        return response()->json([$nonce, $info]);
    } catch (\Throwable $e) {
        return response()->json(['error' => $e->getMessage()], 500);
    }
});

📦 Dependencies

Manual PHP Version

👉 Manual PHP Version (Without Laravel)

If you prefer not to use Laravel or any Laravel-specific packages and want to see a pure PHP implementation of the Moadian API integration, you can check out the following repository:

This alternative project demonstrates how to handle the Moadian API in plain PHP using minimal dependencies. It's ideal for educational purposes, small scripts, or custom non-framework projects.

🪪 License

MIT License © 2025 Max Base

About

A minimal Laravel example demonstrating integration with Iran's national tax system (سامانه مودیان) using the jooyeshgar/moadian PHP package.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0