"""
AdityaMods UPI Payment Gateway - Official Python SDK
Ideal for Telegram bots, Flask, Django, and PythonAnywhere.
"""
import requests
import hmac
import hashlib

class AdityaModsClient:
    def __init__(self, api_key: str, base_url: str = "https://gateway.adityamods.work.gd"):
        self.api_key = api_key
        self.base_url = base_url.rstrip("/")
        self.headers = {
            "Content-Type": "application/json",
            "X-API-KEY": self.api_key
        }

    def create_order(self, amount: float, customer_name: str, customer_email: str, remark: str = "") -> dict:
        url = f"{self.base_url}/api/orders"
        payload = {
            "amount": amount,
            "customer_name": customer_name,
            "customer_email": customer_email,
            "remark": remark
        }
        resp = requests.post(url, json=payload, headers=self.headers, timeout=10)
        return resp.json()

    def get_order_status(self, order_id: str) -> dict:
        url = f"{self.base_url}/api/orders/{order_id}/status"
        resp = requests.get(url, headers=self.headers, timeout=10)
        return resp.json()

    @staticmethod
    def verify_webhook(raw_payload: str, signature: str, secret: str) -> bool:
        computed = hmac.new(secret.encode(), raw_payload.encode(), hashlib.sha256).hexdigest()
        return hmac.compare_digest(computed.lower(), signature.lower())