Create merchant or 'link'


Create merchant or 'link'

In some instances, your platform might require merchants to self on board and use their preferred mode of payment. In this case, each merchant is required to have their dedicated tinypesa short link and API key to initialize STK requests as shown above.

Method Endpoint
POST https://tinypesa.com/api/v1/express/create_link

A request to create a link has the following expected parameters.

NOTE: The APIKEY used in the following request is the master account API key that can be found in the developer's section

Headers

Header Description Value
Accept The Accept request HTTP header advertises which content types, expressed as MIME types, the client can understand. application/json

| |Apikey|Unique API key obtained from your admin link. |Dfw3sdfx234F|

Parameters

The body required to initialize an STK transaction is the target phone number and amount as shown below. In a successful response, the request_id is given for reference in the webhook as the TinyPesaID.

Parameter Description Sample value
name Merchant or link name Juicy caffe
description [Optional] a short merchant description Order smoothies near you
link_mode The payment mode preferred by the merchant
  1. TILL NUMBER
  2. PAYBILL NUMBER
  3. BANK
1 or 2 or 3
short_code The paybill or till number the merchant uses. Required if the link mode is 1 or 2 123456
account_number [Optional] Required if a short code was specified sales
bank [Optional] Required if the link mode is bank uuid from banks list
bank_acc_no [Optional] Required if the link mode is bank. This is the bank account number the merchant holds under selected bank above 011312546400
call_back_url [Optional] Link called after every tinypesa transaction https://IP or https://domain

Responses

Sample success response

{
    "name": "sample link",
    "payment_mode": "BANK",
    "short_code": null,
    "account_number": "345235623532",
    "api_key": "7dme5tvNFPi",
    "bank_id": "bd01f820-7f2e-11eb-84bc-99d41292b108"
}

Examples

Curl

    curl -X POST \
        https://tinypesa.com/api/v1/express/create_link \
        -H "Content-Type: application/x-www-form-urlencoded" \
        -H "ApiKey: erwyuweoyf" \
        -d 'name=Juicy caffe&description=Order smoothies near you&link_mode=1 or 2 or 3&short_code=123456&account_number=sales&bank=uuid&bank_acc_no=011342436400&call_back_url=https://ip or https://domain'

Golang

    const base_url = "https://tinypesa.com/api/v1/"

    func createMerchant(){

        formData := url.Values{
            "name": {"Juicy caffe"}, "description": {"Order smoothies near you"},...
        }

        client := &http.Client{}
        req, err := http.NewRequest("POST", base_url+"express/create_link", strings.NewReader(formData.Encode()))
        if err != nil {
            panic(err.Error())
        }

        req.Header.Add("Accept", "application/json")
        req.Header.Add("Apikey", "Dfw3sdfx234F")
        response, err := client.Do(req)
        if(err!=nil){
            panic(err.Error())
        }

        /*
        From the response retrieve the access token and use it in the valuations request
         */
    }

Php 7.0+

    <?php

    $url="http://www.tinypesa.com/api/v1/express/create_link";
    $data = array(
        'name' => "Juicy caffe",
        'description' => 'Order smoothies near you',
        'link_mode'=>'1'
        'short_code'=>'1234561'
        'account_number'=>'sales'
        'bank'=>'uuid'
        'bank_acc_no'=>'011342436400'
        'call_back_url'=>'https://ip or https://domain'
    );
    $headers = array(
       "Content-Type: application/x-www-form-urlencoded",
       "ApiKey: erwyuweoyf"
    );
    $options = array(
        'http' => array(
            'header'  => $headers,
            'method'  => 'POST',
            'content' => http_build_query($data)
        )
    );

    $context  = stream_context_create($options);
    $resp = file_get_contents($url, false, $context);
    var_dump($resp);

    ?>

Js - using fetch

var url = "https://tinypesa.com/api/v1/express/create_link";

fetch(url, {
    body: "name=Juicy caffe&description=Order smoothies near you&link_mode=1 or 2 or 3&short_code=123456&account_number=sales&bank=uuid&bank_acc_no=011342436400&call_back_url=https://ip or https://domain",
    headers: {
        Apikey: "erwyuweoyf",
        "Content-Type": "application/x-www-form-urlencoded",
    },
    method: "POST",
});