diff --git a/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/AssetsManager.swift b/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/AssetsManager.swift index 961d6eada6..9de525ae70 100644 --- a/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/AssetsManager.swift +++ b/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/AssetsManager.swift @@ -18,6 +18,11 @@ extension PrimerHeadlessUniversalCheckout { return UIImage(named: "\(cardNetwork.rawValue)-logo-colored", in: Bundle.primerResources, compatibleWith: nil) } + public static func getCardNetworkAsset(cardNetworkString: String?) -> PrimerCardNetworkAsset? { + guard let cardNetworkString else { return nil } + return Self.getCardNetworkAsset(for: CardNetwork(cardNetworkStr: cardNetworkString)) + } + public static func getCardNetworkAsset(for cardNetwork: CardNetwork) -> PrimerCardNetworkAsset? { let assetName = "\(cardNetwork.assetName.lowercased())-card-icon-colored" diff --git a/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/VaultManager.swift b/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/VaultManager.swift index fdb0ac7663..bfd602a91d 100644 --- a/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/VaultManager.swift +++ b/Sources/PrimerSDK/Classes/Core/PrimerHeadlessUniversalCheckout/Managers/VaultManager.swift @@ -510,11 +510,11 @@ extension PrimerHeadlessUniversalCheckout { if decodedJWTToken.intent?.contains("STRIPE_ACH") == true { if let sdkCompleteUrlString = decodedJWTToken.sdkCompleteUrl, let sdkCompleteUrl = URL(string: sdkCompleteUrlString) { - + DispatchQueue.main.async { PrimerUIManager.primerRootViewController?.enableUserInteraction(true) } - + firstly { sendAdditionalInfoEvent() } @@ -530,7 +530,7 @@ extension PrimerHeadlessUniversalCheckout { .catch { err in seal.reject(err) } - + } else { let err = PrimerError.invalidClientToken(userInfo: .errorUserInfoDictionary(), diagnosticsId: UUID().uuidString) @@ -813,7 +813,7 @@ extension PrimerHeadlessUniversalCheckout { } } } - + /** * Completes a payment using the provided JWT token and URL. * @@ -832,7 +832,7 @@ extension PrimerHeadlessUniversalCheckout { let apiClient: PrimerAPIClientAchProtocol = PrimerAPIConfigurationModule.apiClient ?? PrimerAPIClient() let timeZone = TimeZone(abbreviation: "UTC") let timeStamp = Date().toString(timeZone: timeZone) - + let body = Request.Body.Payment.Complete(mandateSignatureTimestamp: timeStamp) apiClient.completePayment(clientToken: clientToken, url: completeUrl, paymentRequest: body) { result in switch result { @@ -844,7 +844,7 @@ extension PrimerHeadlessUniversalCheckout { } } } - + /** * Sends additional information via delegate `PrimerHeadlessUniversalCheckoutDelegate` if implemented in the headless checkout context. * @@ -862,10 +862,10 @@ extension PrimerHeadlessUniversalCheckout { seal.fulfill() return } - + let delegate = PrimerHeadlessUniversalCheckout.current.delegate let isAdditionalInfoImplemented = delegate?.primerHeadlessUniversalCheckoutDidReceiveAdditionalInfo != nil - + guard isAdditionalInfoImplemented else { let logMessage = """ @@ -874,23 +874,23 @@ extension PrimerHeadlessUniversalCheckout { """ logger.warn(message: logMessage) - let message = "Couldn't continue as due to unimplemented delegate method `primerHeadlessUniversalCheckoutDidReceiveAdditionalInfo`" + let message = "Couldn't continue due to unimplemented delegate method `primerHeadlessUniversalCheckoutDidReceiveAdditionalInfo`" let error = PrimerError.unableToPresentPaymentMethod(paymentMethodType: self.paymentMethodType, userInfo: .errorUserInfoDictionary(additionalInfo: [ "message": message ]), diagnosticsId: UUID().uuidString) - + seal.reject(error) return } - + let additionalInfo = ACHMandateAdditionalInfo() PrimerDelegateProxy.primerDidReceiveAdditionalInfo(additionalInfo) seal.fulfill() } } - + /** * Waits for a response from the ACHMandateDelegate method. * The response is returned in stripeMandateCompletion handler. @@ -914,7 +914,7 @@ extension PrimerHeadlessUniversalCheckout.VaultManager: ACHMandateDelegate { public func acceptMandate() { achMandateCompletion?(.success(())) } - + public func declineMandate() { let error = ACHHelpers.getCancelledError(paymentMethodType: paymentMethodType) achMandateCompletion?(.failure(error)) @@ -953,7 +953,7 @@ extension PrimerHeadlessUniversalCheckout { public let paymentInstrumentData: Response.Body.Tokenization.PaymentInstrumentData public let analyticsId: String - init( + public init( id: String, paymentMethodType: String, paymentInstrumentType: PaymentInstrumentType, diff --git a/Tests/Primer/Assets/AssetsManagerTests.swift b/Tests/Primer/Assets/AssetsManagerTests.swift index 6c3592cb0e..656da5b42e 100644 --- a/Tests/Primer/Assets/AssetsManagerTests.swift +++ b/Tests/Primer/Assets/AssetsManagerTests.swift @@ -22,6 +22,7 @@ final class AssetsManagerTests: XCTestCase { } func testCardAssets() throws { + XCTAssertNotNil(AssetsManager.getCardNetworkAsset(for: .cartesBancaires)?.cardImage) XCTAssertNotNil(AssetsManager.getCardNetworkAsset(for: .discover)?.cardImage) XCTAssertNotNil(AssetsManager.getCardNetworkAsset(for: .masterCard)?.cardImage) @@ -33,6 +34,17 @@ final class AssetsManagerTests: XCTestCase { XCTAssertNotNil(AssetsManager.getCardNetworkAsset(for: .maestro)?.cardImage) XCTAssertNotNil(AssetsManager.getCardNetworkAsset(for: .mir)?.cardImage) XCTAssertNotNil(AssetsManager.getCardNetworkAsset(for: .unknown)?.cardImage) + } + func testGetNetworkAssetForString() throws { + XCTAssertEqual(AssetsManager.getCardNetworkAsset(cardNetworkString: "VISA")?.cardNetwork, .visa) + XCTAssertNotNil(AssetsManager.getCardNetworkAsset(cardNetworkString: "VISA")?.cardImage) + + XCTAssertEqual(AssetsManager.getCardNetworkAsset(cardNetworkString: "MASTERCARD")?.cardNetwork, .masterCard) + XCTAssertNotNil(AssetsManager.getCardNetworkAsset(cardNetworkString: "MASTERCARD")?.cardImage) + + XCTAssertEqual(AssetsManager.getCardNetworkAsset(cardNetworkString: "CARTES_BANCAIRES")?.cardNetwork, .cartesBancaires) + XCTAssertNotNil(AssetsManager.getCardNetworkAsset(cardNetworkString: "CARTES_BANCAIRES")?.cardImage) + } }