Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Expose VaultedPaymentMethod initialiser #1032

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -530,7 +530,7 @@ extension PrimerHeadlessUniversalCheckout {
.catch { err in
seal.reject(err)
}

} else {
let err = PrimerError.invalidClientToken(userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
Expand Down Expand Up @@ -813,7 +813,7 @@ extension PrimerHeadlessUniversalCheckout {
}
}
}

/**
* Completes a payment using the provided JWT token and URL.
*
Expand All @@ -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 {
Expand All @@ -844,7 +844,7 @@ extension PrimerHeadlessUniversalCheckout {
}
}
}

/**
* Sends additional information via delegate `PrimerHeadlessUniversalCheckoutDelegate` if implemented in the headless checkout context.
*
Expand All @@ -862,10 +862,10 @@ extension PrimerHeadlessUniversalCheckout {
seal.fulfill()
return
}

let delegate = PrimerHeadlessUniversalCheckout.current.delegate
let isAdditionalInfoImplemented = delegate?.primerHeadlessUniversalCheckoutDidReceiveAdditionalInfo != nil

guard isAdditionalInfoImplemented else {
let logMessage =
"""
Expand All @@ -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.
Expand All @@ -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))
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions Tests/Primer/Assets/AssetsManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
Loading