@paylend/mpesa
v1.0.8
Published
A simple wrapper for safaricom daraja api
Downloads
20
Readme
Installation
To install the package do this
const { Mpesa } = require('@paylend/mpesa')
Alternatively, you can require the package and initialize the default configurations as follows:
const { Mpesa } = require('@paylend/mpesa')({
baseUrl: 'https://sandbox.safaricom.co.ke',
consumerKey: process.env.consumerKey,
consumerSecret: process.env.consumerSecret
})
Generating An Oauth Token
To generate an oauth token do:
const { access_token: accessToken } = Mpesa.generateOauthToken()
B2B Payment Request
To make a b2b payment request
const response = Mpesa.b2bPaymentRequest({
initiator,
securityCredential,
commandID,
senderIdentifierType,
recieverIdentifierType,
amount,
partyA,
partyB,
accountReference,
remarks,
queueTimeOutURL,
resultURL
})
Transaction Reversal
To make a reversal
const response = Mpesa.reversal({
initiator,
securityCredential,
transactionID,
amount,
receiverParty,
resultURL,
queueTimeOutURL,
recieverIdentifierType,
remarks,
occasion = ''
})
Query A Transaction Status
Getting the status of a transaction
const response = Mpesa.transactionStatus({
initiator,
securityCredential,
transactionID,
partyA,
identifierType,
resultURL,
queueTimeOutURL,
remarks,
occasion
})
Simulate C2B Payment
Simulate a c2b payment
const response = Mpesa.simulateC2bPayment({
shortCode,
amount,
msisdn,
billRefNumber
})
Make an STK Push
Make an STK push to a customer's phone number
const response = Mpesa.stkPush({
businessShortCode,
password,
timestamp,
amount,
partyA,
partyB,
phoneNumber,
accountReference,
transactionDesc,
callbackUrl
})
Query an STK Push Status
Make an STK push to a customer's phone number
const response = Mpesa.stkPushStatus({
businessShortCode,
password,
timestamp,
checkoutRequestId
})
Account Balance
Query an account balance
const response = Mpesa.accountBalance({
initiator,
securityCredential,
partyA,
remarks,
queueTimeOutURL,
resultURL,
identifierType
})
Register C2B Confirmation URL
Register a c2b confirmation URL
const response = Mpesa.registerC2bConfirmationUrl({
shortCode,
responseType,
confirmationUrl,
validationUrl
})
B2C Payment Request
Make a business to customer payment request
const response = Mpesa.accountBalance({
initiatorName,
securityCredential,
commandID,
amount,
partyA,
partyB,
remarks,
queueTimeOutURL,
resultURL,
occasion
})