Mobile Payments Requests
Introduction
The Mobile Payments API allows you to receive funds directly to a recipient's mobile wallet (e.g., M-PESA) through a single, unified endpoint.
Making Payment Requests
To make payment requests, users need to send an HTTP POST request to the specified endpoint with the required parameters.
Endpoint
https:api.mypayd.app//api/v3/payments
Authorization
Users need to include basic authentication credentials in the request headers.
Authorization: Basic <base64-encoded-username:password>
Content-Type: application/json
X-Payd-Merchant-ID: <your_merchant_id>
Request Body
This payload allows you to make mobile payments using the Payd API. The request body must include the following structure:
{
"username": "paydconsultant",
"network_code": "7ea6df5c-6bba-46b2-a7e6-f511959e7edb",
"account_name": "momo",
"account_number": "+254712434671",
"amount": 50,
"phone_number": "07712345671",
"channel_id": "7c7833d8-2f26-430e-8675-7ff07a5caf0c",
"narration": "Payment for goods",
"currency": "KES",
"callback_url": "https://payd-test.free.beeceptor.com",
"transaction_channel": "mobile"
}
Below are code examples in different programming languages demonstrating how to make card payments using HTTP POST requests.
- Curl
- Go
- Nodejs
- Python
- PHP
curl --location 'https:api.mypayd.app//api/v3/payments' \
--data-raw '{
"username": "paydconsultant",
"network_code": "7ea6df5c-6bba-46b2-a7e6-f511959e7edb",
"account_name": "momo",
"account_number": "+254712434671",
"amount": 50,
"phone_number": "07712345671",
"channel_id": "7c7833d8-2f26-430e-8675-7ff07a5caf0c",
"narration": "Payment for goods",
"currency": "KES",
"callback_url": "https://payd-test.free.beeceptor.com",
"transaction_channel": "mobile"
}`
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https:api.mypayd.app/api/v3/payments
"
method := "POST"
payload := strings.NewReader(`curl --location 'https:api.mypayd.app/api/v3/payments' \
--data-raw '{
"username": "paydconsultant",
"network_code": "7ea6df5c-6bba-46b2-a7e6-f511959e7edb",
"account_name": "momo",
"account_number": "+254712434671",
"amount": 50,
"phone_number": "07712345671",
"channel_id": "7c7833d8-2f26-430e-8675-7ff07a5caf0c",
"narration": "Payment for goods",
"currency": "KES",
"callback_url": "https://payd-test.free.beeceptor.com",
"transaction_channel": "mobile"
}'
)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
var axios = require('axios');
var data = "{\\n\\"username\\": \\"paydconsultant\\",\\n\\"network_code\\": \\"7ea6df5c-6bba-46b2-a7e6-f511959e7edb\\",\\n\\"account_name\\": \\"momo\\",\\n\\"account_number\\": \\"+254712434671\\",\\n\\"amount\\": 50,\\n\\"phone_number\\": \\"07712345671\\",\\n\\"channel_id\\": \\"7c7833d8-2f26-430e-8675-7ff07a5caf0c\\",\\n\\"narration\\": \\"Payment for goods\\",\\n\\"currency\\": \\"KES\\",\\n\\"callback_url\\": \\"https://payd-test.free.beeceptor.com\\",\\n\\"transaction_channel\\": \\"mobile\\"\\n}";
var config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https:api.mypayd.app/api/v3/payments',
headers: { },
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
url = "https:api.mypayd.app/api/v3/payments"
payload = "{\\n\\"username\\": \\"paydconsultant\\",\\n\\"network_code\\": \\"7ea6df5c-6bba-46b2-a7e6-f511959e7edb\\",\\n\\"account_name\\": \\"momo\\",\\n\\"account_number\\": \\"+254712434671\\",\\n\\"amount\\": 50,\\n\\"phone_number\\": \\"07712345671\\",\\n\\"channel_id\\": \\"7c7833d8-2f26-430e-8675-7ff07a5caf0c\\",\\n\\"narration\\": \\"Payment for goods\\",\\n\\"currency\\": \\"KES\\",\\n\\"callback_url\\": \\"https://payd-test.free.beeceptor.com\\",\\n\\"transaction_channel\\": \\"mobile\\"\\n}"
headers = {}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https:api.mypayd.app/api/v3/payments');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setBody("{\\n\\"username\\": \\"paydconsultant\\",\\n\\"network_code\\": \\"7ea6df5c-6bba-46b2-a7e6-f511959e7edb\\",\\n\\"account_name\\": \\"momo\\",\\n\\"account_number\\": \\"+254712434671\\",\\n\\"amount\\": 50,\\n\\"phone_number\\": \\"07712345671\\",\\n\\"channel_id\\": \\"7c7833d8-2f26-430e-8675-7ff07a5caf0c\\",\\n\\"narration\\": \\"Payment for goods\\",\\n\\"currency\\": \\"KES\\",\\n\\"callback_url\\": \\"https://payd-test.free.beeceptor.com\\",\\n\\"transaction_channel\\": \\"mobile\\"\\n}");
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
Example of a successful response
{
"status": "SUCCESS",
"transaction_reference": "VGC124302386eR",
"success": true,
"message": "Processed successfully",
"trackingId": "",
"reference": "",
"result": null
}
Conclusion
The Mobile Payments endpoint enables seamless and secure transactions through mobile channels such as M-PESA by using the unified v3/payments endpoint, all mobile payment flows—across providers and currencies—can be handled with a single API call.