diff --git a/Checkout/Source/Tokenisation/CheckoutAPIService.swift b/Checkout/Source/Tokenisation/CheckoutAPIService.swift index f8bfa4897..e955f0b0d 100644 --- a/Checkout/Source/Tokenisation/CheckoutAPIService.swift +++ b/Checkout/Source/Tokenisation/CheckoutAPIService.swift @@ -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: @@ -144,13 +144,15 @@ final public class CheckoutAPIService: CheckoutAPIProtocol { } } - private func createToken(requestParameters: NetworkManager.RequestParameters, completion: @escaping (Result) -> Void) { + private func createToken(requestParameters: NetworkManager.RequestParameters, + paymentType: TokenRequest.TokenType, + completion: @escaping (Result) -> 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): @@ -176,10 +178,12 @@ final public class CheckoutAPIService: CheckoutAPIProtocol { } } - private func logTokenResponse(tokenResponseResult: NetworkRequestResult, httpURLResponse: HTTPURLResponse?) { + private func logTokenResponse(tokenResponseResult: NetworkRequestResult, + 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, @@ -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, diff --git a/CheckoutTests/Tokenisation/CheckoutAPIServiceTests.swift b/CheckoutTests/Tokenisation/CheckoutAPIServiceTests.swift index e1d83a01e..24b593aab 100644 --- a/CheckoutTests/Tokenisation/CheckoutAPIServiceTests.swift +++ b/CheckoutTests/Tokenisation/CheckoutAPIServiceTests.swift @@ -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() @@ -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,