mcpetrade-api
Version:
API Wrapper для взаимодействия с mcpetrade api
60 lines (48 loc) • 1.85 kB
JavaScript
const fetch = require('node-fetch')
const request = require('request-promise')
module.exports = class MCPETRADE {
constructor({
shop = null,
server = null,
}) {
if (!shop) throw new Error(`Не задан параметр "shop"`)
if (!server) throw new Error(`Не задан параметр "server"`)
this.shop = shop
this.server = server
}
async createPayment(productId, username, coupon = '') {
var uri = `https://api.mcpetrade.com/shop.createPayment?shop=${this.shop}&server=${this.server}&product=${productId}&username=${username}&coupon=${coupon}`;
var res = encodeURI(uri);
let json = await request(res);
let x = JSON.parse(json);
return x
}
async getServers() {
var uri = `https://api.mcpetrade.com/shop.getServers?shop=${this.shop}`;
var res = encodeURI(uri);
let json = await request(res);
let x = JSON.parse(json);
return x
}
async getOnline() {
var uri = `https://api.mcpetrade.com/shop.getOnline?shop=${this.shop}`;
var res = encodeURI(uri);
let json = await request(res);
let x = JSON.parse(json);
return x
}
async getProducts(category = '') {
var uri = `https://api.mcpetrade.com/shop.getProducts?shop=${this.shop}&server=${this.server}&category=${category}`;
var res = encodeURI(uri);
let json = await request(res);
let x = JSON.parse(json);
return x
}
async getPaymentStatus(billId) {
var uri = `https://api.mcpetrade.com/payment.getStatus?billid=${billId}`;
var res = encodeURI(uri);
let json = await request(res);
let x = JSON.parse(json);
return x
}
}