Skip to content

Commit

Permalink
Merge pull request #44 from DatepollSystems/wr-378-already-payed
Browse files Browse the repository at this point in the history
WR-378: Fix error message for already payed
  • Loading branch information
dev-Fabi committed Sep 17, 2024
2 parents 4471b43 + 18dcc6d commit e4cda08
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
7 changes: 7 additions & 0 deletions shared/localization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ billing:
noOpenBill:
en: There is currently no open bill for table \"%1$s - %2$s\"
de: Es gibt derzeit keine offene Rechnung für den Tisch \"%1$s - %2$s\"
productsAlreadyPayed:
title:
en: Already payed
de: Bereits bezahlt
desc:
en: Some of the selected products are already payed.
de: Einige der ausgewählten Produkte sind bereits bezahlt.
amountToLow:
en: The selected payment method requires a minimum amount of %1$s.
de: Die ausgewählte Zahlungsmethode erfordert einen Mindestbetrag von %1$s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ internal sealed class ApiException : Exception() {
@SerialName("BILL_AMOUNT_TOO_LOW")
class BillAmountTooLow(val minAmount: Cents) : ApiException()

@Serializable
@SerialName("BILL_PRODUCTS_ALREADY_PAYED")
class BillProductsAlreadyPayed(val orderProductIds: Set<Long>) : ApiException()

@Serializable
@SerialName("STRIPE_NOT_ACTIVATED")
class StripeNotActivated(val eventId: Long) : ApiException()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.datepollsystems.waiterrobot.shared.features.billing.viewmodel

import org.datepollsystems.waiterrobot.shared.core.CommonApp
import org.datepollsystems.waiterrobot.shared.core.data.api.ApiException
import org.datepollsystems.waiterrobot.shared.core.navigation.NavOrViewModelEffect
import org.datepollsystems.waiterrobot.shared.core.viewmodel.AbstractViewModel
import org.datepollsystems.waiterrobot.shared.core.viewmodel.DialogState
Expand Down Expand Up @@ -57,18 +58,27 @@ class BillingViewModel internal constructor(

reduce { state.withViewState(viewState = ViewState.Loading) }

val newBillItems = billingRepository.payBill(
table = table,
items = state.billItems.filter { it.selectedForBill > 0 },
selectAll = CommonApp.settings.paymentSelectAllProductsByDefault
)
try {
val newBillItems = billingRepository.payBill(
table = table,
items = state.billItems.filter { it.selectedForBill > 0 },
selectAll = CommonApp.settings.paymentSelectAllProductsByDefault
)

reduce {
state.copy(
viewState = ViewState.Idle,
_billItems = newBillItems.associateBy { it.virtualId },
change = null,
moneyGivenText = ""
reduce {
state.copy(
viewState = ViewState.Idle,
_billItems = newBillItems.associateBy { it.virtualId },
change = null,
moneyGivenText = ""
)
}
} catch (_: ApiException.BillProductsAlreadyPayed) {
logger.i("Some products have already been payed.")
reduceError(
L.billing.productsAlreadyPayed.title(),
L.billing.productsAlreadyPayed.desc(),
dismiss = ::loadBill
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ internal fun ApiException.getLocalizedUserMessage(): String = when (this) {
is ApiException.StripeNotActivated -> L.stripeInit.error.disabledForEvent()
is ApiException.ProductStockToLow -> L.order.stockToLow.title()
is ApiException.OrderAlreadySubmitted -> L.order.alreadyCreated()
is ApiException.BillProductsAlreadyPayed -> L.billing.productsAlreadyPayed.desc()

// Unknown exceptions or exceptions that should normally not happen
is ApiException.Generic,
Expand Down

0 comments on commit e4cda08

Please sign in to comment.