node package manager

gocoin

A JavaScript client library for the GoCoin API.

gocoin-js

A JavaScript client library for the GoCoin API. It is written in CoffeeScript and is ready for use in both modern browsers and Node.js servers.

npm install gocoin

Examples

*Example code *Full API spec

Basic Usage

#coffee
GoCoin = require 'gocoin'
client = new GoCoin.Client()
 
client.setToken myAccessToken
 
client.users.self (err, user)->
  console.log user
  
 

Xrate

#coffee
gocoin = new GoCoin.Client()
gocoin.xrate.get (err, resp) ->
  xrate = resp

Methods

Note: All callbacks follow the standard argument pattern of:

#js
  function(error, result) {}
#coffee
  (error, result) ->

Constructor

parameter description type default value
logger logging function, must be an instance of winston Function custom logger
host api host string "api.gocoin.com"
secure SSL on or off, will default @port to 443 or 80 boolean true
port port to route requests through - supercedes "secure" parameter integer null
path used for prefixing routes string "/api"
api_version api version string "v1"
method default request method string "GET"
headers add a header to all requests object null
parse_json when true, this automatically parses responses as JSON string true
request_id include a request_id with every request - useful for debugging string null
#coffee
gocoin = new GoCoin.Client
  secure: true
  parse_json: true
  request_id: "12345"

Client

client.setToken(access_token)

Stores the access token for use with all requests #### client.getToken() Will return the client instance access token #### client.getCodeUrl(params) Returns the Authorization Code URL

#coffee
params = {
  client_id: <application id>,
  response_type: 'code'
  redirect_uri: <application redirect uri>
  scope: "user_read invoice_read_write"
  state: <optional string>
}
url = gocoin.getCodeUrl params

client.authenticate(params, callback)

Obtains an access token

params = {
  client_id: <application id>,
  client_secret: <application secret key>
  redirect_uri: <application redirect uri>
  grant_type: "authorization_code"
  code: <access token authorization code>
}
gocoin.authenticate params, (err, body) ->
  access_token = body.access_token
  #store access token in db (recommended) or instantiate token
  gocoin.setToken access_token
  #make other requests

Users

users.self(callback)
users.get(user_id, callback)
users.update(params, callback)
params = {id: user_id, data: <updated user obj>}
users.update_password(params, callback)
params = {
  id: user_id,
  data: {
    current_password: "password",
    password: "passwordtwo",
    password_confirmation: "passwordtwo"
  }
}

Merchants

merchants.get(merchant_id, callback)
merchants.update(params, callback)
params = {id: merchant_id, data: <updated merchant obj>}
merchants.getSplit(params, callback)
params = {id: merchant_id, currency_code: "BTC"}
merchants.updateSplit(params, callback)
params = {
  id: merchant_id,
  currency_code: "BTC"
  payment_crypto_split: 100
  }
merchants.getSettings(merchant_id, callback)
merchants.updateSettings(params, callback)
params = {id: merchant_id, data: <updated settings obj>}
merchants.listCurrencies(merchant_id, callback)

Accounts

accounts.list(merchant_id, callback)
accounts.getTransactions(params, callback)
params = {id: merchant_id, data: <optional search parameters>}

Invoices

invoices.create(params, callback)
params = {id: merchant_id, data: <invoice obj>}
invoices.get(params, callback)
params = {id: invoice_id, verbose: <optional boolean>}
invoices.search(params, callback)
params = {id: merchant_id, data: <optional search parameters>}
invoices.confirmPaymentMethod(params, callback)
params = {id: merchant_id, data: <updated invoice obj>}
invoices.fulfill(invoice_id, callback)
invoices.sendWebhook(params, callback)
params = {
  id: merchant_id,
  data: {
    event_type: "invoice_ready_to_ship",
    callback_url: "https://testurl.com"
  }
}

Payouts

payouts.get(params, callback)
params = {id: payout_id, verbose: <optional boolean>}
payouts.list(merchant_id, callback)

Xrate

xrate.get(callback)

License

Copyright 2013 GoCoin Pte. Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.