yamoney provides you with easy and nice interface in order to access Yandex.Money payment system.
$ npm install yamoney
#!/usr/bin/env coffee
yamoney = require('yamoney')
TEST_TOKEN = require('./token.json').access_token
client = new yamoney.Client(new yamoney.Service(TEST_TOKEN))
client.accountInfo((error, data) ->
unless error?
console.log('Account: ' + data.account)
console.log('Currency: ' + data.currency)
console.log('Balance: ' + data.balance)
undefined
)
Next example revokes your token, so you will not be able to use it any longer.
client.revokeToken((error) ->
unless error?
console.log('Bye-bye, my token!')
else
console.log(error)
undefined
)
client.accountInfo((error, info) ->
unless error?
console.log(info)
else
console.log(error)
undefined
)
client.operationHistory(type: 'deposition', start_record: 5, records: 3, (error, history) ->
unless error?
console.log(history)
else
console.log(error)
undefined
)
client.operationDetails(operation_id: '111111111111111', (error, details) ->
unless error?
console.log(details)
else
console.log(error)
undefined
)
Usually you need not to use Service class directly, but in some cases in can be usefull.
Let's now add custom header which will be sent to Yandex.Money:
extend = require('extend')
Service = require('yamoney').Service
class MyService extends Service
# My funny header generator
headers: () ->
extend(super, 'user-agent': 'my cool client')