Giter Club home page Giter Club logo

meteor-synapsepay's Introduction

meteor add parlay:synapsepay

Wraps and adds to SynapsePay's API V3 node library synapse_pay_rest.

  1. Use
  2. Example data
  3. Setup 1. IP address 1. Fingerprint
  4. Flow 1. Create users 1. Create accounts
    1. Account numbers
    2. Username password 1. Transactions
    3. Create
    4. Receive updates
  5. Constants 1. Document types 1. Banks
  6. Dev
  7. Test

Use

Endpoints, arguments, and responses mirror the V3 REST API.

Example data

See example arguments and response data in tests.coffee

Setup

Keys

There are three options for setting your SynapsePay client_id and client_secret:

# 1. settings.json
{
  "synapsepay": {
    "id": "fakeid"
    "secret": "fakesecret"
  }
}
# then in code:
client = new SynapsePay opts

# 2. global init function
SynapsePay.init('fakeid', 'fakesecret')
client = new SynapsePay opts

# 3. include with every client creation
client = new SynapsePay
  client_id: 'fakeid'
  client_secret: 'fakesecret'
  ip_address: '...'
  ...

IP address

Inside methods, the IP address can be obtained from this.connection.clientAddress.

Fingerprint

One option is to save a random string in each browser and send the string along to any methods that need it. TODO

# client.coffee
unless localStorage.getItem 'browserId'
  localStorage.setItem 'browserId', Random.id 20

Meteor.call 'foo', localStorage.getItem 'browserId'

# server.coffee
Meteor.methods
  foo: (browserId) ->
    client = new SynapsePay
      ip_address: @connection.clientAddress
      fingerprint: browserId

User

When hitting a nodes.* or transactions.* endpoint, the client must be created with a user id, and it must have requested an oauth token. Retrieving an oauth token is done automatically for you. If you'd like to do this yourself, use the dontRefresh: true option:

client = new SynapsePay
  ...
  dontRefresh: true
, userId

user = client.users.get user_id: userId
client.users.refresh refresh_token: user.refresh_token

Flow

Create users

synapse = new SynapsePay opts

user = synapse.users.create userData
synapse.users.refresh refresh_token: user.refresh_token
# now `synapse` will send user's id and oauth_key in headers of subsequent
# requests

user = synapse.users.addDoc kyc
if not user.success
  synapse.users.attachFile governmentID
else if response.question_set?
  user = synapse.users.answerKBA answers
  # user.permission is 'RECEIVE'
else
  # user.permission is 'RECEIVE'

# if you need user to have SEND permissions (be able to debit from their bank
# account)
user = synapse.users.attachFile picOrGovernmentID
# now user.permission will be 'SEND-AND-RECEIVE'

Create accounts

Aka nodes. Sometimes these requests can take a few seconds to return, because SynapsePay has to hit slow bank APIs before they can respond to you.

Account numbers

response = synapse.nodes.add accountNumbers
node = response.nodes[0]
# node.allowed should be 'CREDIT'

# after two business days, prompt user to enter microdeposits
response = synapse.nodes.verify node._id, micro: [.1,.1]
node = response.nodes[0]
# node.allowed should be 'CREDIT-AND-DEBIT'

Username password

response = synapse.nodes.add usernamePassword
if response.mfa?
  mfaQuestion = response
  response = synapse.nodes.add
    access_token: mfaQuestion.mfa.access_token
    mfa_answer: 'test_answer'

# response.nodes has all accounts under that usernamePassword, each with
# 'CREDIT-AND-DEBIT' permissions

Transactions

Create

txnData.to =
  type: 'ACH-US'
  id: toNode._id

txnData.extra.webhook = 'www.myapp.com/synapse/transactions'

txn = synapse.trans.create fromNode._id, txnData

Receive updates

Using package simple:json-routes:

JsonRoutes.add 'post', '/synapse/transactions', (req, res, next) ->
  txn = req.body
  signature = req.headers['x-synapse-signature']
  hash = new SynapsePay().client.Client.createHMAC txn

  unless signature is hash
    throw new Meteor.Error 'bad-sig'

  ...

  JsonRoutes.sendResult res, 200

Constants

Document types

SynapsePay.documentTypes =
  SSN:
    code: 'SSN'
    displayText: 'Social Security Number (last 4)'
  ...

  all: -> [
    @SSN
    @PASSPORT
    @DRIVERS_LICENSE
    @PERSONAL_IDENTIFICATION
  ]

  US: -> [
    @SSN
    @DRIVERS_LICENSE
  ]

Banks

If you're not using their bank login widget, then you'll need the list of banks they support:

SynapsePay.banks = [
  {
    code: "bofa"
    name: "Bank of America"
    logo:
      file: "bofa"
      url: "https://s3.amazonaws.com/synapse_django/bank_logos/bofa.png"
  }
  ...
]

Helper functions:

SynapsePay.banks.get code: 'bofa'
SynapsePay.banks.get name: 'Bank of America'
SynapsePay.banks.isValid code: 'bofa'

Dev

Test

meteor create testapp
cd testapp
mkdir packages
cd packages
git clone [email protected]:parlaywithme/meteor-synapsepay.git
cd ..
meteor add parlay:synapsepay
meteor test-packages --driver-package velocity:console-reporter parlay:synapsepay

Then reload localhost:3000 to run tests - output in server console. Some logged errors are expected (409 and 404).

meteor-synapsepay's People

Contributors

lorensr avatar

Watchers

James Cloos avatar Sanjay Kumar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.