Skip to content

Commit

Permalink
refactor: update how frames options are sent to riskSDK
Browse files Browse the repository at this point in the history
- internally improves log instrumentation
  • Loading branch information
precious-ossai-cko committed Jun 10, 2024
1 parent f56b3c3 commit b32ae6c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object Versions {
const val moshi = "1.15.1"

// Risk SDK Dependencies
const val riskSdk = "1.0.6"
const val riskSdk = "2.0.0"

// Unit Testing Dependencies
const val junit5Jupiter = "5.8.0"
Expand Down
10 changes: 8 additions & 2 deletions checkout/src/main/java/com/checkout/CheckoutApiServiceFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.checkout.logging.EventLoggerProvider
import com.checkout.logging.Logger
import com.checkout.logging.model.LoggingEvent
import com.checkout.network.OkHttpProvider
import com.checkout.risk.FramesOptions
import com.checkout.threedsecure.Executor
import com.checkout.threedsecure.ThreeDSExecutor
import com.checkout.threedsecure.logging.ThreeDSEventLogger
Expand All @@ -32,6 +33,7 @@ import com.squareup.moshi.Moshi

public object CheckoutApiServiceFactory {
private lateinit var correlationId: String
private lateinit var riskSDKFramesOptions: FramesOptions

@JvmStatic
public fun create(
Expand All @@ -40,9 +42,13 @@ public object CheckoutApiServiceFactory {
context: Context,
): CheckoutApiService {
val logger = EventLoggerProvider.provide()

logger.setup(context, environment)
correlationId = logger.correlationId
riskSDKFramesOptions = FramesOptions(
version = BuildConfig.PRODUCT_VERSION,
productIdentifier = BuildConfig.PRODUCT_IDENTIFIER,
correlationId,
)

return CheckoutApiClient(
provideTokenRepository(context, publicKey, environment),
Expand Down Expand Up @@ -71,7 +77,7 @@ public object CheckoutApiServiceFactory {
logger = TokenizationEventLogger(EventLoggerProvider.provide()),
publicKey = publicKey,
cvvTokenizationNetworkDataMapper = CVVTokenizationNetworkDataMapper(),
riskSdkUseCase = RiskSdkUseCase(environment, context, publicKey, correlationId, RiskInstanceProvider),
riskSdkUseCase = RiskSdkUseCase(environment, context, publicKey, riskSDKFramesOptions, RiskInstanceProvider),
)

private fun provideNetworkApiClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.checkout.tokenization.usecase

import android.content.Context
import com.checkout.base.model.Environment
import com.checkout.risk.FramesOptions
import com.checkout.risk.Risk
import com.checkout.risk.RiskConfig
import com.checkout.risk.RiskEnvironment
Expand All @@ -13,7 +14,7 @@ internal object RiskInstanceProvider {
context: Context,
publicKey: String,
environment: Environment,
correlationId: String,
framesOptions: FramesOptions,
): Risk? {
if (riskInstance != null) {
return riskInstance
Expand All @@ -31,8 +32,7 @@ internal object RiskInstanceProvider {
RiskConfig(
publicKey = publicKey,
environment = riskEnvironment,
framesMode = true,
correlationId = correlationId,
framesOptions = framesOptions,
),
)
return riskInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package com.checkout.tokenization.usecase

import android.content.Context
import com.checkout.base.model.Environment
import com.checkout.risk.FramesOptions
import com.checkout.tokenization.model.TokenResult

internal class RiskSdkUseCase(
private val environment: Environment,
private val context: Context,
private val publicKey: String,
private val correlationId: String,
private val framesOptions: FramesOptions,
private val riskInstanceProvider: RiskInstanceProvider,
) {
suspend fun execute(data: TokenResult<String>) {
val riskInstance = riskInstanceProvider.provide(context, publicKey, environment, correlationId)
val riskInstance = riskInstanceProvider.provide(context, publicKey, environment, framesOptions)
when (data) {
is TokenResult.Success -> riskInstance?.publishData(cardToken = data.result)
is TokenResult.Failure -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.checkout.tokenization
import android.content.Context
import com.checkout.base.error.CheckoutError
import com.checkout.base.model.Environment
import com.checkout.risk.FramesOptions
import com.checkout.risk.Risk
import com.checkout.tokenization.model.TokenDetails
import com.checkout.tokenization.model.TokenResult
Expand All @@ -18,6 +19,9 @@ import org.junit.jupiter.api.Test

public class RiskSdkUseCaseTest {
private val correlationId: String = "testCorrelationId"
private val version: String = "1.0.0"
private val productIdentifier: String = "productIdentifier"
private val framesOptions: FramesOptions = FramesOptions(version, productIdentifier, correlationId)
private val environment: Environment = Environment.SANDBOX
private val riskInstanceProvider: RiskInstanceProvider = mockk()
private val riskInstance: Risk = mockk()
Expand All @@ -28,23 +32,23 @@ public class RiskSdkUseCaseTest {
@BeforeEach
public fun setup() {
coEvery { tokenDetails.token } returns TOKEN
coEvery { riskInstanceProvider.provide(context, PUBLIC_KEY, environment, correlationId) } returns riskInstance
coEvery { riskInstanceProvider.provide(context, PUBLIC_KEY, environment, framesOptions) } returns riskInstance
coEvery { riskInstance.publishData(any()) } returns mockk()
useCase =
RiskSdkUseCase(
environment = environment,
context = context,
publicKey = PUBLIC_KEY,
riskInstanceProvider = riskInstanceProvider,
correlationId = correlationId,
framesOptions = framesOptions,
)
}

@Test
public fun `Success result should trigger publishData`() {
runBlocking {
useCase.execute(TokenResult.Success(tokenDetails.token))
coVerify { riskInstanceProvider.provide(context, PUBLIC_KEY, environment, correlationId) }
coVerify { riskInstanceProvider.provide(context, PUBLIC_KEY, environment, framesOptions) }
coVerify { riskInstance.publishData(TOKEN) }
}
}
Expand Down

0 comments on commit b32ae6c

Please sign in to comment.