import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)
let parameters = "{\r\n \"provider_name\": \"Vodacom\",\r\n \"provider_code\": \"MPESA\"\r\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shoket.co/v1/verify/OB3J177Lqnp6Rg6wHqr3q")!,timeoutInterval: Double.infinity)
request.addValue("Bearer sk_test_mfpgBhidcAlPYEWbYR", forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "GET"
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 GET request Shoket will return a JSON data with transaction data.
NOTICE: The returned transaction data does not mean that the transaction was made successfully, you have to verify that the status of the transaction is Success (this identifies that the transaction was completed). Please read down the table of Status and their meaning.