Skip to content

Commit 6beebb9

Browse files
authored
Provide integration ready fiserv composable (#202)
1 parent 5a0eae5 commit 6beebb9

File tree

4 files changed

+59
-36
lines changed

4 files changed

+59
-36
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ All notable changes to this project will be documented in this file.
77
### Removed
88
### Fixed
99

10+
## [0.75.4]
11+
### Added
12+
* Provide integration ready Fiserv composable
13+
14+
## [0.75.3]
15+
### Added
16+
* Add empty implementation for the ShoppingCartListener #201
17+
1018
## [0.75.2]
1119
### Fixed
1220
* ui: crash due to missing project id when adding a credit card

ui/src/main/java/io/snabble/sdk/ui/payment/PaymentInputViewHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object PaymentInputViewHelper {
4545
usePayone -> Payone.registerCard(activity, project, paymentMethod, Snabble.formPrefillData)
4646
useFiserv -> {
4747
args.putString(FiservInputView.ARG_PROJECT_ID, projectId)
48-
args.putSerializable(FiservInputView.ARG_PAYMENT_TYPE, paymentMethod)
48+
args.putSerializable(FiservInputView.ARG_PAYMENT_TYPE, paymentMethod.name)
4949
SnabbleUI.executeAction(context, SnabbleUI.Event.SHOW_FISERV_INPUT, args)
5050
}
5151

ui/src/main/java/io/snabble/sdk/ui/payment/creditcard/fiserv/FiservInputFragment.kt

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import android.view.LayoutInflater
55
import android.view.View
66
import android.view.ViewGroup
77
import androidx.appcompat.app.AppCompatActivity
8+
import androidx.compose.runtime.Composable
89
import androidx.compose.ui.platform.ComposeView
10+
import androidx.compose.ui.platform.LocalContext
911
import androidx.compose.ui.viewinterop.AndroidView
1012
import androidx.fragment.app.Fragment
11-
import androidx.fragment.app.viewModels
1213
import androidx.lifecycle.compose.collectAsStateWithLifecycle
14+
import androidx.lifecycle.viewmodel.compose.viewModel
1315
import io.snabble.sdk.PaymentMethod
1416
import io.snabble.sdk.ui.payment.PaymentMethodMetaDataHelper
1517
import io.snabble.sdk.ui.payment.creditcard.shared.CustomerInfoInputScreen
@@ -18,57 +20,70 @@ import io.snabble.sdk.ui.utils.serializableExtra
1820

1921
open class FiservInputFragment : Fragment() {
2022

21-
private val viewModel: FiservViewModel by viewModels { FiservViewModelFactory(requireContext()) }
22-
23-
private lateinit var paymentMethod: PaymentMethod
23+
private lateinit var paymentMethod: String
2424
private lateinit var projectId: String
2525

2626
override fun onCreate(savedInstanceState: Bundle?) {
2727
super.onCreate(savedInstanceState)
2828

2929
paymentMethod =
30-
arguments?.serializableExtra<PaymentMethod>(FiservInputView.ARG_PAYMENT_TYPE)
30+
arguments?.serializableExtra<String>(FiservInputView.ARG_PAYMENT_TYPE)
3131
?: kotlin.run { activity?.onBackPressed(); return }
3232

3333
projectId = arguments?.serializableExtra<String>(FiservInputView.ARG_PROJECT_ID)
3434
?: kotlin.run { activity?.onBackPressed(); return }
3535

3636
(requireActivity() as? AppCompatActivity)?.supportActionBar?.title =
37-
PaymentMethodMetaDataHelper(requireContext()).labelFor(paymentMethod)
37+
PaymentMethodMetaDataHelper(requireContext()).labelFor(PaymentMethod.valueOf(paymentMethod))
3838
}
3939

4040
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
4141
ComposeView(inflater.context).apply {
4242
setContent {
43-
val uiState: UiState = viewModel.uiState.collectAsStateWithLifecycle().value
43+
FiservScreen(
44+
projectId = projectId,
45+
paymentMethod = PaymentMethod.valueOf(paymentMethod),
46+
onBackNavigationClick = { activity?.onBackPressed() }
47+
)
48+
}
49+
}
50+
}
4451

45-
when {
46-
uiState.formUrl == null ->
47-
ThemeWrapper {
48-
CustomerInfoInputScreen(
49-
onErrorProcessed = { viewModel.errorHandled() },
50-
isLoading = uiState.isLoading,
51-
onSendAction = { viewModel.sendUserData(it) },
52-
showError = uiState.showError,
53-
countryItems = uiState.countryItems,
54-
onBackNavigationClick = { activity?.onBackPressed() }
55-
)
56-
}
52+
@Composable
53+
fun FiservScreen(
54+
projectId: String,
55+
paymentMethod: PaymentMethod,
56+
onBackNavigationClick: () -> Unit,
57+
) {
58+
val context = LocalContext.current
59+
val viewModel: FiservViewModel = viewModel(factory = FiservViewModelFactory(context))
60+
val uiState: UiState = viewModel.uiState.collectAsStateWithLifecycle().value
5761

58-
else -> AndroidView(
59-
factory = { context ->
60-
FiservInputView(context)
61-
.apply {
62-
load(
63-
projectId,
64-
paymentMethod,
65-
uiState.formUrl,
66-
uiState.deletePreAuthUrl
67-
)
68-
}
69-
}
70-
)
71-
}
62+
when {
63+
uiState.formUrl == null ->
64+
ThemeWrapper {
65+
CustomerInfoInputScreen(
66+
onErrorProcessed = { viewModel.errorHandled() },
67+
isLoading = uiState.isLoading,
68+
onSendAction = { viewModel.sendUserData(it) },
69+
showError = uiState.showError,
70+
countryItems = uiState.countryItems,
71+
onBackNavigationClick = onBackNavigationClick
72+
)
7273
}
73-
}
74+
75+
else -> AndroidView(
76+
factory = { ctx ->
77+
FiservInputView(ctx)
78+
.apply {
79+
load(
80+
projectId,
81+
paymentMethod,
82+
uiState.formUrl,
83+
uiState.deletePreAuthUrl
84+
)
85+
}
86+
}
87+
)
88+
}
7489
}

ui/src/main/java/io/snabble/sdk/ui/payment/creditcard/fiserv/FiservViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal class FiservViewModel(
2525
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
2626

2727
private val paymentMethod =
28-
savedStateHandle.get<PaymentMethod>(FiservInputView.ARG_PAYMENT_TYPE)
28+
savedStateHandle.get<String>(FiservInputView.ARG_PAYMENT_TYPE)?.let { PaymentMethod.valueOf(it) }
2929
private val projectId = savedStateHandle.get<String>(FiservInputView.ARG_PROJECT_ID)
3030

3131
fun sendUserData(customerInfo: CustomerInfo) {

0 commit comments

Comments
 (0)