RotsiDocs
  • 😃Welcome to ROTSI API Documentation
  • Reference
    • API Reference
      • STK Push
      • B2C Disbursements
      • Paybill
      • BuyGoods
      • Bank Payments
        • Bank Code List
      • Bulk SMS
      • Thank you Page
Powered by GitBook
On this page
  1. Reference
  2. API Reference

Paybill

This API enables you to pay bills directly from your business account to a pay bill number, or a paybill store. You can use this API to pay on behalf of a consumer/requester.

PreviousB2C DisbursementsNextBuyGoods

Last updated 1 year ago

Creating a Paybill Request.

For this to be successful, ensure that you have a minimum of 10 KSH in your account. Also ensure that the amount is equal or greater than 10 Kenyan Shillings.

Endpoint for the API request.

POST

Request Body

Name
Type
Description

username*

string

The username of the account, as per the Rotsi Dashboard.

amount*

Integer

The amount of the transaction

phone*

string

The phone number the payment is being performed on behalf of. Use the 254 format. Eg. 254722000000

recipientSC*

String

The Paybill of the recipient.

accountNumber*

String

The account Number of the paybill receiving the funds.

const axios = require('axios');

const data = {
  amount: 10,
  recipientSC: "000000",
  accountNumber: "353353",
  username: "username",
  phone: "254722000000"
};

const config = {
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'secret_key'
  }
};

axios.post('https://api.rotsi.co.ke/payments/paybill/v1', data, config)
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });
import requests

url = "https://api.rotsi.co.ke/payments/paybill/v1"
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'secret_key'
}
data = {
    "amount": 10,
    "recipientSC": "000000",
    "accountNumber": "353353",
    "username": "username",
    "phone": "254722000000"
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://api.rotsi.co.ke/paybill/v1")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request["Authorization"] = "secret_key"
request.body = JSON.dump({
  "amount" => 10,
  "recipientSC" => "000000",
  "accountNumber" => "353353",
  "username" => "username",
  "phone" => "254722000000"
})

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end

puts response.body
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class ApiRequest {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://api.rotsi.co.ke/payments/paybill/v1");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("Authorization", "secret_key");
            connection.setDoOutput(true);

            String jsonInputString = "{\"amount\": 10, \"recipientSC\": \"000000\", \"accountNumber\": \"353353\", \"username\": \"username\", \"phone\": \"254722000000\"}";
            
            try(OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);           
            }

            int code = connection.getResponseCode();
            System.out.println("Response Code: " + code);
            // Read response if needed

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
<?php

$url = "https://api.rotsi.co.ke/payments/paybill/v1";
$data = array(
    "amount" => 10,
    "recipientSC" => "000000",
    "accountNumber" => "353353",
    "username" => "username",
    "phone" => "254722000000"
);
$headers = array(
    'Content-Type: application/json',
    'Authorization: secret_key'
);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);

?>
curl -X POST \
  https://api.rotsi.co.ke/payments/paybill/v1 \
  -H 'Content-Type: application/json' \
  -H 'Authorization: secret_key' \
  -d '{
    "amount": 10,
    "recipientSC": "000000",
    "accountNumber":"353353",
    "username": "username",
    "phone":"254722000000"
}'
{
    "status": "Success",
    "Service": "RotsiPaybill",
    "RotsiAPITransactionId": PBP719hcbjh2,
    "CustomerMessage": "The request is being processed"
}
{ 
"status": "Failed",
"Service": "RotsiB2C",
"message": "Payment request cancelled by the user",
"RotsiAPITransactionId": PBP719hcbjh2,
}

If youre integrating for a client using his/her shortCode, this will require the Paybill product to be added to your shortCode. Consult with support@rotsi.co.ke, to confirm status of the product. However if youre testing as a demo client, the payment will go through as long as it is a valid paybill shortcode

https://api.rotsi.co.ke/payments/paybill/v1