{"id":49136794,"url":"https://github.com/pourjanali/sepidar-php-sdk","last_synced_at":"2026-04-21T22:10:33.604Z","repository":{"id":320354822,"uuid":"1081770091","full_name":"pourjanali/sepidar-php-sdk","owner":"pourjanali","description":"A dependency-free, lightweight PHP SDK for seamless integration with the Sepidar API. (یک SDK سبک و بدون وابستگی برای اتصال آسان به وب‌سرویس سپیدار در PHP)","archived":false,"fork":false,"pushed_at":"2025-11-29T16:07:26.000Z","size":802,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-01T17:55:09.953Z","etag":null,"topics":["accounting-api","api-client","farsi","iran","persian","php","sdk","sepidar","sepidar-api","vanilla-php"],"latest_commit_sha":null,"homepage":"http://sepidar-php.freehost.io/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pourjanali.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-23T09:05:53.000Z","updated_at":"2025-11-29T16:07:29.000Z","dependencies_parsed_at":"2025-10-23T11:22:47.601Z","dependency_job_id":"26c23a1b-7e20-4197-a4ea-88028f8d2f08","html_url":"https://github.com/pourjanali/sepidar-php-sdk","commit_stats":null,"previous_names":["pourjanali/sepidar-php-sdk"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pourjanali/sepidar-php-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pourjanali%2Fsepidar-php-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pourjanali%2Fsepidar-php-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pourjanali%2Fsepidar-php-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pourjanali%2Fsepidar-php-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pourjanali","download_url":"https://codeload.github.com/pourjanali/sepidar-php-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pourjanali%2Fsepidar-php-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32112162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accounting-api","api-client","farsi","iran","persian","php","sdk","sepidar","sepidar-api","vanilla-php"],"created_at":"2026-04-21T22:10:33.054Z","updated_at":"2026-04-21T22:10:33.599Z","avatar_url":"https://github.com/pourjanali.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 Sepidar PHP SDK\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/PHP-8.0%2B-blue.svg\" alt=\"PHP Version\"\u003e\u003c/a\u003e\n  \u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/Dependencies-Zero-brightgreen.svg\" alt=\"Dependencies\"\u003e\u003c/a\u003e\n  \u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-darkgreen.svg\" alt=\"License\"\u003e\u003c/a\u003e\n  \u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/Persistence-Enabled-success.svg\" alt=\"Persistence\"\u003e\u003c/a\u003e\n  \u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/Auth%20Methods-2-orange.svg\" alt=\"Authentication Methods\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\nA dependency-free, lightweight PHP SDK for seamless integration with the Sepidar API with built-in authentication persistence and dual authentication methods.\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\nیک SDK سبک و بدون وابستگی برای اتصال آسان به وب‌سرویس سپیدار در PHP با قابلیت ذخیره‌سازی وضعیت احراز هویت و دو روش احراز هویت\n\u003c/p\u003e\n\n---\n\n## 📚 Related Resources\n\n- 🌐 **Swagger API Docs (v111):** [https://pourjanali.github.io/sepidar-api-docs](https://pourjanali.github.io/sepidar-api-docs)  \n- 📚 **API Docs Repository:** [https://github.com/pourjanali/sepidar-api-docs](https://github.com/pourjanali/sepidar-api-docs)\n- ⭕️ **Interactive Demo:** [http://sepidar-php.freehost.io/](http://sepidar-php.freehost.io/)\n\n---\n\n## 🎯 Overview\n\nThis SDK provides a straightforward and hassle-free way to connect your PHP applications to the Sepidar accounting system's web services.  \nIt's designed to be portable, with **zero external dependencies**, making it perfect for any PHP environment — including shared hosting or projects without Composer.\n\n**✨ NEW: Dual Authentication Methods \u0026 Built-in Persistence** - The SDK now supports two authentication approaches and automatically saves authentication state between requests.\n\nاین SDK یک راهکار ساده و بی‌دردسر برای اتصال برنامه‌های PHP شما به وب‌سرویس سیستم حسابداری سپیدار فراهم می‌کند.  \nاین پکیج با هدف پرتابل بودن و **بدون هیچ گونه وابستگی خارجی** طراحی شده و برای هر محیط PHP، از جمله هاست‌های اشتراکی یا پروژه‌هایی که از Composer استفاده نمی‌کنند، ایده‌آل است.\n\n**✨ جدید: دو روش احراز هویت و ذخیره‌سازی خودکار** - اکنون SDK از دو روش احراز هویت پشتیبانی می‌کند و به طور خودکار وضعیت احراز هویت را بین درخواست‌ها ذخیره می‌کند.\n\n---\n\n## 🔐 Authentication Methods (روش‌های احراز هویت)\n\n### Method 1: Traditional Login (روش اول: لاگین سنتی) - **RECOMMENDED**\n\nThis method uses username/password to authenticate and automatically handles the complete Sepidar authentication flow:\n\n1. **Device Registration** - Register your application with Sepidar\n2. **Public Key Extraction** - Extract and cache the RSA public key\n3. **User Login** - Authenticate with credentials\n4. **Token Management** - Automatically handle token expiration (23 hours)\n\n```php\n$client-\u003elogin('username', 'password');\n```\n\n**✅ Advantages:**\n- Standard Sepidar authentication flow\n- Automatic token refresh\n- Secure credential-based authentication\n- Unique user session\n\n**🎯 Recommended For:**\n- Single application instances\n- Standard web applications\n- Scenarios where you control the credentials\n\n### Method 2: Direct Keys (روش دوم: کلیدهای مستقیم)\n\nThis method allows you to provide pre-authenticated headers directly:\n\n```php\n$client-\u003esetDirectKeys(\n    $integrationId,\n    $arbitraryCode, \n    $encArbitraryCode,\n    $generationVersion,\n    $bearerToken\n);\n```\n\n**🔄 Use Case:**\n- Multiple application instances connecting to the same Sepidar service\n- Distributed systems\n- Scenarios where you need to share authentication between applications\n\n**⚠️ Important Note about Sepidar Single-User Limitation:**\nThe Sepidar web service is inherently **single-user** and maintains data internally. If multiple applications try to register and login separately, you'll encounter conflicts. The direct keys method solves this by allowing shared authentication headers across multiple instances.\n\nسرویس وب سپیدار ذاتاً **تک کاربره** است و داده‌ها را به صورت داخلی نگهداری می‌کند. اگر چندین برنامه سعی کنند به طور جداگانه ثبت و لاگین کنند، با خطا مواجه خواهید شد. روش کلیدهای مستقیم این مشکل را با اجازه دادن به اشتراک‌گذاری هدرهای احراز هویت بین چندین نمونه برنامه حل می‌کند.\n\n---\n\n## 🏆 Recommendation (توصیه)\n\n### **Use Traditional Login Method** (استفاده از روش لاگین سنتی)\n\nWe strongly recommend using the **Traditional Login Method** for most use cases because:\n\n1. **Unique User Sessions** - Creates proper user sessions in Sepidar\n2. **Standard Flow** - Follows Sepidar's intended authentication process\n3. **Automatic Management** - SDK handles all complexity automatically\n4. **Security** - Proper credential-based authentication\n\nما به شدت استفاده از **روش لاگین سنتی** را برای اکثر موارد استفاده توصیه می‌کنیم زیرا:\n\n1. **سشن‌های کاربری یکتا** - سشن‌های کاربری مناسب در سپیدار ایجاد می‌کند\n2. **فرآیند استاندارد** - فرآیند احراز هویت مورد نظر سپیدار را دنبال می‌کند\n3. **مدیریت خودکار** - SDK تمام پیچیدگی‌ها را به طور خودکار مدیریت می‌کند\n4. **امنیت** - احراز هویت مبتنی بر اعتبار مناسب\n\n### **When to Use Direct Keys** (چه زمانی از کلیدهای مستقیم استفاده کنیم)\n\nOnly use the direct keys method when:\n- You have multiple applications connecting to the same Sepidar instance\n- You're building a distributed system\n- You need to avoid multiple device registrations\n\nفقط زمانی از روش کلیدهای مستقیم استفاده کنید که:\n- چندین برنامه دارید که به یک نمونه سپیدار متصل می‌شوند\n- در حال ساخت یک سیستم توزیع شده هستید\n- نیاز به جلوگیری از ثبت چندین دستگاه دارید\n\n---\n\n## ⚡ Quick Start (شروع سریع)\n\n### Method 1: Traditional Login (روش لاگین سنتی)\n\n```php\n\u003c?php\nrequire_once 'SepidarApiClient.php';\n\nuse App\\Sepidar\\SepidarApiClient;\n\n$config = [\n    'api_url' =\u003e 'http://127.0.0.1:7373/api',\n    'serial' =\u003e 'YOUR_SEPIDAR_SERIAL',\n    'version' =\u003e '110',\n    'username' =\u003e 'web',\n    'password' =\u003e 'web'\n];\n\ntry {\n    $client = new SepidarApiClient(\n        $config['api_url'],\n        $config['serial'], \n        $config['version']\n    );\n    \n    // Login handles entire auth flow automatically\n    $loginResult = $client-\u003elogin($config['username'], $config['password']);\n    \n    if ($loginResult['success']) {\n        echo \"✅ Login successful!\\n\";\n        \n        // Use authenticated requests\n        $items = $client-\u003egetItems();\n        print_r($items);\n    }\n    \n} catch (Exception $e) {\n    echo \"❌ Error: \" . $e-\u003egetMessage();\n}\n```\n\n### Method 2: Direct Keys (روش کلیدهای مستقیم)\n\n```php\n\u003c?php\nrequire_once 'SepidarApiClient.php';\n\nuse App\\Sepidar\\SepidarApiClient;\n\n$config = [\n    'api_url' =\u003e 'http://127.0.0.1:7373/api',\n    'integration_id' =\u003e 'YOUR_INTEGRATION_ID',\n    'arbitrary_code' =\u003e 'YOUR_ARBITRARY_CODE',\n    'enc_arbitrary_code' =\u003e 'YOUR_ENC_ARBITRARY_CODE', \n    'generation_version' =\u003e '110',\n    'bearer_token' =\u003e 'YOUR_BEARER_TOKEN'\n];\n\ntry {\n    $client = new SepidarApiClient(\n        $config['api_url'],\n        'direct_keys_mode', // Dummy serial for direct keys mode\n        $config['generation_version']\n    );\n    \n    // Set direct authentication keys\n    $client-\u003esetDirectKeys(\n        $config['integration_id'],\n        $config['arbitrary_code'],\n        $config['enc_arbitrary_code'],\n        $config['generation_version'],\n        $config['bearer_token']\n    );\n    \n    // Use authenticated requests directly\n    $items = $client-\u003egetItems();\n    print_r($items);\n    \n} catch (Exception $e) {\n    echo \"❌ Error: \" . $e-\u003egetMessage();\n}\n```\n\n---\n\n## 🛠️ Installation (نصب)\n\n### Method 1: Manual Installation (نصب دستی)\n```php\nrequire_once 'path/to/SepidarApiClient.php';\n```\n\n### Method 2: Composer\n```bash\ncomposer require pourjanali/sepidar-php-sdk\n```\n\n\u003e ⚠️ **Laravel Integration Guide**\n\u003e\n\u003e If you're using Laravel framework, we provide separate repository with sample code and ready-to-use Service Classes for faster implementation.\n\u003e\n\u003e 📋 **[View Laravel Examples \u0026 Guide](https://github.com/pourjanali/sepidar-laravel)**\n\n---\n\n## 🎪 Interactive Demo (دموی تعاملی)\n\nWe provide a comprehensive demo file `example-with-two-authentication-methods.php` that includes:\n\n- **Dual Method Support** - Switch between both authentication methods\n- **Real-time Headers Display** - See exactly what headers are being sent\n- **Authentication Status** - Monitor current auth state\n- **Cache Management** - Clear cache or force re-login\n- **Beautiful Persian UI** - Professional interface with Vazirmatn font\n\nما یک فایل دموی جامع `example-with-two-authentication-methods.php` ارائه می‌دهیم که شامل:\n\n- **پشتیبانی از هر دو روش** - بین دو روش احراز هویت سوییچ کنید\n- **نمایش لحظه‌ای هدرها** - دقیقاً ببینید چه هدرهایی ارسال می‌شوند\n- **وضعیت احراز هویت** - وضعیت فعلی احراز هویت را مانیتور کنید\n- **مدیریت کش** - کش را پاک کنید یا لاگین مجدد اجباری انجام دهید\n- **رابط کاربری فارسی زیبا** - رابط کاربری حرفه‌ای با فونت وزیرمتن\n\n### Running the Demo (اجرای دمو)\n\n1. Place files in your web directory\n2. Access via browser: `http://your-server/sepidar-demo/example-with-two-authentication-methods.php`\n3. Choose your preferred authentication method\n4. Enter your credentials and test the connection\n\n---\n\n## 🔧 Core Features (ویژگی‌های اصلی)\n\n### 🎯 Authentication \u0026 Security\n- **Dual Auth Methods** - Traditional login + direct keys support\n- **Auto Token Management** - 23-hour token lifetime with automatic handling\n- **RSA Encryption** - Secure public key encryption for requests\n- **Header Validation** - Real-time header display for debugging\n\n### ⚡ Performance \u0026 Optimization  \n- **Zero Dependencies** - No Guzzle, phpseclib, or Composer required\n- **Smart Caching** - Automatic persistence of device registration and tokens\n- **State Optimization** - Skip redundant operations on subsequent requests\n- **Memory Efficient** - Single class design with minimal overhead\n\n### 🔄 State Management\n- **Auth Status Monitoring** - Real-time authentication state tracking\n- **Cache Control** - Manual cache clearance and force login options\n- **Serial-based Storage** - Separate cache for each Sepidar serial\n- **Token Recovery** - Automatic handling of expired tokens\n\n---\n\n## 📖 API Reference (مرجع API)\n\n### Core Methods (متدهای اصلی)\n\n#### Authentication Methods (متدهای احراز هویت)\n```php\n// Method 1: Traditional Login\n$client-\u003elogin(string $username, string $password): array\n\n// Method 2: Direct Keys  \n$client-\u003esetDirectKeys(\n    string $integrationId,\n    string $arbitraryCode,\n    string $encArbitraryCode, \n    string $generationVersion,\n    string $token\n): void\n\n// Force fresh login (ignore cache)\n$client-\u003eforceLogin(string $username, string $password): array\n```\n\n#### API Methods (متدهای API)\n```php\n// Get items list (requires authentication)\n$client-\u003egetItems(): array\n\n// Generic GET request\n$client-\u003eget(string $endpoint): array\n\n// Generic POST request  \n$client-\u003epost(string $endpoint, array $data = []): array\n```\n\n#### State Management (مدیریت وضعیت)\n```php\n// Check current authentication status\n$client-\u003egetAuthStatus(): array\n\n// Check if device is registered\n$client-\u003eisDeviceRegistered(): bool\n\n// Check if user is logged in\n$client-\u003eisLoggedIn(): bool\n\n// Get cached token\n$client-\u003egetCachedToken(): ?string\n\n// Clear all authentication cache\n$client-\u003eclearAuthState(): void\n```\n\n---\n\n## 🚨 Troubleshooting (عیب‌یابی)\n\n### Common Issues (مشکلات رایج)\n\n#### Authentication Problems (مشکلات احراز هویت)\n- **\"Device registration failed\"** - Verify Sepidar service is running on port 7373\n- **\"Invalid credentials\"** - Check username/password in Sepidar system\n- **\"Token expired\"** - Use `forceLogin()` or wait for auto-refresh\n\n#### Connection Issues (مشکلات اتصال)\n- **\"cURL extension not enabled\"** - Enable `extension=curl` in php.ini\n- **\"OpenSSL extension not enabled\"** - Enable `extension=openssl` in php.ini  \n- **\"No host part in URL\"** - Verify API URL format (include http://)\n\n#### Cache Issues (مشکلات کش)\n- **\"Cache not working\"** - Check directory permissions for storage path\n- **\"Multiple device registration\"** - Use direct keys method for multiple instances\n\n### Testing Checklist (چک‌لیست تست)\n\n- [ ] Sepidar service running on `http://127.0.0.1:7373`\n- [ ] Port 7373 accessible from your application\n- [ ] cURL and OpenSSL extensions enabled\n- [ ] Valid Sepidar serial and credentials\n- [ ] Write permissions for cache directory (if using persistence)\n\n---\n\n## 📊 Performance Comparison (مقایسه عملکرد)\n\n| Operation | Traditional Login | Direct Keys |\n|-----------|-------------------|-------------|\n| First Request | Full auth flow (reg + login) | Direct API calls |\n| Subsequent Requests | Cached headers | Direct API calls |\n| Multiple Instances | Conflicts possible | Perfect for scaling |\n| Token Management | Automatic (23h) | Manual management |\n| Recommended For | Single applications | Distributed systems |\n\n---\n\n## 🔄 Migration Guide (راهنمای مهاجرت)\n\n### From Single to Multiple Instances (از تک نمونه به چند نمونه)\n\nIf you're moving from a single application to multiple instances:\n\n1. **Current Setup**: Using Traditional Login in one application\n2. **Problem**: Cannot register multiple devices with same credentials\n3. **Solution**: Switch to Direct Keys method\n\n```php\n// Get current headers from working instance\n$headers = $client-\u003egetAuthenticatedHeaders();\n\n// Use these headers in other instances\n$client-\u003esetDirectKeys(\n    $headers['IntegrationID'],\n    $headers['ArbitraryCode'],\n    $headers['EncArbitraryCode'], \n    $headers['GenerationVersion'],\n    str_replace('Bearer ', '', $headers['Authorization'])\n);\n```\n\n---\n\n## 🤝 Contributing (مشارکت)\n\nWe welcome contributions! Please feel free to:\n\n- Submit pull requests for new features or bug fixes\n- Open issues for any bugs or feature requests\n- Improve documentation\n- Share your use cases and experiences\n\nاز مشارکت شما استقبال می‌کنیم! لطفاً:\n\n- درخواست‌های pull برای ویژگی‌های جدید یا رفع خطاها ارسال کنید\n- issue برای باگ‌ها یا درخواست ویژگی‌های جدید ایجاد کنید\n- مستندات را بهبود بخشید\n- موارد استفاده و تجربیات خود را به اشتراک بگذارید\n\n## 📄 License (مجوز)\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\nاین پروژه تحت مجوز MIT منتشر شده است. برای جزئیات بیشتر به فایل [LICENSE](LICENSE) مراجعه کنید.\n\n---\n\n## 🎉 What's New in v2.1\n\n- **Dual Authentication Methods** - Traditional login + direct keys support\n- **Enhanced Header Display** - Real-time visibility of authentication headers\n- **Improved Documentation** - Comprehensive guides for both methods\n- **Better Error Handling** - Detailed error messages and troubleshooting\n- **Interactive Demo** - Web interface to test both authentication methods\n\n**شروع سریع**: فایل `example-with-two-authentication-methods.php` را اجرا کنید - این فایل تمام قابلیت‌های جدید از جمله پشتیبانی از دو روش احراز هویت، نمایش لحظه‌ای هدرها و رابط مدیریت کش را نمایش می‌دهد.\n\n---\n\n## 📞 Support \u0026 Community (پشتیبانی و جامعه)\n\n- **GitHub Issues**: [Report bugs or request features](https://github.com/pourjanali/sepidar-php-sdk/issues)\n- **Documentation**: [Complete API documentation](https://pourjanali.github.io/sepidar-api-docs)\n- **Examples**: [Working code examples](https://github.com/pourjanali/sepidar-php-sdk/tree/main/examples)\n\n**یادآوری مهم**: همیشه از روش لاگین سنتی استفاده کنید مگر اینکه واقعاً نیاز به اتصال چندین برنامه به یک نمونه سپیدار داشته باشید. این روش استانداردتر، امن‌تر و بهتر مدیریت می‌شود.\n\n**Important Reminder**: Always use the Traditional Login method unless you genuinely need multiple applications connecting to the same Sepidar instance. This method is more standard, secure, and better managed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpourjanali%2Fsepidar-php-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpourjanali%2Fsepidar-php-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpourjanali%2Fsepidar-php-sdk/lists"}