pam-api-docs

Create and power your business with PAM API's.

View the Project on GitHub SHIFTECH-AFRICA/pam-api-docs

PAM API DOCS

How To Get Started

Generating Access Token GET

  https://pam.api.easyncpay.com/api/v1/token
var request = require('request');
var options = {
   'method': 'GET',
   'url': 'https://pam.api.easyncpay.com/api/v1/token',
   'headers': {
       'Content-Type': 'application/json',
       'Accept': 'application/json',
       'Authorization': 'Basic ACCOUNT_API_TOKEN'
             }
       };
request(options, function (error, response) {
if (error) throw new Error(error);
   console.log(response.body);
});

Expected response:

{
    "data": {
        "Token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvcGFtLmFwaS5lYXN5bmNwYXkuY29tXC9hcGlcL3YxXC90b2tlbiIsImlhdCI6MTYxNDU5NTI4MywiZXhwIjoxNjE0NTk4ODgzLCJuYmYiOjE2MTQ1OTUyODMsImp0aSI6IkYzVmpQNDJQb1ZjU0YycjIiLCJzdWIiOiI4OTczODllMy01ZjdjLTRhYjAtYjI2OS01YjFmNmI3NTM2NGEiLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.KWJbcAoIW6yF0IgCaylv7EqotDZnkXt5MvmuEZrjNbA",
        "TokenType": "Bearer",
        "Expires": 3600
    },
    "success": true
}

listing your linked Paybill/Till numbers GET

   https://pam.api.easyncpay.com/api/v1/shortcode
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://pam.api.easyncpay.com/api/v1/shortcode',
  'headers': {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

Listing all your apps Get

   https://pam.api.easyncpay.com/api/v1/app
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://pam.api.easyncpay.com/api/v1/app',
  'headers': {
    'Accept': 'application/json'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

Listing all your latest transaction Get

    https://pam.api.easyncpay.com/api/v1/pay-loads
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://pam.api.easyncpay.com/api/v1/pay-loads',
  'headers': {
    'Accept': 'application/json'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

Validating Paybill/Till Number

Provide all the valid information to check if the paybill/till number credentials are valid.

POST

  https://pam.api.easyncpay.com/api/v1/m-pesa/shortcode validate

Params

var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://pam.api.easyncpay.com/api/v1/m-pesa/shortcode/validate',
  'headers': {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({"ConsumerKey":"","ConsumerSecret":"","Environment":"sandbox/production"})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

expected response if the Paybill/Till Number credentials are valid

{
    "data": {
        "Message": "The m-pesa app keys are valid."
    },
    "success": true
}

Register C2B callback POST

  https://pam.api.easyncpay.com/api/v1/m-pesa/c2b/register-url

var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://pam.api.easyncpay.com/api/v1/m-pesa/c2b/register-url',
  'headers': {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  body: JSON.stringify({"Secret":""})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

expected response

{
    "data": {
        "Message": "Validation and Confirmation URLs are already registered"
    },
    "success": true
}

STK PUSH

This section shows how to make stk push and callback data for both stk-push and lipa na mpesa.

https://pam.api.easyncpay.com/api/v1/m-pesa/c2b/stk-push

var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://pam.api.easyncpay.com/api/v1/m-pesa/c2b/stk-push',
  'headers': {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({"CallingCode":"254","Secret":"","PhoneNumber":"","Amount":"1","ResultUrl":"","Description":"Testing the PAM API","TransactionType":"CustomerPayBillOnline/CustomerBuyGoodsOnline"})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

STK paid expected response


"data": {
      "Success": true,
      "Description": "Transaction description.",
      "ReferenceNumber": "2BONOSBBTN",
      "PhoneNumber": "254XXXXXXXXX",
      "MpesaReceiptNumber": "PBO2ZOBY44",
      "Amount": 20000
}

Expected response for a paid C2B

"data": {
        "Success": true,
        "Description": "Transaction description.",
        "ReferenceNumber": "2BONOSBBTN",
        "PhoneNumber": "254XXXXXXXXX",
        "MpesaReceiptNumber": "PBO2ZOBY44",
        "Amount": 20000,
        'TransactionType': 'Pay Bill'
        'OrgAccountBalance': 50000
}

Expected response for a not paid STK

"data": {
        "Success": false,
        "Description": "Request cancelled by user",
        "ReferenceNumber": "2BOXRDNMLU",
        "PhoneNumber": "254XXXXXXXXX"
}

confirming stk paymentPOST

  https://pam.api.easyncpay.com/api/v1/m-pesa/c2b/confirm-stk-payment

var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://pam.api.easyncpay.com/api/v1/m-pesa/c2b/confirm-stk-payment',
  'headers': {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  body: JSON.stringify({"Secret":"", "ReferenceNumber":"", "ResultUrl":"",})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

Expected response if the payment has been done


"data": {
      "Success": true,
      "Description": "Transaction description.",
      "ReferenceNumber": "2BONOSBBTN",
      "PhoneNumber": "254XXXXXXXXX",
      "MpesaReceiptNumber": "PBO2ZOBY44",
      "Amount": 20000
}

Expected response if the payment has not been done

"data": {
        "Success": false,
        "Description": "Request cancelled by user",
        "ReferenceNumber": "2BOXRDNMLU",
        "PhoneNumber": "254XXXXXXXXX"
}

B2C ( business to customer )POST

This is where all the bulk payments are made.

https://pam.api.easyncpay.com/api/v1/m-pesa/b2c
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://pam.api.easyncpay.com/api/v1/m-pesa/b2c',
  'headers': {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  body: JSON.stringify({"CallingCode":"254","Secret":"","PhoneNumber":"","Amount":"10","ResultUrl":"","Description":"Testing the PAM API","TransactionType":"BusinessPayment/SalaryPayment/PromotionPayment"})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

Response for payment recieved through B2C


"data": {
       'Success' => true,
       'Description' => 'Salary payment',
       'ReferenceNumber' => '2BO6BCTLYF',
       'PhoneNumber' => '254XXXXXXXXX',
       'MpesaReceiptNumber' => 'PBO2ZOBY44',
       'Amount' => 50000,
       'B2CUtilityAccountAvailableFunds' => 70000,
       'B2CWorkingAccountAvailableFunds' => 70000,
       'B2CChargesPaidAccountAvailableFunds' => 70000
    }

payment not received from B2C

"data": {
       "Success": false,
        "Description": "The initiator information is invalid.",
        "ReferenceNumber": "2BO6BCTLYF",
        "PhoneNumber": "254XXXXXXXXX"
}

confirming B2C payment

confirming stk paymentPOST

  https://pam.api.easyncpay.com/api/v1/m-pesa/b2c/confirm-withdraw

var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://pam.api.easyncpay.com/api/v1/m-pesa/b2c/confirm-withdraw',
  'headers': {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  body: JSON.stringify({"Secret":"", "ReferenceNumber":"", "ResultUrl":"",})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

Expected response if the payment has been made


"data": {
       'Success' => true,
       'Description' => 'Salary payment',
       'ReferenceNumber' => '2BO6BCTLYF',
       'PhoneNumber' => '254XXXXXXXXX',
       'MpesaReceiptNumber' => 'PBO2ZOBY44',
       'Amount' => 50000,
       'B2CUtilityAccountAvailableFunds' => 70000,
       'B2CWorkingAccountAvailableFunds' => 70000,
       'B2CChargesPaidAccountAvailableFunds' => 70000
    }
Expected response if the payment has not been made
"data": {
       "Success": false,
        "Description": "The initiator information is invalid.",
        "ReferenceNumber": "2BO6BCTLYF",
        "PhoneNumber": "254XXXXXXXXX"
}

API libraries

Having trouble with API integration?. Check out our libraries for a quick intergration, or contact support and we’ll help you sort it out.