Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@
BlueprintName = "StripePaymentSheetTests"
ReferencedContainer = "container:StripePaymentSheet/StripePaymentSheet.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "MPELatencyTest">
</Test>
<Test
Identifier = "MPELatencyTest/testLoadLatency()">
</Test>
</SkippedTests>
</TestableReference>
<TestableReference
skipped = "NO">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A74928FD0171C3213676E29C"
BuildableName = "StripePaymentSheet.framework"
BlueprintName = "StripePaymentSheet"
ReferencedContainer = "container:StripePaymentSheet/StripePaymentSheet.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "NO">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A74928FD0171C3213676E29C"
BuildableName = "StripePaymentSheet.framework"
BlueprintName = "StripePaymentSheet"
ReferencedContainer = "container:StripePaymentSheet/StripePaymentSheet.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "FB_REFERENCE_IMAGE_DIR"
value = "$(SRCROOT)/../Tests/ReferenceImages"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "RECORD_LATENCY_TESTS"
value = "$(RECORD_LATENCY_TESTS)"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "BITRISE_GIT_COMMIT"
value = "$(BITRISE_GIT_COMMIT)"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "BITRISE_BUILD_URL"
value = "$(BITRISE_BUILD_URL)"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<TestPlans>
<TestPlanReference
reference = "container:StripePaymentSheet/StripePaymentSheetTests/StripePaymentSheet-LatencyTests.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9A93AB1D98A0A1EC6ADEA65D"
BuildableName = "StripePaymentSheetTests.xctest"
BlueprintName = "StripePaymentSheetTests"
ReferencedContainer = "container:StripePaymentSheet/StripePaymentSheet.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A74928FD0171C3213676E29C"
BuildableName = "StripePaymentSheet.framework"
BlueprintName = "StripePaymentSheet"
ReferencedContainer = "container:StripePaymentSheet/StripePaymentSheet.xcodeproj">
</BuildableReference>
</MacroExpansion>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A74928FD0171C3213676E29C"
BuildableName = "StripePaymentSheet.framework"
BlueprintName = "StripePaymentSheet"
ReferencedContainer = "container:StripePaymentSheet/StripePaymentSheet.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,8 @@ import Foundation
// MARK: - STPApplePayContext
case applePayContextStarted = "stripeios.applepaycontext.confirm.started"
case applePayContextFinished = "stripeios.applepaycontext.confirm.finished"

// MARK: - Synthetic latency tests
case mpeSyntheticLatency = "mpe.synthetic_latency"

}
19 changes: 15 additions & 4 deletions StripeCore/StripeCore/Source/Analytics/STPAnalyticsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ import UIKit

@objc public var productUsage: Set<String> = Set()
private var additionalInfoSet: Set<String> = Set()
private(set) var urlSession: URLSession = URLSession(
configuration: StripeAPIConfiguration.sharedUrlSessionConfiguration
)
let urlSession: URLSession
let url = URL(string: "https://q.stripe.com")!
private let analyticsEventTranslator = STPAnalyticsEventTranslator()

public init(
urlSession: URLSession = URLSession(configuration: StripeAPIConfiguration.sharedUrlSessionConfiguration)
) {
self.urlSession = urlSession
}

@objc public class func tokenType(fromParameters parameters: [AnyHashable: Any]) -> String? {
let parameterKeys = parameters.keys

Expand Down Expand Up @@ -140,7 +145,7 @@ import UIKit
}

// If in testing, don't log analytic, instead append payload to log history
guard !STPAnalyticsClient.isUnitOrUITest else {
guard shouldSendAnalytic() else {
objc_sync_enter(self)
_testLogHistoryStorage.append(payload)
objc_sync_exit(self)
Expand All @@ -152,6 +157,12 @@ import UIKit
let task: URLSessionDataTask = urlSession.dataTask(with: request as URLRequest)
task.resume()
}

/// Whether to send the analytic or not. If `false`, appends payload to `self._testLogHistory` instead.
/// This is a function so that it can be overriden by subclasses.
public func shouldSendAnalytic() -> Bool {
return !STPAnalyticsClient.isUnitOrUITest
}
}

// MARK: - Helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import Foundation
@_spi(STP) @testable import StripeCore

@_spi(STP) public class STPTestingAnalyticsClient: STPAnalyticsClient {
public var forceAlwaysSendAnalytics: Bool = false
public var events = [Analytic]()

public override func shouldSendAnalytic() -> Bool {
return forceAlwaysSendAnalytics
}

public override func log(analytic: Analytic, apiClient: STPAPIClient = .shared) {
events.append(analytic)
super.log(analytic: analytic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
BlueprintName = "StripePaymentSheetTests"
ReferencedContainer = "container:StripePaymentSheet.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "MPELatencyTest">
</Test>
<Test
Identifier = "MPELatencyTest/testLoadLatency()">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
</TestAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ final class LinkAccountService: LinkAccountServiceProtocol {
) { [apiClient] result in
switch result {
case .success(let lookupResponse):
// TODO: Since success can include cases where we *don't* look up, we log "look up complete" even when no lookup was performed - is this intentional or desired?
STPAnalyticsClient.sharedClient.logLinkAccountLookupComplete(lookupResult: lookupResponse.responseType)
switch lookupResponse.responseType {
case .found(let session):
Expand Down
Loading
Loading