Skip to content

Commit

Permalink
Merge branch 'develop' into COIOS-774_pay-by-bank-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
goergisn authored Nov 19, 2024
2 parents 5f53c0b + 74d3d0c commit 8a05f5e
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--disable blankLinesAtStartOfScope,blankLinesAtEndOfScope,unusedArguments,redundantSelf,wrapMultilineStatementBraces,extensionAccessControl,redundantClosure,redundantInternal,preferForLoop,redundantRawValues
--disable blankLinesAtStartOfScope,blankLinesAtEndOfScope,unusedArguments,redundantSelf,wrapMultilineStatementBraces,extensionAccessControl,redundantClosure,redundantInternal,preferForLoop,redundantRawValues,docCommentsBeforeModifiers
--swiftversion "5.7"
--commas inline
--ranges nospace
Expand Down
8 changes: 4 additions & 4 deletions Adyen/Analytics/AnalyticsProvider/AnalyticsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ internal final class AnalyticsProvider: AnyAnalyticsProvider {
internal var eventAnalyticsProvider: AnyEventAnalyticsProvider?

private let uniqueAssetAPIClient: UniqueAssetAPIClient<InitialAnalyticsResponse>
private let context: AnalyticsContext
private let configuration: AnalyticsConfiguration

// MARK: - Initializers

internal init(
apiClient: APIClientProtocol,
context: AnalyticsContext,
configuration: AnalyticsConfiguration,
eventAnalyticsProvider: AnyEventAnalyticsProvider?
) {
self.context = context
self.configuration = configuration
self.eventAnalyticsProvider = eventAnalyticsProvider
self.uniqueAssetAPIClient = UniqueAssetAPIClient<InitialAnalyticsResponse>(apiClient: apiClient)
}
Expand All @@ -40,7 +40,7 @@ internal final class AnalyticsProvider: AnyAnalyticsProvider {
let analyticsData = AnalyticsData(
flavor: flavor,
additionalFields: additionalFields,
context: context
configuration: configuration
)

let initialAnalyticsRequest = InitialAnalyticsRequest(data: analyticsData)
Expand Down
17 changes: 17 additions & 0 deletions Adyen/Analytics/Models/AdyenAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,20 @@ public struct AdditionalAnalyticsFields {
self.sessionId = sessionId
}
}

/// Describes the levels that determine which analytics calls are made.
internal enum AnalyticsLevel: String, Encodable {

/// Indicates all analytics are enabled.
case all

/// Indicates only the initial call is enabled.
case initial
}

extension AnalyticsConfiguration {

internal var analyticsLevel: AnalyticsLevel {
isEnabled ? .all : .initial
}
}
10 changes: 7 additions & 3 deletions Adyen/Analytics/Models/AnalyticsData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,24 @@ internal struct AnalyticsData: Encodable {
internal var paymentMethods: [String] = []

internal let component: String

internal let level: AnalyticsLevel

// MARK: - Initializers

internal init(
flavor: AnalyticsFlavor,
additionalFields: AdditionalAnalyticsFields?,
context: AnalyticsContext
configuration: AnalyticsConfiguration
) {
self.flavor = flavor.value
self.amount = additionalFields?.amount
self.sessionId = additionalFields?.sessionId

self.version = context.version
self.platform = context.platform.rawValue
self.version = configuration.context.version
self.platform = configuration.context.platform.rawValue

self.level = configuration.analyticsLevel

switch flavor {
case let .dropIn(type, paymentMethods):
Expand Down
3 changes: 3 additions & 0 deletions Adyen/Analytics/Requests/InitialAnalyticsRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal struct InitialAnalyticsRequest: APIRequest {
private let containerWidth: Int?
private let paymentMethods: [String]
private let component: String
internal let level: String
internal let amount: Amount?
internal let sessionId: String?

Expand All @@ -67,6 +68,7 @@ internal struct InitialAnalyticsRequest: APIRequest {
self.containerWidth = data.containerWidth
self.paymentMethods = data.paymentMethods
self.component = data.component
self.level = data.level.rawValue
self.amount = data.amount
self.sessionId = data.sessionId
}
Expand All @@ -86,6 +88,7 @@ internal struct InitialAnalyticsRequest: APIRequest {
case containerWidth
case paymentMethods
case component
case level
case amount
case sessionId
}
Expand Down
2 changes: 1 addition & 1 deletion Adyen/Core/AdyenContext/AdyenContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public final class AdyenContext: PaymentAware {

return AnalyticsProvider(
apiClient: APIClient(apiContext: analyticsApiContext),
context: analyticsConfiguration.context,
configuration: analyticsConfiguration,
eventAnalyticsProvider: eventAnalyticsProvider
)
}
Expand Down
7 changes: 3 additions & 4 deletions Tests/UnitTests/Analytics/AnalyticsEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AnalyticsEventTests: XCTestCase {
apiClient.mockedResults = [checkoutAttemptIdResult]
sut = AnalyticsProvider(
apiClient: apiClient,
context: .init(),
configuration: .init(),
eventAnalyticsProvider: nil
)
}
Expand All @@ -40,7 +40,7 @@ class AnalyticsEventTests: XCTestCase {
// Given
sut = AnalyticsProvider(
apiClient: apiClient,
context: .init(),
configuration: .init(),
eventAnalyticsProvider: nil
)

Expand All @@ -61,10 +61,9 @@ class AnalyticsEventTests: XCTestCase {

func testSendInitialEventGivenEnabledAndFlavorIsDropInShouldSendInitialRequest() throws {
// Given
let analyticsConfiguration = AnalyticsConfiguration()
sut = AnalyticsProvider(
apiClient: apiClient,
context: .init(),
configuration: .init(),
eventAnalyticsProvider: nil
)

Expand Down
18 changes: 12 additions & 6 deletions Tests/UnitTests/Analytics/AnalyticsProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ class AnalyticsProviderTests: XCTestCase {

func testAnalyticsProviderIsInitializedWithCorrectDefaultConfigurationValues() throws {
// Given
let analyticsConfiguration = AnalyticsConfiguration()
let sut = AnalyticsProvider(
apiClient: APIClientMock(),
context: AnalyticsContext(),
configuration: AnalyticsConfiguration(),
eventAnalyticsProvider: nil
)

Expand Down Expand Up @@ -103,6 +102,7 @@ class AnalyticsProviderTests: XCTestCase {
XCTAssertNil(initialAnalyticsdRequest.amount)
XCTAssertEqual(initialAnalyticsdRequest.version, adyenSdkVersion)
XCTAssertEqual(initialAnalyticsdRequest.platform, "iOS")
XCTAssertEqual(initialAnalyticsdRequest.level, "all")
analyticsExpectation.fulfill()
}
}
Expand All @@ -129,7 +129,7 @@ class AnalyticsProviderTests: XCTestCase {
)
let sut = AnalyticsProvider(
apiClient: APIClientMock(),
context: AnalyticsContext(),
configuration: AnalyticsConfiguration(),
eventAnalyticsProvider: eventAnalyticsProvider
)

Expand Down Expand Up @@ -199,9 +199,11 @@ class AnalyticsProviderTests: XCTestCase {
}
}

var configuration = AnalyticsConfiguration()
configuration.context = AnalyticsContext(version: "version", platform: .reactNative)
let analyticsProvider = AnalyticsProvider(
apiClient: apiClient,
context: .init(version: "version", platform: .reactNative),
configuration: configuration,
eventAnalyticsProvider: nil
)

Expand All @@ -214,10 +216,13 @@ class AnalyticsProviderTests: XCTestCase {

func testInitialRequestEncoding() throws {

var configuration = AnalyticsConfiguration()
configuration.context = AnalyticsContext(version: "version", platform: .flutter)

let analyticsData = AnalyticsData(
flavor: .components(type: .achDirectDebit),
additionalFields: AdditionalAnalyticsFields(amount: .init(value: 1, currencyCode: "EUR"), sessionId: "test_session_id"),
context: AnalyticsContext(version: "version", platform: .flutter)
configuration: configuration
)

let request = InitialAnalyticsRequest(data: analyticsData)
Expand All @@ -237,6 +242,7 @@ class AnalyticsProviderTests: XCTestCase {
"referrer": analyticsData.referrer,
"deviceBrand": analyticsData.deviceBrand,
"deviceModel": analyticsData.deviceModel,
"level": analyticsData.level.rawValue,
"amount": [
"currency": "EUR",
"value": 1
Expand All @@ -260,7 +266,7 @@ class AnalyticsProviderTests: XCTestCase {
private func createSUT(apiClient: APIClientMock) -> AnalyticsProvider {
let sut = AnalyticsProvider(
apiClient: apiClient,
context: AnalyticsContext(),
configuration: AnalyticsConfiguration(),
eventAnalyticsProvider: nil
)

Expand Down

0 comments on commit 8a05f5e

Please sign in to comment.