Skip to content

Commit

Permalink
Send payment type in error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
okhan-okbay-cko committed Apr 12, 2024
1 parent 78bce17 commit cec9195
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Checkout/Source/Tokenisation/CheckoutAPIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ final public class CheckoutAPIService: CheckoutAPIProtocol {
tokenType: tokenRequest.type,
publicKey: publicKey
)))
createToken(requestParameters: requestParameters, completion: completion)
createToken(requestParameters: requestParameters, paymentType: tokenRequest.type, completion: completion)
case .failure(let error):
switch error {
case .baseURLCouldNotBeConvertedToComponents, .couldNotBuildURL:
Expand All @@ -144,13 +144,15 @@ final public class CheckoutAPIService: CheckoutAPIProtocol {
}
}

private func createToken(requestParameters: NetworkManager.RequestParameters, completion: @escaping (Result<TokenDetails, TokenisationError.TokenRequest>) -> Void) {
private func createToken(requestParameters: NetworkManager.RequestParameters,
paymentType: TokenRequest.TokenType,
completion: @escaping (Result<TokenDetails, TokenisationError.TokenRequest>) -> Void) {
requestExecutor.execute(
requestParameters,
responseType: TokenResponse.self,
responseErrorType: TokenisationError.ServerError.self
) { [weak self, tokenDetailsFactory, logManager, logTokenResponse] tokenResponseResult, httpURLResponse in
logTokenResponse(tokenResponseResult, httpURLResponse)
logTokenResponse(tokenResponseResult, paymentType, httpURLResponse)

switch tokenResponseResult {
case .response(let tokenResponse):
Expand All @@ -176,10 +178,12 @@ final public class CheckoutAPIService: CheckoutAPIProtocol {
}
}

private func logTokenResponse(tokenResponseResult: NetworkRequestResult<TokenResponse, TokenisationError.ServerError>, httpURLResponse: HTTPURLResponse?) {
private func logTokenResponse(tokenResponseResult: NetworkRequestResult<TokenResponse, TokenisationError.ServerError>,
paymentType: TokenRequest.TokenType,
httpURLResponse: HTTPURLResponse?) {
switch tokenResponseResult {
case .response(let tokenResponse):
let tokenRequestData = CheckoutLogEvent.TokenRequestData(tokenType: tokenResponse.type, publicKey: publicKey)
let tokenRequestData = CheckoutLogEvent.TokenRequestData(tokenType: paymentType, publicKey: publicKey)
let tokenResponseData = CheckoutLogEvent.TokenResponseData(
tokenID: tokenResponse.token,
scheme: tokenResponse.scheme,
Expand All @@ -189,7 +193,7 @@ final public class CheckoutAPIService: CheckoutAPIProtocol {

logManager.queue(event: .tokenResponse(tokenRequestData, tokenResponseData))
case .errorResponse(let errorResponse):
let tokenRequestData = CheckoutLogEvent.TokenRequestData(tokenType: nil, publicKey: publicKey)
let tokenRequestData = CheckoutLogEvent.TokenRequestData(tokenType: paymentType, publicKey: publicKey)
let tokenResponseData = CheckoutLogEvent.TokenResponseData(
tokenID: nil,
scheme: nil,
Expand Down

0 comments on commit cec9195

Please sign in to comment.