Node JS library to interact with the Routefusion API
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.gitignore
README.md
index.js
package-lock.json
package.json

README.md

Routefusion Node.js SDK

Contents

Get Started

For API access, register for an API key at https://routefusion.co/sign_up.

Aftern signup, login and go to 'developer'. Create an API key (CLIENT_ID) / (SECRET) pair.

If you plan to use the SDK set your API key / secret pair as environment variables, or create a credentials file where you can manage all of your keys in one place. The location of your credentials file should be ~/.rf/credentials for unix systems and C:\%USERPROFILE%\.rf\credentials for windows systems.

Note: API and SDK are compatible with async / await.


Initialize an instance of the sdk like so

const rf = require('routefusion-sdk').Instance({
  RF_CLIENT_ID: '137F1AA06E004F96BEE9B4644F8F7A46CDA45CACB0052B2583D674C530252B6C',
  RF_SECRET: '6C075288B9E43af4e329d9999dEB180D6b5fbE6F1565939DBCabB626ae886C59',
  RF_BASE_URL: 'https://sandbox.api.routefusion.co' // will default to sandbox
});

Or, if you would like to use environment variables or a credientials file instead initialize without any arguments and setup your credentials. This pattern is used in the rest of the docs

const rf = require('routefusion-sdk').Instance();

Set environment variables for the SDK to access

export RF_CLIENT_ID=137F1AA06E004F96BEE9B4644F8F7A46CDA45CACB0052B2583D674C530252B6C
export RF_SECRET=6C075288B9E43af4e329d9999dEB180D6b5fbE6F1565939DBCabB626ae886C59
export RF_BASE_URL='https://sandbox.api.routefusion.co' # will default to sandbox

Or, create a credentials file

~/.rf/credentials

[Rich] #profile name
client_id=137F1AA06E004F96BEE9B4644F8F7A46CDA45CACB0052B2583D674C530252B6C
secret=6C075288B9E43af4e329d9999dEB180D6b5fbE6F1565939DBCabB626ae886C59
base_url=https://sandbox.api.routefusion.co  # will default to sandbox

[Paul]
client_id=25D0A96BA42FBFDF3D68A86950523B23DBF65F276D3D340DC2FA5716D7662548
secret=57B1144d25FEB3a8c68a9A6a803844f09d644278947dB63E211EFc43D49Ed26E
Then, set your desired profile as an environment variable

then export your desired profile

export RF_PROFILE=Rich

Note: The credentials lookup priority is Instance config, environment variables, then credentials file

Users

Get User

const rf = require('routefusion-sdk').Instance();

rf.getUser()
  .then(resp => resp)
  .catch(err => err)

response:

{
    "id": 1,
    "uuid": "d48cb8b3-8945-4748-9bed-kd3d9vc15m",
    "wyre_id": null,
    "wyre_pusher_channel": null,
    "username": "",
    "first_name": "Rico",
    "last_name": "Suave",
    "occupation": "",
    "date_of_birth": "1980-03-12",
    "email": "email@email.com",
    "phone_number": "",
    "country": "US",
    "city": "Austin",
    "street": "100 Congress",
    "state": "TX",
    "zipcode": "78750",
    "verified": true,
    "admin": false,
    "type": null,
    "verification_submitted": true,
    "company_name": null,
    "created_at": "2018-08-10T22:31:55.972Z",
    "updated_at": "2018-12-09T20:56:27.258Z",
    "deleted_at": null,
    "password_reset_token": null,
    "password_reset_token_expires_at": null,
    "third_party_ids": null
}

Update User

const rf = require('routefusion-sdk').Instance();

let body = {
  first_name: "Bob",
  last_name: "TheBuilder",
  street: "1250 San Jacinto"
};

rf.updateUser(body)
  .then(resp => resp)
  .catch(err => err)

response:

{
    "id": 1,
    "uuid": "d48cb8b3-8945-4748-9bed-kd3d9vc15m",
    "wyre_id": null,
    "wyre_pusher_channel": null,
    "username": "",
    "first_name": "Bob",
    "last_name": "TheBuilder",
    "occupation": "",
    "date_of_birth": "1980-03-12",
    "email": "email@email.com",
    "phone_number": "",
    "country": "US",
    "city": "Austin",
    "street": "1250 San Jacinto",
    "state": "TX",
    "zipcode": "78750",
    "verified": true,
    "admin": false,
    "type": null,
    "verification_submitted": true,
    "company_name": null,
    "created_at": "2018-08-10T22:31:55.972Z",
    "updated_at": "2018-12-09T20:56:27.258Z",
    "deleted_at": null,
    "password_reset_token": null,
    "password_reset_token_expires_at": null,
    "third_party_ids": null
}

Beneficiaries

Get Beneficiaries

const rf = require('routefusion-sdk').Instance();

rf.getBenefiaries()
  .then(resp => resp)
  .catch(err => err)

response:

[
  {
    "id": 6,
    "uuid": "b45b64de-c620-4f18-bfad-5bdefcb522c1",
    "user_id": 1,
    "company_name": "",
    "first_name_on_account": "China",
    "last_name_on_accout": "China",
    "type": "personal",
    "bank_name": "中国建设银行",
    "branch_name": "中国建设银行",
    "bank_city": "中国建设银行",
    "account_type": "personal",
    "account_number": "12345678910",
    "beneficiary_email": "china.china@china.com",
    "beneficiary_phone_number": "1231231234",
    "country": "CN",
    "city": null,
    "bank_province": "中国建设银行",
    "currency": "CNY",
    "cpfcnpj": ""
  },
  {
    ...
]

Get Beneficiary

const rf = require('routefusion-sdk').Instance();

let beneficiaryId = 6;

rf.getBenefiary(beneficiaryId)
  .then(resp => resp)
  .catch(err => err)

response:

{
  "id": 6,
  "uuid": "b45b64de-c620-4f18-bfad-5bdefcb522c1",
  "user_id": 1,
  "company_name": "",
  "first_name_on_account": "China",
  "last_name_on_accout": "China",
  "type": "personal",
  "bank_name": "中国建设银行",
  "branch_name": "中国建设银行",
  "bank_city": "中国建设银行",
  "account_type": "personal",
  "account_number": "12345678910",
  "beneficiary_email": "china.china@china.com",
  "beneficiary_phone_number": "1231231234",
  "country": "CN",
  "city": null,
  "bank_province": "中国建设银行",
  "currency": "CNY",
  "cpfcnpj": ""
}

Create Beneficiary

const rf = require('routefusion-sdk').Instance();

let beneficiaryData = {
  company_name: "beneficiaryCompanyName",
  first_name_on_account: "companyOwnerFirstName",
  last_name_on_account: "companyOwnerLastName",
  type: "business",
  currency: "USD",
  bank_name: "Citibank",
  branch_name: "",
  bank_address1: "5252 Madison Ave.",
  bank_address2: "",
  bank_city: "New York City",
  bank_state_province: "New York",
  bank_postal_code: "00000",
  bank_country: "US", // 2 letter code
  bank_code: "",
  branch_code: "",
  swift_bic: "CITINY732", // 8 or 11 character code
  account_type: "business",
  account_number: "2315345432",
  routing_number: "113193532",
  clabe: "",
  tax_number: "",
  cpfcpnj: "",
  email: "company@email.com",
  phone_number: "",
  address1: "beneficiaryAddress",
  address2: "",
  city: "beneficiaryCity",
  state_province: "beneficiaryStateOrProvince",
  postal_code: "00000",
  country: "US" // 2 letter code
};

rf.createBenefiary(beneficiaryData)
  .then(resp => resp)
  .catch(err => err)

response:

{
  "company_name": "beneficiaryCompany",
  "first_name_on_account": "companyOwnerFirstName",
  "last_name_on_account": "companyOwnerLastName",
  "type": "business",
  "currency": "USD",
  "bank_name": "Citibank",
  "branch_name": "",
  "bank_address1": "5252 Madison Ave.",
  "bank_address2": "",
  "bank_city": "New York City",
  "bank_state_province": "New York",
  "bank_postal_code": "00000",
  "bank_country": "US",
  "bank_code": "",
  "branch_code": "",
  "swift_bic": "CITINY732",
  "account_type": "business",
  "account_number": "2315345432",
  "routing_number": "113193532",
  "clabe": "",
  "tax_number": "",
  "cpfcpnj": "",
  "email": "company@email.com",
  "phone_number": "",
  "address1": "beneficiaryAddress",
  "address2": "",
  "city": "beneficiaryCity",
  "state_province": "beneficiaryStateOrProvince",
  "postal_code": "00000",
  "country": "US"
}

Update Beneficiary

const rf = require('routefusion-sdk').Instance();

let beneficiaryData = {
  address1: "newBeneficiaryAddress",
};

rf.updateBenefiary(beneficiaryData)
  .then(resp => resp)
  .catch(err => err)

response:

{
  "company_name": "beneficiaryCompany",
  "first_name_on_account": "companyOwnerFirstName",
  "last_name_on_account": "companyOwnerLastName",
  "type": "business",
  "currency": "USD",
  "bank_name": "Citibank",
  "branch_name": "",
  "bank_address1": "5252 Madison Ave.",
  "bank_address2": "",
  "bank_city": "New York City",
  "bank_state_province": "New York",
  "bank_postal_code": "00000",
  "bank_country": "US",
  "bank_code": "",
  "branch_code": "",
  "swift_bic": "CITINY732",
  "account_type": "business",
  "account_number": "2315345432",
  "routing_number": "113193532",
  "clabe": "",
  "tax_number": "",
  "cpfcpnj": "",
  "email": "company@email.com",
  "phone_number": "",
  "address1": "newBeneficiaryAddress",
  "address2": "",
  "city": "beneficiaryCity",
  "state_province": "beneficiaryStateOrProvince",
  "postal_code": "00000",
  "country": "US"
}

Transfers

Create Transfer

const rf = require('routefusion-sdk').Instance();

let transferData = {
  beneficiary_id: 6,
  source_amount: 1000
};

rf.createTransfer(transferData)
  .then(resp => resp)
  .catch(err => err)

response:

{
    "id": 120,
    "user_id": 1,
    "account_id": null,
    "beneficiary_id": 6,
    "source_amount": "1000",
    "exchange_rate": null,
    "fee": null,
    "currency_pairs": "USDUSD",
    "created_at": "2018-12-14T00:41:38.661Z",
    "updated_at": null,
    "uuid": "b1e3f2fa-27f1-4424-987c-105009fed4fe",
    "state": "created",
    "payout_partner_uuid": null,
    "authorizing_ip": "::1",
    "transfer_states": [
        {
            "state": "created",
            "created_at": "2018-12-14T00:41:38.643Z"
        }
    ],
    "source_currency": "USD",
    "destination_amount": null,
    "destination_currency": "USD",
    "payout_partner_fee": null,
    "payout_partner": null,
    "payout_partner_status": null
}

Get Transfer

const rf = require('routefusion-sdk').Instance();

let transferUuid = '1c511f62-f8b1-4070-a27a-c1581e7fg79a';

rf.createTransfer(transferUuid)
  .then(resp => resp)
  .catch(err => err)

response:

{
    "state": "processing",
    "created_at": "2018-12-03T20:35:31.017Z"
}

Balance

Get Balance

const rf = require('routefusion-sdk').Instance();

rf.getBalance()
  .then(resp => resp)
  .catch(err => err)

response

{
    "balance": 200
}