Skip to content

Instantly share code, notes, and snippets.

@divinity76
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divinity76/9464357 to your computer and use it in GitHub Desktop.
Save divinity76/9464357 to your computer and use it in GitHub Desktop.
console.log(convertCurrency("100000", "SEK", "USD"));
function convertCurrency(currencyAmount, currencyFrom, currencyTo) {
var xhr = new XMLHttpRequest();
var url = "https://devtools-paypal.com/apiexplorer/processReq";
//url="https://svcs.sandbox.paypal.com/AdaptivePayments/ConvertCurrency";
var bigO = {};
bigO.httpMethod = "POST";
bigO.oauth = "";
bigO.methodUri = "";
bigO.methodName = "ConvertCurrency";
bigO.dataFormat = "";
var params = {};
params["ConvertCurrencyRequest.requestEnvelope.errorLanguage"] = "EN_US";
params["ConvertCurrencyRequest.requestEnvelope.detailLevel"] = "";
params["ConvertCurrencyRequest.baseAmountList.currency(0).code"] = currencyFrom;
params["ConvertCurrencyRequest.baseAmountList.currency(0).amount"] = currencyAmount;
params["ConvertCurrencyRequest.convertToCurrencyList.currencyCode"] = currencyTo;
params["ConvertCurrencyRequest.countryCode"] = "";
params["ConvertCurrencyRequest.conversionType"] = "";
bigO.params = params;
bigO.apiKey = undefined;
bigO.apiSecret = undefined;
bigO.apiName = "AdaptivePayments";
bigO.userName = "jb-us-seller_api1.paypal.com";
bigO.password = "WX4WTU3S8MY44S7F";
bigO.signature = "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy";
bigO.appId = "APP-80W284485P519543T";
bigO.authorization = undefined;
xhr.open("POST", url, false);
var headers = [
"X-PAYPAL-SECURITY-USERID:jb-us-seller_api1.paypal.com, ",
"X-PAYPAL-SECURITY-PASSWORD:WX4WTU3S8MY44S7F, ",
"X-PAYPAL-SECURITY-SIGNATURE:AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy, ",
"X-PAYPAL-APPLICATION-ID:APP-80W284485P519543T, ",
"X-PAYPAL-REQUEST-DATA-FORMAT:JSON, ",
"X-PAYPAL-RESPONSE-DATA-FORMAT:JSON, ",
"X-PAYPAL-DEVICE-IPADDRESS:127.0.0.1, ",
"X-PAYPAL-REQUEST-SOURCE:merchant-php-sdk-2.0.96, ",
"X-PAYPAL-SANDBOX-EMAIL-ADDRESS:Platform.sdk.seller@gmail.com, "
];
var i = 0;
for (i = 0; i < headers.length; ++i) {
xhr.setRequestHeader(headers[i].split(":")[0].trim(), headers[i].split(":")[1].split(",")[0].trim());
};
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
xhr.send(JSON.stringify(bigO));
var p1 = JSON.parse(xhr.responseText);
var p2 = JSON.parse(p1.response);
return p2.estimatedAmountTable.currencyConversionList[0]["currencyList"]["currency"][0]["amount"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment