Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
ee4cf7b
Update POProxy3DSServiceRequest (remove random UUID) and POProxy3DSSe…
vitalii-vanziak-cko Nov 25, 2024
762b28b
PODynamicCheckoutLauncher: send Close after cleanup, improve 3ds even…
vitalii-vanziak-cko Nov 25, 2024
dbec2a0
Type fix
vitalii-vanziak-cko Nov 25, 2024
bf0df98
PODefaultProxy3DSService: use UUID for all events and handle Close
vitalii-vanziak-cko Nov 25, 2024
d6213e3
Provide new 3ds service instance on each invoice authorization and ha…
vitalii-vanziak-cko Nov 25, 2024
7dac3b6
'isInvoiceValid = false' on restart for consistency
vitalii-vanziak-cko Nov 25, 2024
fabff07
Refactored GooglePay, APM and authorize invoice
vitalii-vanziak-cko Nov 25, 2024
25f2397
Removed 'isInvoiceValid' from interactor state and simplified related…
vitalii-vanziak-cko Nov 26, 2024
c000e82
Return Job from authorizeInvoice()
vitalii-vanziak-cko Dec 4, 2024
7877c3b
POCustomTabAuthorizationActivity logs
vitalii-vanziak-cko Dec 4, 2024
d4fa535
Added EXTRA_FORCE_FINISH to CustomTab and WebView contracts
vitalii-vanziak-cko Dec 4, 2024
30a24a1
CustomTab, WebView contracts and related classes - open with internal…
vitalii-vanziak-cko Dec 4, 2024
cc7a8f3
Handle EXTRA_FORCE_FINISH in POCustomTabAuthorizationActivity
vitalii-vanziak-cko Dec 4, 2024
60e229b
Handle EXTRA_FORCE_FINISH in POWebViewAuthorizationActivity
vitalii-vanziak-cko Dec 4, 2024
1296e92
Cancel web authorization
vitalii-vanziak-cko Dec 5, 2024
52d0931
DynamicCheckoutInteractor - AuthorizeInvoiceJob, restart/cancellation…
vitalii-vanziak-cko Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.processout.sdk.core.ProcessOutResult
import com.processout.sdk.core.logger.POLogAttribute
import com.processout.sdk.core.logger.POLogger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -79,39 +80,37 @@ internal class DefaultInvoicesService(
request: POInvoiceAuthorizationRequest,
threeDSService: PO3DSService,
callback: (ProcessOutResult<Unit>) -> Unit
) {
scope.launch {
when (val result = repository.authorizeInvoice(request)) {
is ProcessOutResult.Success ->
result.value.customerAction?.let { action ->
this@DefaultInvoicesService.threeDSService
.handle(action, threeDSService) { serviceResult ->
@Suppress("DEPRECATION")
when (serviceResult) {
is ProcessOutResult.Success ->
authorizeInvoice(
request.copy(source = serviceResult.value),
threeDSService,
callback
)
is ProcessOutResult.Failure -> {
threeDSService.cleanup()
callback(serviceResult)
}
): Job = scope.launch {
when (val result = repository.authorizeInvoice(request)) {
is ProcessOutResult.Success ->
result.value.customerAction?.let { action ->
this@DefaultInvoicesService.threeDSService
.handle(action, threeDSService) { serviceResult ->
@Suppress("DEPRECATION")
when (serviceResult) {
is ProcessOutResult.Success ->
authorizeInvoice(
request.copy(source = serviceResult.value),
threeDSService,
callback
)
is ProcessOutResult.Failure -> {
threeDSService.cleanup()
callback(serviceResult)
}
}
} ?: run {
threeDSService.cleanup()
callback(ProcessOutResult.Success(Unit))
}
is ProcessOutResult.Failure -> {
POLogger.warn(
message = "Failed to authorize invoice: %s", result,
attributes = mapOf(POLogAttribute.INVOICE_ID to request.invoiceId)
)
}
} ?: run {
threeDSService.cleanup()
callback(result)
callback(ProcessOutResult.Success(Unit))
}
is ProcessOutResult.Failure -> {
POLogger.warn(
message = "Failed to authorize invoice: %s", result,
attributes = mapOf(POLogAttribute.INVOICE_ID to request.invoiceId)
)
threeDSService.cleanup()
callback(result)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.processout.sdk.api.model.response.PONativeAlternativePaymentMethodTra
import com.processout.sdk.core.ProcessOutCallback
import com.processout.sdk.core.ProcessOutResult
import com.processout.sdk.core.annotation.ProcessOutInternalApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.SharedFlow

/**
Expand Down Expand Up @@ -41,7 +42,7 @@ interface POInvoicesService {
request: POInvoiceAuthorizationRequest,
threeDSService: PO3DSService,
callback: (ProcessOutResult<Unit>) -> Unit
)
): Job

/**
* Initiates native alternative payment with the given request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import java.util.UUID

/** @suppress */
@ProcessOutInternalApi
class PODefaultProxy3DSService(
private val scope: CoroutineScope = MainScope(),
private val eventDispatcher: POEventDispatcher = POEventDispatcher
private val scope: CoroutineScope = MainScope()
) : POProxy3DSService {

private val uuid = UUID.randomUUID()
private val eventDispatcher = POEventDispatcher

private var authenticationCallback: ((ProcessOutResult<PO3DS2AuthenticationRequest>) -> Unit)? = null
private var challengeCallback: ((ProcessOutResult<Boolean>) -> Unit)? = null
private var redirectCallback: ((ProcessOutResult<String>) -> Unit)? = null
Expand All @@ -28,10 +31,14 @@ class PODefaultProxy3DSService(
eventDispatcher.subscribeForResponse<POProxy3DSServiceResponse>(
coroutineScope = scope
) { response ->
if (response.uuid != uuid) {
return@subscribeForResponse
}
when (response) {
is POProxy3DSServiceResponse.Authentication -> authenticationCallback?.invoke(response.result)
is POProxy3DSServiceResponse.Challenge -> challengeCallback?.invoke(response.result)
is POProxy3DSServiceResponse.Redirect -> redirectCallback?.invoke(response.result)
is POProxy3DSServiceResponse.Close -> close()
}
}
}
Expand All @@ -41,38 +48,34 @@ class PODefaultProxy3DSService(
callback: (ProcessOutResult<PO3DS2AuthenticationRequest>) -> Unit
) {
authenticationCallback = callback
scope.launch {
eventDispatcher.send(Authentication(configuration = configuration))
}
dispatch(Authentication(uuid = uuid, configuration = configuration))
}

override fun handle(
challenge: PO3DS2Challenge,
callback: (ProcessOutResult<Boolean>) -> Unit
) {
challengeCallback = callback
scope.launch {
eventDispatcher.send(Challenge(challenge = challenge))
}
dispatch(Challenge(uuid = uuid, challenge = challenge))
}

override fun handle(
redirect: PO3DSRedirect,
callback: (ProcessOutResult<String>) -> Unit
) {
redirectCallback = callback
scope.launch {
eventDispatcher.send(Redirect(redirect = redirect))
}
dispatch(Redirect(uuid = uuid, redirect = redirect))
}

override fun cleanup() {
authenticationCallback = null
challengeCallback = null
redirectCallback = null
scope.launch {
eventDispatcher.send(Cleanup())
}
dispatch(Cleanup(uuid = uuid))
}

private fun dispatch(request: POProxy3DSServiceRequest) {
scope.launch { eventDispatcher.send(request) }
}

override fun close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@ import java.util.UUID
sealed interface POProxy3DSServiceRequest : POEventDispatcher.Request {

data class Authentication(
override val uuid: UUID = UUID.randomUUID(),
override val uuid: UUID,
val configuration: PO3DS2Configuration
) : POProxy3DSServiceRequest

data class Challenge(
override val uuid: UUID = UUID.randomUUID(),
override val uuid: UUID,
val challenge: PO3DS2Challenge
) : POProxy3DSServiceRequest

data class Redirect(
override val uuid: UUID = UUID.randomUUID(),
override val uuid: UUID,
val redirect: PO3DSRedirect
) : POProxy3DSServiceRequest

data class Cleanup(
override val uuid: UUID = UUID.randomUUID()
) : POProxy3DSServiceRequest
data class Cleanup(override val uuid: UUID) : POProxy3DSServiceRequest
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ sealed interface POProxy3DSServiceResponse : POEventDispatcher.Response {
override val uuid: UUID,
val result: ProcessOutResult<String>
) : POProxy3DSServiceResponse

data class Close(override val uuid: UUID) : POProxy3DSServiceResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import com.processout.sdk.core.logger.POLogger
import com.processout.sdk.ui.web.WebAuthorizationActivityResultDispatcher
import com.processout.sdk.ui.web.WebAuthorizationDelegate
import com.processout.sdk.ui.web.WebAuthorizationDelegateCache
import com.processout.sdk.ui.web.customtab.CustomTabAuthorizationActivityContract
import com.processout.sdk.ui.web.customtab.CustomTabConfiguration
import com.processout.sdk.ui.web.customtab.POCustomTabAuthorizationActivityContract
import com.processout.sdk.ui.web.customtab.POCustomTabConfiguration
import com.processout.sdk.ui.web.webview.WebViewAuthorizationActivityLauncher
import com.processout.sdk.ui.web.webview.WebViewConfiguration
import com.processout.sdk.ui.web.webview.POWebViewConfiguration

/**
* Launcher that starts [POCustomTabAuthorizationActivity][com.processout.sdk.ui.web.customtab.POCustomTabAuthorizationActivity]
Expand All @@ -30,7 +30,7 @@ class POAlternativePaymentMethodCustomTabLauncher private constructor(
private val delegateCache: WebAuthorizationDelegateCache
) {

private lateinit var customTabLauncher: ActivityResultLauncher<CustomTabConfiguration>
private lateinit var customTabLauncher: ActivityResultLauncher<POCustomTabConfiguration>
private lateinit var webViewFallbackLauncher: WebViewAuthorizationActivityLauncher

companion object {
Expand All @@ -48,7 +48,7 @@ class POAlternativePaymentMethodCustomTabLauncher private constructor(
).apply {
val activityResultHandler = ActivityResultHandler(alternativePaymentMethods, callback)
customTabLauncher = from.registerForActivityResult(
CustomTabAuthorizationActivityContract(from.requireActivity()),
POCustomTabAuthorizationActivityContract(from.requireActivity()),
activityResultHandler
)
webViewFallbackLauncher = WebViewAuthorizationActivityLauncher.create(
Expand All @@ -70,7 +70,7 @@ class POAlternativePaymentMethodCustomTabLauncher private constructor(
).apply {
val activityResultHandler = ActivityResultHandler(alternativePaymentMethods, callback)
customTabLauncher = from.registerForActivityResult(
CustomTabAuthorizationActivityContract(from),
POCustomTabAuthorizationActivityContract(from),
from.activityResultRegistry,
activityResultHandler
)
Expand All @@ -92,7 +92,7 @@ class POAlternativePaymentMethodCustomTabLauncher private constructor(
WebAuthorizationActivityResultDispatcher
).apply {
customTabLauncher = from.registerForActivityResult(
CustomTabAuthorizationActivityContract(from.requireActivity()),
POCustomTabAuthorizationActivityContract(from.requireActivity()),
activityResultCallback
)
webViewFallbackLauncher = WebViewAuthorizationActivityLauncher.create(
Expand All @@ -113,7 +113,7 @@ class POAlternativePaymentMethodCustomTabLauncher private constructor(
WebAuthorizationActivityResultDispatcher
).apply {
customTabLauncher = from.registerForActivityResult(
CustomTabAuthorizationActivityContract(from),
POCustomTabAuthorizationActivityContract(from),
from.activityResultRegistry,
activityResultCallback
)
Expand Down Expand Up @@ -145,7 +145,7 @@ class POAlternativePaymentMethodCustomTabLauncher private constructor(
fun launch(uri: Uri, returnUrl: String) {
if (ProcessOut.instance.browserCapabilities.isCustomTabsSupported()) {
customTabLauncher.launch(
CustomTabConfiguration(
POCustomTabConfiguration(
uri = uri,
returnUri = Uri.parse(returnUrl),
timeoutSeconds = null
Expand All @@ -154,7 +154,7 @@ class POAlternativePaymentMethodCustomTabLauncher private constructor(
} else {
POLogger.info("Custom Chrome Tabs is not supported on device. Will use WebView.")
webViewFallbackLauncher.launch(
WebViewConfiguration(
POWebViewConfiguration(
uri = uri,
returnUris = listOf(
Uri.parse(ApiConstants.CHECKOUT_RETURN_URL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.processout.sdk.api.network.ApiConstants
import com.processout.sdk.core.ProcessOutResult
import com.processout.sdk.ui.web.WebAuthorizationDelegate
import com.processout.sdk.ui.web.webview.ProcessOutWebView
import com.processout.sdk.ui.web.webview.WebViewConfiguration
import com.processout.sdk.ui.web.webview.POWebViewConfiguration

@Deprecated("Use POAlternativePaymentMethodCustomTabLauncher.")
class POAlternativePaymentMethodWebViewBuilder(
Expand All @@ -30,7 +30,7 @@ class POAlternativePaymentMethodWebViewBuilder(

fun build(): WebView = ProcessOutWebView(
activity,
WebViewConfiguration(
POWebViewConfiguration(
uri = delegate?.uri,
returnUris = listOf(Uri.parse(ApiConstants.CHECKOUT_RETURN_URL)),
sdkVersion = ProcessOut.VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import com.processout.sdk.api.network.ApiConstants
import com.processout.sdk.core.POFailure
import com.processout.sdk.core.ProcessOutResult
import com.processout.sdk.core.logger.POLogger
import com.processout.sdk.ui.web.ActivityResultApi
import com.processout.sdk.ui.web.POActivityResultApi
import com.processout.sdk.ui.web.WebAuthorizationActivityResultDispatcher
import com.processout.sdk.ui.web.WebAuthorizationDelegate
import com.processout.sdk.ui.web.WebAuthorizationDelegateCache
import com.processout.sdk.ui.web.customtab.CustomTabAuthorizationActivityContract
import com.processout.sdk.ui.web.customtab.CustomTabConfiguration
import com.processout.sdk.ui.web.customtab.POCustomTabAuthorizationActivityContract
import com.processout.sdk.ui.web.customtab.POCustomTabConfiguration
import com.processout.sdk.ui.web.webview.WebViewAuthorizationActivityLauncher
import com.processout.sdk.ui.web.webview.WebViewConfiguration
import com.processout.sdk.ui.web.webview.POWebViewConfiguration

/**
* Launcher that starts [POCustomTabAuthorizationActivity][com.processout.sdk.ui.web.customtab.POCustomTabAuthorizationActivity]
Expand All @@ -27,7 +27,7 @@ class PO3DSRedirectCustomTabLauncher private constructor(
private val delegateCache: WebAuthorizationDelegateCache
) {

private lateinit var contract: CustomTabAuthorizationActivityContract
private lateinit var contract: POCustomTabAuthorizationActivityContract
private lateinit var webViewFallbackLauncher: WebViewAuthorizationActivityLauncher

companion object {
Expand All @@ -37,7 +37,7 @@ class PO3DSRedirectCustomTabLauncher private constructor(
fun create(from: Fragment) = PO3DSRedirectCustomTabLauncher(
WebAuthorizationActivityResultDispatcher
).apply {
contract = CustomTabAuthorizationActivityContract(from.requireActivity())
contract = POCustomTabAuthorizationActivityContract(from.requireActivity())
webViewFallbackLauncher = WebViewAuthorizationActivityLauncher.create(
from, activityResultCallback = null
)
Expand All @@ -49,7 +49,7 @@ class PO3DSRedirectCustomTabLauncher private constructor(
fun create(from: ComponentActivity) = PO3DSRedirectCustomTabLauncher(
WebAuthorizationActivityResultDispatcher
).apply {
contract = CustomTabAuthorizationActivityContract(from)
contract = POCustomTabAuthorizationActivityContract(from)
webViewFallbackLauncher = WebViewAuthorizationActivityLauncher.create(
from, activityResultCallback = null
)
Expand Down Expand Up @@ -82,25 +82,25 @@ class PO3DSRedirectCustomTabLauncher private constructor(

if (ProcessOut.instance.browserCapabilities.isCustomTabsSupported()) {
contract.startActivity(
CustomTabConfiguration(
POCustomTabConfiguration(
uri = delegate.uri,
returnUri = Uri.parse(returnUrl),
timeoutSeconds = redirect.timeoutSeconds,
resultApi = ActivityResultApi.Dispatcher
resultApi = POActivityResultApi.Dispatcher
)
)
} else {
POLogger.info("Custom Chrome Tabs is not supported on device. Will use WebView.")
webViewFallbackLauncher.startActivity(
WebViewConfiguration(
POWebViewConfiguration(
uri = delegate.uri,
returnUris = listOf(
Uri.parse(ApiConstants.CHECKOUT_RETURN_URL),
Uri.parse(returnUrl)
),
sdkVersion = ProcessOut.VERSION,
timeoutSeconds = redirect.timeoutSeconds,
resultApi = ActivityResultApi.Dispatcher
resultApi = POActivityResultApi.Dispatcher
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.processout.sdk.api.network.ApiConstants
import com.processout.sdk.core.ProcessOutResult
import com.processout.sdk.ui.web.WebAuthorizationDelegate
import com.processout.sdk.ui.web.webview.ProcessOutWebView
import com.processout.sdk.ui.web.webview.WebViewConfiguration
import com.processout.sdk.ui.web.webview.POWebViewConfiguration

@Deprecated("Use PO3DSRedirectCustomTabLauncher.")
class PO3DSRedirectWebViewBuilder(
Expand All @@ -29,7 +29,7 @@ class PO3DSRedirectWebViewBuilder(

fun build(): WebView = ProcessOutWebView(
activity,
WebViewConfiguration(
POWebViewConfiguration(
uri = delegate?.uri,
returnUris = listOf(Uri.parse(ApiConstants.CHECKOUT_RETURN_URL)),
sdkVersion = ProcessOut.VERSION,
Expand Down
Loading