perfectpago
Version:
A Simple integration for mercadopago
58 lines (57 loc) • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class Refunds {
constructor(options) {
this.accessToken = options.accessToken;
this.BASE_URL = ' https://api.mercadopago.com';
}
/**
*
* @param {string} id - Payment ID
* @param {string} refund_id - Refund ID
* @returns PaymentData
*/
async get(id, refund_id) {
const data = await fetch(`${this.BASE_URL}/v1/payments/${id}/refunds/${refund_id}`, {
method: "GET",
headers: {
'Authorization': `Bearer ${this.accessToken}`
}
});
return await data.json();
}
/**
*
* @param {string} id - Payment ID
* @returns
*/
async getAll(id) {
const data = await fetch(`${this.BASE_URL}/v1/payments/${id}/refunds`, {
method: "GET",
headers: {
'Authorization': `Bearer ${this.accessToken}`
}
});
return await data.json();
}
/**
*
* @param {string} id - Payment ID
* @param {string} amount - Refund Value or null for refund all
* @returns
*/
async create(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 = Refunds;