"""
Delivery-provider integration point.

Replace the methods below with the API of your real top-up supplier.
Do not put supplier secrets in source code; load them from .env.
"""

import os
import aiohttp

class TopupProvider:
    def __init__(self):
        self.base_url=os.getenv("PROVIDER_BASE_URL","")
        self.api_key=os.getenv("PROVIDER_API_KEY","")

    async def create_order(self, game, sku, player_id, server_id=None):
        if not self.base_url:
            raise RuntimeError("PROVIDER_BASE_URL is not configured")
        payload={"game":game,"sku":sku,"player_id":player_id,"server_id":server_id}
        headers={"Authorization":f"Bearer {self.api_key}"}
        async with aiohttp.ClientSession() as s:
            async with s.post(self.base_url+"/orders",json=payload,headers=headers,timeout=30) as r:
                r.raise_for_status()
                return await r.json()

    async def order_status(self, provider_order_id):
        headers={"Authorization":f"Bearer {self.api_key}"}
        async with aiohttp.ClientSession() as s:
            async with s.get(self.base_url+f"/orders/{provider_order_id}",headers=headers,timeout=30) as r:
                r.raise_for_status()
                return await r.json()
