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

[size check] Delete unused code #2880

Closed
wants to merge 1 commit into from
Closed
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
32 changes: 32 additions & 0 deletions Stripe.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"pins" : [
{
"identity" : "ios-snapshot-test-case",
"kind" : "remoteSourceControl",
"location" : "https://github.com/uber/ios-snapshot-test-case",
"state" : {
"revision" : "7b10770333a961be6e5a41c9ce04b8c6d3990126",
"version" : "8.0.0"
}
},
{
"identity" : "ocmock",
"kind" : "remoteSourceControl",
"location" : "https://github.com/erikdoe/ocmock",
"state" : {
"branch" : "master",
"revision" : "05cbc9d934e84ad32530fa53fd7d29c7966d5828"
}
},
{
"identity" : "ohhttpstubs",
"kind" : "remoteSourceControl",
"location" : "https://github.com/eurias-stripe/OHHTTPStubs",
"state" : {
"branch" : "master",
"revision" : "94cf8e1d9e38b0edd580ddc699dda23a7bf66515"
}
}
],
"version" : 2
}
16 changes: 16 additions & 0 deletions Stripe/StripeiOSTests/LinkInMemoryCookieStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,19 @@ extension LinkInMemoryCookieStoreTests {
}

}

final class LinkInMemoryCookieStore: LinkCookieStore {
private var data: [LinkCookieKey: String] = [:]

func write(key: LinkCookieKey, value: String, allowSync: Bool) {
data[key] = value
}

func read(key: LinkCookieKey) -> String? {
return data[key]
}

func delete(key: LinkCookieKey) {
data.removeValue(forKey: key)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ extension String.Localized {
)
}

static var pay_another_way: String {
STPLocalizedString(
"Pay another way",
"Label of a button that when tapped allows the user to select a different form of payment."
)
}

static func pay_faster_at_$merchant_and_thousands_of_merchants(merchantDisplayName: String) -> String {
String(
format: STPLocalizedString(
Expand Down Expand Up @@ -69,23 +62,6 @@ extension String.Localized {
STPLocalizedString("Back", "Text for back button")
}

static var update_card: String {
STPLocalizedString(
"Update card",
"""
Title for a button that when tapped, presents a screen for updating a card. Also
the heading the screen itself.
"""
)
}

static var show_menu: String {
STPLocalizedString(
"Show menu",
"Accessibility label for an action or a button that shows a menu."
)
}

static var enter_address_manually: String {
STPLocalizedString("Enter address manually", "Text for a button that allows manual entry of an address")
}
Expand All @@ -104,20 +80,6 @@ extension String.Localized {
)
}

static var or: String {
STPLocalizedString(
"Or",
"Separator label between two options"
)
}

static var add_a_payment_method: String {
STPLocalizedString(
"Add a payment method",
"Text for a button that, when tapped, displays another screen where the customer can add a new payment method"
)
}

static var save_address: String {
STPLocalizedString("Save address", "Title for address entry section")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import UIKit
protocol PaymentSheetLinkAccountInfoProtocol {
var email: String { get }
var lastPM: LinkPMDisplayDetails? { get }
var redactedPhoneNumber: String? { get }
var isRegistered: Bool { get }
var isLoggedIn: Bool { get }
}

struct LinkPMDisplayDetails {
Expand Down Expand Up @@ -52,18 +50,10 @@ class PaymentSheetLinkAccount: PaymentSheetLinkAccountInfoProtocol {
return linkAccountService.getLastPMDetails()
}

var redactedPhoneNumber: String? {
return currentSession?.redactedPhoneNumber
}

var isRegistered: Bool {
return currentSession != nil
}

var isLoggedIn: Bool {
return sessionState == .verified
}

var sessionState: SessionState {
if let currentSession = currentSession {
// sms verification is not required if we are in the signup flow
Expand All @@ -74,10 +64,6 @@ class PaymentSheetLinkAccount: PaymentSheetLinkAccountInfoProtocol {
}
}

var hasStartedSMSVerification: Bool {
return currentSession?.hasStartedSMSVerification ?? false
}

private var currentSession: ConsumerSession?

init(
Expand Down Expand Up @@ -148,27 +134,6 @@ class PaymentSheetLinkAccount: PaymentSheetLinkAccountInfoProtocol {
}
}

func createLinkAccountSession(
completion: @escaping (Result<LinkAccountSession, Error>) -> Void
) {
guard let session = currentSession else {
assertionFailure()
completion(
.failure(
PaymentSheetError.linkingWithoutValidSession
)
)
return
}

retryingOnAuthError(completion: completion) { [publishableKey] completionWrapper in
session.createLinkAccountSession(
consumerAccountPublishableKey: publishableKey,
completion: completionWrapper
)
}
}

func createPaymentDetails(
with paymentMethodParams: STPPaymentMethodParams,
completion: @escaping (Result<ConsumerPaymentDetails, Error>) -> Void
Expand All @@ -190,120 +155,6 @@ class PaymentSheetLinkAccount: PaymentSheetLinkAccountInfoProtocol {
)
}
}

func createPaymentDetails(
linkedAccountId: String,
completion: @escaping (Result<ConsumerPaymentDetails, Error>) -> Void
) {
guard let session = currentSession else {
assertionFailure()
completion(.failure(PaymentSheetError.savingWithoutValidLinkSession))
return
}
retryingOnAuthError(completion: completion) { [publishableKey] completionWrapper in
session.createPaymentDetails(
linkedAccountId: linkedAccountId,
consumerAccountPublishableKey: publishableKey,
completion: completionWrapper
)
}
}

func listPaymentDetails(
completion: @escaping (Result<[ConsumerPaymentDetails], Error>) -> Void
) {
guard let session = currentSession else {
assertionFailure()
completion(.failure(PaymentSheetError.payingWithoutValidLinkSession))
return
}

retryingOnAuthError(completion: completion) { [apiClient, publishableKey] completionWrapper in
session.listPaymentDetails(
with: apiClient,
consumerAccountPublishableKey: publishableKey,
completion: completionWrapper
)
}
}

func deletePaymentDetails(id: String, completion: @escaping (Result<Void, Error>) -> Void) {
guard let session = currentSession else {
assertionFailure()
return completion(
.failure(
PaymentSheetError.deletingWithoutValidLinkSession
)
)
}

retryingOnAuthError(completion: completion) { [apiClient, publishableKey] completionWrapper in
session.deletePaymentDetails(
with: apiClient,
id: id,
consumerAccountPublishableKey: publishableKey,
completion: completionWrapper
)
}
}

func updatePaymentDetails(
id: String,
updateParams: UpdatePaymentDetailsParams,
completion: @escaping (Result<ConsumerPaymentDetails, Error>) -> Void
) {
guard let session = currentSession else {
assertionFailure()
return completion(
.failure(
PaymentSheetError.updatingWithoutValidLinkSession
)
)
}

retryingOnAuthError(completion: completion) { [apiClient, publishableKey] completionWrapper in
session.updatePaymentDetails(
with: apiClient,
id: id,
updateParams: updateParams,
consumerAccountPublishableKey: publishableKey,
completion: completionWrapper
)
}
}

func logout(completion: (() -> Void)? = nil) {
guard let session = currentSession else {
assertionFailure("Cannot logout without an active session")
completion?()
return
}

session.logout(
with: apiClient,
cookieStore: cookieStore,
consumerAccountPublishableKey: publishableKey
) { _ in
completion?()
}

// Delete cookie.
cookieStore.delete(key: .session)

markEmailAsLoggedOut()

// Forget current session.
self.currentSession = nil
}

func markEmailAsLoggedOut() {
guard let hashedEmail = email.lowercased().sha256 else {
return
}

cookieStore.write(key: .lastLogoutEmail, value: hashedEmail)
}

}

// MARK: - Equatable
Expand Down Expand Up @@ -419,68 +270,8 @@ extension PaymentSheetLinkAccount {

}

// MARK: - Payment method availability

extension PaymentSheetLinkAccount {

/// Returns a set containing the Payment Details types that the user is able to use for confirming the given `intent`.
/// - Parameter intent: The Intent that the user is trying to confirm.
/// - Returns: A set containing the supported Payment Details types.
func supportedPaymentDetailsTypes(for intent: Intent) -> Set<ConsumerPaymentDetails.DetailsType> {
guard let currentSession = currentSession, let fundingSources = intent.linkFundingSources else {
return []
}

let fundingSourceDetailsTypes = Set(fundingSources.compactMap { $0.detailsType })

// Take the intersection of the consumer session types and the merchant-provided Link funding sources
var supportedPaymentDetailsTypes = fundingSourceDetailsTypes.intersection(currentSession.supportedPaymentDetailsTypes)

// Special testmode handling
if apiClient.isTestmode && Self.emailSupportsMultipleFundingSourcesOnTestMode(email) {
supportedPaymentDetailsTypes.insert(.bankAccount)
}

return supportedPaymentDetailsTypes
}

func supportedPaymentMethodTypes(for intent: Intent) -> [STPPaymentMethodType] {
var supportedPaymentMethodTypes = [STPPaymentMethodType]()

for paymentDetailsType in supportedPaymentDetailsTypes(for: intent) {
switch paymentDetailsType {
case .card:
supportedPaymentMethodTypes.append(.card)
case .bankAccount:
supportedPaymentMethodTypes.append(.linkInstantDebit)
case .unparsable:
break
}
}

if supportedPaymentMethodTypes.isEmpty {
// Card is the default payment method type when no other type is available.
supportedPaymentMethodTypes.append(.card)
}

return supportedPaymentMethodTypes
}
}

// MARK: - Helpers

private extension PaymentSheetLinkAccount {

/// On *testmode* we use special email addresses for testing multiple funding sources. This method returns `true`
/// if the given `email` is one of such email addresses.
///
/// - Parameter email: Email.
/// - Returns: Whether or not should enable multiple funding sources on test mode.
static func emailSupportsMultipleFundingSourcesOnTestMode(_ email: String) -> Bool {
return email.contains("+multiple_funding_sources@")
}

}

private extension LinkSettings.FundingSource {
var detailsType: ConsumerPaymentDetails.DetailsType? {
Expand All @@ -492,20 +283,3 @@ private extension LinkSettings.FundingSource {
}
}
}

// MARK: UpdatePaymentDetailsParams

struct UpdatePaymentDetailsParams {
enum DetailsType {
case card(expiryDate: CardExpiryDate, billingDetails: STPPaymentMethodBillingDetails? = nil)
// updating bank not supported
}

let isDefault: Bool?
let details: DetailsType?

init(isDefault: Bool? = nil, details: DetailsType? = nil) {
self.isDefault = isDefault
self.details = details
}
}
Loading