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.
- Demonstrates basic usage of the
jooyeshgar/moadian
package - Retrieves:
- A server nonce via the Moadian API
- Server info
- Basic error handling for API responses
This example is built on top of a fresh Laravel installation and adds a sample route at /test-moadian
that interacts with the سامانه مودیان.
The /test-moadian
route initializes the Moadian client using your private key, certificate, and base API URL. It then sends two test requests:
getNonce()
: Gets a unique one-time token from the tax system.getServerInfo()
: Fetches server information.
The route returns both responses as JSON.
-
Clone the Repository
git clone https://github.com/BaseMax/moadian-api-laravel-example.git cd moadian-api-laravel-example
-
Install Dependencies
composer install
-
Generate Application Key
php artisan key:generate
-
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
-
Serve the Application
php artisan serve
-
Test the Endpoint
Visit:
http://localhost:8000/test-moadian
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);
}
});
- PHP 8.1+
- Laravel 10+
- jooyeshgar/moadian
👉 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.
MIT License © 2025 Max Base