286 lines
22 KiB
PHP
286 lines
22 KiB
PHP
<?php
|
||
/**
|
||
* Template Name: مرجع API
|
||
*
|
||
* @package Hesabix2
|
||
*/
|
||
|
||
get_header();
|
||
|
||
$wrap = 'max-w-[1600px] mx-auto px-4 sm:px-6 lg:px-8';
|
||
$docs_url = function_exists('hesabix2_fp_docs_url') ? hesabix2_fp_docs_url() : home_url('/docs/');
|
||
$swagger = function_exists('hesabix2_api_docs_swagger_ui_url') ? hesabix2_api_docs_swagger_ui_url() : '';
|
||
$openapi_dl = function_exists('hesabix2_api_docs_openapi_url') ? hesabix2_api_docs_openapi_url() : '';
|
||
$postman_url = rest_url('hesabix/v1/postman');
|
||
$default_tag = function_exists('hesabix2_api_docs_default_tag') ? hesabix2_api_docs_default_tag() : 'احراز هویت';
|
||
?>
|
||
|
||
<section class="api-docs-hero bg-gradient-to-l from-brand-600 to-brand-500 text-white py-12 sm:py-14 relative overflow-hidden">
|
||
<div class="<?php echo esc_attr($wrap); ?> relative z-10">
|
||
<div class="flex flex-col lg:flex-row lg:items-end lg:justify-between gap-6">
|
||
<div class="text-center lg:text-right flex-1">
|
||
<p class="text-white/80 text-sm font-medium mb-2"><?php esc_html_e('توسعهدهندگان و یکپارچهسازی', 'hesabix2'); ?></p>
|
||
<h1 class="text-2xl sm:text-3xl lg:text-4xl font-bold mb-3 leading-tight"><?php esc_html_e('مرجع API حسابیکس', 'hesabix2'); ?></h1>
|
||
<p class="text-white/90 text-sm sm:text-base max-w-2xl mx-auto lg:mx-0 mb-4">
|
||
<?php esc_html_e('مستندات فنی REST از منبع رسمی OpenAPI — همگام، قابل جستجو و آمادهٔ اجرای درخواست.', 'hesabix2'); ?>
|
||
</p>
|
||
<ul id="api-docs-hero-stats" class="api-docs-hero-stats list-none p-0 m-0 flex flex-wrap justify-center lg:justify-start gap-3" hidden></ul>
|
||
</div>
|
||
<div class="flex flex-wrap justify-center lg:justify-end gap-2 shrink-0">
|
||
<?php if ($openapi_dl) : ?>
|
||
<a href="<?php echo esc_url($openapi_dl); ?>" class="api-docs-hero-btn api-docs-hero-btn--ghost" target="_blank" rel="noopener noreferrer" dir="ltr">openapi.json</a>
|
||
<?php endif; ?>
|
||
<a href="<?php echo esc_url($postman_url); ?>" class="api-docs-hero-btn api-docs-hero-btn--ghost" download="hesabix-api.postman_collection.json">Postman</a>
|
||
<?php if ($swagger) : ?>
|
||
<a href="<?php echo esc_url($swagger); ?>" class="api-docs-hero-btn api-docs-hero-btn--ghost" target="_blank" rel="noopener noreferrer">Swagger UI</a>
|
||
<?php endif; ?>
|
||
<a href="#api-docs-explorer" class="api-docs-hero-btn api-docs-hero-btn--solid"><?php esc_html_e('مرور API', 'hesabix2'); ?></a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section id="quick-start" class="api-docs-quickstart py-8 bg-white border-b border-slate-100">
|
||
<div class="<?php echo esc_attr($wrap); ?>">
|
||
<h2 class="text-lg font-bold text-slate-800 mb-4 text-center lg:text-right"><?php esc_html_e('شروع سریع', 'hesabix2'); ?></h2>
|
||
<ol class="api-docs-quickstart__steps grid sm:grid-cols-3 gap-4 list-none p-0 m-0">
|
||
<li class="api-docs-quickstart__step">
|
||
<span class="api-docs-quickstart__num">۱</span>
|
||
<p class="font-semibold text-slate-800 mb-1"><?php esc_html_e('کپچا و تنظیمات', 'hesabix2'); ?></p>
|
||
<p class="text-sm text-slate-600 mb-2"><?php esc_html_e('POST /api/v1/auth/captcha', 'hesabix2'); ?></p>
|
||
<button type="button" class="api-docs-quickstart__link text-sm text-brand-600 font-medium" data-goto-tag="احراز هویت" data-goto-op="generate_captcha_api_v1_auth_captcha_post"><?php esc_html_e('مشاهده', 'hesabix2'); ?></button>
|
||
</li>
|
||
<li class="api-docs-quickstart__step">
|
||
<span class="api-docs-quickstart__num">۲</span>
|
||
<p class="font-semibold text-slate-800 mb-1"><?php esc_html_e('ورود و api_key', 'hesabix2'); ?></p>
|
||
<p class="text-sm text-slate-600 mb-2"><?php esc_html_e('POST /api/v1/auth/login', 'hesabix2'); ?></p>
|
||
<button type="button" class="api-docs-quickstart__link text-sm text-brand-600 font-medium" data-goto-tag="<?php echo esc_attr($default_tag); ?>" data-goto-op="login_api_v1_auth_login_post"><?php esc_html_e('مشاهده', 'hesabix2'); ?></button>
|
||
</li>
|
||
<li class="api-docs-quickstart__step">
|
||
<span class="api-docs-quickstart__num">۳</span>
|
||
<p class="font-semibold text-slate-800 mb-1"><?php esc_html_e('فراخوانی محافظتشده', 'hesabix2'); ?></p>
|
||
<p class="text-sm text-slate-600 mb-2" dir="ltr">Authorization: ApiKey …</p>
|
||
<button type="button" class="api-docs-quickstart__link text-sm text-brand-600 font-medium" data-goto-tag="<?php echo esc_attr($default_tag); ?>" data-goto-op="get_current_user_info_api_v1_auth_me_get"><?php esc_html_e('GET /auth/me', 'hesabix2'); ?></button>
|
||
</li>
|
||
</ol>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="py-4 bg-slate-50 border-b border-slate-100">
|
||
<div class="<?php echo esc_attr($wrap); ?>">
|
||
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 text-sm text-slate-600">
|
||
<p id="api-docs-sync-status" class="mb-0" role="status" aria-live="polite"><?php esc_html_e('در حال اتصال…', 'hesabix2'); ?></p>
|
||
<div class="flex flex-wrap items-center gap-3">
|
||
<a href="<?php echo esc_url($docs_url); ?>" class="text-brand-600 font-medium hover:underline"><?php esc_html_e('راهنمای کاربری', 'hesabix2'); ?></a>
|
||
<button type="button" id="api-docs-toggle-schemas" class="text-slate-500 hover:text-brand-600" hidden><?php esc_html_e('مدلهای داده', 'hesabix2'); ?></button>
|
||
<?php if (current_user_can('manage_options')) : ?>
|
||
<button type="button" id="api-docs-admin-refresh" class="text-slate-500 hover:text-brand-600" hidden><?php esc_html_e('بهروزرسانی کش', 'hesabix2'); ?></button>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="api-docs-intro-wrap border-b border-slate-100 bg-white">
|
||
<div class="<?php echo esc_attr($wrap); ?>">
|
||
<details class="api-docs-intro" id="api-docs-intro" open>
|
||
<summary class="api-docs-intro__summary">
|
||
<span><?php esc_html_e('راهنمای کامل: احراز هویت، هدرها و قرارداد پاسخ', 'hesabix2'); ?></span>
|
||
<svg class="api-docs-intro__chevron" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7"/></svg>
|
||
</summary>
|
||
<div id="api-docs-intro-body" class="api-docs-intro__body api-docs-markdown text-slate-600 text-sm leading-relaxed"></div>
|
||
</details>
|
||
</div>
|
||
</section>
|
||
|
||
<section id="api-docs-schemas-panel" class="api-docs-schemas-panel hidden border-b border-slate-200 bg-slate-50">
|
||
<div class="<?php echo esc_attr($wrap); ?> py-6">
|
||
<div class="flex flex-col sm:flex-row sm:items-center gap-3 mb-4">
|
||
<h2 class="text-lg font-bold text-slate-800 m-0"><?php esc_html_e('مدلهای داده (Schemas)', 'hesabix2'); ?></h2>
|
||
<input type="search" id="api-docs-schema-search" class="api-docs-search api-docs-schema-search" placeholder="<?php esc_attr_e('جستجو…', 'hesabix2'); ?>" />
|
||
</div>
|
||
<ul id="api-docs-schema-list" class="api-docs-schema-list"></ul>
|
||
<pre id="api-docs-schema-detail" class="api-docs-schema-detail" hidden dir="ltr"></pre>
|
||
</div>
|
||
</section>
|
||
|
||
<section id="api-docs-explorer" class="api-docs-explorer py-6 sm:py-8 bg-slate-50/80">
|
||
<div class="<?php echo esc_attr($wrap); ?> api-docs-explorer__inner">
|
||
|
||
<div id="api-docs-loading" class="api-docs-loading" role="status" aria-live="polite">
|
||
<div class="api-docs-loading__spinner" aria-hidden="true"></div>
|
||
<p class="api-docs-loading__text"><?php esc_html_e('در حال بارگذاری فهرست API…', 'hesabix2'); ?></p>
|
||
</div>
|
||
|
||
<div id="api-docs-error" class="api-docs-error" hidden role="alert">
|
||
<p class="api-docs-error__msg"></p>
|
||
<button type="button" class="api-docs-btn api-docs-btn--primary" id="api-docs-retry"><?php esc_html_e('تلاش مجدد', 'hesabix2'); ?></button>
|
||
</div>
|
||
|
||
<div id="api-docs-app" class="api-docs-app" hidden>
|
||
|
||
<div class="api-docs-toolbar" role="region" aria-label="<?php esc_attr_e('ابزارها', 'hesabix2'); ?>">
|
||
<div class="api-docs-toolbar__search-wrap">
|
||
<label class="sr-only" for="api-docs-search"><?php esc_html_e('جستجو', 'hesabix2'); ?></label>
|
||
<input type="search" id="api-docs-search" class="api-docs-search" autocomplete="off" spellcheck="false" />
|
||
<kbd class="api-docs-search-kbd" id="api-docs-search-kbd" aria-hidden="true">Ctrl+K</kbd>
|
||
</div>
|
||
<div class="api-docs-toolbar__actions">
|
||
<label class="api-docs-field api-docs-field--server">
|
||
<span class="api-docs-field__label"><?php esc_html_e('آدرس پایه', 'hesabix2'); ?></span>
|
||
<input type="url" id="api-docs-server" class="api-docs-input" dir="ltr" />
|
||
</label>
|
||
<label class="api-docs-toggle-readonly" title="<?php esc_attr_e('بدون ارسال درخواست از مرورگر', 'hesabix2'); ?>">
|
||
<input type="checkbox" id="api-docs-readonly" />
|
||
<span><?php esc_html_e('فقط مشاهده', 'hesabix2'); ?></span>
|
||
</label>
|
||
<button type="button" id="api-docs-auth-btn" class="api-docs-btn api-docs-btn--outline api-docs-auth-btn">
|
||
<span id="api-docs-auth-label"><?php esc_html_e('کلید API', 'hesabix2'); ?></span>
|
||
<span id="api-docs-auth-badge" class="api-docs-auth-badge" hidden aria-hidden="true"></span>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="api-docs-layout">
|
||
<aside class="api-docs-sidebar" aria-label="<?php esc_attr_e('دستهبندی', 'hesabix2'); ?>">
|
||
<div class="api-docs-sidebar__inner">
|
||
<nav id="api-docs-group-nav" class="api-docs-group-nav" aria-label="<?php esc_attr_e('دستههای اصلی', 'hesabix2'); ?>"></nav>
|
||
<div id="api-docs-tag-nav-wrap" class="api-docs-tag-nav-wrap">
|
||
<p class="api-docs-sidebar__label"><?php esc_html_e('بخشها', 'hesabix2'); ?></p>
|
||
<nav id="api-docs-tag-nav" class="api-docs-tag-nav"></nav>
|
||
</div>
|
||
</div>
|
||
</aside>
|
||
|
||
<div class="api-docs-panel">
|
||
<div id="api-docs-op-list-wrap" class="api-docs-op-list-wrap">
|
||
<div class="api-docs-op-list-header">
|
||
<h2 id="api-docs-op-list-title" class="api-docs-op-list-title"></h2>
|
||
<p id="api-docs-op-list-range" class="api-docs-op-list-range text-xs text-slate-500 m-0"></p>
|
||
</div>
|
||
<div id="api-docs-op-list-scroller" class="api-docs-op-list-scroller" tabindex="0">
|
||
<ul id="api-docs-op-list" class="api-docs-op-list" role="list"></ul>
|
||
</div>
|
||
<button type="button" id="api-docs-load-more" class="api-docs-load-more" hidden><?php esc_html_e('بارگذاری بیشتر', 'hesabix2'); ?></button>
|
||
</div>
|
||
|
||
<div class="api-docs-detail-column">
|
||
<article id="api-docs-detail" class="api-docs-detail" hidden>
|
||
<header class="api-docs-detail__header">
|
||
<button type="button" id="api-docs-back" class="api-docs-back lg:hidden"><?php esc_html_e('بازگشت', 'hesabix2'); ?></button>
|
||
<div class="api-docs-detail__badges">
|
||
<span id="api-docs-secured-badge" class="api-docs-secured-badge" hidden></span>
|
||
</div>
|
||
<div class="api-docs-detail__method-path">
|
||
<span id="api-docs-detail-method" class="api-docs-method"></span>
|
||
<code id="api-docs-detail-path" class="api-docs-path" dir="ltr"></code>
|
||
</div>
|
||
<h2 id="api-docs-detail-summary" class="api-docs-detail__title"></h2>
|
||
<p id="api-docs-detail-desc" class="api-docs-detail__desc api-docs-markdown"></p>
|
||
</header>
|
||
|
||
<div id="api-docs-code-samples" class="api-docs-code-samples" hidden>
|
||
<h3 class="api-docs-section-title"><?php esc_html_e('نمونه کد', 'hesabix2'); ?></h3>
|
||
<div class="api-docs-code-tabs" role="tablist">
|
||
<button type="button" class="api-docs-code-tab is-active" data-lang="curl" role="tab">curl</button>
|
||
<button type="button" class="api-docs-code-tab" data-lang="javascript" role="tab">JavaScript</button>
|
||
<button type="button" class="api-docs-code-tab" data-lang="python" role="tab">Python</button>
|
||
<button type="button" class="api-docs-code-tab" data-lang="php" role="tab">PHP</button>
|
||
</div>
|
||
<pre id="api-docs-code-block" class="api-docs-code-block" dir="ltr"></pre>
|
||
<button type="button" id="api-docs-copy-code" class="api-docs-btn api-docs-btn--outline api-docs-btn--sm"><?php esc_html_e('کپی', 'hesabix2'); ?></button>
|
||
</div>
|
||
|
||
<div id="api-docs-detail-sections" class="api-docs-detail__sections"></div>
|
||
<p id="api-docs-spec-loading" class="api-docs-spec-loading text-sm text-slate-500" hidden><?php esc_html_e('در حال بارگذاری جزئیات کامل…', 'hesabix2'); ?></p>
|
||
|
||
<section class="api-docs-try" aria-labelledby="api-docs-try-heading">
|
||
<h3 id="api-docs-try-heading" class="api-docs-section-title"><?php esc_html_e('اجرای درخواست', 'hesabix2'); ?></h3>
|
||
<p class="api-docs-try__warn text-amber-800 bg-amber-50 border border-amber-200 rounded-lg px-3 py-2 text-xs mb-4">
|
||
<?php esc_html_e('کلید API را فقط در محیط امن وارد کنید. درخواست از دامنهٔ سایت ممکن است بهخاطر CORS محدود شود — در آن صورت از curl یا Swagger UI استفاده کنید.', 'hesabix2'); ?>
|
||
</p>
|
||
<fieldset class="api-docs-try-headers">
|
||
<legend class="api-docs-field__label"><?php esc_html_e('هدرهای درخواست', 'hesabix2'); ?></legend>
|
||
<div class="api-docs-try-headers__grid">
|
||
<label class="api-docs-field">
|
||
<span class="api-docs-field__label"><?php esc_html_e('زبان', 'hesabix2'); ?></span>
|
||
<select id="api-docs-h-lang" class="api-docs-input">
|
||
<option value="fa">fa</option>
|
||
<option value="en">en</option>
|
||
</select>
|
||
</label>
|
||
<label class="api-docs-field">
|
||
<span class="api-docs-field__label"><?php esc_html_e('تقویم', 'hesabix2'); ?></span>
|
||
<select id="api-docs-h-calendar" class="api-docs-input">
|
||
<option value="jalali">jalali</option>
|
||
<option value="gregorian">gregorian</option>
|
||
</select>
|
||
</label>
|
||
<label class="api-docs-field api-docs-field--grow">
|
||
<span class="api-docs-field__label">X-Business-ID</span>
|
||
<input type="text" id="api-docs-h-business" class="api-docs-input" dir="ltr" placeholder="<?php esc_attr_e('اختیاری', 'hesabix2'); ?>" />
|
||
</label>
|
||
</div>
|
||
</fieldset>
|
||
<div id="api-docs-try-params" class="api-docs-try__params"></div>
|
||
<label class="api-docs-field api-docs-field--block" id="api-docs-try-body-wrap">
|
||
<span class="api-docs-field__label"><?php esc_html_e('بدنهٔ JSON', 'hesabix2'); ?></span>
|
||
<textarea id="api-docs-try-body" class="api-docs-textarea" rows="6" dir="ltr" spellcheck="false"></textarea>
|
||
</label>
|
||
<div class="api-docs-try__actions">
|
||
<button type="button" id="api-docs-execute" class="api-docs-btn api-docs-btn--primary"><?php esc_html_e('ارسال', 'hesabix2'); ?></button>
|
||
<button type="button" id="api-docs-copy-curl" class="api-docs-btn api-docs-btn--outline"><?php esc_html_e('کپی curl', 'hesabix2'); ?></button>
|
||
</div>
|
||
<div id="api-docs-cors-hint" class="api-docs-cors-hint" hidden role="alert"></div>
|
||
<div id="api-docs-try-result" class="api-docs-try__result" hidden>
|
||
<div class="api-docs-try__result-meta">
|
||
<span id="api-docs-result-status"></span>
|
||
<span id="api-docs-result-time"></span>
|
||
</div>
|
||
<pre id="api-docs-result-body" class="api-docs-result-pre" dir="ltr"></pre>
|
||
</div>
|
||
</section>
|
||
</article>
|
||
|
||
<div id="api-docs-placeholder" class="api-docs-placeholder" role="status">
|
||
<div class="api-docs-empty">
|
||
<div class="api-docs-empty__icon" aria-hidden="true">
|
||
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
|
||
</div>
|
||
<h3 class="api-docs-empty__title"><?php esc_html_e('جزئیات endpoint اینجا نمایش داده میشود', 'hesabix2'); ?></h3>
|
||
<p class="api-docs-empty__lead"><?php esc_html_e('از ستون وسط یک درخواست API را انتخاب کنید تا توضیحات، پارامترها، نمونه کد و امکان اجرای آزمایشی (Try it) را ببینید.', 'hesabix2'); ?></p>
|
||
<ol class="api-docs-empty__steps">
|
||
<li><?php esc_html_e('چپ: دستهٔ اصلی (مثلاً شروع و احراز هویت)', 'hesabix2'); ?></li>
|
||
<li><?php esc_html_e('وسط: یکی از عملیات را بزنید', 'hesabix2'); ?></li>
|
||
<li><?php esc_html_e('راست: مستندات کامل همان عملیات', 'hesabix2'); ?></li>
|
||
</ol>
|
||
<p class="api-docs-empty__hint"><?php esc_html_e('پیشنهاد برای شروع:', 'hesabix2'); ?></p>
|
||
<div id="api-docs-empty-suggestions" class="api-docs-empty__suggestions"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<dialog id="api-docs-auth-dialog" class="api-docs-dialog">
|
||
<form class="api-docs-dialog__inner" id="api-docs-auth-form">
|
||
<h2 class="api-docs-dialog__title"><?php esc_html_e('کلید API', 'hesabix2'); ?></h2>
|
||
<p class="api-docs-dialog__hint text-sm text-slate-500 mb-3"><?php esc_html_e('فرمت: ApiKey ak_live_… یا ApiKey hsx_…', 'hesabix2'); ?></p>
|
||
<input type="text" id="api-docs-auth-input" class="api-docs-input api-docs-input--full" dir="ltr" autocomplete="off" placeholder="ApiKey ak_live_..." />
|
||
<label class="api-docs-dialog__session mt-3 flex items-center gap-2 text-sm text-slate-600">
|
||
<input type="checkbox" id="api-docs-auth-session" />
|
||
<?php esc_html_e('فقط این نشست (پاک شدن با بستن مرورگر)', 'hesabix2'); ?>
|
||
</label>
|
||
<div class="api-docs-dialog__actions">
|
||
<button type="submit" class="api-docs-btn api-docs-btn--primary"><?php esc_html_e('ذخیره', 'hesabix2'); ?></button>
|
||
<button type="button" id="api-docs-auth-clear" class="api-docs-btn api-docs-btn--outline"><?php esc_html_e('پاک کردن', 'hesabix2'); ?></button>
|
||
<button type="button" class="api-docs-btn api-docs-btn--ghost" data-close-dialog><?php esc_html_e('بستن', 'hesabix2'); ?></button>
|
||
</div>
|
||
</form>
|
||
</dialog>
|
||
|
||
<?php
|
||
get_footer();
|