Spektra Pay is the unofficial Javascript SDK for Spektra payment platform. It takes a Promise based or Async Await approach. Its been made to be very simple and easy to use.
- First head over to https://spektra.co to create an account. Submit all relevant documents to be able to go live.
- Head over to your dashboard and to the developers page. Generate new public and secret keys and or copy the existing ones over to your project.
- Install the SDK by typing
npm install @koficypher/spektra
- In your project create a
.env
file and place it in your project's base path. We have a sample.env.example
in this repo for you to take a look at. - In your
.env
file update thePUBLIC_KEY
ANDSECRET_KEY
accordingly - Do not forget to specify which environment you want to run in by also editing the
ENVIRONMENT
key in the.env
. If you specify to run a development as theENVIRONMENT
you must - Also not that if you specify development
ENVIRONMENT
key in your.env
file, kindly note that all request and transactions will be against a sandbox account. You can head over here to create a sandbox account, generate and copy the public and secret keys accordingly and paste them in your.env
file. - You are now ready to recieve payments.
Using this SDK is very simple. To get started you have to require and instantiate it like so:
const Spektra = require('@koficypher/spektra')
const Pay = new Spektra();
To request payment from a mobile number, you need to pass the ff parameters into an object:
let data = {
account: "254797123456",
spektraAccountName: "mysubaccount", //optional, used for subaccount-specific payments
amount: 1000
}
account
is the mobile number you want to request payment from. The number should always follow the MSIDN format. e.g. 254797123456spektraAccountName
is the an optional parameter which is used if you want to accept payments or request payments on behalf of a subaccount or business.amount
is the amount you wish to charge.
The next step is to call this method off this SDK's instance and pay the data object as a parameter. Console log the response to see the results.
Pay.receivePayment(data).then(resp => { console.log(resp) });
The Spektra API also allows you to transfer money from your Spektra account to any mobile money number directly. To do that, you will need to construct a data object and call another method off the SDK's instance.
const Spektra = require('@koficypher/spektra')
const Pay = new Spektra();
let data = {
account: "254797123456",
amount: 1000
}
Pay.payMobileNumber(data).then(resp => {
console.log(resp);
});
Mobile money merchants are not left out. With Spektra you can also pay directly to merchants using their till number.
const Spektra = require('@koficypher/spektra')
const Pay = new Spektra();
let data = {
account: "12458",
amount: 1000
}
Pay.payTillNumber(data).then(resp => {
console.log(resp);
});
In this example, account
is the till number.
You can also pay Banks directly from your Spektra account. You will need to add your bank details such as name of the account holder, bank name and branch.
const Spektra = require('@koficypher/spektra')
const Pay = new Spektra();
let data = {
account: "123456789012",
accountName: "John Doe",
bankName: "ABC Bank",
bankBranch: "Nairobi",
amount: 1000
}
Pay.payToBank(data).then(resp => {
console.log(resp);
});
Email me skcypher6@gmail.com
Email me skcypher6@gmail.com
Open an issue in this repo if you detect any bugs.