1.0.3 • Published 4 years ago

mpesa-package v1.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

MPESA PACKAGE - NODE.JS

Instantiate

Instantiate the payment package with default setting from daraja

  const Payment = require('payment')
  const payment = new Payment({
    consumerKey: '<Get from daraja api>',
    consumerSecret: '<Get from daraja api>',
    businessShortCode: '174379', // From daraja api for testing
    passKey: 'bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919' // Also from daraja api ,
    uri: 'https://sandbox.safaricom.co.ke' 
  })

Authentication

  • After instantiating, the next step should be to set authentication
  payment.setAuthentication()
  • The above sets you a token, payment.token that will be used for authenticating mpesa api requests going forward

Stk

  • Processes stk push for a transaction
  • We'll still be using the created payment object above
  • processStk function params
FieldRequiredDescription
amounttrueAmount to be paid
phoneNumbertruePhone number of paying user
callbackUrltrueCallback url on success or failure
accountReferencetrueAccount reference for payment
transactionDescriptiontrueTransaction description

processStk function

await payment.setAuthentication()
await payment.processStk({
  amount,
  phoneNumber,
  callbackUrl,
  accountReference,
  transactionDescription
})

Stk callback

  • Once an stk push has been processed, then mpesa api will need a way to inform your application that your payment has been processed or rejected
  • To do this, set up webhooks on your app that will receive this information
1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago