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

Porter/improve dead code checking #4073

Closed
wants to merge 14 commits into from
Closed
42 changes: 21 additions & 21 deletions .periphery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,41 +50,41 @@ targets:
# - PaymentSheetLocalizationScreenshotGenerator
# - PaymentSheetUITest
- Stripe3DS2
- Stripe3DS2Tests
# - Stripe3DS2Tests
- StripeApplePay
- StripeApplePayTests
# - StripeApplePayTests
- StripeCameraCore
- StripeCameraCoreTestUtils
- StripeCameraCoreTests
# - StripeCameraCoreTestUtils
# - StripeCameraCoreTests
- StripeCardScan
- StripeCardScanTests
# - StripeCardScanTests
- StripeConnect
# - StripeConnect Example
# - StripeConnect ExampleUITests
- StripeConnectTests
# - StripeConnectTests
- StripeCore
- StripeCoreTestUtils
- StripeCoreTests
# - StripeCoreTestUtils
# - StripeCoreTests
- StripeFinancialConnections
- StripeFinancialConnectionsTests
# - StripeFinancialConnectionsTests
- StripeIdentity
- StripeIdentityTests
# - StripeIdentityTests
- StripePaymentSheet
- StripePaymentSheetTestHostApp
- StripePaymentSheetTests
# - StripePaymentSheetTestHostApp
# - StripePaymentSheetTests
- StripePayments
- StripePaymentsObjcTestUtils
- StripePaymentsTestHostApp
- StripePaymentsTestUtils
- StripePaymentsTests
# - StripePaymentsObjcTestUtils
# - StripePaymentsTestHostApp
# - StripePaymentsTestUtils
# - StripePaymentsTests
- StripePaymentsUI
- StripePaymentsUITests
# - StripePaymentsUITests
- StripeUICore
- StripeUICoreTests
# - StripeUICoreTests
- StripeiOS
- StripeiOSAppHostedTests
- StripeiOSTestHostApp
- StripeiOSTests
# - StripeiOSAppHostedTests
# - StripeiOSTestHostApp
# - StripeiOSTests
# - UI Examples

retain_public: true
Expand Down
153 changes: 2 additions & 151 deletions Example/UI Examples/UI Examples/Source/BrowseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ import UIKit
@testable import Stripe
@_spi(STP) import StripePaymentsUI

class BrowseViewController: UITableViewController, STPAddCardViewControllerDelegate,
STPPaymentOptionsViewControllerDelegate, STPShippingAddressViewControllerDelegate
class BrowseViewController: UITableViewController
{

enum Demo: Int {
static var count: Int = 11
static var count: Int = 8

case STPPaymentCardTextField
case STPPaymentCardTextFieldWithCBC
case STPPaymentOptionsViewController
case STPPaymentOptionsFPXViewController
case STPShippingInfoViewController
case STPAUBECSFormViewController
case STPCardFormViewController
case STPCardFormViewControllerCBC
Expand All @@ -36,9 +32,6 @@ class BrowseViewController: UITableViewController, STPAddCardViewControllerDeleg
switch self {
case .STPPaymentCardTextField: return "Card Field"
case .STPPaymentCardTextFieldWithCBC: return "Card Field (CBC)"
case .STPPaymentOptionsViewController: return "Payment Option Picker"
case .STPPaymentOptionsFPXViewController: return "Payment Option Picker (With FPX)"
case .STPShippingInfoViewController: return "Shipping Info Form"
case .STPAUBECSFormViewController: return "AU BECS Form"
case .STPCardFormViewController: return "Card Form"
case .STPCardFormViewControllerCBC: return "Card Form (CBC)"
Expand All @@ -52,9 +45,6 @@ class BrowseViewController: UITableViewController, STPAddCardViewControllerDeleg
switch self {
case .STPPaymentCardTextField: return "STPPaymentCardTextField"
case .STPPaymentCardTextFieldWithCBC: return "STPPaymentCardTextField"
case .STPPaymentOptionsViewController: return "STPPaymentOptionsViewController"
case .STPPaymentOptionsFPXViewController: return "STPPaymentOptionsViewController"
case .STPShippingInfoViewController: return "STPShippingInfoViewController"
case .STPAUBECSFormViewController: return "STPAUBECSFormViewController"
case .STPCardFormViewController: return "STPCardFormViewController"
case .STPCardFormViewControllerCBC: return "STPCardFormViewController (CBC)"
Expand All @@ -65,13 +55,6 @@ class BrowseViewController: UITableViewController, STPAddCardViewControllerDeleg
}
}

let customerContext: MockCustomerContext = {
let keyManager = STPEphemeralKeyManager(
keyProvider: MockKeyProvider(),
apiVersion: STPAPIClient.apiVersion,
performsEagerFetching: true)
return MockCustomerContext(keyManager: keyManager, apiClient: .shared)
}()
let themeViewController = ThemeViewController()

override func viewDidLoad() {
Expand Down Expand Up @@ -121,47 +104,6 @@ class BrowseViewController: UITableViewController, STPAddCardViewControllerDeleg
let navigationController = UINavigationController(rootViewController: viewController)
navigationController.navigationBar.stp_theme = theme
present(navigationController, animated: true, completion: nil)
case .STPPaymentOptionsFPXViewController:
let config = STPPaymentConfiguration()
config.fpxEnabled = true
config.requiredBillingAddressFields = .none
config.appleMerchantIdentifier = "dummy-merchant-id"
config.cardScanningEnabled = true
let viewController = STPPaymentOptionsViewController(
configuration: config,
theme: theme,
customerContext: self.customerContext,
delegate: self)
let navigationController = UINavigationController(rootViewController: viewController)
navigationController.navigationBar.stp_theme = theme
present(navigationController, animated: true, completion: nil)
case .STPPaymentOptionsViewController:
let config = STPPaymentConfiguration()
config.requiredBillingAddressFields = .none
config.appleMerchantIdentifier = "dummy-merchant-id"
config.cardScanningEnabled = true
let viewController = STPPaymentOptionsViewController(
configuration: config,
theme: theme,
customerContext: self.customerContext,
delegate: self)
let navigationController = UINavigationController(rootViewController: viewController)
navigationController.navigationBar.stp_theme = theme
present(navigationController, animated: true, completion: nil)
case .STPShippingInfoViewController:
let config = STPPaymentConfiguration()
config.requiredShippingAddressFields = [.postalAddress]
let viewController = STPShippingAddressViewController(
configuration: config,
theme: theme,
currency: "usd",
shippingAddress: nil,
selectedShippingMethod: nil,
prefilledInformation: nil)
viewController.delegate = self
let navigationController = UINavigationController(rootViewController: viewController)
navigationController.navigationBar.stp_theme = theme
present(navigationController, animated: true, completion: nil)
case .STPAUBECSFormViewController:
let viewController = AUBECSDebitFormViewController()
viewController.theme = theme
Expand Down Expand Up @@ -193,95 +135,4 @@ class BrowseViewController: UITableViewController, STPAddCardViewControllerDeleg
}
}

// MARK: STPAddCardViewControllerDelegate

func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
dismiss(animated: true, completion: nil)
}

func addCardViewController(
_ addCardViewController: STPAddCardViewController,
didCreatePaymentMethod paymentMethod: STPPaymentMethod,
completion: @escaping STPErrorBlock
) {
dismiss(animated: true, completion: nil)
}

// MARK: STPPaymentOptionsViewControllerDelegate

func paymentOptionsViewControllerDidCancel(
_ paymentOptionsViewController: STPPaymentOptionsViewController
) {
dismiss(animated: true, completion: nil)
}

func paymentOptionsViewControllerDidFinish(
_ paymentOptionsViewController: STPPaymentOptionsViewController
) {
dismiss(animated: true, completion: nil)
}

func paymentOptionsViewController(
_ paymentOptionsViewController: STPPaymentOptionsViewController,
didFailToLoadWithError error: Error
) {
dismiss(animated: true, completion: nil)
}

// MARK: STPShippingAddressViewControllerDelegate

func shippingAddressViewControllerDidCancel(
_ addressViewController: STPShippingAddressViewController
) {
dismiss(animated: true, completion: nil)
}

func shippingAddressViewController(
_ addressViewController: STPShippingAddressViewController,
didFinishWith address: STPAddress,
shippingMethod method: PKShippingMethod?
) {
self.customerContext.updateCustomer(withShippingAddress: address, completion: nil)
dismiss(animated: true, completion: nil)
}

func shippingAddressViewController(
_ addressViewController: STPShippingAddressViewController,
didEnter address: STPAddress,
completion: @escaping STPShippingMethodsCompletionBlock
) {
let upsGround = PKShippingMethod()
upsGround.amount = 0
upsGround.label = "UPS Ground"
upsGround.detail = "Arrives in 3-5 days"
upsGround.identifier = "ups_ground"
let upsWorldwide = PKShippingMethod()
upsWorldwide.amount = 10.99
upsWorldwide.label = "UPS Worldwide Express"
upsWorldwide.detail = "Arrives in 1-3 days"
upsWorldwide.identifier = "ups_worldwide"
let fedEx = PKShippingMethod()
fedEx.amount = 5.99
fedEx.label = "FedEx"
fedEx.detail = "Arrives tomorrow"
fedEx.identifier = "fedex"

DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
if address.country == nil || address.country == "US" {
completion(.valid, nil, [upsGround, fedEx], fedEx)
} else if address.country == "AQ" {
let error = NSError(
domain: "ShippingError", code: 123,
userInfo: [
NSLocalizedDescriptionKey: "Invalid Shipping Address",
NSLocalizedFailureReasonErrorKey: "We can't ship to this country.",
])
completion(.invalid, error, nil, nil)
} else {
fedEx.amount = 20.99
completion(.valid, nil, [upsWorldwide, fedEx], fedEx)
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,74 +110,3 @@ class MockKeyProvider: NSObject, STPCustomerEphemeralKeyProvider {
completion(nil, NSError.stp_ephemeralKeyDecodingError())
}
}

class MockCustomerContext: STPCustomerContext {

let customer = MockCustomer()

override func retrieveCustomer(_ completion: STPCustomerCompletionBlock? = nil) {
if let completion = completion {
completion(customer, nil)
}
}

override func attachPaymentMethod(
toCustomer paymentMethod: STPPaymentMethod, completion: STPErrorBlock? = nil
) {
customer.paymentMethods.append(paymentMethod)
if let completion = completion {
completion(nil)
}
}

override func detachPaymentMethod(
fromCustomer paymentMethod: STPPaymentMethod, completion: STPErrorBlock? = nil
) {
if let index = customer.paymentMethods.firstIndex(where: {
$0.stripeId == paymentMethod.stripeId
}) {
customer.paymentMethods.remove(at: index)
}
if let completion = completion {
completion(nil)
}
}

override func listPaymentMethodsForCustomer(completion: STPPaymentMethodsCompletionBlock? = nil)
{
if let completion = completion {
completion(customer.paymentMethods, nil)
}
}

func selectDefaultCustomerPaymentMethod(
_ paymentMethod: STPPaymentMethod, completion: @escaping STPErrorBlock
) {
if customer.paymentMethods.contains(where: { $0.stripeId == paymentMethod.stripeId }) {
customer.defaultPaymentMethod = paymentMethod
}
completion(nil)
}

override func updateCustomer(
withShippingAddress shipping: STPAddress, completion: STPErrorBlock?
) {
customer.shippingAddress = shipping
if let completion = completion {
completion(nil)
}
}

override func retrieveLastSelectedPaymentMethodIDForCustomer(
completion: @escaping (String?, Error?) -> Void
) {
completion(nil, nil)
}
override func saveLastSelectedPaymentMethodID(
forCustomer paymentMethodID: String?, completion: STPErrorBlock?
) {
if let completion = completion {
completion(nil)
}
}
}
Loading
Loading