Paytalk is a finance management system, helping you with mobile money integrations (C2B, B2C & B2B). Paytalk enables your software (website, mobile app, desktop app etc) to communicate with Mpesa servers using our available API keys. API keys can be generated and managed in your Paytalk developer account https://developer.paytalk.co.ke/
Below are the documentations on how to use Paytalk Lipa Na Mpesa WooCommerce Extension. Kindly note that each release of this extension would have its own documentation, therefore, you should always take note of the version number.
Download Paytalk Lipa Na Mpesa Plugin
INSTALLATION
$environment = ( $yourTestVariable == "yes" ) ? 'TRUE' : 'FALSE';
// Decide which URL to post to
$environment_url = ( "FALSE" == $environment )
? 'https://developer.paytalk.co.ke/api/'
: 'https://developer.paytalk.co.ke/api/';
$payload = [
// Paytalk.co.ke Credentials and API Info
"trans_key" => "Your API transaction Key",
"api_user" => "Your API User Key",
"paytill" => "Your Paybill/Till number",
"x_version" => "1.5.0",
"x_amount" => "Total Amount Payable",
// Lipa Na Mpesa Information
"mpesa_code" => "Mpesa Trensaction ID",
"mpesa_phone" => "Phone number",
"x_type" => 'AUTH_CAPTURE',
"x_invoice_num" => "Your invoice/order number",
"x_test_request" => $environment,
"x_delim_char" => '|',
"x_encap_char" => '',
"x_delim_data" => "TRUE",
"x_relay_response" => "FALSE",
"x_method" => "mpesa",
"order_id" => "Get order id",
"x_customer_ip" => $_SERVER['REMOTE_ADDR']
];
$data = json_encode($payload);
$environment_url = "htts://developer.paytalk.co.ke/apis/";
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => $environment_url,
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data
);
curl_setopt_array($ch, $curlConfig);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
curl_close($ch);
api_user
trans_key
x_amount
mpesa_phone
mpesa_code
order_id
Important: You cannot run the sample requests in this guide as-is. Replace call-specific parameters such as API Keys and Paybill/Till Number with your own values.
PayTalk API calls return HTTP status codes. Some API calls also return JSON response bodies that include information about the resource including one or more contextual links. Use these links to request more information about and construct an API flow that is relative to a specific request.
In the responses, PayTalk returns one of the following responses:
Status | Description |
Empty - ""//Null response |
Unable to verify payment |
no_account "no_account" |
Unable to verify your API keys |
Numeric Value is_numeric() |
Payment made was below the expected amount |
no_trans "no_trans" |
Transaction ID/ Phone number error |
Success "Success" |
Payment verified |
For HTTP Request, do a POST to the following URL;
https://developer.paytalk.co.ke/apis/?api_user="YOUR_API_USERNAME"&trans_key="YOUR_API_TRANSACTION_KEY"&x_amount="CAPTURED_AMOUNT"&mpesa_phone="CUSTOMER_PHONE_NUMBER"&mpesa_code="TRANSACTION_ID&order_id="INVOICE/ORDER_NUMBER_ID"