1.0.0 • Published 2 years ago

kuda-quick-node v1.0.0

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
2 years ago

Kuda Node.js Library

NodeJS wrapper for making secure request to Kuda API

Getting started

  • paste your private and public key (both in XML format) in your project directory
  • Your client key is the name of your private key file

Using the library

While the repo is not yet on npm, simply clone this repo and run yarn or npm install

Library setup

const fs = require("fs");
const Kuda = require("./index"); // or require('kuda-node') if it becomes an npm package and that's the name

const publicKey = fs.readFileSync("./kuda.public.xml"); // or path to your kuda public key
const privateKey = fs.readFileSync("./path-to-private-key.xml"); // or path to your kuda kuda private key
const clientKey = "name-of-private-key-file"; // name of private key file without the .xml suffix (extension)

const kuda = Kuda("./index")({
  publicKey,
  privateKey,
  clientKey
}); // this initialize the Kuda function

Making a request

kuda({
  serviceType: "SERVICE_TYPE",
  requestRef: "requestReference",
  data: {
    param: value
  }
});

Sample request

// account creation
const shortid = require("shortid"); // this libarary will generate random id for you. You can install with `yarn add shortid` or `npm i shortid`. You can use any other random key generatring library of your choice

kuda(
  {
    serviceType: "CREATE_VIRTUAL_ACCOUNT",
    requestRef: Math.floor(Math.random() * 1000000000000 + 1), // you can generate your random number your own way. This is just an example.
    data: {
      email: "ajala@obi.com",
      phoneNumber: "08012345678",
      firstName: "Ajala",
      lastName: "Obi",
      trackingReference: "vAcc-" + shortid.generate() // you can generate your trackingReference some other way you choose.
    }
  },
  data => {
    // data => decrypted response from Kuda API
    // do anything with your data
    console.log(JSON.stringify(data, null, 2));
  }
);

// it can also be called with in an async await fashion like so
const onboardUser = async(email, phoneNumber, firstName, lastName, trackingReference) => {
  const response = await kuda({
    serviceType: 'CREATE_VIRTUAL_ACCOUNT',
    requestRef: Number, // like Math.floor(Math.random() * 1000000000000 + 1)
    data: { email, phoneNumber, firstName, lastName, trackingReference }
  })
}

Refer to documentation for respective data types for each fields in the payload

Contribution & Issues

  • Simply fork the repo, make changes and make a pull request
  • You can open an issue for support or suggestions

Authors

Acknowledgements

  • Kuda Bank Team
  • Ebidhaa Services Tech Team
1.0.0

2 years ago