Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,7 +14,7 @@ import okhttp3.RequestBody.Companion.toRequestBody

internal interface DatatransRemoteDataSource {

suspend fun sendUserData(customerDataDto: CustomerDataDto): Result<AuthDataDto>
suspend fun sendUserData(customerDataDto: CustomerDataDto, projectId: String): Result<AuthDataDto>
}

internal class DatatransRemoteDataSourceImpl(
Expand All @@ -24,9 +24,10 @@ internal class DatatransRemoteDataSourceImpl(

override suspend fun sendUserData(
customerDataDto: CustomerDataDto,
projectId: String
): Result<AuthDataDto> {
val project =
snabble.checkedInProject.value ?: return Result.failure(Exception("Missing projectId"))
val project = snabble.projects.find { it.id == projectId }
?: return Result.failure(Exception("Missing projectId"))

val customerInfoPostUrl =
project.paymentMethodDescriptors.getTokenizationUrlFor(customerDataDto.paymentMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ internal class DatatransRepositoryImpl(

override suspend fun sendUserData(
customerInfo: CustomerInfo,
paymentMethod: PaymentMethod
paymentMethod: PaymentMethod,
projectId: String
): Result<AuthData> {
return datatransRemoteDataSource.sendUserData(createTokenizationRequest(customerInfo, paymentMethod))
return datatransRemoteDataSource.sendUserData(createCustomerData(customerInfo, paymentMethod), projectId)
.map { it.toResponse() }
}
}

private fun createTokenizationRequest(
private fun createCustomerData(
customerInfo: CustomerInfo,
paymentMethod: PaymentMethod
) = CustomerDataDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal interface DatatransRepository {

suspend fun sendUserData(
customerInfo: CustomerInfo,
paymentMethod: PaymentMethod
paymentMethod: PaymentMethod,
projectId: String
): Result<AuthData>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.launch

class DatatransFragment : Fragment() {
open class DatatransFragment : Fragment() {

private val viewModel: DatatransViewModel by viewModels { DatatransViewModelFactory(requireContext()) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ internal class DatatransViewModel(
fun sendUserData(customerInfo: CustomerInfo) {
viewModelScope.launch {
paymentMethod ?: return@launch
datatransRepository.sendUserData(customerInfo, paymentMethod)
projectId ?: return@launch

datatransRepository.sendUserData(customerInfo, paymentMethod, projectId)
.onSuccess { info ->
_uiState.update { it.copy(isLoading = false) }
_event.update { Event.TransActionCreated(createTransaction(info.mobileToken, info.isTesting)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import io.snabble.sdk.PaymentMethod
import io.snabble.sdk.Snabble
import io.snabble.sdk.ui.payment.PaymentMethodMetaDataHelper
import io.snabble.sdk.ui.payment.creditcard.shared.CustomerInfoInputScreen
import io.snabble.sdk.ui.utils.ThemeWrapper
import io.snabble.sdk.ui.utils.serializableExtra

class FiservInputFragment : Fragment() {
open class FiservInputFragment : Fragment() {

private val viewModel: FiservViewModel by viewModels { FiservViewModelFactory(requireContext()) }

private lateinit var paymentMethod: PaymentMethod
private lateinit var projectId: String

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -30,6 +30,9 @@ class FiservInputFragment : Fragment() {
arguments?.serializableExtra<PaymentMethod>(FiservInputView.ARG_PAYMENT_TYPE)
?: kotlin.run { activity?.onBackPressed(); return }

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

(requireActivity() as? AppCompatActivity)?.supportActionBar?.title =
PaymentMethodMetaDataHelper(requireContext()).labelFor(paymentMethod)
}
Expand Down Expand Up @@ -57,7 +60,7 @@ class FiservInputFragment : Fragment() {
FiservInputView(context)
.apply {
load(
Snabble.checkedInProject.value?.id,
projectId,
paymentMethod,
uiState.formUrl,
uiState.deletePreAuthUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ internal class FiservViewModel(
savedStateHandle: SavedStateHandle
) : ViewModel() {

private val _uiState = MutableStateFlow(UiState(countryItems = countryItemsRepo.loadCountryItems()))
private val _uiState =
MutableStateFlow(UiState(countryItems = countryItemsRepo.loadCountryItems()))
val uiState: StateFlow<UiState> = _uiState.asStateFlow()

private val paymentMethod = savedStateHandle.get<PaymentMethod>(FiservInputView.ARG_PAYMENT_TYPE)
private val paymentMethod =
savedStateHandle.get<PaymentMethod>(FiservInputView.ARG_PAYMENT_TYPE)
private val projectId = savedStateHandle.get<String>(FiservInputView.ARG_PROJECT_ID)

fun sendUserData(customerInfo: CustomerInfo) {
viewModelScope.launch {
paymentMethod ?: return@launch
projectId ?: return@launch

_uiState.update { it.copy(isLoading = true, showError = false) }

fiservRepo.sendUserData(customerInfo, paymentMethod)
fiservRepo.sendUserData(customerInfo, paymentMethod, projectId)
.onSuccess { info ->
_uiState.update {
it.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ internal interface FiservRemoteDataSource {

suspend fun sendUserData(
customerInfo: CustomerInfoDto,
paymentMethod: PaymentMethod
paymentMethod: PaymentMethod,
projectId: String
): Result<AuthDataDto>
}

Expand All @@ -28,10 +29,11 @@ internal class FiservRemoteDataSourceImpl(

override suspend fun sendUserData(
customerInfo: CustomerInfoDto,
paymentMethod: PaymentMethod
paymentMethod: PaymentMethod,
projectId: String
): Result<AuthDataDto> {
val project =
snabble.checkedInProject.value ?: return Result.failure(Exception("Missing projectId"))
val project = snabble.projects.find { it.id == projectId }
?: return Result.failure(Exception("Missing projectId"))

val customerInfoPostUrl =
project.paymentMethodDescriptors.getTokenizationUrlFor(paymentMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ internal class FiservRepositoryImpl(

override suspend fun sendUserData(
customerInfo: CustomerInfo,
paymentMethod: PaymentMethod
paymentMethod: PaymentMethod,
projectId: String
): Result<AuthData> =
remoteDataSource
.sendUserData(customerInfo.toDto(), paymentMethod)
.sendUserData(customerInfo.toDto(), paymentMethod, projectId)
.map { AuthData(it.links.formUrl.href, it.links.deleteUrl.href) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal interface FiservRepository {

suspend fun sendUserData(
customerInfo: CustomerInfo,
paymentMethod: PaymentMethod
paymentMethod: PaymentMethod,
projectId: String
): Result<AuthData>
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,6 @@ private fun List<CountryItem>?.loadDefaultCountry(): CountryItem =
?: CountryItem(
displayName = Locale.GERMANY.country.displayName,
code = Locale.GERMANY.country,
numericCode = "",
numericCode = "276",
stateItems = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal suspend inline fun <reified T> OkHttpClient.post(request: Request, gson
}

val result = if (data == null) {
Log.e("Payment", body ?: "Unkown cause")
Result.failure(Exception("Missing content"))
} else {
Result.success(data)
Expand All @@ -47,13 +48,15 @@ internal suspend inline fun <reified T> OkHttpClient.post(request: Request, gson
}

else -> {
response.body?.string()
val body = response.body?.string()
Log.e("Payment", body ?: "Unkown cause")
it.resume(Result.failure(Exception(response.message)))
}
}
}

override fun onFailure(call: Call, e: IOException) {
Log.e("Payment", e.localizedMessage ?: "Unkown cause")
it.resume(Result.failure(e))
}
})
Expand Down