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 15, 2024
1 parent 78bce17 commit 4b4b03a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 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
4 changes: 2 additions & 2 deletions CheckoutTests/Tokenisation/CheckoutAPIServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ final class CheckoutAPIServiceTests: XCTestCase {
XCTAssertEqual(result, .failure(.couldNotBuildURLForRequest))
}

func test_createToken_failure_serverError() {
func test_createToken_failure_card_payment_serverError() {
let card = StubProvider.createCard()
let tokenRequest = StubProvider.createTokenRequest()
let requestParameters = StubProvider.createRequestParameters()
Expand All @@ -148,7 +148,7 @@ final class CheckoutAPIServiceTests: XCTestCase {
stubRequestExecutor.executeCalledWithCompletion?(.errorResponse(serverError), HTTPURLResponse())

XCTAssertEqual(StubLogManager.queueCalledWith.last, .tokenResponse(
.init(tokenType: nil, publicKey: "publicKey"),
.init(tokenType: .card, publicKey: "publicKey"),
.init(
tokenID: nil,
scheme: nil,
Expand Down

0 comments on commit 4b4b03a

Please sign in to comment.