UNPKG

easydonate-api

Version:

API Wrapper для взаимодействия с easydonate api

56 lines (45 loc) 1.48 kB
const fetch = require('node-fetch') const request = require('request-promise') module.exports = class MCPETRADE { constructor({ token = null, }) { if (!token) throw new Error(`Не задан параметр "token"`) this.token = token } async call(section, method = '', param = '', queryParams = {}) { var uri = `https://easydonate.ru/api/v1/${section}/${this.token}/${method}/${param}${new URLSearchParams(queryParams).toString()}`; var res = encodeURI(uri); let json = await request(res); let x = JSON.parse(json); return x } async getShopInfo() { return this.call('shop') } async getShopProducts() { return this.call('shop', 'products') } async getProductInfo(id) { return this.call('shop', 'product', id) } async getShopServers() { return this.call('shop', 'servers') } async getServerInfo(id) { return this.call('shop', 'server', id) } async getSuccessPayments() { return this.call('shop', 'payments') } async getPaymentInfo(id) { return this.call('shop', 'payment', id) } async createPayment(customer, server_id, products) { return this.call('shop', 'payment', 'create', { customer: customer, server_id: server_id, products: products }) } }