Transaction module - Interacts with the M-Pesa API by exposing c2b, query and reverse methods.
Throws errors if any of the methods receives incomplete or invalid parameters, including the class constructor
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
- Source:
'Missing or invalid configuration parameters' Error if options object is incomplete or invalid
Returns:
Transaction
- Type
- Class
Example
Transaction = require('mpesa-mz-nodejs-lib')
tx = new Transaction(options)
Members
(inner) _api_host :string
API Host - Required by the M-Pesa API
Type:
- string
- Source:
(inner) _api_key :string
API key - Required by the M-Pesa API
Type:
- string
- Source:
(inner) _initiator_identifier :string
Initiator Identifier - Required by the M-Pesa API
Type:
- string
- Source:
(inner) _origin :string
Origin - Required by the M-Pesa API
Type:
- string
- Source:
(inner) _public_key :string
Public key - Required by the M-Pesa API
Type:
- string
- Source:
(inner) _security_credential :string
Security Credential - Required by the M-Pesa API
Type:
- string
- Source:
(inner) _service_provider_code :number
Service Provider Code - Required by the M-Pesa API
Type:
- number
- Source:
(inner) _validMSISDN
MSISDN Validation
- Source:
(inner) validation_errors
Validation buffer
- Source:
Methods
(static) c2b(transaction_data) → {object}
Initiates a C2B (Client-to-Business) transaction on the M-Pesa API.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
transaction_data |
object |
Properties
|
- Source:
'Missing or invalid C2B parameters' Error if params are missing or invalid
Returns:
Promise
- Type
- object
Example
Transaction = require('mpesa-mz-nodejs-lib')
// Instantiate Transaction object with valid options params
tx = new Transaction(options)
tx.c2b({
amount: 1,
msisdn: '821234567'
reference: 'T001',
third_party_reference: '12345'
}).then(function(data){
console.log(data)
}).catch(function(error){
console.log(error)
})
(static) query(query_data) → {object}
Initiates a C2B (Client-to-Business) transaction Query on the M-Pesa API.
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
query_data |
object |
Properties
|
- Source:
'Missing or invalid Query parameters' Error is params are missing or invalid
Returns:
Promise
- Type
- object
Example
Transaction = require('mpesa-mz-nodejs-lib')
// Instantiate Transaction object with valid params
tx = new Transaction(options)
tx.query({
query_reference:'08y844du6gs',
third_party_reference:'12345'
}).then(function(data){
console.log(data)
}).catch(function(error){
console.log(error)
})
(static) reverse(transaction_data) → {object}
Initiates a C2B (Client-to-Business) transaction Reversal on the M-Pesa API
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
transaction_data |
object |
Properties
|
- Source:
'Missing or invalid Reversal parameters' Error if params are missing or invalid
Returns:
Promise
- Type
- object
Example
Transaction = require('mpesa-mz-nodejs-lib')
// Instantiate Transaction object with valid params
tx = new Transaction(options)
tx.reversal({
amount:1,
transaction_id: 'tvfs2503x1d'
third_party_reference:'12345'
}).then(function(data){
console.log(data)
}).catch(function(error){
console.log(error)
})
(inner) _getBearerToken() → {string}
Generates a Bearer Token
- Source:
'Missing or invalid configuration parameters' Error if _public_key or _api_key are missing or invalid from object instantiation
Returns:
bearer_token
- Type
- string
(inner) _isValidated(type, data) → {boolean}
Validates all configuration parameters
Parameters:
Name | Type | Description |
---|---|---|
type |
string | |
data |
object |
- Source:
Returns:
- Type
- boolean
(inner) _isValidMSISDN(msisdn) → {boolean}
Validates a customer's MSISDN (Phone number)
Parameters:
Name | Type | Description |
---|---|---|
msisdn |
string |
- Source:
Returns:
isValid
- Type
- boolean
(inner) _request_headers(_origin, _public_key, _api_key) → {object}
Holds the request headers for each API request
Parameters:
Name | Type | Description |
---|---|---|
_origin |
string | origin value from initialization |
_public_key |
string | public_key value from initialization |
_api_key |
string | api_key value from initialization |
- Source:
'Missing or invalid configuration parameters' Error if _api_key, _origin or _public_key are missing or invalid from object instantiation
Returns:
- Type
- object