Skip to content

Commit

Permalink
Remove init for token
Browse files Browse the repository at this point in the history
  • Loading branch information
NQuinn27 committed Oct 24, 2024
1 parent 7b39edc commit b548715
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
137 changes: 7 additions & 130 deletions Tests/Primer/Assets/AssetsManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit b548715

Please sign in to comment.