Payment Requests
Introduction
Payment requests allow users to initiate transactions by sending money to recipients using various payment networks. This documentation provides details on how to make payment requests via HTTP POST requests and includes code examples in different programming languages.
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/v2/payments
Authorization
Users need to include basic authentication credentials in the request headers.
Request Body (Token Object)
The request body should include the necessary parameters for the transaction, such as the username, network code, amount, recipient's phone number, narration, currency, and callback URL.
{
"username": "johndoee",
"network_code": "57",
"amount": 100,
"phone_number": "0712345678",
"narration": "Payment for goods",
"currency": "KES",
"callback_url": "https://example.com/callback"
}
Code Examples
Below are code examples in different programming languages demonstrating how to send money to a mobile number using HTTP POST requests.
- Curl
- Go
- Nodejs
- Python
- PHP
curl --location -g 'https://api.mypayd.app/api/v2/payments' \
--data '{
"username": "johndoee",
"network_code": "57",
"amount": 100,
"phone_number": "0712345678",
"narration": "Payment for goods",
"currency": "KES",
"callback_url": "https://example.com/callback"
}
'
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.mypayd.app/api/v2/payments"
method := "POST"
payload := strings.NewReader(`{
"username": "johndoee",
"network_code": "57",
"amount": 100,
"phone_number": "0712345678",
"narration": "Payment for goods",
"currency": "KES",
"callback_url": "https://example.com/callback"
}
`)
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": "johndoee",\n "network_code": "57",\n "amount": 100,\n "phone_number": "0712345678",\n "narration": "Payment for goods",\n "currency": "KES",\n "callback_url": "https://example.com/callback"\n}\n';
var config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.mypayd.app/api/v2/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/v2/payments"
payload = "{\n \"username\": \"johndoee\",\n \"network_code\": \"57\",\n \"amount\": 100,\n \"phone_number\": \"0712345678\",\n \"narration\": \"Payment for goods\",\n \"currency\": \"KES\",\n \"callback_url\": \"https://example.com/callback\"\n}\n"
headers = {}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.mypayd.app/api/v2/payments');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setBody('{\n "username": "johndoee",\n "network_code": "57",\n "amount": 100,\n "phone_number": "0712345678",\n "narration": "Payment for goods",\n "currency": "KES",\n "callback_url": "https://example.com/callback"\n}\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();
}
Conclusion
Payment requests offer a seamless way for users to initiate transactions and send money securely to recipients through various payment networks. By following the instructions outlined in this documentation, users can easily integrate payment request functionality into their applications or services.