UNPKG

perfectpago

Version:

A Simple integration for mercadopago

69 lines (68 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Stores { constructor(options) { this.accessToken = options.accessToken; this.BASE_URL = ' https://api.mercadopago.com'; this.user_id = null; } /** * * @param {string} id - Card ID * @returns */ async get(id) { const data = await fetch(`${this.BASE_URL}/stores${id}`, { method: "GET", headers: { 'Authorization': `Bearer ${this.accessToken}` } }); return await data.json(); } /** * * @param {string} user_id - CARD ID * @param {CardUpdateOptions} options - Options * @returns */ async create(user_id, options) { const data = await fetch(`${this.BASE_URL}/users/${user_id || this.user_id}/stores`, { method: "POST", headers: { 'Authorization': `Bearer ${this.accessToken}` }, body: JSON.stringify(options) }); return await data.json(); } async update(user_id, id, options) { const data = await fetch(`${this.BASE_URL}/users/${user_id || this.user_id}/stores/${id}`, { method: "PUT", headers: { 'Authorization': `Bearer ${this.accessToken}` }, body: JSON.stringify(options) }); return await data.json(); } async delete(id, user_id) { const data = await fetch(`${this.BASE_URL}/users/${user_id || this.user_id}/stores/${id}`, { method: "DELETE", headers: { 'Authorization': `Bearer ${this.accessToken}` } }); return await data.json(); } async fetch(user_id) { const data = await fetch(`${this.BASE_URL}/users/${user_id || this.user_id}/stores/search`, { method: "GET", headers: { 'Authorization': `Bearer ${this.accessToken}` } }); return await data.json(); } } exports.default = Stores;