-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: inject Risk SDK as UseCase
- Loading branch information
1 parent
3fbb17e
commit a007293
Showing
4 changed files
with
67 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
checkout/src/main/java/com/checkout/tokenization/usecase/RiskSdkUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.checkout.tokenization.usecase | ||
|
||
import android.content.Context | ||
import com.checkout.base.model.Environment | ||
import com.checkout.base.usecase.UseCase | ||
import com.checkout.risk.PublishDataResult | ||
import com.checkout.risk.Risk | ||
import com.checkout.risk.RiskConfig | ||
import com.checkout.risk.RiskEnvironment | ||
import com.checkout.tokenization.model.TokenDetails | ||
import com.checkout.tokenization.model.TokenResult | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
internal class RiskSdkUseCase( | ||
private val environment: Environment, | ||
private val context: Context, | ||
private val publicKey: String, | ||
) : UseCase<TokenResult<TokenDetails>, Unit> { | ||
override fun execute(data: TokenResult<TokenDetails>) { | ||
val riskEnvironment = | ||
when (environment) { | ||
Environment.PRODUCTION -> RiskEnvironment.PRODUCTION | ||
Environment.SANDBOX -> RiskEnvironment.SANDBOX | ||
} | ||
|
||
CoroutineScope(Dispatchers.IO).launch { | ||
val riskInstance = | ||
Risk.getInstance( | ||
context, | ||
RiskConfig( | ||
publicKey = publicKey, | ||
environment = riskEnvironment, | ||
framesMode = true, | ||
), | ||
).let { | ||
it ?: run { | ||
null | ||
} | ||
} | ||
|
||
when (data) { | ||
is TokenResult.Success -> { | ||
riskInstance?.publishData(cardToken = data.result.token) | ||
} | ||
is TokenResult.Failure -> {} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters