From b548715a1716b437773f56797534cf25a09861ab Mon Sep 17 00:00:00 2001 From: Niall Quinn Date: Thu, 24 Oct 2024 07:32:57 +0200 Subject: [PATCH] Remove init for token --- .../Managers/AssetsManager.swift | 12 -- Tests/Primer/Assets/AssetsManagerTests.swift | 137 +----------------- 2 files changed, 7 insertions(+), 142 deletions(-) diff --git a/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/AssetsManager.swift b/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/AssetsManager.swift index b318e9bd3..9de525ae7 100644 --- a/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/AssetsManager.swift +++ b/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/AssetsManager.swift @@ -18,18 +18,6 @@ extension PrimerHeadlessUniversalCheckout { return UIImage(named: "\(cardNetwork.rawValue)-logo-colored", in: Bundle.primerResources, compatibleWith: nil) } - public static func getCardNetworkAsset(tokenData: Response.Body.Tokenization.PaymentInstrumentData) -> PrimerCardNetworkAsset? { - if let network = tokenData.network { - return Self.getCardNetworkAsset(cardNetworkString: network) - } else if let binNetwork = tokenData.binData?.network { - return Self.getCardNetworkAsset(cardNetworkString: binNetwork) - } else if let firstSix = tokenData.first6Digits { - return Self.getCardNetworkAsset(for: CardNetwork(cardNumber: firstSix)) - } else { - return Self.getCardNetworkAsset(for: .unknown) - } - } - public static func getCardNetworkAsset(cardNetworkString: String?) -> PrimerCardNetworkAsset? { guard let cardNetworkString else { return nil } return Self.getCardNetworkAsset(for: CardNetwork(cardNetworkStr: cardNetworkString)) diff --git a/Tests/Primer/Assets/AssetsManagerTests.swift b/Tests/Primer/Assets/AssetsManagerTests.swift index 6fd379169..656da5b42 100644 --- a/Tests/Primer/Assets/AssetsManagerTests.swift +++ b/Tests/Primer/Assets/AssetsManagerTests.swift @@ -37,137 +37,14 @@ final class AssetsManagerTests: XCTestCase { } - func testGetNetworkAssetForTokenData() throws { - XCTAssertEqual(AssetsManager.getCardNetworkAsset(tokenData: .visaNetworkToken)?.cardNetwork, .visa) - XCTAssertNotNil(AssetsManager.getCardNetworkAsset(tokenData: .visaNetworkToken)?.cardImage) + func testGetNetworkAssetForString() throws { + XCTAssertEqual(AssetsManager.getCardNetworkAsset(cardNetworkString: "VISA")?.cardNetwork, .visa) + XCTAssertNotNil(AssetsManager.getCardNetworkAsset(cardNetworkString: "VISA")?.cardImage) - XCTAssertEqual(AssetsManager.getCardNetworkAsset(tokenData: .mcNetworkToken)?.cardNetwork, .masterCard) - XCTAssertNotNil(AssetsManager.getCardNetworkAsset(tokenData: .mcNetworkToken)?.cardImage) + XCTAssertEqual(AssetsManager.getCardNetworkAsset(cardNetworkString: "MASTERCARD")?.cardNetwork, .masterCard) + XCTAssertNotNil(AssetsManager.getCardNetworkAsset(cardNetworkString: "MASTERCARD")?.cardImage) - XCTAssertEqual(AssetsManager.getCardNetworkAsset(tokenData: .cbNetworkToken)?.cardNetwork, .cartesBancaires) - XCTAssertNotNil(AssetsManager.getCardNetworkAsset(tokenData: .cbNetworkToken)?.cardImage) - - XCTAssertEqual(AssetsManager.getCardNetworkAsset(tokenData: .visaBinNetworkToken)?.cardNetwork, .visa) - XCTAssertNotNil(AssetsManager.getCardNetworkAsset(tokenData: .visaBinNetworkToken)?.cardImage) - - XCTAssertEqual(AssetsManager.getCardNetworkAsset(tokenData: .visafirstSixToken)?.cardNetwork, .visa) - XCTAssertNotNil(AssetsManager.getCardNetworkAsset(tokenData: .visafirstSixToken)?.cardImage) + XCTAssertEqual(AssetsManager.getCardNetworkAsset(cardNetworkString: "CARTES_BANCAIRES")?.cardNetwork, .cartesBancaires) + XCTAssertNotNil(AssetsManager.getCardNetworkAsset(cardNetworkString: "CARTES_BANCAIRES")?.cardImage) } } - -private extension Response.Body.Tokenization.PaymentInstrumentData { - static let visaNetworkToken = Self.init(paypalBillingAgreementId: nil, - first6Digits: nil, - last4Digits: nil, - expirationMonth: nil, - expirationYear: nil, - cardholderName: nil, - network: "VISA", - isNetworkTokenized: nil, - klarnaCustomerToken: nil, - sessionData: nil, - externalPayerInfo: nil, - shippingAddress: nil, - binData: nil, - threeDSecureAuthentication: nil, - gocardlessMandateId: nil, - authorizationToken: nil, - mx: nil, - currencyCode: nil, - productId: nil, - paymentMethodConfigId: nil, - paymentMethodType: "PAYMENT_CARD", - sessionInfo: nil) - - static let mcNetworkToken = Self.init(paypalBillingAgreementId: nil, - first6Digits: nil, - last4Digits: nil, - expirationMonth: nil, - expirationYear: nil, - cardholderName: nil, - network: "MASTERCARD", - isNetworkTokenized: nil, - klarnaCustomerToken: nil, - sessionData: nil, - externalPayerInfo: nil, - shippingAddress: nil, - binData: nil, - threeDSecureAuthentication: nil, - gocardlessMandateId: nil, - authorizationToken: nil, - mx: nil, - currencyCode: nil, - productId: nil, - paymentMethodConfigId: nil, - paymentMethodType: "PAYMENT_CARD", - sessionInfo: nil) - - static let cbNetworkToken = Self.init(paypalBillingAgreementId: nil, - first6Digits: nil, - last4Digits: nil, - expirationMonth: nil, - expirationYear: nil, - cardholderName: nil, - network: "CARTES_BANCAIRES", - isNetworkTokenized: nil, - klarnaCustomerToken: nil, - sessionData: nil, - externalPayerInfo: nil, - shippingAddress: nil, - binData: nil, - threeDSecureAuthentication: nil, - gocardlessMandateId: nil, - authorizationToken: nil, - mx: nil, - currencyCode: nil, - productId: nil, - paymentMethodConfigId: nil, - paymentMethodType: "PAYMENT_CARD", - sessionInfo: nil) - - static let visaBinNetworkToken = Self.init(paypalBillingAgreementId: nil, - first6Digits: nil, - last4Digits: nil, - expirationMonth: nil, - expirationYear: nil, - cardholderName: nil, - network: nil, - isNetworkTokenized: nil, - klarnaCustomerToken: nil, - sessionData: nil, - externalPayerInfo: nil, - shippingAddress: nil, - binData: BinData(network: "VISA"), - threeDSecureAuthentication: nil, - gocardlessMandateId: nil, - authorizationToken: nil, - mx: nil, - currencyCode: nil, - productId: nil, - paymentMethodConfigId: nil, - paymentMethodType: "PAYMENT_CARD", - sessionInfo: nil) - - static let visafirstSixToken = Self.init(paypalBillingAgreementId: nil, - first6Digits: "401288", - last4Digits: nil, - expirationMonth: nil, - expirationYear: nil, - cardholderName: nil, - network: nil, - isNetworkTokenized: nil, - klarnaCustomerToken: nil, - sessionData: nil, - externalPayerInfo: nil, - shippingAddress: nil, - binData: nil, - threeDSecureAuthentication: nil, - gocardlessMandateId: nil, - authorizationToken: nil, - mx: nil, - currencyCode: nil, - productId: nil, - paymentMethodConfigId: nil, - paymentMethodType: "PAYMENT_CARD", - sessionInfo: nil) -}