Created
February 9, 2014 05:37
-
-
Save fidelisrafael/8894852 to your computer and use it in GitHub Desktop.
Paypal profile address autocomplete example (only runs from paypal website)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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