Basically I have a loop where I find an url in an api, then I need to return it and use it outside of the loop, in order to return it to the client.
but im not able to access urlFinal from outside of the loop..
this the code
let urlFinal
const bucle = setInterval(function () {
console.log('antes de Axios')
axios
.get(url, {
headers: { Authorization: AuthorizationWompi },
})
.then(function (response) {
console.log('Then antes de If')
if (response.data.data.payment_method.extra.async_payment_url) {
urlFinal =
response.data.data.payment_method.extra.async_payment_url
clearInterval(bucle)
console.log('al final del if')
}
})
}, 1000)
console.log(urlFinal)
return {
statusCode: 200, // <-- Important!
body: JSON.stringify({
id: transaccion,
link: urlFinal,
}),
}