1.0.0 • Published 5 years ago

headnote-sdk v1.0.0

Weekly downloads
4
License
-
Repository
-
Last release
5 years ago

Headnote Integration SDK

Installation

$ npm install headnote-sdk

Usage

Minimal example implementations for the frontend and backend using javascript. If your backend is not javascript, equivalent functionality can be achieved in any language.

FrontEnd

// Headnote SDK initialization
const headnote = new Headnote.ECheck({ env: 'sandbox' });

async createTransaction() {
  const tokenData = await headnote.getToken();
  const amount = 100;

  await axios.post('<YOUR-API-URL>', { amount, tokenData });

  console.log(`Transaction sent to API successfully. Transaction tokenData ${tokenData}`);
}

Example tokenData object returned from headnote.getToken()

{ 
  achLogin: {
    accountId: "ggNb9aJ4L3T99Pwop5dBUoynR3wewZFg6qZdL",
    publicToken: "public-sandbox-e4ddd676-f5c5-468c-b7c1-dd83806c1fad"
  },
  institution: {
    institutionId: "ins_3",
    name: "Chase"
  }
}

BackEnd

async createTransaction(amount, tokenData) {
  // tokenData is the tokenData object received from the frontend from the headnote.getToken() function. 
  const headnotePaymentUrl = 'https://integration-dev.headnote.com/payment/echeck';
  const xApiKey = '<API-KEY>'; // integration api key, provided by headnote
  const xIntegrationKey = '<FIRM-INTEGRATION-KEY>'; // firm integration key, provided by any firm administrator

  const transaction = await axios.post(headnotePaymentUrl, { amount, achLogin: tokenData.achLogin }, {
    'X-API-KEY': xApiKey,
    'X-INTEGRATION-KEY': xIntegrationKey
  });

  console.log(`Transaction completed successfully. Transaction id ${transaction.id}`);
}