-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
429 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
env: | ||
node: true | ||
es6: true | ||
|
||
# enable ECMAScript features | ||
ecmaFeatures: | ||
blockBindings: true | ||
templateStrings: true | ||
octalLiterals: true | ||
binaryLiterals: true | ||
generators: true | ||
forOf: true | ||
|
||
rules: | ||
# Possible Errors | ||
# list: https://github.com/eslint/eslint/tree/master/docs/rules#possible-errors | ||
## check debugger sentence | ||
no-debugger: 2 | ||
## check duplicate arguments | ||
no-dupe-args: 2 | ||
## check duplicate object keys | ||
no-dupe-keys: 2 | ||
## check duplicate switch-case | ||
no-duplicate-case: 2 | ||
## disallow assignment of exceptional params | ||
no-ex-assign: 2 | ||
## disallow use of reserved words as keys like enum, class | ||
quote-props: [2, "as-needed"] | ||
## disallow unreachable code | ||
no-unreachable: 2 | ||
## require valid typeof compared string like typeof foo === 'strnig' | ||
valid-typeof: 2 | ||
|
||
# Best Practices | ||
# list: https://github.com/eslint/eslint/tree/master/docs/rules#best-practices | ||
## require falls through comment on switch-case | ||
no-fallthrough: 2 | ||
|
||
prefer-const: 2 | ||
|
||
# Stylistic Issues | ||
# list: https://github.com/eslint/eslint/tree/master/docs/rules#stylistic-issues | ||
## use single quote, we can use double quote when escape chars | ||
quotes: | ||
- 2 | ||
- "single" | ||
- "avoid-escape" | ||
## 2 space indentation | ||
indent: | ||
- 2 | ||
- 2 | ||
## add space after comma | ||
## set to 'warn' because of https://github.com/eslint/eslint/issues/2408 | ||
comma-spacing: 1 | ||
## put semi-colon | ||
semi: 2 | ||
## require spaces operator like var sum = 1 + 1; | ||
space-infix-ops: 2 | ||
## require spaces return, throw, case | ||
keyword-spacing: 2 | ||
## no space before function, eg. 'function()' | ||
space-before-function-paren: [1, {"anonymous": "always", "named": "never"}] | ||
## require space before blocks, eg 'function() {' | ||
space-before-blocks: [2, "always"] | ||
## disallow dangling underscores in identifiers | ||
no-underscore-dangle: 0 | ||
## require parens for Constructor | ||
new-parens: 2 | ||
## max 100 length | ||
max-len: | ||
- 2 | ||
- 100 | ||
- 2 | ||
|
||
# Strict Mode | ||
# list: https://github.com/eslint/eslint/tree/master/docs/rules#strict-mode | ||
## 'use strict' on top | ||
strict: | ||
- 2 | ||
- "global" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Licensed under the MIT License | ||
* | ||
* @author Kanstantsin A Kamkou (2ka.by) | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @link https://github.com/kkamkou/node-concardis | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const xml2js = require('xml2js'); | ||
|
||
/*public abstract*/ class Order { | ||
constructor(request) { | ||
this._request = request; | ||
} | ||
|
||
toJson() { | ||
return new Promise((resolve, reject) => { | ||
this.toString() | ||
.then( | ||
xml => | ||
xml2js.parseString(xml, (err, json) => | ||
err ? reject(err) : resolve(json.ncresponse.$)) | ||
) | ||
.catch(reject); | ||
}); | ||
} | ||
|
||
toString() { | ||
return new Promise((resolve, reject) => { | ||
return this._request.submit() | ||
.then(response => resolve(response.toString())) | ||
.catch(reject); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = Order; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// .catch(e => setImmediate(() => { throw e; })); | ||
|
||
/** | ||
* Licensed under the MIT License | ||
* | ||
* @author Kanstantsin A Kamkou (2ka.by) | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @link https://github.com/kkamkou/node-concardis | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const OrderValid = require('./OrderValid'), | ||
SignedHttp = require('../request/SignedHttp'), | ||
SignedCollection = require('../request/SignedCollection'), | ||
ObjectCollection = require('../request/ObjectCollection'), | ||
CollectionChecksum = require('../request/CollectionChecksum'); | ||
|
||
const instance = (endpoint, secret, obj, algorithm) => { | ||
const collection = new ObjectCollection(obj); | ||
return new OrderValid( | ||
new SignedHttp( | ||
endpoint, | ||
{timeout: 10000, method: 'POST', headers: {'User-Agent': 'node-concardis'}}, | ||
new SignedCollection( | ||
'shasign', | ||
new CollectionChecksum(collection, secret, algorithm), | ||
collection | ||
) | ||
) | ||
); | ||
}; | ||
|
||
module.exports = { | ||
test: (secret, obj, algorithm) => | ||
instance('https://secure.payengine.de/ncol/test/orderdirect.asp', secret, obj, algorithm), | ||
production: (secret, obj, algorithm) => | ||
instance('https://secure.payengine.de/ncol/prod/orderdirect.asp', secret, obj, algorithm) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// .catch(e => setImmediate(() => { throw e; })); | ||
|
||
/** | ||
* Licensed under the MIT License | ||
* | ||
* @author Kanstantsin A Kamkou (2ka.by) | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @link https://github.com/kkamkou/node-concardis | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Order = require('./Order'); | ||
|
||
/*public final*/ class OrderValid extends Order { | ||
constructor(request) { | ||
super(request); | ||
|
||
const requiredIfNoAlias = ['CARDNO', 'ED', 'CVC'], | ||
required = [ | ||
'PSPID', 'ORDERID', 'AMOUNT', 'CURRENCY', 'OPERATION', 'SHASIGN', 'USERID', 'PSWD' | ||
]; | ||
|
||
required.forEach(k => { | ||
if (!this._request.has(k)) { | ||
throw new Error(`The "${k}" param is required`); | ||
} | ||
}); | ||
|
||
if (!this._request.has('ALIAS')) { | ||
requiredIfNoAlias.forEach(k => { | ||
if (!this._request.has(k)) { | ||
throw new Error(`The "${k}" param is required`); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
module.exports = OrderValid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Licensed under the MIT License | ||
* | ||
* @author Kanstantsin A Kamkou (2ka.by) | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @link https://github.com/kkamkou/node-concardis | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/* istanbul ignore next */ | ||
const path = require('path'); | ||
|
||
/* istanbul ignore next */ | ||
['Order', 'OrderSmart', 'OrderValid'] | ||
.forEach(c => module.exports[c] = require(path.join(__dirname, c))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.