UNPKG

perfectpago

Version:

A Simple integration for mercadopago

78 lines (77 loc) 2.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const PaymentsMethods_1 = __importDefault(require("./PaymentsMethods")); class Payments { constructor(options) { this.accessToken = options.accessToken; this.BASE_URL = ' https://api.mercadopago.com'; this.payment_methods = new PaymentsMethods_1.default({ accessToken: this.accessToken }); } /** * * @param {PaymentCreateBody} body - Payment Body * @returns */ async create(body) { const data = await fetch(`${this.BASE_URL}/v1/payments`, { method: "POST", headers: { 'Authorization': `Bearer ${this.accessToken}` }, body: JSON.stringify(body) }); return await data.json(); } /** * * @param {string} id - Payment ID * @returns */ async get(id) { const data = await fetch(`${this.BASE_URL}/v1/payments/${id}`, { method: "GET", headers: { 'Authorization': `Bearer ${this.accessToken}` } }); return await data.json(); } /** * * @param {string} id - Payment ID * @returns */ async cancel(id) { const data = await fetch(`${this.BASE_URL}/v1/payments/${id}`, { method: "PUT", headers: { 'Authorization': `Bearer ${this.accessToken}` }, body: JSON.stringify({ status: 'cancelled' }) }); return await data.json(); } /** * * @param {string} id - Payment ID * @param {number} amount - Refund Amount or null for refund all * @returns */ async refund(id, amount) { const data = await fetch(`${this.BASE_URL}/v1/payments/${id}/refunds`, { method: "POST", headers: { 'Authorization': `Bearer ${this.accessToken}` }, body: JSON.stringify({ id: id, amount: amount ? amount : null }) }); return await data.json(); } } exports.default = Payments;