Skip to content

Commit

Permalink
Merge pull request #29 from checkout/PRISM-11214-accept-more-frames-o…
Browse files Browse the repository at this point in the history
…ptions-on-risk-i-os

PRISM-11214 - Improve frames mode logs
  • Loading branch information
precious-ossai-cko authored Apr 25, 2024
2 parents a5df46e + 69124ad commit d9d8bcb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Risk.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Risk"
s.version = "2.0.3"
s.version = "3.0.0"
s.summary = "Checkout Risk package in Swift"
s.description = <<-DESC
Checkout Risk package in Swift.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Risk/Logging/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

enum Constants {
static let productName = "risk-ios-sdk"
static let riskSdkVersion = "2.0.3"
static let riskSdkVersion = "3.0.0"
static let userAgent = "checkout-sdk-risk-ios/\(riskSdkVersion)"
static let loggerTypeIdentifier = "com.checkout.risk-mobile-sdk"
}
50 changes: 12 additions & 38 deletions Sources/Risk/Logging/LoggerService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extension LoggerServiceProtocol {
let maskedPublicKey = getMaskedPublicKey(publicKey: internalConfig.merchantPublicKey)
let ddTags = getDDTags(environment: internalConfig.environment.rawValue)
var monitoringLevel: MonitoringLevel
let framesMode = internalConfig.framesOptions != nil
let properties: [String: AnyCodable]

switch riskEvent {
Expand All @@ -69,13 +70,12 @@ extension LoggerServiceProtocol {
case .published, .collected:
properties = [
"Block": AnyCodable(latencyMetric.block),
"CorrelationId": AnyCodable(internalConfig.correlationId),
"DeviceDataPersist": AnyCodable(latencyMetric.deviceDataPersist),
"FpLoad": AnyCodable(latencyMetric.fpload),
"FpPublish": AnyCodable(latencyMetric.fppublish),
"Total": AnyCodable(latencyMetric.total),
"EventType": AnyCodable(riskEvent.rawValue),
"FramesMode": AnyCodable(internalConfig.framesMode),
"FramesMode": AnyCodable(framesMode),
"MaskedPublicKey": AnyCodable(maskedPublicKey),
"ddTags": AnyCodable(ddTags),
"RiskSDKVersion": AnyCodable(Constants.riskSdkVersion),
Expand All @@ -86,13 +86,12 @@ extension LoggerServiceProtocol {
case .publishFailure, .loadFailure, .publishDisabled:
properties = [
"Block": AnyCodable(latencyMetric.block),
"CorrelationId": AnyCodable(internalConfig.correlationId),
"DeviceDataPersist": AnyCodable(latencyMetric.deviceDataPersist),
"FpLoad": AnyCodable(latencyMetric.fpload),
"FpPublish": AnyCodable(latencyMetric.fppublish),
"Total": AnyCodable(latencyMetric.total),
"EventType": AnyCodable(riskEvent.rawValue),
"FramesMode": AnyCodable(internalConfig.framesMode),
"FramesMode": AnyCodable(framesMode),
"MaskedPublicKey": AnyCodable(maskedPublicKey),
"ddTags": AnyCodable(ddTags),
"RiskSDKVersion": AnyCodable(Constants.riskSdkVersion),
Expand All @@ -104,7 +103,7 @@ extension LoggerServiceProtocol {
}

return Event(
typeIdentifier: Constants.loggerTypeIdentifier,
typeIdentifier: riskEvent.rawValue,
time: Date(),
monitoringLevel: monitoringLevel,
properties: properties
Expand All @@ -131,15 +130,9 @@ struct LoggerService: LoggerServiceProtocol {
}

private func setup() {

let appBundle = Bundle.main
let appPackageName = appBundle.bundleIdentifier ?? "unavailableAppPackageName"
let appPackageVersion = appBundle
.infoDictionary?["CFBundleShortVersionString"] as? String ?? "unavailableAppPackageVersion"

let deviceName = getDeviceModel()
let osVersion = UIDevice.current.systemVersion
let logEnvironment: Environment
let productIdentifier = internalConfig.framesOptions?.productIdentifier ?? Constants.productName
let productVersion = internalConfig.framesOptions?.version ?? Constants.riskSdkVersion

switch internalConfig.environment {
case .qa, .sandbox:
Expand All @@ -155,17 +148,14 @@ struct LoggerService: LoggerServiceProtocol {
logger.enableRemoteProcessor(
environment: logEnvironment,
remoteProcessorMetadata: RemoteProcessorMetadata(
productIdentifier: Constants.productName,
productVersion: Constants.riskSdkVersion,
environment: internalConfig.environment.rawValue,
appPackageName: appPackageName,
appPackageVersion: appPackageVersion,
deviceName: deviceName,
platform: "iOS",
osVersion: osVersion
productIdentifier: productIdentifier,
productVersion: productVersion,
environment: internalConfig.environment.rawValue
)
)


guard let correlationID = internalConfig.framesOptions?.correlationId else { return }
logger.add(metadata: CheckoutEventLogger.MetadataKey.correlationID.rawValue, value: correlationID)
}

func log(riskEvent: RiskEvent, blockTime: Double? = nil, deviceDataPersistTime: Double? = nil, fpLoadTime: Double? = nil, fpPublishTime: Double? = nil, deviceSessionId: String? = nil, requestId: String? = nil, error: RiskLogError? = nil) {
Expand All @@ -177,20 +167,4 @@ struct LoggerService: LoggerServiceProtocol {
let event = formatEvent(internalConfig: internalConfig, riskEvent: riskEvent, deviceSessionId: deviceSessionId, requestId: requestId, error: error, latencyMetric: latencyMetric)
logger.log(event: event)
}

private func getDeviceModel() -> String {
#if targetEnvironment(simulator)
if let identifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] {
return identifier
}
#endif

var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
return machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
}
}
7 changes: 3 additions & 4 deletions Sources/Risk/Models/RiskSDKInternalConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ struct RiskSDKInternalConfig {
let fingerprintEndpoint: String
let integrationType: RiskIntegrationType
let sourceType: SourceType
let framesMode: Bool
let environment: RiskEnvironment
let correlationId: String
let framesOptions: FramesOptions?

init(config: RiskConfig) {
framesOptions = config.framesOptions
let framesMode = framesOptions != nil
merchantPublicKey = config.publicKey
environment = config.environment
framesMode = config.framesMode
correlationId = config.framesMode ? config.correlationId : ""
integrationType = framesMode ? .inFrames : .standalone
sourceType = framesMode ? .cardToken : .riskSDK

Expand Down
18 changes: 14 additions & 4 deletions Sources/Risk/RiskSDKConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ public enum RiskEnvironment: String {
public struct RiskConfig {
let publicKey: String
let environment: RiskEnvironment
let framesMode: Bool
let correlationId: String
let framesOptions: FramesOptions?

public init(publicKey: String, environment: RiskEnvironment, framesMode: Bool = false, correlationId: String = "") {
public init(publicKey: String, environment: RiskEnvironment, framesOptions: FramesOptions? = nil) {
self.publicKey = publicKey
self.environment = environment
self.framesMode = framesMode
self.framesOptions = framesOptions
}
}

public struct FramesOptions {
let correlationId: String
let version: String
let productIdentifier: String

public init(productIdentifier: String, version: String, correlationId: String) {
self.productIdentifier = productIdentifier
self.version = version
self.correlationId = correlationId
}
}

0 comments on commit d9d8bcb

Please sign in to comment.