Try It Out
Please set your authentication token in the sidebar to test this API.
Run Request
Code Samples
cURL
JavaScript
Node.js
Python
PHP
Java
Go
Ruby
C#
Swift
Kotlin
curl -X POST \
'https://upesipay.com/api/v2/payments' \
-H 'Authorization: Basic YOUR_AUTH_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"amount":100,"phone_number":"0787677677","channel_id":2133,"provider":"m-pesa","external_reference":"INV-009","customer_name":"John Doe","callback_url":""}'
const url = 'https://upesipay.com/api/v2/payments' ;
const options = {
method : 'POST' ,
headers : {
'Authorization' : 'Basic YOUR_AUTH_TOKEN' ,
'Content-Type' : 'application/json' ,
},
body : JSON . stringify ({
"amount" : 100 ,
"phone_number" : "0787677676" ,
"channel_id" : 133 ,
"provider" : "m-pesa" ,
"external_reference" : "INV-009" ,
"customer_name" : "John Doe" ,
"callback_url" : "https://example.com/callback.php"
})
};
fetch (url, options)
. then (response => response. json ())
. then (data => console . log (data))
. catch (error => console . error ( 'Error:' , error));
const axios = require ( 'axios' );
const config = {
method : 'POST' ,
url : 'https://upesipay.com/api/v2/payments' ,
headers : {
'Authorization' : 'Basic YOUR_AUTH_TOKEN' ,
'Content-Type' : 'application/json' ,
}
,
data : {
"amount" : 100 ,
"phone_number" : "0787677676" ,
"channel_id" : 133 ,
"provider" : "m-pesa" ,
"external_reference" : "INV-009" ,
"customer_name" : "John Doe" ,
"callback_url" : "https://example.com/callback.php"
}
};
axios (config)
. then ( function (response) {
console . log ( JSON . stringify (response.data));
})
. catch ( function (error) {
console . log (error);
});
import requests
import json
url = 'https://upesipay.com/api/v2/payments'
headers = {
'Authorization' : 'Basic YOUR_AUTH_TOKEN' ,
'Content-Type' : 'application/json' ,
}
payload = {
"amount" : 100 ,
"phone_number" : "0787677676" ,
"channel_id" : 133 ,
"provider" : "m-pesa" ,
"external_reference" : "INV-009" ,
"customer_name" : "John Doe" ,
"callback_url" : "https://example.com/callback.php"
}
response = requests.post(url, json=payload, headers=headers)
print (response.json())
<?php
$curl = curl_init ();
curl_setopt_array ($curl, array(
CURLOPT_URL => 'https://upesipay.com/api/v2/payments' ,
CURLOPT_RETURNTRANSFER => true ,
CURLOPT_ENCODING => '' ,
CURLOPT_MAXREDIRS => 10 ,
CURLOPT_TIMEOUT => 0 ,
CURLOPT_FOLLOWLOCATION => true ,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 ,
CURLOPT_CUSTOMREQUEST => 'POST' ,
CURLOPT_POSTFIELDS => '{
"amount" : 100 ,
"phone_number" : "0787677676" ,
"channel_id" : 133 ,
"provider" : "m-pesa" ,
"external_reference" : "INV-009" ,
"customer_name" : "John Doe" ,
"callback_url" : "https://example.com/callback.php"
}' ,
CURLOPT_HTTPHEADER => array(
'Authorization: Basic YOUR_AUTH_TOKEN' ,
'Content-Type: application/json' ,
),
));
$response = curl_exec ($curl);
curl_close ($curl);
echo $response;
?>
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
HttpClient client = HttpClient . newHttpClient ();
HttpRequest . Builder requestBuilder = HttpRequest . newBuilder ()
. uri ( URI . create ( "https://upesipay.com/api/v2/payments" ))
. post ( BodyPublishers . ofString ( "{\"amount\":100,\"phone_number\":\"0787677676\",\"channel_id\":133,\"provider\":\"m-pesa\",\"external_reference\":\"INV-009\",\"customer_name\":\"John Doe\",\"callback_url\":\"https://example.com/callback.php\"}" ));
requestBuilder.header( "Authorization" , "Basic YOUR_AUTH_TOKEN" );
requestBuilder.header( "Content-Type" , "application/json" );
HttpRequest request = requestBuilder.build();
try {
HttpResponse <String> response = client.send(request, BodyHandlers . ofString ());
System . out . println (response.body());
} catch (Exception e) {
e.printStackTrace();
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main () {
url := "https://upesipay.com/api/v2/payments"
payload := map[string]interface{}{
"amount" : 100 ,
"phone_number" : "0787677676" ,
"channel_id" : 133 ,
"provider" : "m-pesa" ,
"external_reference" : "INV-009" ,
"customer_name" : "John Doe" ,
"callback_url" : "https://example.com/callback.php" ,
}
jsonData , _ := json.Marshal(payload)
req , _ := http.NewRequest( "POST" , url, bytes.NewBuffer(jsonData))
req.Header.Set( "Authorization" , "Basic YOUR_AUTH_TOKEN" )
req.Header.Set( "Content-Type" , "application/json" )
client := &http.Client{}
resp , err := client.Do(req)
if err != nil {
panic (err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}
require 'net/http'
require 'json'
require 'uri'
uri = URI ( 'https://upesipay.com/api/v2/payments' )
http = Net :: HTTP . new (uri.host, uri.port)
http .use_ssl = true
request = Net :: HTTP :: Post . new (uri)
request[ 'Content-Type' ] = 'application/json'
request[ 'Authorization' ] = 'Basic YOUR_AUTH_TOKEN'
request.body = '{"amount":100,"phone_number":"0787677676","channel_id":133,"provider":"m-pesa","external_reference":"INV-009","customer_name":"John Doe","callback_url":"https://example.com/callback.php"}'
response = http.request(request)
puts JSON . parse (response.body)
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main ()
{
var client = new HttpClient ();
client.DefaultRequestHeaders.Add( "Content-Type" , "application/json" );
client.DefaultRequestHeaders.Add( "Authorization" , "Basic YOUR_AUTH_TOKEN" );
var request = new HttpRequestMessage ( HttpMethod . POST , "https://upesipay.com/api/v2/payments" );
var json = JsonSerializer . Serialize ( new {
amount = 100 ,
phone_number = "0787677676" ,
channel_id = 133 ,
provider = "m-pesa" ,
external_reference = "INV-009" ,
customer_name = "John Doe" ,
callback_url = "https://example.com/callback.php"
});
request.Content = new StringContent (json, Encoding . UTF8 , "application/json" );
var response = await client.SendAsync(request);
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
import Foundation
let url = URL (string: "https://upesipay.com/api/v2/payments" )!
var request = URLRequest (url: url)
request.httpMethod = "POST"
request.setValue( "application/json" , forHTTPHeaderField: "Content-Type" )
request.setValue( "Basic YOUR_AUTH_TOKEN" , forHTTPHeaderField: "Authorization" )
let body: [String: Any] = [
"amount" : 100 ,
"phone_number" : "0787677676" ,
"channel_id" : 133 ,
"provider" : "m-pesa" ,
"external_reference" : "INV-009" ,
"customer_name" : "John Doe" ,
"callback_url" : "https://example.com/callback.php"
]
request.httpBody = try ? JSONSerialization . data (withJSONObject: body)
let task = URLSession . shared . dataTask (with: request) { data, response, error in
if let data = data {
if let json = try ? JSONSerialization . jsonObject (with: data) {
print (json)
}
}
}
task.resume()
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.IOException
val client = OkHttpClient()
val json = """{"amount":100,"phone_number":"0787677676","channel_id":133,"provider":"m-pesa","external_reference":"INV-009","customer_name":"John Doe","callback_url":"https://example.com/callback.php"}"""
val mediaType = "application/json" . toMediaType ()
val body = json. toRequestBody (mediaType)
val request = Request.Builder()
. url ( "https://upesipay.com/api/v2/payments" )
. post (body)
. addHeader ( "Content-Type" , "application/json" )
. addHeader ( "Authorization" , "Basic YOUR_AUTH_TOKEN" )
. build ()
client.newCall(request).enqueue( object : Callback {
override fun onFailure (call: Call, e: IOException) {
e.printStackTrace()
}
override fun onResponse (call: Call, response: Response) {
println (response.body?. string ())
}
})