2013-02-05 123 views
1

我想要的例子複製該如何引導How-to guide但我總是收到此錯誤:流星的Http寶帳戶自適應

XMLHttpRequest cannot load https://svcs.sandbox.paypal.com/AdaptiveAccounts/CreateAccount. Origin http://my.domain.com is not allowed by Access-Control-Allow-Origin. 

可以在任何給我提供一個工作示例或任何提示?謝謝!

這是我的代碼:

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); 
    }) 
+0

我也注意到,我需要在countryCode之後添加一個}:「AU」,因爲這是地址參數應該停止的地方。 –

回答

2

你在客戶端做這個?從服務器端運行它會更安全,因爲您的用戶看不到憑據,另外,如果您從服務器請求文檔,則不應該得到錯誤。您的網絡瀏覽器正在阻止該請求,因爲它的一個cross origin request

服務器

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; 
}); 

客戶

Meteor.call('createaccount', function(error,result) { console.log(result); }); 

注意我已經改變了你的請求,同步請求,以便它可以返回數據到客戶端

+0

真棒!把它放在服務器上的確有竅門! :)我打算把它放到服務器上,一旦我在客戶端上播放它。我正在使用Cloud9 IDE,因此無論何時使用console.log,它都不會在控制檯中顯示任何內容,不幸的是xD謝謝! –