<?php
require_once('../database/header.php');
?>

<!-- Begin Page Content -->
<div class="main-panel">
    <div class="content-wrapper">
        <div class="row mb-4">
            <div class="col-md-12">
                <div class="d-flex justify-content-between align-items-center">
                    <h2 class="text-primary">API 文档</h2>
                </div>
                <p class="text-muted">我们支付网关 API 的集成文档</p>
            </div>
        </div>

        <!-- API Overview Section -->
        <div class="card mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">API 概览</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <h6><i class="fas fa-info-circle text-primary mr-2"></i> 基础 URL</h6>
                        <div class="alert alert-secondary p-2">
                            <code>https://<?php echo htmlspecialchars($_SERVER['HTTP_HOST']); ?>/api/</code>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <h6><i class="fas fa-key text-primary mr-2"></i> API 密钥</h6>
                        <div class="alert alert-secondary p-2">
                            <code><?php echo htmlspecialchars($userdata['api_key']); ?></code>
                        </div>
                    </div>
                </div>
                
<!--                <h6 class="mt-3"><i class="fas fa-exchange-alt text-primary mr-2"></i> Request Format</h6>-->
<!--                <ul>-->
<!--                    <li>All requests must be <code>POST</code> with <code>x-www-form-urlencoded</code> content type</li>-->
<!--                    <li>Include your API key in every request</li>-->
<!--                </ul>-->
                
<!--                <h6 class="mt-3"><i class="fas fa-code text-primary mr-2"></i> Response Format</h6>-->
<!--                <pre class="bg-light p-3 rounded">{-->
<!--    "status": "SUCCESS|FAILED",-->
<!--    "message": "Descriptive message",-->
<!--    "data": {-->
<!--        // Response data-->
<!--    }-->
<!--}</pre>-->
            </div>
        </div>
        
        
        <!-- Create Order API Section -->
<div class="card mb-4">
    <div class="card-header bg-success text-white" style="cursor: pointer;" data-toggle="collapse" data-target="#createOrderSection" aria-expanded="false">
        <div class="d-flex justify-content-between align-items-center">
            <h5 class="mb-0">创建支付订单</h5>
            <div>
                <span class="badge badge-light">POST</span>
                <i class="fas fa-chevron-down ml-2"></i>
            </div>
        </div>
    </div>
    <div class="collapse" id="createOrderSection">
        <div class="card-body">
            <!-- Your existing content goes here -->
            <h6><i class="fas fa-link text-success mr-2"></i> 端点</h6>
            <div class="alert alert-secondary p-2 mb-3">
                <code>https://<?php echo htmlspecialchars($_SERVER['HTTP_HOST']); ?>/api/create-order.php</code>
            </div>

                <h6><i class="fas fa-list text-success mr-2"></i> 参数</h6>
                <div class="table-responsive">
                    <table class="table table-bordered">
                        <thead class="thead-light">
                            <tr>
                                <th width="20%">参数</th>
                                <th width="15%">类型</th>
                                <th width="15%">必须</th>
                                <th>描述</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><code>api_key</code></td>
                                <td>String</td>
                                <td>是</td>
                                <td>您的唯一 API 密钥</td>
                            </tr>
                            <tr>
                                <td><code>orderid</code></td>
                                <td>String</td>
                                <td>是</td>
                                <td>唯一交易 ID（以 'TXN' 开头，后跟数字）</td>
                            </tr>
                            <tr>
                                <td><code>amount</code></td>
                                <td>Decimal</td>
                                <td>是</td>
                                <td>交易金额</td>
                            </tr>
                            <tr>
                                <td><code>customer_name</code></td>
                                <td>String</td>
                                <td>否</td>
                                <td>参考客户名称</td>
                            </tr>
                            <tr>
                                <td><code>redirect_url</code></td>
                                <td>URL</td>
                                <td>是</td>
                                <td>支付后重定向 URL</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                
                <h6 class="mt-4"><i class="fas fa-reply text-success mr-2"></i> 响应示例</h6>
                <pre class="bg-light p-3 rounded">{
    "status": "SUCCESS",
    "message": "Transaction processed successfully",
    "orderid": "TXN74946488",
    "amount": "1",
    "customer_name": "pay2inr",
    "txn_status": "PENDING",
    "qr_code": "https://qr-generator.developer-dhanyainfotech.workers.dev/?upi_id=YANPAY.8Z0Q0L3X2R26101@fbpe&customer_name=pay2inr&amount=1&orderid=TXN74946488",
    "payment_link": "https://fastpay.us.cc/api/payment.php?token=f46c4fa67826f9b90cf58b5bc36268a3"
}</pre>
                
                <div class="mt-4 p-3 bg-light rounded">
                    <h6><i class="fas fa-terminal text-success mr-2"></i> cURL 示例</h6>
                    <pre class="bg-dark text-white p-3 rounded">curl --location 'https://<?php echo htmlspecialchars($_SERVER['HTTP_HOST']); ?>/api/create-order.php' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'api_key=<?php echo htmlspecialchars($userdata['api_key']); ?>' \
--data-urlencode 'orderid=TXN287415798990' \
--data-urlencode 'amount=10' \
--data-urlencode 'customer_name=JUST PAY' \
--data-urlencode 'redirect_url=https://yourdomain.com/callback'</pre>
                </div>
            </div>
        </div>
 </div>
 
 
        <!-- Order Status API Section -->
<div class="card mb-4">
    <div class="card-header bg-info text-white" style="cursor: pointer;" data-toggle="collapse" data-target="#orderStatusSection" aria-expanded="false">
        <div class="d-flex justify-content-between align-items-center">
            <h5 class="mb-0">检查订单状态</h5>
            <div>
                <span class="badge badge-light">POST</span>
                <i class="fas fa-chevron-down ml-2"></i>
            </div>
        </div>
    </div>
    <div class="collapse" id="orderStatusSection">
        <div class="card-body">
                <h6><i class="fas fa-link text-info mr-2"></i> 端点</h6>
                <div class="alert alert-secondary p-2 mb-3">
                    <code>https://<?php echo htmlspecialchars($_SERVER['HTTP_HOST']); ?>/api/order-status.php</code>
                </div>
                
                <h6><i class="fas fa-list text-info mr-2"></i> 参数</h6>
                <div class="table-responsive">
                    <table class="table table-bordered">
                        <thead class="thead-light">
                            <tr>
                                <th width="20%">参数</th>
                                <th width="15%">类型</th>
                                <th width="15%">必须</th>
                                <th>描述</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><code>api_key</code></td>
                                <td>String</td>
                                <td>是</td>
                                <td>您的唯一 API 密钥</td>
                            </tr>
                            <tr>
                                <td><code>orderid</code></td>
                                <td>String</td>
                                <td>是</td>
                                <td>要检查的交易 ID</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                
                <h6 class="mt-4"><i class="fas fa-reply text-info mr-2"></i> 响应示例</h6>
                <pre class="bg-light p-3 rounded">{
    "status": "SUCCESS",
    "message": "Transaction successfully processed",
    "data": {
        "txn_id": "A321CWZNXM07XB_YBL35c8268",
        "orderid": "TXN287415798990",
        "txn_status": "SUCCESS",
        "utr_number": "504327942794",
        "amount": "1.00",
        "received_from": "pay2inr"
    }
}</pre>
                
                <div class="mt-4 p-3 bg-light rounded">
                    <h6><i class="fas fa-terminal text-info mr-2"></i> cURL 示例</h6>
                    <pre class="bg-dark text-white p-3 rounded">curl --location 'https://<?php echo htmlspecialchars($_SERVER['HTTP_HOST']); ?>/api/order-status.php' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'api_key=<?php echo htmlspecialchars($userdata['api_key']); ?>' \
--data-urlencode 'orderid=TXN287415798990'</pre>
                </div>
            </div>
        </div>
         </div>
 
 
 
 
 
 
 
       <!-- VERIFY UTR API Section -->
<div class="card mb-4">
    <div class="card-header bg-info text-white" style="cursor: pointer;" data-toggle="collapse" data-target="#verifyUtrSection" aria-expanded="false">
        <div class="d-flex justify-content-between align-items-center">
            <h5 class="mb-0">验证 UTR</h5>
            <div>
                <span class="badge badge-light">POST</span>
                <i class="fas fa-chevron-down ml-2"></i>
            </div>
        </div>
    </div>
    <div class="collapse" id="verifyUtrSection">
        <div class="card-body">
                <h6><i class="fas fa-link text-info mr-2"></i> 端点</h6>
                <div class="alert alert-secondary p-2 mb-3">
                    <code>https://<?php echo htmlspecialchars($_SERVER['HTTP_HOST']); ?>/api/submit_utr.php</code>
                </div>
                
                <h6><i class="fas fa-list text-info mr-2"></i> 参数</h6>
                <div class="table-responsive">
                    <table class="table table-bordered">
                        <thead class="thead-light">
                            <tr>
                                <th width="20%">参数</th>
                                <th width="15%">类型</th>
                                <th width="15%">必须</th>
                                <th>描述</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><code>api_key</code></td>
                                <td>String</td>
                                <td>是</td>
                                <td>您的唯一 API 密钥</td>
                            </tr>
                            <tr>
                                <td><code>orderid</code></td>
                                <td>String</td>
                                <td>是</td>
                                <td>要检查的交易 ID</td>
                            </tr>
                            <tr>
                                <td><code>utr_number</code></td>
                                <td>String</td>
                                <td>是</td>
                                <td>UTR/参考号</td>
                            </tr>                            
                        </tbody>
                    </table>
                </div>
                
                <h6 class="mt-4"><i class="fas fa-reply text-info mr-2"></i> 响应示例</h6>
                <pre class="bg-light p-3 rounded">{"status":"Success","message":"Transaction successfully
processed","data":{"txn_id":15983156333,"orderid":"LINK7497581905","txn_status":"SUCCESS","utr_number":"511282372328","amount":1,"received_from":"pay2inr","payer_handle":"pay2inr"}}
}</pre>
                
                <div class="mt-4 p-3 bg-light rounded">
                    <h6><i class="fas fa-terminal text-info mr-2"></i> cURL 示例</h6>
                    <pre class="bg-dark text-white p-3 rounded">curl --location 'https://<?php echo htmlspecialchars($_SERVER['HTTP_HOST']); ?>/api/submit_utr.php' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'api_key=<?php echo htmlspecialchars($userdata['api_key']); ?>' \
--data-urlencode 'orderid=TXN287415798990'
--data-urlencode 'utr_number=511282372328'
</pre>
                </div>
            </div>
        </div>
           </div>
           
        
        <!-- Callback Documentation -->
<div class="card">
    <div class="card-header bg-warning text-dark" style="cursor: pointer;" data-toggle="collapse" data-target="#callbackSection" aria-expanded="false">
        <div class="d-flex justify-content-between align-items-center">
            <h5 class="mb-0">回调响应</h5>
                <div>
                <span class="badge badge-light">POST</span>
                <i class="fas fa-chevron-down ml-2"></i>
            </div>
        </div>
    </div>
    <div class="collapse" id="callbackSection">
        <div class="card-body">
                <p>当交易状态发生变化时，我们将向您的回调 URL 发送即时支付通知。</p>
                
                <h6><i class="fas fa-cog text-warning mr-2"></i> 回调 URL 设置</h6>
                <p>在<a href="api-key.php">API 设置</a>页面设置您的回调 URL</p>
                
                <h6 class="mt-3"><i class="fas fa-paper-plane text-warning mr-2"></i> 回调参数</h6>
                <pre class="bg-light p-3 rounded">{
    "user": "username",
    "orderid": "order123",
    "amount": "1000.00",
    "txn_status": "SUCCESS/FAILED",
    "utr_number": "UTR123456789",
    "received_from": "source_name",
    "date": "2023-08-15 14:30:00",
    "api_txn_id": "API12345",
    "transactions_id": "TXN98765"
}</pre>
                
                <div class="alert alert-info mt-3">
                    <i class="fas fa-info-circle"></i> 您的端点应在 5 秒内返回 HTTP 200 OK 响应以确认接收。
                </div>
            </div>
        </div>
    </div>
 </div>


<!-- Add this JavaScript for chevron rotation -->
<script>
$(document).ready(function(){
    $('.card-header').click(function(){
        $(this).find('.fa-chevron-down').toggleClass('rotate-180');
    });
});
</script>

<!-- Add this CSS for smooth rotation -->
<style>
.rotate-180 {
    transform: rotate(180deg);
    transition: transform 0.3s ease;
}
.fa-chevron-down {
    transition: transform 0.3s ease;
}
</style>


<!-- /.container-fluid -->
<?php
require_once('../database/footer.php');
?>