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:
- amount: This field has a value of 10, which presumably represents the amount of money for the transaction.
- message: This field contains the message associated with the transaction, which is "Please send some money."
- callbackUrl: A string field for specifying the URL where a callback or response will be sent after the transaction is processed.
Sample for creating request with callback url
import requests
import json
# Define the API endpoint URL
url = "https://uat-businessapi.spenn.com/api/partner/transaction/request/create"
# Define the headers, including the Authorization header with your actual token
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer eyJhbG...NrEQ41w" # Replace with your actual token
}
# Define the request body as a Python dictionary
request_data = {
"amount": 10,
"message": "Please send some money",
"callbackUrl": "https://mycallbackrul/myurl" # Replace with your actual callback URL
}
# Convert the request data to JSON format
request_data_json = json.dumps(request_data)
# Make the POST request
response = requests.post(url, headers=headers, data=request_data_json)
# Check the response
if response.status_code == 200:
print("Request was successful. Response:")
print(response.json())
else:
print(f"Request failed with status code {response.status_code}.")
print("Response content:")
print(response.text)
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
public class APICallWithCallback {
public static void main(String[] args) {
// Define the API endpoint URL
String url = "https://uat-businessapi.spenn.com/api/partner/transaction/request/create";
// Define the request headers
String authorizationHeader = "Bearer eyJhbG...NrEQ41w"; // Replace with your actual token
String contentType = "application/json";
// Define the request body as a JSON string
String requestJson = "{\"amount\": 10, \"message\": \"Please send some money\", \"callbackUrl\": \"https://mycallbackrul/myurl\"}";
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
// Create the HTTP POST request
HttpPost request = new HttpPost(url);
// Set the request headers
request.addHeader("Content-Type", contentType);
request.addHeader("Authorization", authorizationHeader);
// Set the request body
request.setEntity(new StringEntity(requestJson));
// Execute the request
HttpResponse response = httpClient.execute(request);
// Check the response
if (response.getStatusLine().getStatusCode() == 200) {
System.out.println("Request was successful. Response:");
// Process and print the response here if needed
} else {
System.out.println("Request failed with status code " + response.getStatusLine().getStatusCode() + ".");
System.out.println("Response content:");
// Print the response content here if needed
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
// In a browser environment, you can directly use the fetch API.
// In a Node.js environment, you can use a library like node-fetch.
// Define the API endpoint URL
const url = "https://uat-businessapi.spenn.com/api/partner/transaction/request/create";
// Define the request headers
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer eyJhbG...NrEQ41w', // Replace with your actual token
};
// Define the request body as a JavaScript object
const requestData = {
amount: 10,
message: 'Please send some money',
callbackUrl: 'https://mycallbackrul/myurl', // Replace with your actual callback URL
};
// Make the POST request
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(requestData),
})
.then(response => {
if (response.status === 200) {
return response.json();
} else {
console.error(`Request failed with status code ${response.status}.`);
return response.text();
}
})
.then(data => {
console.log('Response:', data);
})
.catch(error => {
console.error('Error:', 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:
- RequestId: A unique identifier (UUID) representing the request.
- 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