perfectpago
Version:
A Simple integration for mercadopago
75 lines (74 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class Cards {
constructor(options) {
this.accessToken = options.accessToken;
this.BASE_URL = ' https://api.mercadopago.com';
}
/**
*
* @param {string} id - Customer ID
* @param {string} token - CARD TOKEN
* @returns
*/
async save(id, token) {
const data = await fetch(`${this.BASE_URL}/v1/customers/${id}/cards`, {
method: "POST",
headers: {
'Authorization': `Bearer ${this.accessToken}`
},
body: JSON.stringify({
token: token
})
});
return await data.json();
}
/**
*
* @param {string} customer_id - Customer ID
* @param {string} id - Card ID
* @returns
*/
async get(customer_id, id) {
const data = await fetch(`${this.BASE_URL}/v1/customers/${customer_id}/cards/${id}`, {
method: "GET",
headers: {
'Authorization': `Bearer ${this.accessToken}`
}
});
return await data.json();
}
/**
*
* @param {string} customer_id - Customer ID
* @param {string} id - CARD ID
* @param {CardUpdateOptions} options - Options
* @returns
*/
async update(customer_id, id, options) {
const data = await fetch(`${this.BASE_URL}/v1/customers/${customer_id}/cards/${id}`, {
method: "PUT",
headers: {
'Authorization': `Bearer ${this.accessToken}`
},
body: JSON.stringify(options)
});
return await data.json();
}
/**
*
* @param {string} customer_id - Customer ID
* @param {string} id - Card ID
* @returns
*/
async delete(customer_id, id) {
const data = await fetch(`${this.BASE_URL}/v1/customers/${customer_id}/cards/${id}`, {
method: "DELETE",
headers: {
'Authorization': `Bearer ${this.accessToken}`
},
});
return await data.json();
}
}
exports.default = Cards;