Skip to content

Instantly share code, notes, and snippets.

@fidelisrafael
Created February 9, 2014 05:37
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 fidelisrafael/8894852 to your computer and use it in GitHub Desktop.
Save fidelisrafael/8894852 to your computer and use it in GitHub Desktop.
Paypal profile address autocomplete example (only runs from paypal website)
var paypalAddressClient = (function() {
"use strict" ;
var SERVICE_URL = 'https://www.paypal.com/br/cgi-bin/webscr?cmd=_prefilladdress&countryCode={{#country}}&zipcode={{#zip_code}}'
var httpClient = new XMLHttpRequest();
httpClient.onreadystatechange = function() {
if(this.status == 200 && this.readyState == httpClient.DONE) {
var response = this.responseText,
json_response = response.slice(response.indexOf("{")),
response_object = JSON.parse(json_response);
if(this.__returnCallback != undefined) {
this.__returnCallback.call(null, response_object);
}
}
}
return {
setup: function(countryCode, zipCode) {
httpClient.open('GET', SERVICE_URL.replace("{{#country}}", countryCode).replace("{{#zip_code}}", zipCode))
},
send: function(callback) {
httpClient.__returnCallback = callback;
httpClient.send();
}
}
});
// Only runs from paypal domain
var paypalClient = new paypalAddressClient();
paypalClient.setup('BR', '05016-000');
paypalClient.send(function(response) {
console.log('Getting address data to zipCode 05016-000 (BR)');
console.log(response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment