====================================================================
 SecurePay Payment Gateway  -  SMM Panel Module  (premium)
====================================================================
SecurePay (new API) integration for the SMM social media marketing
panel. Provides responsive, mobile-friendly pages and safe, verified,
idempotent balance crediting.

CONTENTS
--------
  app/controller/addfunds/Initiators/securepaybd.php   <- add-funds initiator
  app/controller/payment/securepaybd.php               <- callback / verifier
  db.sql                                               <- payment method 69 setup
  admin-method69-upgrade.txt                           <- optional admin UI upgrade

REQUIREMENTS
------------
  - SMM panel with PDO MySQL.
  - SecurePay merchant account with: Gateway URL, API Key, exchange rate.
  - PHP 5.6 / 7.x (the module does not use PHP 8 syntax).

INSTALL
-------
1) Copy the two files into your SMM installation:

   app/controller/addfunds/Initiators/securepaybd.php
   app/controller/payment/securepaybd.php

2) FIX THE STOCK ROUTING BUG (IMPORTANT).
   In app/controller/payment.php the stock code routes the
   "securepaybd" callback to payment/tuktakpay.php. Change it to:

       if ($callbackSlug == "securepaybd") {
           require("payment/securepaybd.php");
           exit;
       }

3) DATABASE - run db.sql on your SMM panel database (phpMyAdmin or CLI).
   It inserts payment method id 69 (INSERT IGNORE, safe to re-run). If
   your install already has method 69 the script also documents the one
   line that adds the api_url field to the existing extras (JSON_SET).

4) (Optional but recommended) apply admin-method69-upgrade.txt so the
   admin can set the Gateway URL from the panel. Without it the method
   69 settings only have API Key + Exchange Rate, which is enough as
   long as "Gateway URL" is filled in directly in the extras JSON.

5) In the SMM panel admin:
   Payment Methods -> SecurePay (method 69):
     - Status        : Active
     - Min / Max     : 10 / 50000 (or your limits)
     - Fee / Bonus   : as desired
     - Gateway URL   : your SecurePay base URL, e.g.
                       https://payment.example.com   (no trailing slash)
     - API Key       : the brand API key from your SecurePay account
     - Exchange Rate : 1 unit of your panel currency = ? Taka (BDT).

   IMPORTANT: the panel must be reachable from the Internet at a real
   public domain/IP. SecurePay refuses private (localhost/127.0.0.1 /
   .local / 10.x / 192.168.x) callback URLs in production.

HOW IT WORKS
------------
  Create  : user starts Add Funds -> row inserted in `payments`
            (payment_extra = order reference) -> POST /api/create
            -> responsive redirect screen -> gateway checkout.
  Verify  : gateway redirects back AND posts a webhook to
            /payment/securepaybd carrying the transaction id.
            The module calls POST /api/verify with the API key and only
            credits the balance when the gateway confirms COMPLETED.
  Credit  : exactly once (existing order/status guard), amount is
            cross-checked against the gateway amount, fee/bonus rules
            from the method settings are applied, client balance is
            updated and the session is restored.
  Replies : webhook -> plain "OK"/"PENDING"; return trip -> styled,
            mobile-friendly success/error/waiting page that auto
            redirects back to Add Funds.

NOTES
-----
  - The panel fee is charged WITH the payment (gateway amount =
    amount+fee) and the credited balance follows the original
    SecurePay module behaviour.
  - If your plan uses manual bank/deposit review the webhook will
    answer "PENDING" until the merchant approves the deposit.
  - Debugging: enable the gateway-side logs and test with a small
    amount first (see TESTING).

TESTING
-------
  1. Set a 10 Taka test amount in Add Funds with method SecurePay.
  2. Complete a real payment at the gateway checkout.
  3. Check your balance increased and the payment appears under
     "Payment history" with status completed.
  4. Open the payment history twice / reload the return page and
     confirm the balance is NOT credited twice.
  5. Try a cancelled payment on the checkout screen -> you are
     returned to Add Funds with no balance change.