-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeli.js
31 lines (27 loc) · 1.2 KB
/
meli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const firstUrl = 'https://www.mercadopago.com.ar/developers/panel/app';
// Make first request
const xhr = new XMLHttpRequest();
xhr.open('GET', firstUrl);
xhr.onload = function() {
// Extract app number from first response using regular expression
const appNumberRegex = /Número de aplicación: (\d+)/;
const appNumberMatch = appNumberRegex.exec(xhr.responseText);
const appNumber = appNumberMatch[1];
// Make second request using app number from first response
const secondUrl = `https://www.mercadopago.com.ar/developers/panel/app/${appNumber}/credentials/production`;
const xhr2 = new XMLHttpRequest();
xhr2.open('GET', secondUrl);
xhr2.onload = function() {
// Extract public and secret key from second response
const passwordRegex = /class="credentials-container__key-secret" value="([^"]+)"/;
const passwordMatch = passwordRegex.exec(xhr2.responseText);
const password = passwordMatch[1];
const keyRegex = /<div class="credentials-container__key">([^<]+)<\/div>/;
const keyMatch = keyRegex.exec(xhr2.responseText);
const key = keyMatch[1];
// Alert the extracted values
alert(`Public key: ${password}\n\nAccess Token: ${key}`);
};
xhr2.send();
};
xhr.send();