With Shoket, you can collect payments from customers using any of these payment methods: Mobile money, Card.
Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error.
You can generate an API key from your Dashboard at any time. Shoket private key can be obtained here.
Collect customer information
To make a transaction you will need to pass customer information such as (number used, amount, channel, email, customer name). The request must be made with Shoket private key which can be obtained here. Here are full list of parameters and their meaning.
Make a payment request
Here is an example of a POST request to charge a customer.
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'POST',
'hostname': 'api.shoket.co',
'path': '/v1/charge/',
'headers': {
'Authorization': 'Bearer sk_mpBicAlPYEWbYR',
'Content-Type': 'application/json'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = JSON.stringify({
"amount": "5000",
"customer_name": "John Doe",
"email": "john@user.com",
"number_used": "255612345678",
"channel": "Tigo"
});
req.write(postData);
req.end();
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)
let parameters = "{\r\n \"amount\": \"5000\",\r\n \"customer_name\": \"John Doe\",\r\n \"email\": \"john@user.com\",\r\n \"number_used\": \"255612345678\",\r\n \"channel\": \"Tigo\"\r\n }"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shoket.co/v1/charge/")!,timeoutInterval: Double.infinity)
request.addValue("Bearer sk_mpBicAlPYE", forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()
After making a POST request Shoket will return a JSON data with transaction data. Also this request will pop up a USSD push to the customer's phone number which you provided
NOTICE: The returned transaction data does not mean that the transaction was made successfully, you have to verify that the status of transaction is Success(this identifies that the transaction was completed). Please read down the table of Status and their meaning.