const axios = require('axios'); class Api { constructor(apiKey) { this.api_url = 'https://roicmedya.com/api/v2'; this.api_key = apiKey; } // Add order async order(data) { const post = { ...data, key: this.api_key, action: 'add' }; return await this.connect(post); } // Get order status async status(orderId) { return await this.connect({ key: this.api_key, action: 'status', order: orderId, }); } // Get multiple orders status async multiStatus(orderIds) { return await this.connect({ key: this.api_key, action: 'status', orders: orderIds.join(','), }); } // Get services async services() { return await this.connect({ key: this.api_key, action: 'services', }); } // Refill order async refill(orderId) { return await this.connect({ key: this.api_key, order: orderId, }); } // Refill multiple orders async multiRefill(orderIds) { return await this.connect({ key: this.api_key, orders: orderIds.join(','), }); } // Get balance async balance() { return await this.connect({ key: this.api_key, action: 'balance', }); } // Helper method to connect to API async connect(post) { try { const response = await axios.post(this.api_url, new URLSearchParams(post).toString(), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, }); return response.data; } catch (error) { console.error('Error connecting to API:', error); return null; } } } // Example usage (async () => { const api = new Api('your-api-key'); const services = await api.services(); console.log(services); const balance = await api.balance(); console.log(balance); const order = await api.order({ service: 1, link: 'http://example.com/test', quantity: 100, runs: 2, interval: 5, }); console.log(order); const status = await api.status(order.order); console.log(status); })();