Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

connext

Package Overview
Dependencies
Maintainers
2
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connext - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

build/default/Connext.js

39

package.json
{
"name": "connext",
"version": "0.2.0",
"version": "1.0.0",
"description": "Connext is a payment api for Ethereum applications",
"main": "connext.js",
"main": "build/node4/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "babel-build-all",
"lint": "snazzy && echint",
"pretest": "npm run lint && npm run build",
"test": "tap test --node-arg=--require --node-arg=babel-register",
"coverage": "tap test --reporter silent --coverage --nyc-arg=--require --nyc-arg=babel-register"
},

@@ -13,2 +17,16 @@ "repository": {

},
"files": [
"build",
"src"
],
"standard": {
"ignore": [
"build/**"
]
},
"echint": {
"ignore": [
"build/**"
]
},
"keywords": [

@@ -24,3 +42,3 @@ "payment",

],
"author": "Arjun Bhuptani <arjunbhuptani@gmail.com>, Layne Haber <laynehaber@gmail.com> (http://connextapi.com)",
"author": "Rahul Sethuram, <rahul@connextapi.com>, Arjun Bhuptani <arjun@connextapi.com>, Layne Haber <layne@connextapi.com> (http://connextapi.com)",
"license": "MIT",

@@ -31,6 +49,15 @@ "bugs": {

"homepage": "https://github.com/ConnextAPI/connext#readme",
"devDependencies": {
"@ahmadnassri/babel-build-all": "*",
"babel-plugin-add-module-exports": "*",
"babel-preset-env": "^1.6.0",
"babel-register": "*",
"echint": "*",
"snazzy": "*",
"tap": "*"
},
"dependencies": {
"request": "^2.81.0",
"web3": "^0.19.0"
"axios": "^0.16.2",
"check-types": "^7.3.0"
}
}

113

README.md

@@ -12,9 +12,13 @@ # Connext

2) Construct your connext object in a separate connext.js file and export it. This will reduce the risk of key and secret information being leaked.
2) Do not save your API key and secret into source control. Use other strategies such as a git-ignored config file or environment variables.
```
//connext.js
var Connext = require('connext');
var connext = new Connext(ApiKey, ApiSecret);
const Connext = require('connext');
const apiKey = process.env.API_KEY
const apiSecret = process.env.API_SECRET
const connext = new Connext(apiKey, apiSecret);
module.exports = connext;

@@ -25,16 +29,18 @@ ```

### getKey() [to be deprecated soon for security reasons]
All of the Connext object methods return Promises. See this article for an overview on how to use them: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises.
Inputs: (email, password, [callback])
Outputs: (error, {key, secret})
### getKey(email, password) [to be deprecated soon for security reasons]
Retrieves your key and secret if you already have an account. Outputs get returned into a callback.
Inputs: (email, password)
Outputs: Promise that resolves with object `{ key, secret }`
Retrieves your key and secret if you already have an account.
Usage:
```
connext.getKey(email, password, function(auth_details) {
var key = auth_details.key;
var secret = auth_details.secret;
})
connext.getKey(email, password).then(({ key, secret }) => {
console.log(key, secret);
})
```

@@ -44,27 +50,39 @@

Inputs: ([callback])
Outputs: (error, token)
Inputs: ()
Generates an empty token object to be filled out into a callback. You can ```console.log()``` it to find out what the possible data fields are. You should call this on your client side and fill out the data fields there so that no credit card info touches your servers.
Outputs: Promise that resolves with an object `{ ...tokenParameters }`
### tokenize()
Generates an empty token object to be filled out into a Promise. You can `console.log()` it to find out what the possible data fields are. You should call this on your client side and fill out the data fields there so that no credit card info touches your servers.
Inputs: (token, [callback])
Outputs: (error, updated_token)
Usage:
```
connext.newToken().then(token => {
console.log(token); // show token parameters
})
```
### tokenize(token)
Inputs: (token)
Outputs: Promise that resolves with an object `{ ...updatedTokenParameters }`
Sends the card info to connext servers and returns a token in a callback. The token is a redacted version of the information which is saveable on your servers without violating PCI compliancy. Like above, call only from the client side to make sure credit card info never touches your servers.
### chargeCard()
Usage:
Inputs: (token, amount, [callback])
Outputs: (error, receipt)
```
connext.tokenize(token).then(newToken => {
console.log(newToken);
})
```
Actually charges the card. *Amount must be written as payment(in dollars)x100*. Eg: $30.10 becomes 3010. The tokenization and charge process are separated to facilitate recurring payments or a second attempt at a payment if the payment fails. Returns a receipt object in the callback. For now, the receipt object only has a success field.
### chargeCard(token, amount, chargebackDestination, tokenContractAddress)
### chargeEth() [COMING SOON]
Inputs: (token, amount, chargebackDestination, tokenContractAddress)
Inputs: (key, secret, to, from, from_key, amount, [callback])
Outputs: 1st callback(error, transaction hash), 2nd callback(error, transaction receipt)
Outputs: Promise that resolves with an object `{ vaultAddress }`
Not deployed yet. This will eventually be an easy to integrate "Pay with Eth" button that works with metamask out of the box!
Actually charges the card and deploys a vault contract to receive the tokens. `chargebackDestination` must be a valid Ethereum address that will be the "escape hatch" for tokens that are returned in the case of a charge reversal. `tokenContractAddress` must be a valid Ethereum address that is the ERC20 token contract for the tokens that will be sent to the vault upon settlement of the transaction. *Amount must be written as payment(in dollars)x100, as a number*. Eg: $30.10 becomes 3010. The tokenization and charge process are separated to facilitate recurring payments or a second attempt at a payment if the payment fails. The resolved Promise object contains the vault address.

@@ -74,29 +92,22 @@ ## Example usage:

```
//connext.js
var Connext = require('connext');
var connext = new Connext(ApiKey, ApiSecret);
connext.newToken()
.then(token => {
return connext.tokenize(token);
})
.then(newToken => {
// add payment info here from input fields
// ...
return connext.chargeCard(newToken, 101, "0x1111111111111111", "0x1111111111111112");
})
.then(response => {
const { vaultAddress } = response; // destructure vault address from response
// send tokens to vault
})
.catch(error => {
// handle me
});
```
module.exports = connext;
## Error Handling
//index.js
var connext = require('./path/to/connext.js');
connext.newToken(function(err, token){
if (err) return (err);
//add payment info here from input fields
//...
//tokenize the card data
connext.tokenize(token, function(err, updated_token) {
if (err) return (err);
//actually charge the card
connext.chargeCard(updated_token, 101, function(err, receipt) {
if (err) return (err);
console.log(receipt); //logs "success"
})
})
})
```
The Connext API makes use of [axios](https://github.com/mzabriskie/axios) for HTTP calls. Errors are returned directly from axios, so they should be handled appropriately using this guide as reference: https://github.com/mzabriskie/axios#handling-errors
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc