Comments (2)
You're correct, and I should have implemented them in server codes.
I solved my situation by implementing those codes in server without any issues now.
Thank you so much. 👍 💯
from nodejs-sdk.
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 /
will call WePay's /checkout/create
endpoint using the Node SDK, print the response to console, and send a "Success!" response string. You can observe this by visiting http://localhost:3000
in a browser - you should see "Success!" printed on the screen and you should see WePay's API response in your server logs.
Please let me know if I've incorrectly assessed your situation or if you're still having trouble. Thanks!
from nodejs-sdk.
Related Issues (11)
- Cannot find node module. HOT 1
- Error 503 first byte timeout
- Update npm module HOT 1
- doesn't work
- Accent in value of one of the values of payer_rbits fails the payment HOT 2
- Use Promises
- Valid email addresses marked as invalid (false positive)
- callback argument is a Buffer HOT 2
- WEPAY constructor options not used HOT 1
- /checkout/create response is incomplete HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodejs-sdk.