Skip to content

Commit ddbf98b

Browse files
fix(ad-hoc): (nAPM) Open UI automatically when headless mode is not supported (#385)
1 parent 9584f58 commit ddbf98b

5 files changed

Lines changed: 33 additions & 12 deletions

File tree

‎build.gradle‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ ext {
8282
okhttpVersion = '4.12.0'
8383
okioVersion = '3.10.2'
8484
coilVersion = '2.7.0'
85-
commonMarkVersion = '0.27.0'
86-
libphonenumberVersion = '9.0.19'
85+
commonMarkVersion = '0.28.0'
86+
libphonenumberVersion = '9.0.30'
8787
zxingVersion = '3.5.4'
8888
jjwtVersion = '0.13.0'
8989
slf4jVersion = '1.7.36'

‎sdk/src/main/kotlin/com/processout/sdk/core/POFailure.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.processout.sdk.core
44

55
import android.os.Parcelable
6+
import com.processout.sdk.core.annotation.ProcessOutInternalApi
67
import com.squareup.moshi.Json
78
import com.squareup.moshi.JsonClass
89
import kotlinx.parcelize.Parcelize
@@ -289,7 +290,10 @@ class POFailure private constructor() {
289290
resourceNotLinked("resource.not-linked"),
290291
routingRulesTransactionBlocked("routing-rules.transaction-blocked"),
291292
sandboxNotSupported("sandbox.not-supported"),
292-
serviceNotSupported("service.not-supported")
293+
serviceNotSupported("service.not-supported"),
294+
295+
@ProcessOutInternalApi
296+
mobileHeadlessModeNotSupported("processout-mobile.generic.headless-mode-not-supported")
293297
}
294298

295299
/**

‎ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import com.processout.sdk.api.model.response.napm.v2.PONativeAlternativePaymentS
3636
import com.processout.sdk.api.service.POCustomerTokensService
3737
import com.processout.sdk.api.service.POInvoicesService
3838
import com.processout.sdk.core.POFailure.Code.*
39-
import com.processout.sdk.core.POFailure.GenericCode.mobileOperationNotSupported
39+
import com.processout.sdk.core.POFailure.GenericCode.mobileHeadlessModeNotSupported
4040
import com.processout.sdk.core.POFailure.InvalidField
4141
import com.processout.sdk.core.POFailure.ValidationCode
4242
import com.processout.sdk.core.ProcessOutResult
@@ -352,10 +352,10 @@ internal class NativeAlternativePaymentInteractor(
352352
): Boolean {
353353
if (configuration.redirect?.enableHeadlessMode == true && redirect == null) {
354354
val failure = ProcessOutResult.Failure(
355-
code = Generic(genericCode = mobileOperationNotSupported),
355+
code = Generic(genericCode = mobileHeadlessModeNotSupported),
356356
message = "Headless mode is not supported: redirect parameters are missing in the response."
357357
)
358-
POLogger.error(
358+
POLogger.info(
359359
message = "Unsupported operation: %s", failure,
360360
attributes = configuration.logAttributes
361361
)

‎ui/src/main/kotlin/com/processout/sdk/ui/napm/PONativeAlternativePaymentConfiguration.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ data class PONativeAlternativePaymentConfiguration(
395395
* @param[enableHeadlessMode] Enables headless mode.
396396
* The redirect (web or deep link) will be handled directly when it's the first step in the flow, without starting the bottom sheet.
397397
* It will also capture the payment in the background when it's required by the flow.
398-
* __Note:__ use only with flows that do not require user input or instructions in the native UI.
398+
* __Note:__ The bottom sheet will still start automatically when the payment method requires user input in the native UI.
399399
* @param[redirectButton] Redirect button configuration.
400400
* Pass _null_ to hide and redirect automatically, this is a default behaviour.
401401
*/

‎ui/src/main/kotlin/com/processout/sdk/ui/napm/PONativeAlternativePaymentLauncher.kt‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ import androidx.lifecycle.repeatOnLifecycle
1616
import com.processout.sdk.R
1717
import com.processout.sdk.api.dispatcher.POEventDispatcher
1818
import com.processout.sdk.api.model.response.POAlternativePaymentMethodResponse
19-
import com.processout.sdk.core.POUnit
20-
import com.processout.sdk.core.ProcessOutActivityResult
21-
import com.processout.sdk.core.ProcessOutResult
19+
import com.processout.sdk.core.*
20+
import com.processout.sdk.core.POFailure.GenericCode.mobileHeadlessModeNotSupported
2221
import com.processout.sdk.core.logger.POLogger
23-
import com.processout.sdk.core.toActivityResult
2422
import com.processout.sdk.ui.apm.POAlternativePaymentMethodCustomTabLauncher
2523
import com.processout.sdk.ui.napm.NativeAlternativePaymentCompletion.Failure
2624
import com.processout.sdk.ui.napm.NativeAlternativePaymentCompletion.Success
@@ -281,7 +279,26 @@ class PONativeAlternativePaymentLauncher private constructor(
281279
viewModel.completion.collect { completion ->
282280
when (completion) {
283281
Success -> complete(result = ProcessOutResult.Success(POUnit))
284-
is Failure -> complete(result = completion.failure)
282+
is Failure -> {
283+
val isHeadlessModeNotSupported = when (val code = completion.failure.code) {
284+
is POFailure.Code.Generic -> code.genericCode == mobileHeadlessModeNotSupported
285+
else -> false
286+
}
287+
if (isHeadlessModeNotSupported) {
288+
val configuration = viewModel.configuration
289+
viewModel.reset()
290+
launcher.launch(
291+
input = configuration.copy(
292+
redirect = configuration.redirect?.copy(
293+
enableHeadlessMode = false
294+
)
295+
),
296+
options = activityOptions
297+
)
298+
} else {
299+
complete(result = completion.failure)
300+
}
301+
}
285302
else -> {}
286303
}
287304
}

0 commit comments

Comments
 (0)