meteor add parlay:synapsepay
Wraps and adds to SynapsePay's API V3 node library synapse_pay_rest.
- Use
- Example data
- Setup 1. IP address 1. Fingerprint
- Flow 1. Create users 1. Create accounts
- Constants 1. Document types 1. Banks
- Dev
- Test
Endpoints, arguments, and responses mirror the V3 REST API.
See example arguments and response data in tests.coffee
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: '...'
...
Inside methods, the IP address can be obtained from this.connection.clientAddress
.
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
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
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'
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.
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'
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
txnData.to =
type: 'ACH-US'
id: toNode._id
txnData.extra.webhook = 'www.myapp.com/synapse/transactions'
txn = synapse.trans.create fromNode._id, txnData
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
SynapsePay.documentTypes =
SSN:
code: 'SSN'
displayText: 'Social Security Number (last 4)'
...
all: -> [
@SSN
@PASSPORT
@DRIVERS_LICENSE
@PERSONAL_IDENTIFICATION
]
US: -> [
@SSN
@DRIVERS_LICENSE
]
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'
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).