feat: added profee

This commit is contained in:
Jesse Egbosionu
2024-05-28 02:04:32 +02:00
parent 06dbfaf8a2
commit b5e4cb9435
+171 -47
View File
@@ -1,6 +1,6 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction // Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { log } from 'console'; import { log } from "console";
export default async (req, res) => { export default async (req, res) => {
let rates = []; let rates = [];
@@ -38,14 +38,21 @@ export default async (req, res) => {
redirect: "follow", redirect: "follow",
}; };
const tap_call = fetch("https://api.taptapsend.com/api/fxRates", requestOptions) const tap_call = fetch(
"https://api.taptapsend.com/api/fxRates",
requestOptions
)
.then((response) => response.json()) .then((response) => response.json())
.then((result) => { .then((result) => {
const fxRate = result.availableCountries[1].corridors.find((corridors) => corridors.countryDisplayName == "Nigeria") const fxRate = result.availableCountries[1].corridors.find(
(corridors) => corridors.countryDisplayName == "Nigeria"
);
return { return {
"rate": fxRate["fxRate"], rate: fxRate["fxRate"],
"provider": "TapTap", "bestRate": false, "href": "https://www.taptapsend.com/" provider: "TapTap",
} bestRate: false,
href: "https://www.taptapsend.com/",
};
}) })
.catch((error) => console.log("error", error)); .catch((error) => console.log("error", error));
@@ -55,28 +62,42 @@ export default async (req, res) => {
myHeaders.append("accept-language", "en-GB,en-US;q=0.9,en;q=0.8"); myHeaders.append("accept-language", "en-GB,en-US;q=0.9,en;q=0.8");
myHeaders.append("origin", "https://send.flutterwave.com"); myHeaders.append("origin", "https://send.flutterwave.com");
myHeaders.append("referer", "https://send.flutterwave.com/"); myHeaders.append("referer", "https://send.flutterwave.com/");
myHeaders.append("sec-ch-ua", "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\""); myHeaders.append(
"sec-ch-ua",
'"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"'
);
myHeaders.append("sec-ch-ua-mobile", "?0"); myHeaders.append("sec-ch-ua-mobile", "?0");
myHeaders.append("sec-ch-ua-platform", "\"macOS\""); myHeaders.append("sec-ch-ua-platform", '"macOS"');
myHeaders.append("sec-fetch-dest", "empty"); myHeaders.append("sec-fetch-dest", "empty");
myHeaders.append("sec-fetch-mode", "cors"); myHeaders.append("sec-fetch-mode", "cors");
myHeaders.append("sec-fetch-site", "cross-site"); myHeaders.append("sec-fetch-site", "cross-site");
myHeaders.append("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"); myHeaders.append(
"user-agent",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
);
var requestOptions = { var requestOptions = {
method: 'GET', method: "GET",
headers: myHeaders, headers: myHeaders,
redirect: 'follow' redirect: "follow",
}; };
const send_call = fetch("https://sendgateway.myflutterwave.com/api/v1/config/getcurrencyrate?fromCurrency=EUR&toCurrency=NGN", requestOptions) const send_call = fetch(
.then(response => response.json()) "https://sendgateway.myflutterwave.com/api/v1/config/getcurrencyrate?fromCurrency=EUR&toCurrency=NGN",
.then(response => { requestOptions
return { "rate": parseFloat(response.data[0].baseRate).toFixed(2), "provider": "Send", "bestRate": false, "href": "https://send.flutterwave.com/" } )
.then((response) => response.json())
.then((response) => {
return {
rate: parseFloat(response.data[0].baseRate).toFixed(2),
provider: "Send",
bestRate: false,
href: "https://send.flutterwave.com/",
};
}) })
.catch(error => console.log('error', error)); .catch((error) => console.log("error", error));
const { exec } = require('child_process'); const { exec } = require("child_process");
const curlCommand = `curl 'https://acemoneytransfer.com/make-request' \ const curlCommand = `curl 'https://acemoneytransfer.com/make-request' \
-H 'authority: acemoneytransfer.com' \ -H 'authority: acemoneytransfer.com' \
@@ -94,7 +115,7 @@ export default async (req, res) => {
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' \ -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' \
-H 'x-requested-with: XMLHttpRequest' \ -H 'x-requested-with: XMLHttpRequest' \
--data-raw 'uri=rate%2Fcalculator&type=POST&data%5Bsrc_amount%5D=100&data%5Bdest_amount%5D=&data%5Buser_currency%5D=EUR&data%5Bcalculation_mode%5D=S&data%5Bdest_iso_numeric_code%5D=566&data%5Bsrc_iso_numeric_code%5D=528' --data-raw 'uri=rate%2Fcalculator&type=POST&data%5Bsrc_amount%5D=100&data%5Bdest_amount%5D=&data%5Buser_currency%5D=EUR&data%5Bcalculation_mode%5D=S&data%5Bdest_iso_numeric_code%5D=566&data%5Bsrc_iso_numeric_code%5D=528'
` `;
const ace_call = new Promise((resolve, reject) => { const ace_call = new Promise((resolve, reject) => {
exec(curlCommand, (error, stdout, stderr) => { exec(curlCommand, (error, stdout, stderr) => {
@@ -102,21 +123,35 @@ export default async (req, res) => {
reject(`Error: ${error.message}`); reject(`Error: ${error.message}`);
} }
try { try {
const parsed_rate = JSON.parse(stdout) const parsed_rate = JSON.parse(stdout);
resolve({ "rate": parseFloat(parsed_rate.data.exchange_rate).toFixed(2), "provider": "Ace Transfer", "bestRate": false }); resolve({
rate: parseFloat(parsed_rate.data.exchange_rate).toFixed(2),
provider: "Ace Transfer",
bestRate: false,
});
} catch (parseError) { } catch (parseError) {
console.log("curl_ace_call_exceptions>>>>", parseError) console.log("curl_ace_call_exceptions>>>>", parseError);
reject(parseError.message); reject(parseError.message);
} }
}); });
}).then((result) => { })
return { "rate": parseFloat(result.rate).toFixed(2), "provider": "Ace Transfer", "bestRate": false, "href": "https://acemoneytransfer.com/referral-link/3056004" } .then((result) => {
} return {
).catch((result) => { rate: parseFloat(result.rate).toFixed(2),
console.log("ace_call_exceptions>>>>", result) provider: "Ace Transfer",
return { "rate": 0.00, "provider": "Ace Transfer", "bestRate": false, "href": "https://acemoneytransfer.com/referral-link/3056004" } bestRate: false,
} href: "https://acemoneytransfer.com/referral-link/3056004",
) };
})
.catch((result) => {
console.log("ace_call_exceptions>>>>", result);
return {
rate: 0.0,
provider: "Ace Transfer",
bestRate: false,
href: "https://acemoneytransfer.com/referral-link/3056004",
};
});
const remitlyCurlCommand = `curl --location 'https://api.remitly.io/v5/pricing/estimates?amount=100.00%20EUR&anchor=SEND&conduit=NLD%3AEUR-NGA%3ANGN&purpose=OTHER' \ const remitlyCurlCommand = `curl --location 'https://api.remitly.io/v5/pricing/estimates?amount=100.00%20EUR&anchor=SEND&conduit=NLD%3AEUR-NGA%3ANGN&purpose=OTHER' \
--header 'accept: application/json' \ --header 'accept: application/json' \
@@ -135,7 +170,7 @@ export default async (req, res) => {
--header 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \ --header 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
--header 'x-remitly-perf-reqsize: 0' \ --header 'x-remitly-perf-reqsize: 0' \
--header 'x-remitly-perf-starttime: 1714932144397' --header 'x-remitly-perf-starttime: 1714932144397'
` `;
const remitly_call = new Promise((resolve, reject) => { const remitly_call = new Promise((resolve, reject) => {
exec(remitlyCurlCommand, (error, stdout, stderr) => { exec(remitlyCurlCommand, (error, stdout, stderr) => {
@@ -143,40 +178,129 @@ export default async (req, res) => {
reject(`Error: ${error.message}`); reject(`Error: ${error.message}`);
} }
try { try {
const parsed_rate = JSON.parse(stdout) const parsed_rate = JSON.parse(stdout);
resolve({ "rate": parsed_rate[0].exchange_rate_info.base_rate}); resolve({ rate: parsed_rate[0].exchange_rate_info.base_rate });
} catch (parseError) { } catch (parseError) {
reject(parseError.message); reject(parseError.message);
} }
}); });
}).then((result) => { })
return { "rate": parseFloat(result.rate).toFixed(2), "provider": "Remitly", "bestRate": false, "href": "https://remit.ly/94fqcne9" } .then((result) => {
return {
rate: parseFloat(result.rate).toFixed(2),
provider: "Remitly",
bestRate: false,
href: "https://remit.ly/94fqcne9",
};
})
.catch((error) => {
console.error("Error Calling Ace>>>", error);
return {
rate: 0.0,
provider: "Ace Transfer",
bestRate: false,
href: "https://remit.ly/94fqcne9",
};
});
const profeeCurlCommand = `curl --location 'https://terminal.profee.com/api/v2/transfer/terminal/calculation' \
--header 'accept: application/json, text/plain, */*' \
--header 'accept-language: en-GB,en;q=0.9,nl-NL;q=0.8,nl;q=0.7,en-US;q=0.6' \
--header 'content-type: application/json' \
--header 'cookie: CANARY_NEXTJS=%5B%5D; __cf_bm=Fu.F9TXsck_h0lPuzJW_GmEsyEe9SniZmkKGskRpbNg-1716837733-1.0.1.1-uJc0ixmGe6gJByGEu2ATr5.YZ2OeOJQukkxNiNzwcHHfrjC9TB9HTRxcMP1lefztezHzzzQDM90p_0UlN6Geew; __app_refer=https://www.google.com/; __app_entry_url=https://www.profee.com/; __app_session_refer=https://www.google.com/; __app_session_entry_url=https://www.profee.com/; AMP_MKTG_edb98a63f6=JTdCJTIycmVmZXJyZXIlMjIlM0ElMjJodHRwcyUzQSUyRiUyRnd3dy5nb29nbGUuY29tJTJGJTIyJTJDJTIycmVmZXJyaW5nX2RvbWFpbiUyMiUzQSUyMnd3dy5nb29nbGUuY29tJTIyJTdE; cf_clearance=U7OTNWCrDA0sPxQ5E7LsoAGJcJPUw7ZW19IW.YPft84-1716837735-1.0.1.1-rktBV6kU5ymkhJDVWMhmPenC6CckfUYiSWdw0h5I4Xbc9kSDpDGKwPTYOaLG6mEH9r57aHP7L8HGvoXwbcFsoQ; __app_auth_entry_path=/; __app_browser_id=5e7a969a31a742de3e1933e3737f63b0; __app_visitor_id_ipqs=558b05a8ea7feccb0f5aa72a9cc346191c8488a4342e6a9b83b07aeeecf1cc38; AMP_edb98a63f6=JTdCJTIyZGV2aWNlSWQlMjIlM0ElMjI5OWYxZGE4My01ZGI3LTRjZjItODRiMi0yMThjNTIxM2JmNTclMjIlMkMlMjJ1c2VySWQlMjIlM0ElMjJXTC0xMDAwMDAwMDAxMDM5MzQ5JTIyJTJDJTIyc2Vzc2lvbklkJTIyJTNBMTcxNjgzNzczNDk4MSUyQyUyMm9wdE91dCUyMiUzQWZhbHNlJTJDJTIybGFzdEV2ZW50VGltZSUyMiUzQTE3MTY4MzgyMTExNzYlMkMlMjJsYXN0RXZlbnRJZCUyMiUzQTU3JTJDJTIycGFnZUNvdW50ZXIlMjIlM0EwJTdE; JSESSIONID=M2hVaXriuve_e1Q0N1fEoqCpdaJylSoki7KTNn-A; JWT_ACCESS_TOKEN=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ7XCJ3YWxJZFwiOlwiV0wtMTAwMDAwMDAwMTAzOTM0OVwiLFwiand0Um9sZVwiOlwiVFJBTlNGRVJcIn0iLCJpc3MiOiJ0ZXJtaW5hbCIsImlhdCI6MTcxNjgzODIxMSwiZXhwIjoxNzE2ODQxODExLCJhdWQiOiJyZXN0LWFwaSx0ZXJtaW5hbCx3d3cifQ.SAYlC3BuKYmCFfCTEbRQIsDNaNkzz1kLjIv3QxiL1VrFHz-95pcVr6KsA5AIGBlPEHpzXVQWjBQ6lr6imq2bgw; __cf_bm=Xt6ZUfYD5BEac9GQ9gJv2YxPKxY28O7PHXPZaBv1yO4-1716854052-1.0.1.1-aFWNnTO2aoSoAZvUrHnSkIatITPtQzp2zwLmXtEtmvufWViVpHlo0WfJYJ457QJBHTlGBGV8gx2qnbWtaUwnwA; JSESSIONID=ajkmviH6OZbYlzZRicO3TQVcifs4vL1cgfwGIDub' \
--header 'origin: https://www.profee.com' \
--header 'priority: u=1, i' \
--header 'referer: https://www.profee.com/' \
--header 'sec-ch-ua: "Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--header 'sec-fetch-dest: empty' \
--header 'sec-fetch-mode: cors' \
--header 'sec-fetch-site: same-site' \
--header 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36' \
--header 'x-browser-id: 5e7a969a31a742de3e1933e3737f63b0' \
--header 'x-request-id: 8a5aa5aa-8238-41f7-ad32-02ce182f30e8' \
--header 'x-requested-by: send-next 1.8.697' \
--data '{
"methodId": "D2A161795786D8ED5CEE4A183095DCF8A20DFD5C",
"from": {
"currency": "EUR",
"amount": 10,
"country": 528
},
"to": {
"currency": "NGN",
"amount": null,
"country": 566
},
"skipLimitValidation": true
}'`;
const profee_call = new Promise((resolve, reject) => {
exec(profeeCurlCommand, (error, stdout, stderr) => {
if (error) {
reject(`Error: ${error.message}`);
} }
).catch((result) => { try {
return { "rate": 0.00, "provider": "Ace Transfer", "bestRate": false, "href": "https://remit.ly/94fqcne9" } const parsed_rate = JSON.parse(stdout);
resolve({ rate: parsed_rate.body.currencyRate.rate });
} catch (parseError) {
reject(parseError.message);
}
});
})
.then((result) => {
return {
rate: parseFloat(result.rate).toFixed(2),
provider: "Profee",
bestRate: false,
href: "https://profee.link/3sk4tj",
};
})
.catch((error) => {
console.error("Error Calling Profee>>>", error);
return {
rate: 0.0,
provider: "Profee",
bestRate: false,
href: "https://profee.link/3sk4tj",
};
});
await Promise.all([ace_call, send_call, tap_call, remitly_call, profee_call])
.then(
([
ace_reponse,
send_response,
tap_response,
remitly_response,
profee_call,
]) => {
rates = [
ace_reponse,
send_response,
tap_response,
remitly_response,
profee_call,
];
} }
) )
.catch((error) => {
await Promise.all([ace_call, send_call, tap_call, remitly_call])
.then(([ace_reponse, send_response, tap_response, remitly_response]) => {
rates = [ace_reponse, send_response, tap_response,remitly_response]
})
.catch(error => {
console.error(error); console.error(error);
}); });
const maxRateIndex = rates.reduce(
const maxRateIndex = rates.reduce((maxIndex, currentObject, currentIndex, array) => { (maxIndex, currentObject, currentIndex, array) => {
const currentRate = parseFloat(currentObject.rate); const currentRate = parseFloat(currentObject.rate);
const maxRate = parseFloat(array[maxIndex].rate); const maxRate = parseFloat(array[maxIndex].rate);
return currentRate > maxRate ? currentIndex : maxIndex; return currentRate > maxRate ? currentIndex : maxIndex;
}, 0); },
0
);
rates.forEach((object, index) => { rates.forEach((object, index) => {
object.bestRate = index === maxRateIndex; object.bestRate = index === maxRateIndex;
}); });
res.setHeader('Cache-Control', 's-maxage=86400')
return res.status(200).json(rates); return res.status(200).json(rates);
}; };