From 6b57a59e36c843fbfd3f247a6cf8eac804d9988a Mon Sep 17 00:00:00 2001 From: Joyce Qin Date: Mon, 30 Sep 2024 14:19:12 -0700 Subject: [PATCH] periphery detected dead code --- .../xcshareddata/swiftpm/Package.resolved | 5 +- Stripe/Stripe.xcodeproj/project.pbxproj | 32 -- ...rizationViewController+Stripe_Blocks.swift | 31 -- .../Source/STPAPIClient+BasicUI.swift | 103 ---- .../STPBankSelectionViewController.swift | 5 - Stripe/StripeiOS/Source/STPCameraView.swift | 9 - Stripe/StripeiOS/Source/STPCardScanner.swift | 488 ------------------ .../Source/STPCardScannerTableViewCell.swift | 67 --- .../Source/STPCoreViewController.swift | 25 - .../Source/STPPaymentCardTextFieldCell.swift | 91 ---- .../Source/STPPaymentContextAmountModel.swift | 96 ---- .../STPPaymentOptionTableViewCell.swift | 326 ------------ .../Source/STPPaymentOptionTuple.swift | 88 ---- .../Source/STPSectionHeaderView.swift | 161 ------ .../STPShippingMethodTableViewCell.swift | 147 ------ Stripe/StripeiOSTests/STPAPIClientTest.swift | 4 +- .../STPAnalyticsClientPaymentsTest.swift | 11 - Stripe/StripeiOSTests/STPSwiftFixtures.swift | 10 - .../Source/Helpers/PaymentsSDKVariant.swift | 4 - 19 files changed, 4 insertions(+), 1699 deletions(-) delete mode 100644 Stripe/StripeiOS/Source/STPCardScanner.swift delete mode 100644 Stripe/StripeiOS/Source/STPCardScannerTableViewCell.swift delete mode 100644 Stripe/StripeiOS/Source/STPPaymentCardTextFieldCell.swift delete mode 100644 Stripe/StripeiOS/Source/STPPaymentContextAmountModel.swift delete mode 100644 Stripe/StripeiOS/Source/STPPaymentOptionTableViewCell.swift delete mode 100644 Stripe/StripeiOS/Source/STPPaymentOptionTuple.swift delete mode 100644 Stripe/StripeiOS/Source/STPSectionHeaderView.swift delete mode 100644 Stripe/StripeiOS/Source/STPShippingMethodTableViewCell.swift diff --git a/Stripe.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Stripe.xcworkspace/xcshareddata/swiftpm/Package.resolved index 89be92cace5..76c7df6f3b0 100644 --- a/Stripe.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Stripe.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "2ad13697f5d60ad400147e34535361f52e72d2f7a280df77bb3c3521cc5623bc", + "originHash" : "c2f4a8c2436760fc0134632c1cdcb8e7f9b44493c60679a155d27d6838da7d8e", "pins" : [ { "identity" : "capture-core-sp", @@ -38,6 +38,5 @@ } } ], - "version" : 2 + "version" : 3 } - diff --git a/Stripe/Stripe.xcodeproj/project.pbxproj b/Stripe/Stripe.xcodeproj/project.pbxproj index de4fd52880c..fcc4ac773aa 100644 --- a/Stripe/Stripe.xcodeproj/project.pbxproj +++ b/Stripe/Stripe.xcodeproj/project.pbxproj @@ -37,7 +37,6 @@ 22BE2ABB29F77362FF16D945 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C2427C1CDFA85BFC6570F1E9 /* Localizable.strings */; }; 234C71F480318E9062075924 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BBCE3A905041A709E8F279A /* AppDelegate.swift */; }; 23CF725CFAB2ABED416BF416 /* STPApplePayContextFunctionalTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CE268457D21A7209862E004 /* STPApplePayContextFunctionalTest.swift */; }; - 23D1246A5DAB5333650F104F /* STPSectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E1FED5CE5974C9C1162E93 /* STPSectionHeaderView.swift */; }; 240993144289CD0DEC2C73C7 /* STPConfirmPaymentMethodOptionsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05FE1BA89B80336F16924FA2 /* STPConfirmPaymentMethodOptionsTest.swift */; }; 246920234EE8382FB4E56516 /* STPCardFormViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5E08A1651D9DFE502DA021 /* STPCardFormViewTests.swift */; }; 279D2BA91198E18730626CE6 /* STPUserInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1217AD643A9E8F88B60F645 /* STPUserInformation.swift */; }; @@ -56,7 +55,6 @@ 2F0FC4E67BE577AD66CD1475 /* StripePaymentSheet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDC55CC034022DFAC9366E2E /* StripePaymentSheet.framework */; }; 2F18A1903244E144C7802E09 /* STPCardValidationState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A9E7B637A8747431B38FD1D /* STPCardValidationState.swift */; }; 2F9FA9CBCA3C0CE52FAC9B6B /* ConfirmButtonSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 806124200E77795DCFC8418E /* ConfirmButtonSnapshotTests.swift */; }; - 2FFA7C2D1C7337FDB4C608A5 /* STPCardScannerTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B91C4D5B93FF71C61B140F1 /* STPCardScannerTableViewCell.swift */; }; 307FD6A103EF7AF3CE451598 /* STPPaymentResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D964D9E01627B419B4BD23C /* STPPaymentResult.swift */; }; 30D48C62B2FA6B28EC23A5BB /* Stripe-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = A8598727045C6268B57A5FC7 /* Stripe-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; 313F5F792B0BE59100BD98A9 /* Docs.docc in Sources */ = {isa = PBXBuildFile; fileRef = 313F5F782B0BE59000BD98A9 /* Docs.docc */; }; @@ -93,7 +91,6 @@ 43FFF2881D4EFA7B57A60E09 /* STPPaymentMethodCardTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BD02D8298877F10F2EF2A9D /* STPPaymentMethodCardTest.swift */; }; 44672917D3AC4B83F9EC3BC3 /* UIView+Stripe_SafeAreaBounds.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86798C95A778362EF815B4C6 /* UIView+Stripe_SafeAreaBounds.swift */; }; 446A108C8EB6C338A1D774F8 /* STPPaymentConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18FCB69CD3B8C3DAB216A5F0 /* STPPaymentConfiguration.swift */; }; - 447C19BDB2CF5445045F81F7 /* STPPaymentContextAmountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1C876DC7F3E31D7189506A8 /* STPPaymentContextAmountModel.swift */; }; 450FAE41FB4538462D05F2E4 /* LinkSignupViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7C7D85A7FAAFDF4F59BA85E /* LinkSignupViewModelTests.swift */; }; 45FA9B8CC2D18E29BE81CF8F /* STPIntentActionAlipayHandleRedirectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD06AED0AF8A9A7FB4A2E66F /* STPIntentActionAlipayHandleRedirectTest.swift */; }; 460B31EDB22BD6B912567363 /* STPSourceVerificationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E89551702F1F9A3AFF1ED676 /* STPSourceVerificationTest.swift */; }; @@ -106,8 +103,6 @@ 4B0917FC15BF56D0100E0ED1 /* STPGenericInputTextFieldSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58A53F005EA8FDDAA66126BA /* STPGenericInputTextFieldSnapshotTests.swift */; }; 4E09E54E7FEC35C49C59A379 /* STPPushProvisioningDetailsParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B28B8A547CD846277ECD578 /* STPPushProvisioningDetailsParams.swift */; }; 4E31B1864DA407598FB1BBC6 /* STPPostalCodeInputTextFieldTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6618739767139C25C05B3631 /* STPPostalCodeInputTextFieldTests.swift */; }; - 4ED44ACF24949F516867235C /* STPPaymentOptionTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6215A9BF343775B1BD0F62AF /* STPPaymentOptionTableViewCell.swift */; }; - 4EFF8B46B12DA4D9AAB22523 /* STPPaymentCardTextFieldCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01B42BE6FB5EC1F708875AB8 /* STPPaymentCardTextFieldCell.swift */; }; 4FB67F10A0B7106A8142B842 /* STPEphemeralKeyManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 588C260880FFC584A00A89F5 /* STPEphemeralKeyManager.swift */; }; 51044B947A7FDB99451466D8 /* STPGenericInputPickerFieldSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 284C67269D2606DA147AE01D /* STPGenericInputPickerFieldSnapshotTests.swift */; }; 5170651536332C4842E9D009 /* STPPaymentMethodBoletoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E371E9B3B2E343FE954531C /* STPPaymentMethodBoletoTests.swift */; }; @@ -131,7 +126,6 @@ 5D9EB3E2725C38D7098B9965 /* STPPaymentMethodParamsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4002981AC12687681616D21E /* STPPaymentMethodParamsTest.swift */; }; 5E498CDA0115CF9F8463C566 /* STPPaymentMethodAUBECSDebitParamsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FF2B9FF57E100301B5C38DB /* STPPaymentMethodAUBECSDebitParamsTests.swift */; }; 5E5EE69D140F6FEDA5F0A346 /* STPAPIClientTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8DD70E5ED8E9DE8E9752C9E /* STPAPIClientTest.swift */; }; - 5ECED204FD22CFEA3A806767 /* STPPaymentOptionTuple.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDD30E5DB8DB3AA3567F5C20 /* STPPaymentOptionTuple.swift */; }; 609C2C8F10AFAA2711639CD0 /* NSArray+StripeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17799DC7FA54E758EED31A6 /* NSArray+StripeTest.swift */; }; 609E4D384B75F6A111DC0E27 /* STPPaymentActivityIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FFBAA4B44967B157A4F4E91 /* STPPaymentActivityIndicatorView.swift */; }; 610DF5DC2B33597500DA6AAA /* HostedSurfaceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 610DF5DB2B33597500DA6AAA /* HostedSurfaceTest.swift */; }; @@ -173,7 +167,6 @@ 78B70C2EE8334F0FA91439CA /* Stripe.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4259421D2CD26E37B96F97B2 /* Stripe.framework */; }; 795F3783D62AB8E2A00DCD05 /* ConsumerSessionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6312182B5BCAB940D216650 /* ConsumerSessionTests.swift */; }; 7A9D7D156B5053638F9B21E1 /* STPPaymentMethodThreeDSecureUsageTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 916DB8789F65D3C1BCB510C0 /* STPPaymentMethodThreeDSecureUsageTest.swift */; }; - 7B9C0D039EA9EF593AEC682D /* STPShippingMethodTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98544B08552407D41D398C68 /* STPShippingMethodTableViewCell.swift */; }; 7BC98BE168781C5B3EC8A8DB /* STPPaymentMethod+BasicUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C1E9B0EE03825DABF6471A /* STPPaymentMethod+BasicUI.swift */; }; 7D251ABF1EBF65ACA8A4BDD4 /* STPPaymentMethodUSBankAccountParamsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74FDEF9F687C63BADFB96480 /* STPPaymentMethodUSBankAccountParamsTest.swift */; }; 7D2C0D1BF455625997CBC33B /* STPAPIClientNetworkBridgeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9BA8D8467218C7E691C9FAE /* STPAPIClientNetworkBridgeTest.swift */; }; @@ -246,7 +239,6 @@ B8ED1F697519A6FCD3D79431 /* STPPaymentMethodGiropayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583DB466066B47C0F716E474 /* STPPaymentMethodGiropayTests.swift */; }; B917BF282C84507292112B9D /* STPCardBINMetadataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E1C5E08678292561255B1C5 /* STPCardBINMetadataTests.swift */; }; B98D71ED9ACC2E1B47372F53 /* NSDecimalNumber+StripeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20552E792B8E7BA15821AB5D /* NSDecimalNumber+StripeTest.swift */; }; - BAFD06E994739E1C38DFFBBC /* STPCardScanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69BD038947E8E2376A0D240B /* STPCardScanner.swift */; }; BBB734F006FAD749678B87D1 /* STPPaymentMethodRevolutPayParamsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE7BEADD3824A06C2994854 /* STPPaymentMethodRevolutPayParamsTests.swift */; }; BC6912C0DE15008C8D8C303C /* STPFloatingPlaceholderTextFieldSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7385193226663A5B79E69ED /* STPFloatingPlaceholderTextFieldSnapshotTests.swift */; }; BC694A1642DC30D530B60635 /* RotatingCardBrandsViewSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDA32D0C9E8A7A69F4899EDC /* RotatingCardBrandsViewSnapshotTests.swift */; }; @@ -437,7 +429,6 @@ 005650A59D692F820EF20F5F /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 00985EFC6CB7B912FDBF3813 /* STPApplePayPaymentOptionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPApplePayPaymentOptionTest.swift; sourceTree = ""; }; 01B057D99A14E5BA6019C349 /* STPSetupIntentLastSetupErrorTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPSetupIntentLastSetupErrorTest.swift; sourceTree = ""; }; - 01B42BE6FB5EC1F708875AB8 /* STPPaymentCardTextFieldCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentCardTextFieldCell.swift; sourceTree = ""; }; 02FC9ED423D40C88D5A24441 /* STPCoreViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPCoreViewController.swift; sourceTree = ""; }; 03ACDC7EEC28D1FE50008F65 /* STPApplePayPaymentOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPApplePayPaymentOption.swift; sourceTree = ""; }; 04838ACE779F5CC949C276CB /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = ""; }; @@ -452,7 +443,6 @@ 0A16326394D71637A2CF68C3 /* fil */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fil; path = fil.lproj/Localizable.strings; sourceTree = ""; }; 0A8FF64CA314F909D7EC82FE /* STPPaymentMethodGrabPayParamsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentMethodGrabPayParamsTest.swift; sourceTree = ""; }; 0ABB2CA7E96BE249CE8C0566 /* STPPaymentMethodCashAppParamsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentMethodCashAppParamsTests.swift; sourceTree = ""; }; - 0B91C4D5B93FF71C61B140F1 /* STPCardScannerTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPCardScannerTableViewCell.swift; sourceTree = ""; }; 0C44B4366D6C4FD4B11662C8 /* STPPaymentMethodEPSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentMethodEPSTests.swift; sourceTree = ""; }; 0C75157665428685C7A4FD20 /* STPCardExpiryInputTextFieldSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPCardExpiryInputTextFieldSnapshotTests.swift; sourceTree = ""; }; 0C9D6F99E303A17A91101723 /* pl-PL */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pl-PL"; path = "pl-PL.lproj/Localizable.strings"; sourceTree = ""; }; @@ -592,7 +582,6 @@ 61E1CA202BD6B78500A421AE /* STPPaymentMethodMultibancoParamsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentMethodMultibancoParamsTests.swift; sourceTree = ""; }; 61E1CA262BD6BED600A421AE /* STPIntentActionMultibancoDisplayDetailsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPIntentActionMultibancoDisplayDetailsTest.swift; sourceTree = ""; }; 61F8308B7250B642D19827D8 /* STPCameraView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPCameraView.swift; sourceTree = ""; }; - 6215A9BF343775B1BD0F62AF /* STPPaymentOptionTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentOptionTableViewCell.swift; sourceTree = ""; }; 6223E57D3A198F956A37ED89 /* STPNumericDigitInputTextFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPNumericDigitInputTextFormatterTests.swift; sourceTree = ""; }; 63114D0EAAE2606732DF5AA0 /* STPSourceCardDetailsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPSourceCardDetailsTest.swift; sourceTree = ""; }; 63F5F35DB97D8A176FB6ED24 /* NSString+StripeTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSString+StripeTest.swift"; sourceTree = ""; }; @@ -602,7 +591,6 @@ 683F7735569D22CBEC9CA2E6 /* STPPaymentHandlerFunctionalTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = STPPaymentHandlerFunctionalTest.m; sourceTree = ""; }; 6887F19BB9804BF45FD703FF /* STPPushProvisioningContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPushProvisioningContext.swift; sourceTree = ""; }; 6955B3A3353F8442E4FBBBF6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 69BD038947E8E2376A0D240B /* STPCardScanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPCardScanner.swift; sourceTree = ""; }; 6A9E7B637A8747431B38FD1D /* STPCardValidationState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPCardValidationState.swift; sourceTree = ""; }; 6B7A947152A728EB2CBC4DB2 /* STPSourceReceiverTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPSourceReceiverTest.swift; sourceTree = ""; }; 6BA4B9192BF433B200D1F21D /* STPPaymentMethodMobilePayParamsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentMethodMobilePayParamsTests.swift; sourceTree = ""; }; @@ -668,8 +656,6 @@ 967C784618A074FF021B3089 /* STPBankAccountParamsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPBankAccountParamsTest.swift; sourceTree = ""; }; 967DDC94B687B14E07842CC8 /* STPConnectAccountAddressTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPConnectAccountAddressTest.swift; sourceTree = ""; }; 969E196AB597EEF68C38103E /* Project-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Project-Release.xcconfig"; sourceTree = ""; }; - 96E1FED5CE5974C9C1162E93 /* STPSectionHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPSectionHeaderView.swift; sourceTree = ""; }; - 98544B08552407D41D398C68 /* STPShippingMethodTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPShippingMethodTableViewCell.swift; sourceTree = ""; }; 989411FA3CD0CCC38BC227F4 /* STPBankAccountFunctionalTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPBankAccountFunctionalTest.swift; sourceTree = ""; }; 98F9CB667BC68767DFB5FACD /* OneTimeCodeTextFieldTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OneTimeCodeTextFieldTests.swift; sourceTree = ""; }; 9B782E1D974A4C131E60E2BD /* STPBackendAPIAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPBackendAPIAdapter.swift; sourceTree = ""; }; @@ -685,7 +671,6 @@ A1272F2E05A0E294DD9ECA26 /* STPApplePayContextFunctionalTestExtras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPApplePayContextFunctionalTestExtras.swift; sourceTree = ""; }; A15BBFFA401852A8719E3DDD /* STPPaymentMethodCardChecksTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentMethodCardChecksTest.swift; sourceTree = ""; }; A1C67AC5D415615E9F27D3E3 /* STPPaymentMethodBoletoParamsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentMethodBoletoParamsTests.swift; sourceTree = ""; }; - A1C876DC7F3E31D7189506A8 /* STPPaymentContextAmountModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentContextAmountModel.swift; sourceTree = ""; }; A22E5B87755C1F05C3DB438C /* STPInputTextFieldFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPInputTextFieldFormatterTests.swift; sourceTree = ""; }; A39580123A4F1EA96F91768A /* STPAddressTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPAddressTests.swift; sourceTree = ""; }; A41F721AEBB942BB81408A59 /* STPPaymentMethodSEPADebitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentMethodSEPADebitTest.swift; sourceTree = ""; }; @@ -803,7 +788,6 @@ EB6AE83989B0596F0C111E13 /* STPStringUtilsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPStringUtilsTest.swift; sourceTree = ""; }; EB71A4A2762CF864DB198BCF /* Project-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Project-Debug.xcconfig"; sourceTree = ""; }; ECBA5B09A3FD875C93218573 /* STPPaymentMethodAfterpayClearpayParamsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentMethodAfterpayClearpayParamsTest.swift; sourceTree = ""; }; - EDD30E5DB8DB3AA3567F5C20 /* STPPaymentOptionTuple.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentOptionTuple.swift; sourceTree = ""; }; EF48EC440E1ED5D6BAA567FF /* STPPaymentHandlerStubbedMockedFilesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPPaymentHandlerStubbedMockedFilesTests.swift; sourceTree = ""; }; EFD2F6A5A046A620BAB75B41 /* AutoCompleteViewControllerSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoCompleteViewControllerSnapshotTests.swift; sourceTree = ""; }; F13E3DE09A463B4501733B87 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; @@ -924,8 +908,6 @@ E3B42EBAC0DC7ED0D9200DB7 /* STPBlocks.swift */, 61F8308B7250B642D19827D8 /* STPCameraView.swift */, 3E5FB20B2BEFC00D54FDD87D /* STPCard+BasicUI.swift */, - 69BD038947E8E2376A0D240B /* STPCardScanner.swift */, - 0B91C4D5B93FF71C61B140F1 /* STPCardScannerTableViewCell.swift */, 6A9E7B637A8747431B38FD1D /* STPCardValidationState.swift */, 2D1525AF65BDEF691F8BCBE8 /* STPCoreScrollViewController.swift */, B78C72B0DB434EC7F700FDE0 /* STPCoreTableViewController.swift */, @@ -939,22 +921,16 @@ 9EB24EC81CE2C8D1C863B044 /* STPIntentActionLinkAuthenticateAccount.swift */, AFF957F38AABE5F748C38C0B /* STPLocalizedString.swift */, 1FFBAA4B44967B157A4F4E91 /* STPPaymentActivityIndicatorView.swift */, - 01B42BE6FB5EC1F708875AB8 /* STPPaymentCardTextFieldCell.swift */, 18FCB69CD3B8C3DAB216A5F0 /* STPPaymentConfiguration.swift */, - A1C876DC7F3E31D7189506A8 /* STPPaymentContextAmountModel.swift */, 6F01150CD0255164FE2CF3A4 /* STPPaymentIntentParams+BasicUI.swift */, 35C1E9B0EE03825DABF6471A /* STPPaymentMethod+BasicUI.swift */, 53C5AB22D6328E85A6DDF663 /* STPPaymentMethodParams+BasicUI.swift */, 30B694A39D54886392AA5DE3 /* STPPaymentOption.swift */, - 6215A9BF343775B1BD0F62AF /* STPPaymentOptionTableViewCell.swift */, - EDD30E5DB8DB3AA3567F5C20 /* STPPaymentOptionTuple.swift */, 7D964D9E01627B419B4BD23C /* STPPaymentResult.swift */, 3EBB07171F6FDCE6E20C454A /* STPPinManagementService.swift */, 6887F19BB9804BF45FD703FF /* STPPushProvisioningContext.swift */, 89E5DA3029F141B5111A5B2C /* STPPushProvisioningDetails.swift */, 2B28B8A547CD846277ECD578 /* STPPushProvisioningDetailsParams.swift */, - 96E1FED5CE5974C9C1162E93 /* STPSectionHeaderView.swift */, - 98544B08552407D41D398C68 /* STPShippingMethodTableViewCell.swift */, C3B75875C55D2C2723DC5090 /* STPSource+BasicUI.swift */, 8E8CA4361964E1BA400EFC89 /* STPTheme.swift */, B1217AD643A9E8F88B60F645 /* STPUserInformation.swift */, @@ -1586,8 +1562,6 @@ A0AA0B8AEF5B429858D71F6B /* STPBlocks.swift in Sources */, DDBF5AAE607C698618DDE865 /* STPCameraView.swift in Sources */, 66065B1D65D7D5502D4E2F2B /* STPCard+BasicUI.swift in Sources */, - BAFD06E994739E1C38DFFBBC /* STPCardScanner.swift in Sources */, - 2FFA7C2D1C7337FDB4C608A5 /* STPCardScannerTableViewCell.swift in Sources */, 2F18A1903244E144C7802E09 /* STPCardValidationState.swift in Sources */, DF73457BF349BC962A6AC502 /* STPCoreScrollViewController.swift in Sources */, EEFFE199D9769FF449BFD7FF /* STPCoreTableViewController.swift in Sources */, @@ -1602,22 +1576,16 @@ D2869246B446B8B31F1CD368 /* STPIntentActionLinkAuthenticateAccount.swift in Sources */, 98EE8326C1D133E1C998114F /* STPLocalizedString.swift in Sources */, 609E4D384B75F6A111DC0E27 /* STPPaymentActivityIndicatorView.swift in Sources */, - 4EFF8B46B12DA4D9AAB22523 /* STPPaymentCardTextFieldCell.swift in Sources */, 446A108C8EB6C338A1D774F8 /* STPPaymentConfiguration.swift in Sources */, - 447C19BDB2CF5445045F81F7 /* STPPaymentContextAmountModel.swift in Sources */, EA7FEC518AA07BA59405A5E3 /* STPPaymentIntentParams+BasicUI.swift in Sources */, 7BC98BE168781C5B3EC8A8DB /* STPPaymentMethod+BasicUI.swift in Sources */, 812682EA323986B8F698FF3C /* STPPaymentMethodParams+BasicUI.swift in Sources */, F10FC337254A34ED8F13E341 /* STPPaymentOption.swift in Sources */, - 4ED44ACF24949F516867235C /* STPPaymentOptionTableViewCell.swift in Sources */, - 5ECED204FD22CFEA3A806767 /* STPPaymentOptionTuple.swift in Sources */, 307FD6A103EF7AF3CE451598 /* STPPaymentResult.swift in Sources */, 7EAA7334372DBC38DF8FA0AA /* STPPinManagementService.swift in Sources */, 2E35B0FB60FCBE7608080642 /* STPPushProvisioningContext.swift in Sources */, FEE74744B657F86873EA2F3D /* STPPushProvisioningDetails.swift in Sources */, 4E09E54E7FEC35C49C59A379 /* STPPushProvisioningDetailsParams.swift in Sources */, - 23D1246A5DAB5333650F104F /* STPSectionHeaderView.swift in Sources */, - 7B9C0D039EA9EF593AEC682D /* STPShippingMethodTableViewCell.swift in Sources */, 3CE88568CB9648D6F1503B88 /* STPSource+BasicUI.swift in Sources */, F835CEC935464FF32726A0A0 /* STPTheme.swift in Sources */, 279D2BA91198E18730626CE6 /* STPUserInformation.swift in Sources */, diff --git a/Stripe/StripeiOS/Source/PKPaymentAuthorizationViewController+Stripe_Blocks.swift b/Stripe/StripeiOS/Source/PKPaymentAuthorizationViewController+Stripe_Blocks.swift index 590d3342b90..3ad6abceff0 100644 --- a/Stripe/StripeiOS/Source/PKPaymentAuthorizationViewController+Stripe_Blocks.swift +++ b/Stripe/StripeiOS/Source/PKPaymentAuthorizationViewController+Stripe_Blocks.swift @@ -24,38 +24,7 @@ typealias STPShippingAddressSelectionBlock = ( STPAddress, @escaping STPShippingAddressValidationBlock ) -> Void typealias STPPaymentAuthorizationBlock = (PKPayment) -> Void -extension PKPaymentAuthorizationViewController { - class func stp_controller( - with paymentRequest: PKPaymentRequest, - apiClient: STPAPIClient, - onShippingAddressSelection: @escaping STPShippingAddressSelectionBlock, - onShippingMethodSelection: @escaping STPShippingMethodSelectionBlock, - onPaymentAuthorization: @escaping STPPaymentAuthorizationBlock, - onPaymentMethodCreation: @escaping STPApplePayPaymentMethodHandlerBlock, - onFinish: @escaping STPPaymentCompletionBlock - ) -> Self? { - let delegate = STPBlockBasedApplePayDelegate() - delegate.apiClient = apiClient - delegate.onShippingAddressSelection = onShippingAddressSelection - delegate.onShippingMethodSelection = onShippingMethodSelection - delegate.onPaymentAuthorization = onPaymentAuthorization - delegate.onPaymentMethodCreation = onPaymentMethodCreation - delegate.onFinish = onFinish - let viewController = self.init(paymentRequest: paymentRequest) - viewController?.delegate = delegate - if let viewController = viewController { - objc_setAssociatedObject( - viewController, - UnsafeRawPointer(&kSTPBlockBasedApplePayDelegateAssociatedObjectKey), - delegate, - .OBJC_ASSOCIATION_RETAIN_NONATOMIC - ) - } - return viewController - } -} -private var kSTPBlockBasedApplePayDelegateAssociatedObjectKey = 0 typealias STPApplePayShippingMethodCompletionBlock = ( PKPaymentAuthorizationStatus, [PKPaymentSummaryItem]? ) -> Void diff --git a/Stripe/StripeiOS/Source/STPAPIClient+BasicUI.swift b/Stripe/StripeiOS/Source/STPAPIClient+BasicUI.swift index 00e78896600..f7ee681e4d5 100644 --- a/Stripe/StripeiOS/Source/STPAPIClient+BasicUI.swift +++ b/Stripe/StripeiOS/Source/STPAPIClient+BasicUI.swift @@ -47,109 +47,6 @@ extension STPAPIClient { } } - /// Update a customer with parameters - /// - seealso: https://stripe.com/docs/api#update_customer - func updateCustomer( - withParameters parameters: [String: Any], - using ephemeralKey: STPEphemeralKey, - completion: @escaping STPCustomerCompletionBlock - ) { - let endpoint = "\(APIEndpointCustomers)/\(ephemeralKey.customerID ?? "")" - APIRequest.post( - with: self, - endpoint: endpoint, - additionalHeaders: authorizationHeader(using: ephemeralKey), - parameters: parameters - ) { object, _, error in - completion(object, error) - } - } - - /// Attach a Payment Method to a customer - /// - seealso: https://stripe.com/docs/api/payment_methods/attach - func attachPaymentMethod( - _ paymentMethodID: String, - toCustomerUsing ephemeralKey: STPEphemeralKey, - completion: @escaping STPErrorBlock - ) { - guard let customerID = ephemeralKey.customerID else { - assertionFailure() - completion(nil) - return - } - let endpoint = "\(APIEndpointPaymentMethods)/\(paymentMethodID)/attach" - APIRequest.post( - with: self, - endpoint: endpoint, - additionalHeaders: authorizationHeader(using: ephemeralKey), - parameters: [ - "customer": customerID - ] - ) { _, _, error in - completion(error) - } - } - - /// Detach a Payment Method from a customer - /// - seealso: https://stripe.com/docs/api/payment_methods/detach - func detachPaymentMethod( - _ paymentMethodID: String, - fromCustomerUsing ephemeralKey: STPEphemeralKey, - completion: @escaping STPErrorBlock - ) { - let endpoint = "\(APIEndpointPaymentMethods)/\(paymentMethodID)/detach" - APIRequest.post( - with: self, - endpoint: endpoint, - additionalHeaders: authorizationHeader(using: ephemeralKey), - parameters: [:] - ) { _, _, error in - completion(error) - } - } - - /// Retrieves a list of Payment Methods attached to a customer. - /// @note This only fetches card type Payment Methods - func listPaymentMethodsForCustomer( - using ephemeralKey: STPEphemeralKey, - completion: @escaping STPPaymentMethodsCompletionBlock - ) { - let header = authorizationHeader(using: ephemeralKey) - let params: [String: Any] = [ - "customer": ephemeralKey.customerID ?? "", - "type": "card", - ] - APIRequest.getWith( - self, - endpoint: APIEndpointPaymentMethods, - additionalHeaders: header, - parameters: params as [String: Any] - ) { deserializer, _, error in - if let error = error { - completion(nil, error) - } else if let paymentMethods = deserializer?.paymentMethods { - completion(paymentMethods, nil) - } - } - } - - /// Retrieve a customer - /// - seealso: https://stripe.com/docs/api#retrieve_customer - func retrieveCustomer( - using ephemeralKey: STPEphemeralKey, - completion: @escaping STPCustomerCompletionBlock - ) { - let endpoint = "\(APIEndpointCustomers)/\(ephemeralKey.customerID ?? "")" - APIRequest.getWith( - self, - endpoint: endpoint, - additionalHeaders: authorizationHeader(using: ephemeralKey), - parameters: [:] - ) { object, _, error in - completion(object, error) - } - } - // MARK: FPX /// Retrieves the online status of the FPX banks from the Stripe API. /// - Parameter completion: The callback to run with the returned FPX bank list, or an error. diff --git a/Stripe/StripeiOS/Source/STPBankSelectionViewController.swift b/Stripe/StripeiOS/Source/STPBankSelectionViewController.swift index b6fb8cdd235..84a113faae7 100644 --- a/Stripe/StripeiOS/Source/STPBankSelectionViewController.swift +++ b/Stripe/StripeiOS/Source/STPBankSelectionViewController.swift @@ -91,7 +91,6 @@ public class STPBankSelectionViewController: STPCoreTableViewController, UITable private var selectedBank: STPFPXBankBrand = .unknown private var configuration: STPPaymentConfiguration? private weak var imageView: UIImageView? - private var headerView: STPSectionHeaderView? private var loading = false private var bankStatus: STPFPXBankStatusResponse? @@ -128,10 +127,6 @@ public class STPBankSelectionViewController: STPCoreTableViewController, UITable tableView?.reloadData() } - @objc override func useSystemBackButton() -> Bool { - return true - } - func _update(withBankStatus bankStatusResponse: STPFPXBankStatusResponse) { bankStatus = bankStatusResponse diff --git a/Stripe/StripeiOS/Source/STPCameraView.swift b/Stripe/StripeiOS/Source/STPCameraView.swift index 17fa42470b5..c6a6e2010ce 100644 --- a/Stripe/StripeiOS/Source/STPCameraView.swift +++ b/Stripe/StripeiOS/Source/STPCameraView.swift @@ -13,15 +13,6 @@ import UIKit class STPCameraView: UIView { private var flashLayer: CALayer? - var captureSession: AVCaptureSession? { - get { - return (videoPreviewLayer.session)! - } - set(captureSession) { - videoPreviewLayer.session = captureSession - } - } - var videoPreviewLayer: AVCaptureVideoPreviewLayer { return layer as! AVCaptureVideoPreviewLayer } diff --git a/Stripe/StripeiOS/Source/STPCardScanner.swift b/Stripe/StripeiOS/Source/STPCardScanner.swift deleted file mode 100644 index c55e104b467..00000000000 --- a/Stripe/StripeiOS/Source/STPCardScanner.swift +++ /dev/null @@ -1,488 +0,0 @@ -// -// STPCardScanner.swift -// StripeiOS -// -// Created by David Estes on 8/17/20. -// Copyright © 2020 Stripe, Inc. All rights reserved. -// - -import AVFoundation -import Foundation -@_spi(STP) import StripeCore -@_spi(STP) import StripePayments -@_spi(STP) import StripePaymentsUI -import UIKit -import Vision - -enum STPCardScannerError: Int { - /// Camera not available. - case cameraNotAvailable -} - -@available(macCatalyst 14.0, *) -@objc protocol STPCardScannerDelegate: NSObjectProtocol { - @objc(cardScanner:didFinishWithCardParams:error:) func cardScanner( - _ scanner: STPCardScanner, - didFinishWith cardParams: - STPPaymentMethodCardParams?, - error: Error?) -} - -@available(macCatalyst 14.0, *) -@objc(STPCardScanner_legacy) -class STPCardScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate { - // iOS will kill the app if it tries to request the camera without an NSCameraUsageDescription - static let cardScanningAvailableCameraHasUsageDescription = { - return - (Bundle.main.infoDictionary?["NSCameraUsageDescription"] != nil - || Bundle.main.localizedInfoDictionary?["NSCameraUsageDescription"] != nil) - }() - - static var cardScanningAvailable: Bool { - // Always allow in tests: - if NSClassFromString("XCTest") != nil { - return true - } - return cardScanningAvailableCameraHasUsageDescription - } - - weak var cameraView: STPCameraView? - - var feedbackGenerator: UINotificationFeedbackGenerator? - - @objc public var deviceOrientation: UIDeviceOrientation { - get { - return stp_deviceOrientation - } - set(newDeviceOrientation) { - stp_deviceOrientation = newDeviceOrientation - - // This is an optimization for portrait mode: The card will be centered in the screen, - // so we can ignore the top and bottom. We'll use the whole frame in landscape. - let kSTPCardScanningScreenCenter = CGRect( - x: 0, y: CGFloat(0.3), width: 1, height: CGFloat(0.4)) - - // iOS camera image data is returned in LandcapeLeft orientation by default. We'll flip it as needed: - switch newDeviceOrientation { - case .portraitUpsideDown: - videoOrientation = .portraitUpsideDown - textOrientation = .left - regionOfInterest = kSTPCardScanningScreenCenter - case .landscapeLeft: - videoOrientation = .landscapeRight - textOrientation = .up - regionOfInterest = CGRect(x: 0, y: 0, width: 1, height: 1) - case .landscapeRight: - videoOrientation = .landscapeLeft - textOrientation = .down - regionOfInterest = CGRect(x: 0, y: 0, width: 1, height: 1) - case .portrait, .faceUp, .faceDown, .unknown: - fallthrough - default: - videoOrientation = .portrait - textOrientation = .right - regionOfInterest = kSTPCardScanningScreenCenter - } - cameraView?.videoPreviewLayer.connection?.videoOrientation = videoOrientation - } - } - - override init() { - } - - init(delegate: STPCardScannerDelegate?) { - super.init() - self.delegate = delegate - captureSessionQueue = DispatchQueue(label: "com.stripe.CardScanning.CaptureSessionQueue") - deviceOrientation = UIDevice.current.orientation - } - - func start() { - if isScanning { - return - } - STPAnalyticsClient.sharedClient.addClass(toProductUsageIfNecessary: STPCardScanner.self) - startTime = Date() - - isScanning = true - timeoutTime = nil - feedbackGenerator = UINotificationFeedbackGenerator() - feedbackGenerator?.prepare() - - captureSessionQueue?.async(execute: { - #if targetEnvironment(simulator) - // Camera not supported on Simulator - self.stopWithError(STPCardScanner.stp_cardScanningError()) - return - #else - self.detectedNumbers = NSCountedSet() - self.detectedExpirations = NSCountedSet() - self.setupCamera() - DispatchQueue.main.async(execute: { - self.cameraView?.captureSession = self.captureSession - self.cameraView?.videoPreviewLayer.connection?.videoOrientation = - self.videoOrientation - }) - #endif - }) - } - - func stop() { - stopWithError(nil) - } - - private weak var delegate: STPCardScannerDelegate? - private var captureDevice: AVCaptureDevice? - private var captureSession: AVCaptureSession? - private var captureSessionQueue: DispatchQueue? - private var videoDataOutput: AVCaptureVideoDataOutput? - private var videoDataOutputQueue: DispatchQueue? - private var textRequest: VNRecognizeTextRequest? - private var isScanning = false - - private var timeoutTime: Date? - private var didTimeout: Bool { - if let timeoutTime = timeoutTime { - return timeoutTime <= Date() - } - return false - } - - private var stp_deviceOrientation: UIDeviceOrientation! - private var videoOrientation: AVCaptureVideoOrientation! - private var textOrientation: CGImagePropertyOrientation! - private var regionOfInterest = CGRect.zero - private var detectedNumbers = NSCountedSet() - private var detectedExpirations = NSCountedSet() - private var startTime: Date? - - // MARK: Public - - class func stp_cardScanningError() -> Error { - let userInfo = [ - NSLocalizedDescriptionKey: String.Localized.allow_camera_access, - STPError.errorMessageKey: "The camera couldn't be used.", - ] - return NSError( - domain: STPCardScannerErrorDomain, - code: STPCardScannerError.cameraNotAvailable.rawValue, - userInfo: userInfo) - } - - deinit { - if isScanning { - captureDevice?.unlockForConfiguration() - captureSession?.stopRunning() - } - } - - func stopWithError(_ error: Error?) { - if isScanning { - finish(with: nil, error: error) - } - } - - // MARK: Setup - func setupCamera() { - weak var weakSelf = self - textRequest = VNRecognizeTextRequest(completionHandler: { request, error in - let strongSelf = weakSelf - if !(strongSelf?.isScanning ?? false) { - return - } - if error != nil { - strongSelf?.stopWithError(STPCardScanner.stp_cardScanningError()) - return - } - strongSelf?.processVNRequest(request) - }) - - let captureDevice = AVCaptureDevice.default( - .builtInWideAngleCamera, for: .video, position: .back) - self.captureDevice = captureDevice - - captureSession = AVCaptureSession() - captureSession?.sessionPreset = .hd1920x1080 - - var deviceInput: AVCaptureDeviceInput? - do { - if let captureDevice = captureDevice { - deviceInput = try AVCaptureDeviceInput(device: captureDevice) - } - } catch { - stopWithError(STPCardScanner.stp_cardScanningError()) - return - } - - if let deviceInput = deviceInput { - if captureSession?.canAddInput(deviceInput) ?? false { - captureSession?.addInput(deviceInput) - } else { - stopWithError(STPCardScanner.stp_cardScanningError()) - return - } - } - - videoDataOutputQueue = DispatchQueue(label: "com.stripe.CardScanning.VideoDataOutputQueue") - videoDataOutput = AVCaptureVideoDataOutput() - videoDataOutput?.alwaysDiscardsLateVideoFrames = true - videoDataOutput?.setSampleBufferDelegate(self, queue: videoDataOutputQueue) - - // This is the recommended pixel buffer format for Vision: - videoDataOutput?.videoSettings = [ - kCVPixelBufferPixelFormatTypeKey as String: - kCVPixelFormatType_420YpCbCr8BiPlanarFullRange, - ] - - if let videoDataOutput = videoDataOutput { - if captureSession?.canAddOutput(videoDataOutput) ?? false { - captureSession?.addOutput(videoDataOutput) - } else { - stopWithError(STPCardScanner.stp_cardScanningError()) - return - } - } - - // This improves recognition quality, but means the VideoDataOutput buffers won't match what we're seeing on screen. - videoDataOutput?.connection(with: .video)?.preferredVideoStabilizationMode = .auto - - captureSession?.startRunning() - - do { - try self.captureDevice?.lockForConfiguration() - self.captureDevice?.autoFocusRangeRestriction = .near - } catch { - } - } - - // MARK: Processing - func captureOutput( - _ output: AVCaptureOutput, - didOutput sampleBuffer: CMSampleBuffer, - from connection: AVCaptureConnection - ) { - if !isScanning { - return - } - let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) - if pixelBuffer == nil { - return - } - textRequest?.recognitionLevel = .accurate - textRequest?.usesLanguageCorrection = false - textRequest?.regionOfInterest = regionOfInterest - var handler: VNImageRequestHandler? - if let pixelBuffer = pixelBuffer { - handler = VNImageRequestHandler( - cvPixelBuffer: pixelBuffer, orientation: textOrientation, options: [:]) - } - do { - try handler?.perform([textRequest].compactMap { $0 }) - } catch { - } - } - - func processVNRequest(_ request: VNRequest) { - var allNumbers: [String] = [] - for observation in request.results ?? [] { - guard let observation = observation as? VNRecognizedTextObservation else { - continue - } - let candidates = observation.topCandidates(5) - let topCandidate = candidates.first?.string - if STPCardValidator.sanitizedNumericString(for: topCandidate ?? "").count >= 4 { - allNumbers.append(topCandidate ?? "") - } - for recognizedText in candidates { - let possibleNumber = STPCardValidator.sanitizedNumericString( - for: recognizedText.string) - if possibleNumber.count < 4 { - continue // This probably isn't something we're interested in, so don't bother processing it. - } - - // First strategy: We check if Vision sent us a number in a group on its own. If that fails, we'll try - // to catch it later when we iterate over all the numbers. - if STPCardValidator.validationState( - forNumber: possibleNumber, validatingCardBrand: true) - == .valid - { - addDetectedNumber(possibleNumber) - } else if possibleNumber.count >= 4 && possibleNumber.count <= 6 - && STPStringUtils.stringMayContainExpirationDate(recognizedText.string) - { - // Try to parse anything that looks like an expiration date. - let expirationString = STPStringUtils.expirationDateString( - from: recognizedText.string) - let sanitizedExpiration = STPCardValidator.sanitizedNumericString( - for: expirationString ?? "") - let month = (sanitizedExpiration as NSString).substring(to: 2) - let year = (sanitizedExpiration as NSString).substring(from: 2) - - // Ignore expiration dates 10+ years in the future, as they're likely to be incorrect recognitions - let calendar = Calendar(identifier: .gregorian) - let presentYear = calendar.component(.year, from: Date()) - let maxYear = (presentYear % 100) + 10 - - if STPCardValidator.validationState(forExpirationYear: year, inMonth: month) - == .valid - && Int(year) ?? 0 < maxYear - { - addDetectedExpiration(sanitizedExpiration) - } - } - } - } - // Second strategy: We look for consecutive groups of 4/4/4/4 or 4/6/5 - // Vision is sending us groups like ["1234 565", "1234 1"], so we'll normalize these into groups with spaces: - let allGroups = allNumbers.joined(separator: " ").components(separatedBy: " ") - if allGroups.count < 3 { - return - } - for i in 0..<(allGroups.count - 3) { - let string1 = allGroups[i] - let string2 = allGroups[i + 1] - let string3 = allGroups[i + 2] - var string4 = "" - if i + 3 < allGroups.count { - string4 = allGroups[i + 3] - } - // Then we'll go through each group and build a potential match: - let potentialCardString = "\(string1)\(string2)\(string3)\(string4)" - let potentialAmexString = "\(string1)\(string2)\(string3)" - - // Then we'll add valid matches. It's okay if we add a number a second time after doing so above, as the success of that first pass means it's more likely to be a good match. - if STPCardValidator.validationState( - forNumber: potentialCardString, validatingCardBrand: true) - == .valid - { - addDetectedNumber(potentialCardString) - } else if STPCardValidator.validationState( - forNumber: potentialAmexString, validatingCardBrand: true) == .valid - { - addDetectedNumber(potentialAmexString) - } - } - } - - func addDetectedNumber(_ number: String) { - detectedNumbers.add(number) - - // Set a timeout: If we don't get enough scans in the next 0.6 seconds, we'll use the best option we have. - if timeoutTime == nil { - self.timeoutTime = Date().addingTimeInterval(kSTPCardScanningTimeout) - weak var weakSelf = self - DispatchQueue.main.async(execute: { - let strongSelf = weakSelf - strongSelf?.cameraView?.playSnapshotAnimation() - strongSelf?.feedbackGenerator?.notificationOccurred(.success) - }) - // Just in case we don't get any frames, add another call to `finishIfReady` after timeoutTime to check - videoDataOutputQueue?.asyncAfter( - deadline: DispatchTime.now() + kSTPCardScanningTimeout, - execute: { - let strongSelf = weakSelf - if strongSelf?.isScanning ?? false { - strongSelf?.finishIfReady() - } - }) - } - - if (detectedNumbers.count(for: number)) >= kSTPCardScanningMinimumValidScans { - finishIfReady() - } - } - - func addDetectedExpiration(_ expiration: String) { - detectedExpirations.add(expiration) - if (detectedExpirations.count(for: expiration)) >= kSTPCardScanningMinimumValidScans { - finishIfReady() - } - } - - // MARK: Completion - func finishIfReady() { - if !isScanning { - return - } - let detectedNumbers = self.detectedNumbers - let detectedExpirations = self.detectedExpirations - - let topNumber = (detectedNumbers.allObjects as NSArray).sortedArray(comparator: { - obj1, obj2 in - let c1 = detectedNumbers.count(for: obj1) - let c2 = detectedNumbers.count(for: obj2) - if c1 < c2 { - return .orderedAscending - } else if c1 > c2 { - return .orderedDescending - } else { - return .orderedSame - } - }).last - let topExpiration = (detectedExpirations.allObjects as NSArray).sortedArray(comparator: { - obj1, obj2 in - let c1 = detectedExpirations.count(for: obj1) - let c2 = detectedExpirations.count(for: obj2) - if c1 < c2 { - return .orderedAscending - } else if c1 > c2 { - return .orderedDescending - } else { - return .orderedSame - } - }).last - - var didSeeEnoughScans = false - if let topNumber = topNumber, let topExpiration = topExpiration { - didSeeEnoughScans = detectedNumbers.count(for: topNumber) >= kSTPCardScanningMinimumValidScans && - detectedExpirations.count(for: topExpiration) >= kSTPCardScanningMinimumValidScans - } - if didTimeout || didSeeEnoughScans { - let params = STPPaymentMethodCardParams() - params.number = topNumber as? String - if let topExpiration = topExpiration { - params.expMonth = NSNumber( - value: Int((topExpiration as! NSString).substring(to: 2)) ?? 0) - params.expYear = NSNumber( - value: Int((topExpiration as! NSString).substring(from: 2)) ?? 0) - } - finish(with: params, error: nil) - } - } - - func finish(with params: STPPaymentMethodCardParams?, error: Error?) { - var duration: TimeInterval? - if let startTime = startTime { - duration = Date().timeIntervalSince(startTime) - } - isScanning = false - captureDevice?.unlockForConfiguration() - captureSession?.stopRunning() - - DispatchQueue.main.async(execute: { - if params == nil { - STPAnalyticsClient.sharedClient.logCardScanCancelled(withDuration: duration ?? 0.0) - } else { - STPAnalyticsClient.sharedClient.logCardScanSucceeded(withDuration: duration ?? 0.0) - } - self.feedbackGenerator = nil - - self.cameraView?.captureSession = nil - self.delegate?.cardScanner(self, didFinishWith: params, error: error) - }) - } - - // MARK: Orientation -} - -// The number of successful scans required for both card number and expiration date before returning a result. -private let kSTPCardScanningMinimumValidScans = 2 -// Once one successful scan is found, we'll stop scanning after this many seconds. -private let kSTPCardScanningTimeout: TimeInterval = 0.6 -let STPCardScannerErrorDomain = "STPCardScannerErrorDomain" - -/// :nodoc: -@available(macCatalyst 14.0, *) -extension STPCardScanner: STPAnalyticsProtocol { - static var stp_analyticsIdentifier = "STPCardScanner" -} diff --git a/Stripe/StripeiOS/Source/STPCardScannerTableViewCell.swift b/Stripe/StripeiOS/Source/STPCardScannerTableViewCell.swift deleted file mode 100644 index 7692e148785..00000000000 --- a/Stripe/StripeiOS/Source/STPCardScannerTableViewCell.swift +++ /dev/null @@ -1,67 +0,0 @@ -// -// STPCardScannerTableViewCell.swift -// StripeiOS -// -// Created by David Estes on 8/17/20. -// Copyright © 2020 Stripe, Inc. All rights reserved. -// - -import UIKit - -@available(macCatalyst 14.0, *) -class STPCardScannerTableViewCell: UITableViewCell { - private(set) weak var cameraView: STPCameraView? - - private var _theme: STPTheme? - var theme: STPTheme? { - get { - _theme - } - set(theme) { - _theme = theme - updateAppearance() - } - } - - let cardSizeRatio: CGFloat = 2.125 / 3.370 // ID-1 card size (in inches) - - override init( - style: UITableViewCell.CellStyle, - reuseIdentifier: String? - ) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - let cameraView = STPCameraView(frame: bounds) - contentView.addSubview(cameraView) - self.cameraView = cameraView - theme = STPTheme.defaultTheme - self.cameraView?.translatesAutoresizingMaskIntoConstraints = false - contentView.addConstraints( - [ - cameraView.heightAnchor.constraint( - equalTo: cameraView.widthAnchor, - multiplier: cardSizeRatio - ), - cameraView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 0), - cameraView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 0), - cameraView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: 0), - cameraView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 0), - ]) - updateAppearance() - } - - override func layoutSubviews() { - - super.layoutSubviews() - } - - @objc func updateAppearance() { - // The first few frames of the camera view will be black, so our background should be black too. - cameraView?.backgroundColor = UIColor.black - } - - required init?( - coder aDecoder: NSCoder - ) { - super.init(coder: aDecoder) - } -} diff --git a/Stripe/StripeiOS/Source/STPCoreViewController.swift b/Stripe/StripeiOS/Source/STPCoreViewController.swift index 20f66879e6b..a62803667e5 100644 --- a/Stripe/StripeiOS/Source/STPCoreViewController.swift +++ b/Stripe/StripeiOS/Source/STPCoreViewController.swift @@ -69,23 +69,6 @@ public class STPCoreViewController: UIViewController { _theme = .defaultTheme } -// if !useSystemBackButton() { -// cancelItem = UIBarButtonItem( -// barButtonSystemItem: .cancel, -// target: self, -// action: #selector(STPAddCardViewController.handleCancelTapped(_:)) -// ) -// cancelItem?.accessibilityIdentifier = "CoreViewControllerCancelIdentifier" -// -// stp_navigationItemProxy?.leftBarButtonItem = cancelItem -// } -// -// NotificationCenter.default.addObserver( -// self, -// selector: #selector(STPAddCardViewController.updateAppearance), -// name: UIContentSizeCategory.didChangeNotification, -// object: nil -// ) } /// Called in viewDidLoad after doing base implementation, before @@ -151,12 +134,4 @@ public class STPCoreViewController: UIViewController { } } - /// If you override this and return YES, then your CoreVC implementation will not - /// create and set up a cancel and instead just use the default - /// UIViewController back button behavior. - /// You won't receive calls to `handleCancelTapped` if this is YES. - /// Defaults to NO. - func useSystemBackButton() -> Bool { - return false - } } diff --git a/Stripe/StripeiOS/Source/STPPaymentCardTextFieldCell.swift b/Stripe/StripeiOS/Source/STPPaymentCardTextFieldCell.swift deleted file mode 100644 index 40112d5dea9..00000000000 --- a/Stripe/StripeiOS/Source/STPPaymentCardTextFieldCell.swift +++ /dev/null @@ -1,91 +0,0 @@ -// -// STPPaymentCardTextFieldCell.swift -// StripeiOS -// -// Created by Jack Flintermann on 6/16/16. -// Copyright © 2016 Stripe, Inc. All rights reserved. -// - -@_spi(STP) import StripePaymentsUI -import UIKit - -class STPPaymentCardTextFieldCell: UITableViewCell { - private(set) weak var paymentField: STPPaymentCardTextField? - - var theme: STPTheme = STPTheme.defaultTheme { - didSet { - updateAppearance() - } - } - - private var _inputAccessoryView: UIView? - override var inputAccessoryView: UIView? { - get { - _inputAccessoryView - } - set(inputAccessoryView) { - _inputAccessoryView = inputAccessoryView - paymentField?.inputAccessoryView = inputAccessoryView - } - } - - func isEmpty() -> Bool { - return (paymentField?.cardNumber?.count ?? 0) == 0 - } - - override init( - style: UITableViewCell.CellStyle, - reuseIdentifier: String? - ) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - let paymentField = STPPaymentCardTextField(frame: bounds) - paymentField.postalCodeEntryEnabled = false - contentView.addSubview(paymentField) - self.paymentField = paymentField - theme = STPTheme.defaultTheme - updateAppearance() - } - - override func layoutSubviews() { - super.layoutSubviews() - paymentField?.frame = contentView.bounds - } - - @objc func updateAppearance() { - paymentField?.backgroundColor = UIColor.clear - paymentField?.placeholderColor = theme.tertiaryForegroundColor - paymentField?.borderColor = UIColor.clear - paymentField?.textColor = theme.primaryForegroundColor - paymentField?.textErrorColor = theme.errorColor - paymentField?.font = theme.font - backgroundColor = theme.secondaryBackgroundColor - } - - @objc override func becomeFirstResponder() -> Bool { - return paymentField?.becomeFirstResponder() ?? false - } - - override func accessibilityElementCount() -> Int { - return paymentField?.allFields.count ?? 0 - } - - override func accessibilityElement(at index: Int) -> Any? { - return paymentField?.allFields[index] - } - - override func index(ofAccessibilityElement element: Any) -> Int { - let fields = paymentField?.allFields - for i in 0..<(fields?.count ?? 0) { - if (element as? AnyHashable) == fields?[i] { - return i - } - } - return 0 - } - - required init?( - coder aDecoder: NSCoder - ) { - super.init(coder: aDecoder) - } -} diff --git a/Stripe/StripeiOS/Source/STPPaymentContextAmountModel.swift b/Stripe/StripeiOS/Source/STPPaymentContextAmountModel.swift deleted file mode 100644 index c79c13e2041..00000000000 --- a/Stripe/StripeiOS/Source/STPPaymentContextAmountModel.swift +++ /dev/null @@ -1,96 +0,0 @@ -// -// STPPaymentContextAmountModel.swift -// StripeiOS -// -// Created by Brian Dorfman on 8/16/16. -// Copyright © 2016 Stripe, Inc. All rights reserved. -// - -import Foundation -import PassKit -@_spi(STP) import StripePayments - -/// Internal model for STPPaymentContext's `paymentAmount` and -/// `paymentSummaryItems` properties. -class STPPaymentContextAmountModel: NSObject { - private var paymentAmount = 0 - private var paymentSummaryItems: [PKPaymentSummaryItem]? - - init( - amount paymentAmount: Int - ) { - super.init() - self.paymentAmount = paymentAmount - paymentSummaryItems = nil - } - - init( - paymentSummaryItems: [PKPaymentSummaryItem]? - ) { - super.init() - paymentAmount = 0 - self.paymentSummaryItems = paymentSummaryItems - } - - func paymentAmount(withCurrency currency: String?, shippingMethod: PKShippingMethod?) -> Int { - let shippingAmount = - ((shippingMethod != nil) - ? shippingMethod?.amount.stp_amount(withCurrency: currency) : 0) ?? 0 - if paymentSummaryItems == nil { - return paymentAmount + shippingAmount - } else { - let lastItem = paymentSummaryItems?.last - return (lastItem?.amount.stp_amount(withCurrency: currency) ?? 0) + shippingAmount - } - } - - func paymentSummaryItems( - withCurrency currency: String?, - companyName: String?, - shippingMethod: PKShippingMethod? - ) -> [PKPaymentSummaryItem]? { - var shippingItem: PKPaymentSummaryItem? - if let shippingMethod = shippingMethod { - shippingItem = PKPaymentSummaryItem( - label: shippingMethod.label, - amount: shippingMethod.amount - ) - } - if paymentSummaryItems == nil { - let shippingAmount = shippingMethod?.amount.stp_amount(withCurrency: currency) ?? 0 - let total = NSDecimalNumber.stp_decimalNumber( - withAmount: paymentAmount + shippingAmount, - currency: currency - ) - let totalItem = PKPaymentSummaryItem(label: companyName ?? "", amount: total) - var items = [totalItem] - if let shippingItem = shippingItem { - items.insert(shippingItem, at: 0) - } - return items.compactMap { $0 } - } else { - if (paymentSummaryItems?.count ?? 0) > 0 && shippingItem != nil { - var items = paymentSummaryItems - let origTotalItem = items?.last - var newTotal: NSDecimalNumber? - if let amount1 = shippingItem?.amount { - newTotal = origTotalItem?.amount.adding(amount1) - } - var totalItem: PKPaymentSummaryItem? - if let newTotal = newTotal { - totalItem = PKPaymentSummaryItem( - label: origTotalItem?.label ?? "", - amount: newTotal - ) - } - items?.removeLast() - if let items = items { - return items + [shippingItem, totalItem].compactMap { $0 } - } - return nil - } else { - return paymentSummaryItems - } - } - } -} diff --git a/Stripe/StripeiOS/Source/STPPaymentOptionTableViewCell.swift b/Stripe/StripeiOS/Source/STPPaymentOptionTableViewCell.swift deleted file mode 100644 index 9d6bb81ccbe..00000000000 --- a/Stripe/StripeiOS/Source/STPPaymentOptionTableViewCell.swift +++ /dev/null @@ -1,326 +0,0 @@ -// -// STPPaymentOptionTableViewCell.swift -// StripeiOS -// -// Created by Ben Guo on 8/30/16. -// Copyright © 2016 Stripe, Inc. All rights reserved. -// - -@_spi(STP) import StripeCore -@_spi(STP) import StripePaymentsUI -import UIKit - -class STPPaymentOptionTableViewCell: UITableViewCell { - @objc(configureForNewCardRowWithTheme:) func configureForNewCardRow(with theme: STPTheme) { - paymentOption = nil - self.theme = theme - - backgroundColor = theme.secondaryBackgroundColor - - // Left icon - leftIcon.image = STPLegacyImageLibrary.addIcon() - leftIcon.tintColor = theme.accentColor - - // Title label - titleLabel.font = theme.font - titleLabel.textColor = theme.accentColor - titleLabel.text = STPLocalizedString("Add New Card…", "Button to add a new credit card.") - - // Checkmark icon - checkmarkIcon.isHidden = true - - setNeedsLayout() - } - - @objc(configureWithPaymentOption:theme:selected:) func configure( - with paymentOption: STPPaymentOption?, - theme: STPTheme, - selected: Bool - ) { - self.paymentOption = paymentOption - self.theme = theme - - backgroundColor = theme.secondaryBackgroundColor - - // Left icon - leftIcon.image = paymentOption?.templateImage - leftIcon.tintColor = primaryColorForPaymentOption(withSelected: selected) - - // Title label - titleLabel.font = theme.font - titleLabel.attributedText = buildAttributedString(with: paymentOption, selected: selected) - - // Checkmark icon - checkmarkIcon.tintColor = theme.accentColor - checkmarkIcon.isHidden = !selected - - // Accessibility - if selected { - accessibilityTraits.insert(.selected) - } else { - accessibilityTraits.remove(.selected) - } - - setNeedsLayout() - } - - @objc(configureForFPXRowWithTheme:) func configureForFPXRow(with theme: STPTheme) { - paymentOption = nil - self.theme = theme - - backgroundColor = theme.secondaryBackgroundColor - - // Left icon - leftIcon.image = STPImageLibrary.bankIcon() - leftIcon.tintColor = primaryColorForPaymentOption(withSelected: false) - - // Title label - titleLabel.font = theme.font - titleLabel.textColor = self.theme.primaryForegroundColor - titleLabel.text = STPLocalizedString( - "Online Banking (FPX)", - "Button to pay with a Bank Account (using FPX)." - ) - - // Checkmark icon - checkmarkIcon.isHidden = true - accessoryType = .disclosureIndicator - setNeedsLayout() - } - - private var paymentOption: STPPaymentOption? - private var theme: STPTheme = .defaultTheme - private var leftIcon = UIImageView() - private var titleLabel = UILabel() - private var checkmarkIcon = UIImageView(image: STPLegacyImageLibrary.checkmarkIcon()) - - override init( - style: UITableViewCell.CellStyle, - reuseIdentifier: String? - ) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - // Left icon - leftIcon.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview(leftIcon) - - // Title label - titleLabel.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview(titleLabel) - - // Checkmark icon - checkmarkIcon.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview(checkmarkIcon) - - NSLayoutConstraint.activate( - [ - self.leftIcon.centerXAnchor.constraint( - equalTo: contentView.leadingAnchor, - constant: kPadding + 0.5 * kDefaultIconWidth - ), - self.leftIcon.centerYAnchor.constraint( - lessThanOrEqualTo: contentView.centerYAnchor - ), - self.checkmarkIcon.widthAnchor.constraint(equalToConstant: kCheckmarkWidth), - self.checkmarkIcon.heightAnchor.constraint( - equalTo: self.checkmarkIcon.widthAnchor, - multiplier: 1.0 - ), - self.checkmarkIcon.centerXAnchor.constraint( - equalTo: contentView.trailingAnchor, - constant: -kPadding - ), - self.checkmarkIcon.centerYAnchor.constraint(equalTo: contentView.centerYAnchor), - // Constrain label to leadingAnchor with the default - // icon width so that the text always aligns vertically - // even if the icond widths differ - self.titleLabel.leadingAnchor.constraint( - equalTo: contentView.leadingAnchor, - constant: 2.0 * kPadding + kDefaultIconWidth - ), - self.titleLabel.trailingAnchor.constraint( - equalTo: self.checkmarkIcon.leadingAnchor, - constant: -kPadding - ), - self.titleLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor), - ]) - accessibilityTraits.insert(.button) - isAccessibilityElement = true - } - - func primaryColorForPaymentOption(withSelected selected: Bool) -> UIColor { - let fadedColor: UIColor = UIColor(dynamicProvider: { _ in - return self.theme.primaryForegroundColor.withAlphaComponent(0.6) - }) - - return (selected ? theme.accentColor : fadedColor) - } - - func buildAttributedString( - with paymentOption: STPPaymentOption?, - selected: Bool - ) - -> NSAttributedString - { - if let paymentOption = paymentOption as? STPCard { - return buildAttributedString(with: paymentOption, selected: selected) - } else if let source = paymentOption as? STPSource { - if source.type == .card && source.cardDetails != nil { - return buildAttributedString(withCardSource: source, selected: selected) - } - } else if let paymentMethod = paymentOption as? STPPaymentMethod { - if paymentMethod.type == .card && paymentMethod.card != nil { - return buildAttributedString( - withCardPaymentMethod: paymentMethod, - selected: selected - ) - } - if paymentMethod.type == .FPX && paymentMethod.fpx != nil { - return buildAttributedString( - with: STPFPXBank.brandFrom(paymentMethod.fpx?.bankIdentifierCode), - selected: selected - ) - } - } else if paymentOption is STPApplePayPaymentOption { - let label = String.Localized.apple_pay - let primaryColor = primaryColorForPaymentOption(withSelected: selected) - return NSAttributedString( - string: label, - attributes: [ - NSAttributedString.Key.foregroundColor: primaryColor - ] - ) - } else if let paymentMethodParams = paymentOption as? STPPaymentMethodParams { - if paymentMethodParams.type == .card && paymentMethodParams.card != nil { - return buildAttributedString( - withCardPaymentMethodParams: paymentMethodParams, - selected: selected - ) - } - if paymentMethodParams.type == .FPX && paymentMethodParams.fpx != nil { - return buildAttributedString( - with: paymentMethodParams.fpx?.bank ?? STPFPXBankBrand.unknown, - selected: selected - ) - } - } - - // Unrecognized payment method - return NSAttributedString(string: "") - } - - func buildAttributedString(with card: STPCard, selected: Bool) -> NSAttributedString { - return buildAttributedString( - with: card.brand, - last4: card.last4, - selected: selected - ) - } - - func buildAttributedString(withCardSource card: STPSource, selected: Bool) -> NSAttributedString - { - return buildAttributedString( - with: card.cardDetails?.brand ?? .unknown, - last4: card.cardDetails?.last4 ?? "", - selected: selected - ) - } - - func buildAttributedString( - withCardPaymentMethod paymentMethod: STPPaymentMethod, - selected: Bool - ) - -> NSAttributedString - { - return buildAttributedString( - with: paymentMethod.card?.preferredDisplayBrand ?? .unknown, - last4: paymentMethod.card?.last4 ?? "", - selected: selected - ) - } - - func buildAttributedString( - withCardPaymentMethodParams paymentMethodParams: STPPaymentMethodParams, - selected: Bool - ) -> NSAttributedString { - let brand = paymentMethodParams.card?.preferredDisplayBrand ?? .unknown - return buildAttributedString( - with: brand, - last4: paymentMethodParams.card?.last4 ?? "", - selected: selected - ) - } - - func buildAttributedString( - with bankBrand: STPFPXBankBrand, - selected: Bool - ) - -> NSAttributedString - { - let label = (STPFPXBank.stringFrom(bankBrand) ?? "") + " (FPX)" - let primaryColor = primaryColorForPaymentOption(withSelected: selected) - return NSAttributedString( - string: label, - attributes: [ - NSAttributedString.Key.foregroundColor: primaryColor - ] - ) - } - - func buildAttributedString( - with brand: STPCardBrand, - last4: String, - selected: Bool - ) -> NSAttributedString { - let format = String.Localized.card_brand_ending_in_last_4 - let brandString = STPCard.string(from: brand) - let label = String(format: format, brandString, last4) - - let primaryColor = selected ? theme.accentColor : theme.primaryForegroundColor - - let secondaryColor = UIColor(dynamicProvider: { _ in - return primaryColor.withAlphaComponent(0.6) - }) - - let attributes: [NSAttributedString.Key: Any] = [ - NSAttributedString.Key.foregroundColor: secondaryColor, - NSAttributedString.Key.font: self.theme.font, - ] - - let attributedString = NSMutableAttributedString( - string: label, - attributes: attributes as [NSAttributedString.Key: Any] - ) - attributedString.addAttribute( - .foregroundColor, - value: primaryColor, - range: (label as NSString).range(of: brandString) - ) - attributedString.addAttribute( - .foregroundColor, - value: primaryColor, - range: (label as NSString).range(of: last4) - ) - attributedString.addAttribute( - .font, - value: theme.emphasisFont, - range: (label as NSString).range(of: brandString) - ) - attributedString.addAttribute( - .font, - value: theme.emphasisFont, - range: (label as NSString).range(of: last4) - ) - - return attributedString - } - - required init?( - coder aDecoder: NSCoder - ) { - super.init(coder: aDecoder) - } -} - -private let kDefaultIconWidth: CGFloat = 26.0 -private let kPadding: CGFloat = 15.0 -private let kCheckmarkWidth: CGFloat = 14.0 diff --git a/Stripe/StripeiOS/Source/STPPaymentOptionTuple.swift b/Stripe/StripeiOS/Source/STPPaymentOptionTuple.swift deleted file mode 100644 index 6084d1329a1..00000000000 --- a/Stripe/StripeiOS/Source/STPPaymentOptionTuple.swift +++ /dev/null @@ -1,88 +0,0 @@ -// -// STPPaymentOptionTuple.swift -// StripeiOS -// -// Created by Jack Flintermann on 5/17/16. -// Copyright © 2016 Stripe, Inc. All rights reserved. -// - -import Foundation - -class STPPaymentOptionTuple: NSObject { - @objc - public convenience init( - paymentOptions: [STPPaymentOption], - selectedPaymentOption: STPPaymentOption? - ) { - self.init() - self.paymentOptions = paymentOptions - self.selectedPaymentOption = selectedPaymentOption - } - - @objc - public convenience init( - paymentOptions: [STPPaymentOption], - selectedPaymentOption: STPPaymentOption?, - addApplePayOption applePayEnabled: Bool, - addFPXOption fpxEnabled: Bool - ) { - var mutablePaymentOptions = paymentOptions - weak var selected = selectedPaymentOption - - if applePayEnabled { - let applePay = STPApplePayPaymentOption() - mutablePaymentOptions.append(applePay) - - if selected == nil { - selected = applePay - } - } - - if fpxEnabled { - let fpx = STPPaymentMethodFPXParams() - let fpxPaymentOption = STPPaymentMethodParams( - fpx: fpx, - billingDetails: nil, - metadata: nil - ) - mutablePaymentOptions.append(fpxPaymentOption) - } - - self.init( - paymentOptions: mutablePaymentOptions, - selectedPaymentOption: selected - ) - } - - /// Returns a tuple for the given array of STPPaymentMethod, filtered to only include the - /// the types supported by STPPaymentContext/STPPaymentOptionsViewController and adding - /// Apple Pay as a method if appropriate. - /// - Returns: A new tuple ready to be used by the SDK's UI elements - @objc(tupleFilteredForUIWithPaymentMethods:selectedPaymentMethod:configuration:) - public convenience init( - filteredForUIWith paymentMethods: [STPPaymentMethod], - selectedPaymentMethod selectedPaymentMethodID: String?, - configuration: STPPaymentConfiguration - ) { - var paymentOptions: [STPPaymentOption] = [] - var selectedPaymentMethod: STPPaymentMethod? - for paymentMethod in paymentMethods { - if paymentMethod.type == .card { - paymentOptions.append(paymentMethod) - if paymentMethod.stripeId == selectedPaymentMethodID { - selectedPaymentMethod = paymentMethod - } - } - } - - self.init( - paymentOptions: paymentOptions, - selectedPaymentOption: selectedPaymentMethod, - addApplePayOption: configuration.applePayEnabled, - addFPXOption: configuration.fpxEnabled - ) - } - - private(set) weak var selectedPaymentOption: STPPaymentOption? - private(set) var paymentOptions: [STPPaymentOption] = [] -} diff --git a/Stripe/StripeiOS/Source/STPSectionHeaderView.swift b/Stripe/StripeiOS/Source/STPSectionHeaderView.swift deleted file mode 100644 index 2b45b2af198..00000000000 --- a/Stripe/StripeiOS/Source/STPSectionHeaderView.swift +++ /dev/null @@ -1,161 +0,0 @@ -// -// STPSectionHeaderView.swift -// StripeiOS -// -// Created by Ben Guo on 1/3/17. -// Copyright © 2017 Stripe, Inc. All rights reserved. -// - -import UIKit - -class STPSectionHeaderView: UIView { - private var _theme: STPTheme = STPTheme.defaultTheme - var theme: STPTheme { - get { - _theme - } - set(theme) { - _theme = theme - updateAppearance() - } - } - - private var _title: String? - var title: String? { - get { - _title - } - set(title) { - _title = title - if let title = title { - let style = NSMutableParagraphStyle() - style.firstLineHeadIndent = 15 - style.headIndent = style.firstLineHeadIndent - let attributes = [ - NSAttributedString.Key.paragraphStyle: style - ] - label?.attributedText = NSAttributedString( - string: title, - attributes: attributes - ) - } else { - label?.attributedText = nil - } - setNeedsLayout() - } - } - weak var button: UIButton? - - private var _buttonHidden = false - var buttonHidden: Bool { - get { - _buttonHidden - } - set(buttonHidden) { - _buttonHidden = buttonHidden - button?.alpha = buttonHidden ? 0 : 1 - } - } - private weak var label: UILabel? - private let buttonInsets = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 15) - - override init( - frame: CGRect - ) { - super.init(frame: frame) - let label = UILabel() - label.numberOfLines = 0 - label.lineBreakMode = .byWordWrapping - label.accessibilityTraits.insert(.header) - addSubview(label) - self.label = label - let button = UIButton(type: .system) - button.contentHorizontalAlignment = .right - button.titleLabel?.numberOfLines = 0 - button.titleLabel?.lineBreakMode = .byWordWrapping - button.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 15) - button.contentEdgeInsets = .zero - addSubview(button) - self.button = button - backgroundColor = UIColor.clear - updateAppearance() - } - - @objc func updateAppearance() { - label?.font = theme.smallFont - label?.textColor = theme.secondaryForegroundColor - button?.titleLabel?.font = theme.smallFont - button?.tintColor = theme.accentColor - } - - override func layoutSubviews() { - super.layoutSubviews() - let bounds = stp_boundsWithHorizontalSafeAreaInsets() - if buttonHidden { - label?.frame = bounds - } else { - let halfWidth = bounds.size.width / 2 - let heightThatFits = self.heightThatFits(bounds.size) - label?.frame = CGRect( - x: bounds.origin.x, - y: bounds.origin.y, - width: halfWidth, - height: heightThatFits - ) - button?.frame = CGRect( - x: bounds.origin.x + halfWidth, - y: bounds.origin.y, - width: halfWidth, - height: heightThatFits - ) - } - } - - func heightThatFits(_ size: CGSize) -> CGFloat { - let labelPadding: CGFloat = 16 - if buttonHidden { - let labelHeight = label?.sizeThatFits(size).height ?? 0.0 - return labelHeight + labelPadding - } else { - let halfSize = CGSize(width: size.width / 2, height: size.height) - let labelHeight = (label?.sizeThatFits(halfSize).height ?? 0.0) + labelPadding - let buttonHeight = height( - forButtonText: button?.titleLabel?.text, - width: halfSize.width - ) - return CGFloat(max(buttonHeight, labelHeight)) - } - } - - private func height(forButtonText text: String?, width: CGFloat) -> CGFloat { - let insets = buttonInsets - let textSize = CGSize( - width: width - insets.left - insets.right, - height: CGFloat.greatestFiniteMagnitude - ) - var attributes: [NSAttributedString.Key: Any]? - if let font1 = button?.titleLabel?.font { - attributes = [ - NSAttributedString.Key.font: font1 - ] - } - let buttonSize = - text?.boundingRect( - with: textSize, - options: .usesLineFragmentOrigin, - attributes: attributes, - context: nil - ).size ?? .zero - return buttonSize.height + insets.top + insets.bottom - } - - override func sizeThatFits(_ size: CGSize) -> CGSize { - return CGSize(width: size.width, height: heightThatFits(size)) - } - - required init?( - coder aDecoder: NSCoder - ) { - super.init(coder: aDecoder) - } -} diff --git a/Stripe/StripeiOS/Source/STPShippingMethodTableViewCell.swift b/Stripe/StripeiOS/Source/STPShippingMethodTableViewCell.swift deleted file mode 100644 index f40c493c022..00000000000 --- a/Stripe/StripeiOS/Source/STPShippingMethodTableViewCell.swift +++ /dev/null @@ -1,147 +0,0 @@ -// -// STPShippingMethodTableViewCell.swift -// StripeiOS -// -// Created by Ben Guo on 8/30/16. -// Copyright © 2016 Stripe, Inc. All rights reserved. -// - -import PassKit -@_spi(STP) import StripePayments -import UIKit - -class STPShippingMethodTableViewCell: UITableViewCell { - private var _theme: STPTheme? - var theme: STPTheme? { - get { - _theme - } - set(theme) { - _theme = theme - updateAppearance() - } - } - - func setShippingMethod(_ method: PKShippingMethod, currency: String) { - shippingMethod = method - titleLabel?.text = method.label - subtitleLabel?.text = method.detail - var localeInfo = [ - NSLocale.Key.currencyCode.rawValue: currency - ] - localeInfo[NSLocale.Key.languageCode.rawValue] = NSLocale.preferredLanguages.first ?? "" - let localeID = NSLocale.localeIdentifier(fromComponents: localeInfo) - let locale = NSLocale(localeIdentifier: localeID) - numberFormatter?.locale = locale as Locale - let amount = method.amount.stp_amount(withCurrency: currency) - if amount == 0 { - amountLabel?.text = STPLocalizedString("Free", "Label for free shipping method") - } else { - let number = NSDecimalNumber.stp_decimalNumber( - withAmount: amount, - currency: currency - ) - amountLabel?.text = numberFormatter?.string(from: number) - } - setNeedsLayout() - } - - private weak var titleLabel: UILabel? - private weak var subtitleLabel: UILabel? - private weak var amountLabel: UILabel? - private weak var checkmarkIcon: UIImageView? - private var shippingMethod: PKShippingMethod? - private var numberFormatter: NumberFormatter? - - override init( - style: UITableViewCell.CellStyle, - reuseIdentifier: String? - ) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - theme = STPTheme() - let titleLabel = UILabel() - self.titleLabel = titleLabel - let subtitleLabel = UILabel() - self.subtitleLabel = subtitleLabel - let amountLabel = UILabel() - self.amountLabel = amountLabel - let checkmarkIcon = UIImageView(image: STPLegacyImageLibrary.checkmarkIcon()) - self.checkmarkIcon = checkmarkIcon - let formatter = NumberFormatter() - formatter.numberStyle = .currency - formatter.usesGroupingSeparator = true - numberFormatter = formatter - contentView.addSubview(titleLabel) - contentView.addSubview(subtitleLabel) - contentView.addSubview(amountLabel) - contentView.addSubview(checkmarkIcon) - updateAppearance() - } - - override var isSelected: Bool { - get { - return super.isSelected - } - set(selected) { - super.isSelected = selected - updateAppearance() - } - } - - @objc func updateAppearance() { - contentView.backgroundColor = theme?.secondaryBackgroundColor - backgroundColor = UIColor.clear - titleLabel?.font = theme?.font - subtitleLabel?.font = theme?.smallFont - amountLabel?.font = theme?.font - titleLabel?.textColor = isSelected ? theme?.accentColor : theme?.primaryForegroundColor - amountLabel?.textColor = titleLabel?.textColor - var subduedAccentColor: UIColor? - if #available(iOS 13.0, *) { - subduedAccentColor = UIColor(dynamicProvider: { _ in - return self.theme?.accentColor.withAlphaComponent(0.6) ?? UIColor.clear - }) - } else { - subduedAccentColor = theme?.accentColor.withAlphaComponent(0.6) - } - subtitleLabel?.textColor = isSelected ? subduedAccentColor : theme?.secondaryForegroundColor - checkmarkIcon?.tintColor = theme?.accentColor - checkmarkIcon?.isHidden = !isSelected - } - - override func layoutSubviews() { - super.layoutSubviews() - let midY = bounds.midY - checkmarkIcon?.frame = CGRect(x: 0, y: 0, width: 14, height: 14) - checkmarkIcon?.center = CGPoint( - x: bounds.width - 15 - (checkmarkIcon?.bounds.midX ?? 0.0), - y: midY - ) - amountLabel?.sizeToFit() - amountLabel?.center = CGPoint( - x: (checkmarkIcon?.frame.minX ?? 0.0) - 15 - (amountLabel?.bounds.midX ?? 0.0), - y: midY - ) - let labelWidth = (amountLabel?.frame.minX ?? 0.0) - 30 - titleLabel?.sizeToFit() - titleLabel?.frame = CGRect( - x: 15, - y: 8, - width: labelWidth, - height: titleLabel?.frame.size.height ?? 0.0 - ) - subtitleLabel?.sizeToFit() - subtitleLabel?.frame = CGRect( - x: 15, - y: bounds.size.height - 8 - (subtitleLabel?.frame.size.height ?? 0.0), - width: labelWidth, - height: subtitleLabel?.frame.size.height ?? 0.0 - ) - } - - required init?( - coder aDecoder: NSCoder - ) { - super.init(coder: aDecoder) - } -} diff --git a/Stripe/StripeiOSTests/STPAPIClientTest.swift b/Stripe/StripeiOSTests/STPAPIClientTest.swift index 656381cf113..c8731fdf981 100644 --- a/Stripe/StripeiOSTests/STPAPIClientTest.swift +++ b/Stripe/StripeiOSTests/STPAPIClientTest.swift @@ -115,10 +115,10 @@ class STPAPIClientTest: XCTestCase { STPAnalyticsClient.sharedClient.addClass(toProductUsageIfNecessary: MockUAUsageClass.self) var params: [String: Any] = [:] params = STPAPIClient.paramsAddingPaymentUserAgent(params) - XCTAssertEqual(params["payment_user_agent"] as! String, "stripe-ios/\(StripeAPIConfiguration.STPSDKVersion); variant.legacy; MockUAUsageClass") + XCTAssertEqual(params["payment_user_agent"] as! String, "stripe-ios/\(StripeAPIConfiguration.STPSDKVersion); variant.paymentsheet; MockUAUsageClass") params = STPAPIClient.paramsAddingPaymentUserAgent(params, additionalValues: ["foo"]) - XCTAssertEqual(params["payment_user_agent"] as! String, "stripe-ios/\(StripeAPIConfiguration.STPSDKVersion); variant.legacy; MockUAUsageClass; foo") + XCTAssertEqual(params["payment_user_agent"] as! String, "stripe-ios/\(StripeAPIConfiguration.STPSDKVersion); variant.paymentsheet; MockUAUsageClass; foo") } func testSetAppInfo() { diff --git a/Stripe/StripeiOSTests/STPAnalyticsClientPaymentsTest.swift b/Stripe/StripeiOSTests/STPAnalyticsClientPaymentsTest.swift index 1a4c14101b7..bb999baa9f1 100644 --- a/Stripe/StripeiOSTests/STPAnalyticsClientPaymentsTest.swift +++ b/Stripe/StripeiOSTests/STPAnalyticsClientPaymentsTest.swift @@ -171,14 +171,3 @@ private struct MockAnalyticsClass1: STPAnalyticsProtocol { private struct MockAnalyticsClass2: STPAnalyticsProtocol { static let stp_analyticsIdentifier = "MockAnalyticsClass2" } - -private class MockKeyProvider: NSObject, STPCustomerEphemeralKeyProvider { - func createCustomerKey( - withAPIVersion apiVersion: String, - completion: @escaping STPJSONResponseCompletionBlock - ) { - guard apiVersion == "1" else { return } - - completion(nil, NSError.stp_genericConnectionError()) - } -} diff --git a/Stripe/StripeiOSTests/STPSwiftFixtures.swift b/Stripe/StripeiOSTests/STPSwiftFixtures.swift index b3af99c5a6c..1005db9ba80 100644 --- a/Stripe/StripeiOSTests/STPSwiftFixtures.swift +++ b/Stripe/StripeiOSTests/STPSwiftFixtures.swift @@ -9,7 +9,6 @@ import Foundation @testable@_spi(STP) import Stripe -@testable@_spi(STP) import StripeCore @testable@_spi(STP) import StripePayments @testable@_spi(STP) import StripePaymentSheet @testable@_spi(STP) import StripePaymentsUI @@ -33,12 +32,3 @@ extension STPFixtures { return .decodedObject(fromAPIResponse: response)! } } - -class MockEphemeralKeyProvider: NSObject, STPCustomerEphemeralKeyProvider { - func createCustomerKey( - withAPIVersion apiVersion: String, - completion: @escaping STPJSONResponseCompletionBlock - ) { - completion(STPFixtures.ephemeralKey().allResponseFields, nil) - } -} diff --git a/StripeCore/StripeCore/Source/Helpers/PaymentsSDKVariant.swift b/StripeCore/StripeCore/Source/Helpers/PaymentsSDKVariant.swift index 630920aa145..7a2d110a179 100644 --- a/StripeCore/StripeCore/Source/Helpers/PaymentsSDKVariant.swift +++ b/StripeCore/StripeCore/Source/Helpers/PaymentsSDKVariant.swift @@ -9,10 +9,6 @@ import Foundation @_spi(STP) public class PaymentsSDKVariant { @_spi(STP) public static let variant: String = { - if NSClassFromString("STPPaymentContext") != nil { - // This is the full legacy Payments SDK, including Basic Integration - return "legacy" - } if NSClassFromString("STP_Internal_PaymentSheetViewController") != nil { // This is the PaymentSheet SDK return "paymentsheet"