Reputation: 41
I'm trying to copy the example in this How-to guide How-to guide but I always receive this error:
XMLHttpRequest cannot load https://svcs.sandbox.paypal.com/AdaptiveAccounts/CreateAccount. Origin http://my.domain.com is not allowed by Access-Control-Allow-Origin.
Could any provide me with a working example or any hints? Thank You!
This is my code:
Meteor.http.post("https://svcs.sandbox.paypal.com/AdaptiveAccounts/CreateAccount",{
headers: {
"X-PAYPAL-SANDBOX-EMAIL-ADDRESS": "[email protected]",
"X-PAYPAL-SECURITY-USERID": "myuserid",
"X-PAYPAL-SECURITY-PASSWORD": "somepassword",
"X-PAYPAL-SECURITY-SIGNATURE": "thelongsignature",
"X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T",
"X-PAYPAL-DEVICE-IPADDRESS": "192.0.2.0",
"X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON"
},
data: {
accountType: "PERSONAL",
name:{
firstName: "John",
lastName: "Doe"
},
address:{
line1: "123 Main Street",
city: "Sydney",
state: "NSW",
postalCode: "2000",
countryCode: "AU",
citizenshipCountryCode: "AU",
contactPhoneNumber: "12345678",
dateOfBirth: "1990-01-01Z",
createAccountWebOptions:{
returnUrl: "http://my.domain.com/"
},
currencyCode: "AUD",
emailAddress: "[email protected]",
preferredLanguageCode: "en_AU",
registrationType: "Web",
requestEnvelope:{
errorLanguage: "en_US"
}
}
}
},
function(error,result){
alert(error);
alert(result.statuscode);
})
Upvotes: 1
Views: 597
Reputation: 75945
Are you doing this on the client side? It would be safer to run it from the server's end because your users can't see the credentials, additionally you shouldn't get the error if you requested the document from the server. Your web browser is blocking the request because its a cross origin request.
server
Meteor.methods({
'createaccount':function() {
var result = Meteor.http.post("https://svcs.sandbox.paypal.com/AdaptiveAccounts/CreateAccount", {
headers: {
"X-PAYPAL-SANDBOX-EMAIL-ADDRESS": "[email protected]",
"X-PAYPAL-SECURITY-USERID": "myuserid",
"X-PAYPAL-SECURITY-PASSWORD": "somepassword",
"X-PAYPAL-SECURITY-SIGNATURE": "thelongsignature",
"X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T",
"X-PAYPAL-DEVICE-IPADDRESS": "192.0.2.0",
"X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON"
},
data: {
accountType: "PERSONAL",
name:{
firstName: "John",
lastName: "Doe"
},
address:{
line1: "123 Main Street",
city: "Sydney",
state: "NSW",
postalCode: "2000",
countryCode: "AU",
citizenshipCountryCode: "AU",
contactPhoneNumber: "12345678",
dateOfBirth: "1990-01-01Z",
createAccountWebOptions:{
returnUrl: "http://my.domain.com/"
},
currencyCode: "AUD",
emailAddress: "[email protected]",
preferredLanguageCode: "en_AU",
registrationType: "Web",
requestEnvelope:{
errorLanguage: "en_US"
}
}
}
});
return result;
});
client
Meteor.call('createaccount', function(error,result) { console.log(result); });
Note I've altered your request to a synchronous request so that it can return data to the client
Upvotes: 2