<?php
$rootDomain = preg_replace('/^(api|opengame)\./i', '', (string)($_SERVER['SERVER_NAME'] ?? 'noxpay.club'));
$api = "https://api." . $rootDomain . "/v1/";
$urlGame = "https://opengame." . $rootDomain;
$agent = htmlspecialchars(agent_public_name((array)$data_admin), ENT_QUOTES, 'UTF-8');
$token = htmlspecialchars($data_admin['secret_key'], ENT_QUOTES, 'UTF-8');
?>
<style>
    pre {
        background-color: #0d1428;
        color: #ffffff;
        padding: 10px;
        border-radius: 5px;
        overflow-x: auto;
        font-size: 14px;
    }
    .hljs {
    background: #0d1428; /* Warna gelap */
    color: #dcdcdc; /* Warna teks */
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    }
</style>
<div class="app-page-shell">
    <div class="row g-4">
    <div class="col-12">
        <div id="accordionExample">
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0">Docs API Integration</h5>
        </div>
        <div id="collapseMain" class="show">
            <div class="card-body">
                <p>API NOXPAY menggunakan metode <b>Transfer Funds</b> dengan endpoint:</p>
                <div><b>Your BASE_URL:</b> <?= htmlspecialchars($api, ENT_QUOTES, 'UTF-8') ?></div>
                <div><b>Your Agent Name:</b> <?= $agent ?></div>
                <div><b>Your Secret Key:</b> <?= $token ?></div>
            </div>
        </div>
    </div>
  <!-- Create User -->
<div class="card">
    <div class="card-header" id="headingCreateUser">
        <h5 class="mb-0">
            <button class="btn btn-link btn-block text-left collapsed"
                    type="button"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapseCreateUser"
                    aria-expanded="false"
                    aria-controls="collapseCreateUser">
                Create User
            </button>
        </h5>
    </div>

    <div id="collapseCreateUser"
         class="collapse"
         aria-labelledby="headingCreateUser"
         data-bs-parent="#accordionExample">

        <div class="card-body">

            <p><b>Create User Endpoint:</b></p>

            <code>
                POST <?= htmlspecialchars($api, ENT_QUOTES, 'UTF-8') ?>CreateMember.aspx
            </code>

            <p class="mt-2"><b>Content-Type:</b></p>
            <code>application/x-www-form-urlencoded</code>

            <!-- PARAM TABLE -->
            <div class="table-responsive mt-3">
                <table class="table table-striped table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>Parameter</th>
                            <th>Type</th>
                            <th>Required</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><code>user_agent</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Your Agent Name</td>
                        </tr>
                        <tr>
                            <td><code>signature</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Your Secret Key</td>
                        </tr>
                        <tr>
                            <td><code>user_member</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Username dari website Anda</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <!-- RESPONSE INFO -->
            <div class="mt-3">
                <b>Response:</b><br>
                <ul>
                    <li><code>status</code> → <b>200</b> atau <b>fail</b></li>
                    <li><code>message</code> → status message</li>
                    <li><code>data</code> → user info</li>
                </ul>
            </div>

            <!-- SUCCESS RESPONSE -->
            <p class="text-success mt-3"><b>Example Response Success</b></p>
            <pre>{
    "status": 200,
    "message": "success",
    "data": {
        "username": "TEST123",
        "balance": 0
    }
}</pre>

            <!-- ERROR RESPONSE -->
            <p class="text-danger"><b>Example Response Error</b></p>
            <pre>{
    "status": "fail",
    "msg": "MEMBER EXISTED"
}</pre>

        </div>
    </div>
</div>
</div>

<!-- Transfer Funds -->
<div class="card">
    <div class="card-header" id="headingTwo">
        <h5 class="mb-0">
            <button class="btn btn-link btn-block text-left collapsed"
                    type="button"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapseTwo"
                    aria-expanded="false"
                    aria-controls="collapseTwo">
                Transaction (Deposit / Withdraw)
            </button>
        </h5>
    </div>

    <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
        <div class="card-body">

            <p><b>User Transaction Endpoint:</b></p>
            <code>
                POST <?= htmlspecialchars($api, ENT_QUOTES, 'UTF-8') ?>MakeTransfer.aspx
            </code>

            <p class="mt-2"><b>Content-Type:</b></p>
            <code>application/x-www-form-urlencoded</code>

            <div class="table-responsive mt-3">
                <table class="table table-striped table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>Parameter</th>
                            <th>Type</th>
                            <th>Required</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><code>user_agent</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Agent Name</td>
                        </tr>
                        <tr>
                            <td><code>signature</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Secret Key</td>
                        </tr>
                        <tr>
                            <td><code>user_member</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Username member</td>
                        </tr>
                        <tr>
                            <td><code>amount</code></td>
                            <td>Number</td>
                            <td>Yes</td>
                            <td>Nominal transaksi</td>
                        </tr>
                        <tr>
                            <td><code>type</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td><code>deposit</code> / <code>withdraw</code></td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <p class="text-success mt-3"><b>Example Success Response</b></p>
            <pre>{
    "status": 200,
    "message": "success",
    "data": {
        "username": "TEST123",
        "action": "DEPOSIT",
        "amount_balance": 100000
    }
}</pre>

            <p class="text-danger"><b>Example Error Response</b></p>
            <pre>{
    "status": "fail",
    "msg": "INSUFFICIENT AGENT BALANCE"
}</pre>

        </div>
    </div>
</div>

<!-- Get Balance User -->
<div class="card">
    <div class="card-header" id="headingThree">
        <h5 class="mb-0">
            <button class="btn btn-link btn-block text-left collapsed"
                    type="button"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapseThree"
                    aria-expanded="false"
                    aria-controls="collapseThree">
                Get Balance User
            </button>
        </h5>
    </div>

    <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-bs-parent="#accordionExample">
        <div class="card-body">

            <p><b>Get Balance User Endpoint:</b></p>
            <code>
                POST <?= htmlspecialchars($api, ENT_QUOTES, 'UTF-8') ?>GetBalance.ashx
            </code>

            <p class="mt-2"><b>Content-Type:</b></p>
            <code>application/x-www-form-urlencoded</code>

            <div class="table-responsive mt-3">
                <table class="table table-striped table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>Parameter</th>
                            <th>Type</th>
                            <th>Required</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><code>user_agent</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Agent Name</td>
                        </tr>
                        <tr>
                            <td><code>signature</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Secret Key</td>
                        </tr>
                        <tr>
                            <td><code>user_member</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Username member</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <p class="text-success mt-3"><b>Example Success Response</b></p>
            <pre>{
    "status": 200,
    "message": "success",
    "data": {
        "username": "TEST123",
        "balance": 250.75
    }
}</pre>

            <p class="text-danger"><b>Example Error Response</b></p>
            <pre>{
    "status": "fail",
    "msg": "INVALID PARAMETER"
}</pre>

        </div>
    </div>
</div>

    <!-- Launch Game -->
<div class="card">
    <div class="card-header" id="headingFour">
        <h5 class="mb-0">
            <button class="btn btn-link btn-block text-left collapsed"
                    type="button"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapseFour"
                    aria-expanded="false"
                    aria-controls="collapseFour">
                Launch Game
            </button>
        </h5>
    </div>

    <div id="collapseFour" class="collapse" aria-labelledby="headingFour" data-bs-parent="#accordionExample">
        <div class="card-body">

            <p><b>Launch Game Endpoint:</b></p>
            <code>
                POST <?= htmlspecialchars($api, ENT_QUOTES, 'UTF-8') ?>LaunchGame.aspx
            </code>

            <p class="mt-2"><b>Content-Type:</b></p>
            <code>application/x-www-form-urlencoded</code>

            <div class="table-responsive mt-3">
                <table class="table table-striped table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>Parameter</th>
                            <th>Type</th>
                            <th>Required</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><code>user_agent</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Agent Name</td>
                        </tr>
                        <tr>
                            <td><code>signature</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Secret Key</td>
                        </tr>
                        <tr>
                            <td><code>user_member</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Username member</td>
                        </tr>
                        <tr>
                            <td><code>game_code</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Game code dari Game List</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <p class="text-success mt-3"><b>Example Success Response</b></p>
            <pre>{
    "status": 200,
    "message": "success",
    "data": {
        "gameUrl": "<?= htmlspecialchars($urlGame, ENT_QUOTES, 'UTF-8') ?>/?gameUrl=5f4dcc3b5aa765d61d8327deb882cf99"
    }
}</pre>

            <p class="text-danger"><b>Example Error Response</b></p>
            <pre>{
    "status": "fail",
    "msg": "INVALID GAME"
}</pre>

        </div>
    </div>
</div>
<!-- Get Provider List -->
<div class="card">
    <div class="card-header" id="headingFive">
        <h5 class="mb-0">
            <button class="btn btn-link btn-block text-left collapsed"
                    type="button"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapseFive">
                Get Provider List
            </button>
        </h5>
    </div>

    <div id="collapseFive" class="collapse" data-bs-parent="#accordionExample">
        <div class="card-body">

            <p><b>Get Provider List Endpoint:</b></p>
            <code>POST <?= htmlspecialchars($api, ENT_QUOTES, 'UTF-8') ?>GetProviderList.aspx</code>

            <div class="table-responsive mt-3">
                <table class="table table-striped table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>Parameter</th>
                            <th>Type</th>
                            <th>Required</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><code>user_agent</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Agent Name</td>
                        </tr>
                        <tr>
                            <td><code>signature</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Secret Key</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <pre class="mt-3">{
    "status": 200,
    "provider": [...],
    "msg": "SUCCESS"
}</pre>

        </div>
    </div>
</div>
<!-- Get Game List -->
<div class="card">
    <div class="card-header" id="headingSix">
        <h5 class="mb-0">
            <button class="btn btn-link btn-block text-left collapsed"
                    type="button"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapseSix">
                Get Game List
            </button>
        </h5>
    </div>

    <div id="collapseSix" class="collapse" data-bs-parent="#accordionExample">
        <div class="card-body">

            <p><b>Get Game List Endpoint:</b></p>
            <code>POST <?= htmlspecialchars($api, ENT_QUOTES, 'UTF-8') ?>GetGameList.aspx</code>

            <div class="table-responsive mt-3">
                <table class="table table-striped table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>Parameter</th>
                            <th>Type</th>
                            <th>Required</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><code>user_agent</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Agent Name</td>
                        </tr>
                        <tr>
                            <td><code>signature</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Secret Key</td>
                        </tr>
                        <tr>
                            <td><code>provider</code></td>
                            <td>String</td>
                            <td>No</td>
                            <td>PR / PG / CQ / HB</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <pre class="mt-3">{
    "status": 200,
    "data": {
        "games": [...]
    },
    "msg": "SUCCESS"
}</pre>

        </div>
    </div>
</div>

<!-- Get Balance Agent -->
<div class="card">
    <div class="card-header" id="headingSeven">
        <h5 class="mb-0">
            <button class="btn btn-link btn-block text-left collapsed"
                    type="button"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapseSeven"
                    aria-expanded="false"
                    aria-controls="collapseSeven">
                Get Balance Agent
            </button>
        </h5>
    </div>

    <div id="collapseSeven" class="collapse" aria-labelledby="headingSeven" data-bs-parent="#accordionExample">
        <div class="card-body">

            <p><b>Get Balance Agent Endpoint:</b></p>
            <code>
                POST <?= htmlspecialchars($api, ENT_QUOTES, 'UTF-8') ?>GetBalanceAgent.aspx
            </code>

            <p class="mt-2"><b>Content-Type:</b></p>
            <code>application/x-www-form-urlencoded</code>

            <div class="table-responsive mt-3">
                <table class="table table-striped table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>Parameter</th>
                            <th>Type</th>
                            <th>Required</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><code>user_agent</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Your Agent Name</td>
                        </tr>
                        <tr>
                            <td><code>signature</code></td>
                            <td>String</td>
                            <td>Yes</td>
                            <td>Your Secret Key</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="mt-3">
                <b>Response Status:</b>
                <span class="text-success"><i>200</i></span>
                <span>atau</span>
                <span class="text-danger"><i>fail</i></span>
            </div>

            <div><b>Response Message:</b> <i>message / msg</i></div>

            <p class="text-success mt-3"><b>Example Success Response</b></p>
            <pre>{
    "status": 200,
    "message": "success",
    "data": {
        "balance": 1000000
    }
}</pre>

            <p class="text-danger"><b>Example Error Response</b></p>
            <pre>{
    "status": "fail",
    "msg": "INVALID AGENT"
}</pre>

        </div>
    </div>
</div>
<?php include __DIR__ . '/docsCall.php' ?>
<?php include __DIR__ . '/docsGameHistory.php' ?>
<!-- Example Class PHP -->
<div class="card">
    <div class="card-header" id="headingNine">
        <h5 class="mb-0">
            <button class="btn btn-link btn-block text-left collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseNine" aria-expanded="false" aria-controls="collapseNine">
                Example Class PHP
            </button>
        </h5>
    </div>
    <div id="collapseNine" class="collapse" aria-labelledby="headingNine" data-bs-parent="#accordionExample">
        <div class="card-body">
            <p>Example Class PHP:</p>
            <pre><code class="language-php">
&lt;?php
class NOXPAY
{
    private string $url;
    private string $agent;
    private string $signature;

    public function __construct()
    {
        $this->url       = "<?= $api ?>";
        $this->agent     = "<?= $agent ?>";
        $this->signature = "<?= $token ?>";
    }

    /* ===============================
       CREATE USER
    =============================== */
    public function Create(string $username)
    {
        return $this->post("CreateMember.aspx", [
            'user_agent'  => $this->agent,
            'signature'   => $this->signature,
            'user_member' => $username
        ]);
    }

    /* ===============================
       TRANSFER (DEPOSIT / WITHDRAW)
    =============================== */
    public function Transfer(string $username, float $amount, string $type)
    {
        return $this->post("MakeTransfer.aspx", [
            'user_agent'  => $this->agent,
            'signature'   => $this->signature,
            'user_member' => $username,
            'amount'      => $amount,
            'type'        => $type
        ]);
    }

    /* ===============================
       GET USER BALANCE
    =============================== */
    public function GetBalance(string $username)
    {
        return $this->post("GetBalance.ashx", [
            'user_agent'  => $this->agent,
            'signature'   => $this->signature,
            'user_member' => $username
        ]);
    }

    /* ===============================
       GET AGENT BALANCE
    =============================== */
    public function GetAgentBalance()
    {
        return $this->post("GetBalanceAgent.aspx", [
            'user_agent'  => $this->agent,
            'signature'  => $this->signature
        ]);
    }

    /* ===============================
       GET PROVIDER LIST
    =============================== */
    public function GetProviderList()
    {
        return $this->post("GetProviderList.aspx", [
            'user_agent'  => $this->agent,
            'signature'  => $this->signature
        ]);
    }

    /* ===============================
       GET GAME LIST
    =============================== */
    public function GetGameList(?string $provider = null)
    {
        $data = [
            'user_agent'  => $this->agent,
            'signature'  => $this->signature
        ];

        if ($provider !== null) {
            $data['provider'] = $provider;
        }

        return $this->post("GetGameList.aspx", $data);
    }

    /* ===============================
       LAUNCH GAME
       ⚠ provider & type diambil dari DB
    =============================== */
    public function LaunchGame(string $username, string $game_code)
    {
        return $this->post("LaunchGame.aspx", [
            'user_agent'  => $this->agent,
            'signature'   => $this->signature,
            'user_member' => $username,
            'game_code'   => $game_code
        ]);
    }

    /* ===============================
       GAME HISTORY
    =============================== */
    public function GameHistory(string $username, ?string $start = null, ?string $end = null, string $gameType = 'all')
    {
        $data = [
            'user_agent'  => $this->agent,
            'signature'   => $this->signature,
            'user_member' => $username,
            'game_type'   => $gameType
        ];

        if ($start !== null) {
            $data['start'] = $start;
        }

        if ($end !== null) {
            $data['end'] = $end;
        }

        return $this->post("GameHistory.aspx", $data);
    }

    /* ===============================
       CURL POST
    =============================== */
    private function post(string $endpoint, array $data)
    {
        $ch = curl_init($this->url . $endpoint);
        curl_setopt_array($ch, [
            CURLOPT_POST           => true,
            CURLOPT_POSTFIELDS     => http_build_query($data),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_TIMEOUT        => 15,
            CURLOPT_HTTPHEADER     => [
                'Content-Type: application/x-www-form-urlencoded'
            ]
        ]);

        $res = curl_exec($ch);
        curl_close($ch);
        return $res;
    }
}

$API = new NOXPAY();

            </code></pre>
        </div>
    </div>
</div>
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0">Curl PHP Example</h5>
        </div>
        <div id="collapseMain" class="show">
            <div class="card-body">
                <pre>
$url = "ISI_ENDPOINT_API"; // contoh: https://api.domain.com/CreateMember.aspx

$postData = [
    'user_agent'  => 'AGENT_NAME',
    'signature'   => 'SECRET123',

    // OPTIONAL (sesuai endpoint)
    'user_member' => 'TEST123',
    'amount'      => 100000,
    'type'        => 'deposit',
    'game_code'   => 'vs20olympgate',
    'provider_code' => 'PG',
    'game_type'   => 'all',
    'start'       => '2026-05-23 00:00:00',
    'end'         => '2026-05-24 23:59:59'
];

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL            => $url,
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => http_build_query($postData),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_IPRESOLVE      => CURL_IPRESOLVE_V4,
    CURLOPT_AUTOREFERER    => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_USERAGENT      => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.47 Safari/537.36',
    CURLOPT_HTTPHEADER     => [
        'Content-Type: application/x-www-form-urlencoded'
    ],
    CURLOPT_TCP_KEEPALIVE  => 1,
    CURLOPT_TCP_KEEPIDLE   => 2,
    CURLOPT_TCP_KEEPINTVL  => 3,
    CURLOPT_TIMEOUT        => 15
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
                </pre>
            </div>
        </div>
    </div>
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            let buttons = document.querySelectorAll(".btn-link");
            buttons.forEach((button, index) => {
                button.innerHTML = (index + 1) + ". " + button.innerHTML;
            });
        });
    </script>
        </div>
    </div>
</div>
