7
7
//
8
8
9
9
import Foundation
10
+ import QuartzCore
10
11
11
12
struct FingerprintIntegration : Decodable , Equatable {
12
13
let enabled : Bool
@@ -15,6 +16,7 @@ struct FingerprintIntegration: Decodable, Equatable {
15
16
16
17
struct FingerprintConfiguration : Equatable {
17
18
let publicKey : String
19
+ let blockTime : Double
18
20
}
19
21
20
22
struct DeviceDataConfiguration : Decodable , Equatable {
@@ -42,46 +44,50 @@ struct PersistDeviceDataResponse: Decodable, Equatable {
42
44
43
45
protocol DeviceDataServiceProtocol {
44
46
func getConfiguration( completion: @escaping ( Result < FingerprintConfiguration , RiskError . Configuration > ) -> Void )
45
- func persistFpData( fingerprintRequestId: String , cardToken: String ? , completion: @escaping ( Result < PersistDeviceDataResponse , RiskError . Publish > ) -> Void )
47
+ func persistFpData( fingerprintRequestId: String , fpLoadTime : Double , fpPublishTime : Double , cardToken: String ? , completion: @escaping ( Result < PersistDeviceDataResponse , RiskError . Publish > ) -> Void )
46
48
}
47
49
48
- struct DeviceDataService : DeviceDataServiceProtocol {
50
+ final class DeviceDataService : DeviceDataServiceProtocol {
49
51
let config : RiskSDKInternalConfig
50
52
let apiService : APIServiceProtocol
51
53
let loggerService : LoggerServiceProtocol
54
+ var blockTime : Double
52
55
53
56
init ( config: RiskSDKInternalConfig , apiService: APIServiceProtocol = APIService ( ) , loggerService: LoggerServiceProtocol ) {
54
57
self . config = config
55
58
self . apiService = apiService
56
59
self . loggerService = loggerService
60
+ self . blockTime = 0.00
57
61
}
58
62
59
63
func getConfiguration( completion: @escaping ( Result < FingerprintConfiguration , RiskError . Configuration > ) -> Void ) {
64
+ let startBlockTime = CACurrentMediaTime ( )
60
65
let endpoint = " \( config. deviceDataEndpoint) /configuration?integrationType= \( config. integrationType. rawValue) &riskSdkVersion= \( Constants . riskSdkVersion) &timezone= \( TimeZone . current. identifier) "
61
66
let authToken = config. merchantPublicKey
62
67
63
68
apiService. getJSONFromAPIWithAuthorization ( endpoint: endpoint, authToken: authToken, responseType: DeviceDataConfiguration . self) {
64
69
result in
65
70
switch result {
66
71
case . success( let configuration) :
67
-
72
+ let endBlockTime = CACurrentMediaTime ( )
73
+ self . blockTime = ( endBlockTime - startBlockTime) * 1000
68
74
guard configuration. fingerprintIntegration. enabled, let fingerprintPublicKey = configuration. fingerprintIntegration. publicKey else {
69
- loggerService. log ( riskEvent: . publishDisabled, deviceSessionId: nil , requestId: nil , error: RiskLogError ( reason: " getConfiguration " , message: RiskError . Configuration. integrationDisabled. localizedDescription, status: nil , type: " Error " ) )
75
+ self . loggerService. log ( riskEvent: . publishDisabled, blockTime : self . blockTime , deviceDataPersistTime : nil , fpLoadTime : nil , fpPublishTime : nil , deviceSessionId: nil , requestId: nil , error: RiskLogError ( reason: " getConfiguration " , message: RiskError . Configuration. integrationDisabled. localizedDescription, status: nil , type: " Error " ) )
70
76
71
77
return completion ( . failure( . integrationDisabled) )
72
78
}
73
79
74
80
completion ( . success(
75
- FingerprintConfiguration . init ( publicKey: fingerprintPublicKey) ) )
81
+ FingerprintConfiguration . init ( publicKey: fingerprintPublicKey, blockTime : self . blockTime ) ) )
76
82
case . failure( let error) :
77
-
78
- loggerService. log ( riskEvent: . loadFailure, deviceSessionId: nil , requestId: nil , error: RiskLogError ( reason: " getConfiguration " , message: error. localizedDescription, status: nil , type: " Error " ) )
83
+ self . loggerService. log ( riskEvent: . loadFailure, blockTime: nil , deviceDataPersistTime: nil , fpLoadTime: nil , fpPublishTime: nil , deviceSessionId: nil , requestId: nil , error: RiskLogError ( reason: " getConfiguration " , message: error. localizedDescription, status: nil , type: " Error " ) )
79
84
return completion ( . failure( . couldNotRetrieveConfiguration) )
80
85
}
81
86
}
82
87
}
83
88
84
- func persistFpData( fingerprintRequestId: String , cardToken: String ? , completion: @escaping ( Result < PersistDeviceDataResponse , RiskError . Publish > ) -> Void ) {
89
+ func persistFpData( fingerprintRequestId: String , fpLoadTime: Double , fpPublishTime: Double , cardToken: String ? , completion: @escaping ( Result < PersistDeviceDataResponse , RiskError . Publish > ) -> Void ) {
90
+ let startPersistTime = CACurrentMediaTime ( )
85
91
let endpoint = " \( config. deviceDataEndpoint) /fingerprint?riskSdkVersion= \( Constants . riskSdkVersion) "
86
92
let authToken = config. merchantPublicKey
87
93
let integrationType = config. integrationType
@@ -96,11 +102,13 @@ struct DeviceDataService: DeviceDataServiceProtocol {
96
102
97
103
switch result {
98
104
case . success( let response) :
99
- loggerService. log ( riskEvent: . published, deviceSessionId: response. deviceSessionId, requestId: fingerprintRequestId, error: nil )
105
+ let endPersistTime = CACurrentMediaTime ( )
106
+ let persistTime = ( endPersistTime - startPersistTime) * 1000
107
+ self . loggerService. log ( riskEvent: . published, blockTime: self . blockTime, deviceDataPersistTime: persistTime, fpLoadTime: fpLoadTime, fpPublishTime: fpPublishTime, deviceSessionId: response. deviceSessionId, requestId: fingerprintRequestId, error: nil )
100
108
101
109
completion ( . success( response) )
102
110
case . failure( let error) :
103
- loggerService. log ( riskEvent: . publishFailure, deviceSessionId: nil , requestId: nil , error: RiskLogError ( reason: " persistFpData " , message: error. localizedDescription, status: nil , type: " Error " ) )
111
+ self . loggerService. log ( riskEvent: . publishFailure, blockTime : self . blockTime , deviceDataPersistTime : nil , fpLoadTime : fpLoadTime , fpPublishTime : fpPublishTime , deviceSessionId: nil , requestId: nil , error: RiskLogError ( reason: " persistFpData " , message: error. localizedDescription, status: nil , type: " Error " ) )
104
112
105
113
completion ( . failure( . couldNotPersisRiskData) )
106
114
}
0 commit comments