Skip to content

kudabank/openapi-node

Repository files navigation

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

run npm install kuda-node

Library setup

const fs = require("fs");
const Kuda = require('kuda-node'); 

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({
  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: "[email protected]",
      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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •