I am new in using swift5. I am going to integrate Apple Pay with my app, however the datatask seems not working cannot see any log from the console. Can anyone tell me what I am done wrong? also how can I verify/ debug the request and response to the backend server.
struct IssuerRequest: Codable{
let certificates: [Data]
let nonce: Data
let nonceSignature: Data
}
struct IssuerResponse: Codable {
let activationData: Data
let ephemeralPublicKey: Data
let encryptedPassData: Data
}
func execute(request: IssuerRequest, cardNumber: String, onFinish:@escaping (IssuerResponse) -> ()){
guard let prefix = Bundle.infoPlistValue(forKey:"URL") as? String else { return }
let url = URL(string: prefix + "/get/applepay")!
var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = "POST"
do {
let jsonData = try JSONEncoder().encode(request)
urlRequest.httpBody = jsonData
print("req json data: (jsonData)")
}catch let jsonError{
print(jsonError)
}
var issuerResponse: IssuerResponse!
let dataTask = URLSession.shared.dataTask(with: urlRequest) { data, response, error in
if let error = error {
print("Error: (error)")
return
}
guard let data = data, let response = response as? HTTPURLResponse else{
print ("Error: No Response Object")
return
}
guard response.statusCode == 200 else {
print("Error: Server response status (response.statusCode)")
return
}
do {
let issuerResponse = try JSONDecoder().decode(IssuerResponse.self, from: data)
} catch let jsonError {
print(jsonError)
}
onFinish(issuerResponse)
}
dataTask.resume()
}
Hope I can debug the api call