-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CORS errrors when calling API #19
Comments
Hey there @StarNeit! What you're running into is a browser-initiated "Cross Origin Request" issue - browsers are designed to prevent a website from making an HTTP call to a resource that is from a different origin (wepay.com) than the one it is originating from (localhost:3000) unless they pass a pre-flight check (more reading here). Given that your WePay credentials should stay secret on the server-side of your application, and that the WePay API does not allow API calls originating from a browser (which is why you're encountering CORS errors), you should move your WePay logic to your application's server, rather than the webpage. For example: var app = require('express')(); // expressJS, allows you to easily set up a server
var wepay = require('wepay').WEPAY;
var wepay_settings = {
'client_id' : 'XXXXXXX',
'client_secret' : 'XXXXXXXXXXXX',
'access_token' : 'XXXXXXXXXXXX'
};
var wp = new wepay(wepay_settings);
wp.use_staging();
app.get('/', function(req, res) {
wp.call('/checkout/create',
{
"account_id": "XXXXX",
"short_description": "short",
"amount": 100,
"currency": "USD",
"type": "donation"
},
function (response) {
console.log("WePay response:\n", response);
res.send("Success!");
});
});
app.listen(3000, function() {
console.log("Listening on port 3000");
}); The above node application will spin up a server at port 3000, and on a GET request to Please let me know if I've incorrectly assessed your situation or if you're still having trouble. Thanks! |
You're correct, and I should have implemented them in server codes. Thank you so much. 👍 💯 |
Hello.
I am using this npm module in meteor project, and this is my code implementation.
// local variables
var wepay_settings = {
'client_id' : 'XXXXXXX',
'client_secret' : 'XXXXXXX',
'access_token' : 'XXXXXXXXX', // used for oAuth2
// 'api_version': 'API_VERSION'
}
I have got below errors when calling this API
I am pulling my hairs for few days to solve this problem, but I couldn't find any solution yet.
Is there the problem of this package module.
Please help me with this issue. Thank you so mcuh.
The text was updated successfully, but these errors were encountered: