If you want to get notified when a request is approved or rejected by a user you can register a callback url for the request.
In this case SPENN System will initiate a call to the callback url when the user has approved or rejected the request.
Description
- Method: This is a POST request, indicating that data is being sent to the server.
- URL: The URL for this request is https://uat-businessapi.spenn.com/api/Partner/transaction/request
- HTTPS Version: The request is made using HTTPS.
Headers
- Content-Type: The Content-Type header is set to application/json, indicating that the request body contains JSON data.
- Authorization: The Authorization header is used with a bearer token for authentication. The actual token value should replace the placeholder Bearer eyJhbG...NrEQ41w.
Request Body
The request body is in JSON format and contains the following fields:
- phoneNumber: A string representing the phone number (SPENN Account) to which the transaction is being sent.
- amount: A numeric value indicating the amount of the transaction.
- message: A string field for including a message with the transaction.
- callbackUrl: A string field for specifying the URL where a callback or response will be sent after the transaction is processed.
- externalReference: A string field for an external reference associated with the transaction. This can be used as a reference to track the request later. This is an optional parameter.
Sample Request with Callback Url:
import requests
# Define the API endpoint URL
url = 'https://uat-businessapi.spenn.com/api/Partner/transaction/request'
# Define the request headers
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer eyJhbG...NrEQ41w' # Replace with your actual bearer token
}
# Define the request payload (request body) as a dictionary
payload = {
"phoneNumber": "+250783008884",
"amount": 10,
"message": "Please send some money",
"callbackUrl": "https://mycallbackrul/myurl",
"externalReference": "sasd23xfhaxfasdfa2342"
}
# Make the POST request
response = requests.post(url, headers=headers, json=payload)
# Check the response
if response.status_code == 200:
print("Success! Response:")
print(response.json())
else:
print(f"Request failed with status code {response.status_code}")
print(response.text)
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class ApiCallExample {
public static void main(String[] args) {
try {
// Define the API endpoint URL
String url = "https://uat-businessapi.spenn.com/api/Partner/transaction/request";
// Create a connection
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// Set the request method to POST
con.setRequestMethod("POST");
// Set request headers
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer eyJhbG...NrEQ41w"); // Replace with your actual bearer token
// Define the request payload as a JSON string
String payload = "{"
+ "\"phoneNumber\": \"+250783008884\","
+ "\"amount\": 10,"
+ "\"message\": \"Please send some money\","
+ "\"callbackUrl\":\"https://mycallbackrul/myurl\","
+ "\"externalReference\": \"sasd23xfhaxfasdfa2342\""
+ "}";
// Enable input/output streams
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(payload);
wr.flush();
wr.close();
// Get the response code
int responseCode = con.getResponseCode();
// Read the response
if (responseCode == 200) {
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("Success! Response:");
System.out.println(response.toString());
} else {
System.out.println("Request failed with status code " + responseCode);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
const fetch = require('node-fetch');
// Define the API endpoint URL
const url = 'https://uat-businessapi.spenn.com/api/Partner/transaction/request';
// Define the request headers
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer eyJhbG...NrEQ41w', // Replace with your actual bearer token
};
// Define the request payload as a JSON object
const payload = {
phoneNumber: '+250783008884',
amount: 10,
message: 'Please send some money',
callbackUrl:'https://mycallbackrul/myurl',
externalReference: 'sasd23xfhaxfasdfa2342',
};
// Make the POST request
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(payload),
})
.then((response) => response.json())
.then((data) => {
console.log('Success! Response:');
console.log(data);
})
.catch((error) => {
console.error('Request failed:', error);
});
Sample request that SPENN server will initiate towards the callback url:
The callback url should have the proper protocol (http / https) before the www. You should not trust the RequestStatus without verifying it. SPENN recommends that you call the SPENN server as described under “Check the status of a request” to be sure that the callback data is not spoofed.
Request Body
The request body contains data in JSON format with the following fields:
- RequestGuid: A unique identifier (UUID) representing the request.
- ExternalReference: A string field that may serve as a reference to an external system or process.
- RequestStatus: An integer field with a value of 2, which could represent a specific status code or state related to the request.
Status
The following status codes define the status of the transaction.
- 1 - Pending
- 2 - Approved
- 3 - Rejected
- 4 - Cancelled