Skip to content

Commit 9b9723a

Browse files
Updated docs and improved comments in source
1 parent 780755e commit 9b9723a

File tree

7 files changed

+91
-25
lines changed

7 files changed

+91
-25
lines changed

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
SPHINXOPTS =
66
SPHINXBUILD = sphinx-build
77
PAPER =
8-
BUILDDIR = _build
8+
BUILDDIR = /Users/giovannib/Documents/WePay/support-dashboard/pages/
99

1010
# User-friendly check for sphinx-build
1111
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)

docs/architecture.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _kvasirarch:
2+
13
Kvasir's Architecture
24
=========================
35
This page details Kvasir's architecture. It explains in detail why each architecture decision was made.
@@ -40,3 +42,9 @@ In order to achieve this, we came up with this idea of a "middleware component."
4042

4143
This middleware can be provided in any language that the developer chooses, using any structure that they want. As long as it can receive and send back information in the way that Kvasir expects, the rest is up to the developer. The information that Kvasir requests may be spread out across three or four tables for one developer, but be completed contained in a single table for another. This middleware piece allows Kvasir to be apathetic towards a developer's underlying database. This provides us with the necessary flexibility to be able to provide this as a solution to all company's currently using WePay, not just a handful.
4244

45+
46+
Integrating with Kvasir
47+
----------------------------
48+
The entire architectural model assumes that this application is running on an company's internal network. It does not come with any sort of authentication and there are no plans for it. Similarly to database configurations there are a plethora of authentication systems out there that we cannot provide mechanisms to interact with all of them.
49+
50+
You should launch Kvasir on system that is only accessible to your employees and not the greater Internet. Otherwise, you will be exposing your database, and all of the information about your end users.

docs/conf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
# add these directories to sys.path here. If the directory is relative to the
2121
# documentation root, use os.path.abspath to make it absolute, like shown here.
2222
#sys.path.insert(0, os.path.abspath('.'))
23-
23+
sys.path.insert(0,os.path.abspath('sphinxext'))
24+
print (sys.path)
2425
# -- General configuration ------------------------------------------------
2526

2627
# If your documentation needs a minimal Sphinx version, state it here.
2728
#needs_sphinx = '1.0'
2829

2930
primary_domain = "js"
3031

32+
BUILDDIR = "/Users/giovannib/Documents/WePay/support-dashboard/pages"
33+
3134
# Add any Sphinx extension module names here, as strings. They can be
3235
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3336
# ones.
@@ -37,6 +40,7 @@
3740
'sphinx.ext.todo',
3841
'sphinx.ext.mathjax',
3942
'sphinx.ext.viewcode',
43+
'wepay_docs'
4044
]
4145

4246
# Add any paths that contain templates here, relative to this directory.
@@ -116,7 +120,8 @@
116120

117121
# The theme to use for HTML and HTML Help pages. See the documentation for
118122
# a list of builtin themes.
119-
html_theme = 'alabaster'
123+
#html_theme = 'alabaster'
124+
html_theme = "sphinx_rtd_theme"
120125

121126
# Theme options are theme-specific and customize the look and feel of a theme
122127
# further. For a list of options available for each theme, see the

docs/index.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ Welcome to Kvasir's documentation!
88
Kvasir (Vas-eer) is a support dashboard built for WePay partner's to use with their customer support teams.
99
It provides most of the essential functionality that a support teams needs to handle the various actions that merchants and payers need.
1010

11+
.. note::
12+
This documentation was added to GitLab pages and GitHub pages by following this tutorial:
13+
http://lucasbardella.com/blog/2010/02/hosting-your-sphinx-docs-in-github
14+
15+
Getting it to work for GitLab pages required some changes and help from the following link:
16+
https://about.gitlab.com/2016/04/07/gitlab-pages-setup/
17+
18+
1119
Kvasir's Capabilities
1220
---------------------
1321
Kvasir is designed to aid in the completion of many actions that your typical customer support user would have to do after integrating with WePay.
@@ -29,7 +37,7 @@ These actions include:
2937

3038
Tech Stack
3139
-----------
32-
Kvasir is comprised of two major components - a back end server running on `NodeJS <http://https://nodejs.org/en/>_` and a set of front-end JavaScript files built on top of `ReactJS <https://facebook.github.io/react/>_` and `Redux <http://redux.js.org/>_`.
40+
Kvasir is comprised of two major components - a back end server running on `NodeJS <http://https://nodejs.org/en/>`_ and a set of front-end JavaScript files built on top of `ReactJS <https://facebook.github.io/react/>`_ and `Redux <http://redux.js.org/>`_.
3341

3442
You are free to pick and choose what parts of the application you want to use. ReactJS is designed to be back end agnostic - it doesn't care what technology you use on the back end, as long as it receives the information it needs and in the format that it expects. You could chose to scrape the NodeJS server and rebuild it in your own language of choice. The reverse is true as well - if you want to work your support dashboard within an existing infrastructure, then you can throw away the front end component and build your own on top of our NodeJS server.
3543

@@ -42,7 +50,7 @@ NodeJS comes with some nice functions that make compiling our front end JavaScri
4250

4351
Installation
4452
---------------
45-
First make sure that you have `NodeJS <https://nodejs.org/en/download/>_` installed on your machine. Node comes prepackaged with it's package manager `npm <https://www.npmjs.com/>_` which will allow you to download and manage all of the packages and dependencies.
53+
First make sure that you have `NodeJS <https://nodejs.org/en/download/>`_ installed on your machine. Node comes prepackaged with it's package manager `npm <https://www.npmjs.com/>`_ which will allow you to download and manage all of the packages and dependencies.
4654

4755
From within the main application directory run:
4856
>>> npm install
@@ -58,7 +66,7 @@ Contents:
5866
:maxdepth: 2
5967

6068
architecture
61-
69+
frontend
6270

6371

6472
Indices and tables

docs/make.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ if errorlevel 9009 (
7373

7474

7575
if "%1" == "html" (
76-
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
76+
touch *.rst
77+
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
7778
if errorlevel 1 exit /b 1
7879
echo.
7980
echo.Build finished. The HTML pages are in %BUILDDIR%/html.

reducers/accounts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function account(state = [], action) {
5252
case INVALIDATE_ACCOUNT:
5353
case RECEIVE_ACCOUNT:
5454
case REQUEST_ACCOUNT:
55-
return Object.assign({}, state, account_base(state, action))
55+
return Object.assign([], state, account_base(state, action))
5656
case CLEAR_ACCOUNTS:
5757
return {}
5858
default:

server.js

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ var config = require('./webpack.config')
55
var bodyParser = require('body-parser')
66
var request = require("request")
77

8-
8+
// library for securely handeling hashed cookie objects
99
var cookieSession = require("cookie-session")
1010

11+
// WePay library
1112
var WePay = require("wepay").WEPAY;
1213

14+
// express library for defining routes
1315
var express = require("express");
1416

1517
// load app configuration settings
@@ -58,22 +60,14 @@ function sendResponse(package, res) {
5860
}
5961
}
6062

61-
function getDataFromMiddleware(resource, data, callback) {
62-
var uri = app_config.middleware_uri+"/"+resource;
63-
64-
return request.post(
65-
{
66-
"url":uri,
67-
"json":data,
68-
headers: {
69-
"Authorization":app_config.middleware_secret
70-
}
71-
},
72-
callback
73-
);
74-
}
75-
76-
63+
/**
64+
* Request data from the given wepay_endpoint, using the specified access_token and package. This function will immediately send the response back to the client
65+
*
66+
* @param res - Express response object
67+
* @param wepay_endpoint - the WePay API endpoint we want to hit
68+
* @param access_token - the access token we want to use with the request. NOTE: for certain endpoints, this can be *null*
69+
* @param package - the package of data we want to send along with request. This can be an empty object depending on the endpoint
70+
*/
7771
function getWePayData(res, wepay_endpoint, access_token, package) {
7872

7973
var wepay_settings = {}
@@ -99,6 +93,45 @@ function getWePayData(res, wepay_endpoint, access_token, package) {
9993
}
10094
}
10195

96+
/*
97+
* Given a resource, and package of data, send a request to the middleware.
98+
* Once the request is complete, it will call the callback function provided.
99+
*
100+
* Refer to the middleware specification for more details about what resources are available and what each resource expects in it's data package
101+
*
102+
* @params resource - the resource that we want to search on the partner's database. This should be user, account, or payer
103+
* @params data - the package we use to query information about the provided resource
104+
* @params callback - a callback function to execute after the middleware returns information. Typically this is `parseMiddlewareResponse`
105+
*/
106+
function getDataFromMiddleware(resource, data, callback) {
107+
var uri = app_config.middleware_uri+"/"+resource;
108+
109+
return request.post(
110+
{
111+
"url":uri,
112+
"json":data,
113+
headers: {
114+
"Authorization":app_config.middleware_secret
115+
}
116+
},
117+
callback
118+
);
119+
}
120+
121+
/*
122+
* Parse the response from the middleware and decide what to do with it.
123+
* If the middleware sends an error, raise that error back to the client
124+
* If a wepay_endpoint is provided, then use the information provided by the client and request information from the provided endpoint with the wepay_package
125+
* If no wepay_endpoint is provided, then just send the results from the middleware back to the client
126+
*
127+
* @params req - Expresses Request object
128+
* @params res - Express Response object
129+
* @params error - A JSON structure with error information (empty if no error occured)
130+
* @params response - A detailed response object
131+
* @params body - A JSON structure with returned data
132+
* @params wepay_endpoint - The wepay_endpoint to hit after receiving a response from the middleware
133+
* @params wepay_package - The package to send to the wepay_endpoint
134+
*/
102135
function parseMiddlewareResponse(req, res, error, response, body, wepay_endpoint, wepay_package) {
103136
if (body.error) {
104137
// send error
@@ -256,6 +289,11 @@ app.post("/refund", function(req, res) {
256289
}
257290
})
258291

292+
/**
293+
* Get reserve information from the WePay API.
294+
* Requires an access token and an account_id
295+
*
296+
*/
259297
app.post("/reserve", function(req, res) {
260298
if(!req.session.access_token) {
261299
console.log("ERROR: do not have an access token to work with");
@@ -265,6 +303,9 @@ app.post("/reserve", function(req, res) {
265303
}
266304
});
267305

306+
/**
307+
* Given a payer's unique identifying information (such as their email), get a list of all of their checkouts from the middleware
308+
*/
268309
app.post("/payer", function(req, res) {
269310
// get the email from the search
270311
var email = req.body.email;
@@ -278,6 +319,9 @@ app.post("/payer", function(req, res) {
278319
);
279320
})
280321

322+
/*
323+
* Given a credit_card_id (tokenized card) get more information about the card from the v2/credit_card WePay API endpoint
324+
*/
281325
app.post("/credit_card", function(req, res){
282326
var credit_card_id = parseInt(req.body.credit_card_id);
283327

0 commit comments

Comments
 (0)