summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/payment/TransactionPaymentComposable.kt
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/payment/TransactionPaymentComposable.kt')
-rw-r--r--wallet/src/main/java/net/taler/wallet/payment/TransactionPaymentComposable.kt57
1 files changed, 39 insertions, 18 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/payment/TransactionPaymentComposable.kt b/wallet/src/main/java/net/taler/wallet/payment/TransactionPaymentComposable.kt
index c760bb4..0f6d661 100644
--- a/wallet/src/main/java/net/taler/wallet/payment/TransactionPaymentComposable.kt
+++ b/wallet/src/main/java/net/taler/wallet/payment/TransactionPaymentComposable.kt
@@ -32,6 +32,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import net.taler.common.Amount
import net.taler.common.ContractMerchant
+import net.taler.common.CurrencySpecification
import net.taler.common.Timestamp
import net.taler.common.toAbsoluteTime
import net.taler.wallet.R
@@ -39,22 +40,27 @@ import net.taler.wallet.backend.TalerErrorCode
import net.taler.wallet.backend.TalerErrorInfo
import net.taler.wallet.compose.TalerSurface
import net.taler.wallet.transactions.AmountType
-import net.taler.wallet.transactions.DeleteTransactionComposable
import net.taler.wallet.transactions.ErrorTransactionButton
-import net.taler.wallet.transactions.ExtendedStatus
-import net.taler.wallet.transactions.PaymentStatus
+import net.taler.wallet.transactions.TransactionAction
+import net.taler.wallet.transactions.TransactionAction.Abort
+import net.taler.wallet.transactions.TransactionAction.Retry
+import net.taler.wallet.transactions.TransactionAction.Suspend
import net.taler.wallet.transactions.TransactionAmountComposable
import net.taler.wallet.transactions.TransactionInfo
import net.taler.wallet.transactions.TransactionInfoComposable
import net.taler.wallet.transactions.TransactionLinkComposable
+import net.taler.wallet.transactions.TransactionMajorState.Pending
import net.taler.wallet.transactions.TransactionPayment
+import net.taler.wallet.transactions.TransactionState
+import net.taler.wallet.transactions.TransitionsComposable
@Composable
fun TransactionPaymentComposable(
t: TransactionPayment,
devMode: Boolean,
+ spec: CurrencySpecification?,
onFulfill: (url: String) -> Unit,
- onDelete: () -> Unit,
+ onTransition: (t: TransactionAction) -> Unit,
) {
val scrollState = rememberScrollState()
Column(
@@ -69,25 +75,40 @@ fun TransactionPaymentComposable(
text = t.timestamp.ms.toAbsoluteTime(context).toString(),
style = MaterialTheme.typography.bodyLarge,
)
- TransactionAmountComposable(
- label = stringResource(id = R.string.transaction_paid),
- amount = t.amountEffective,
- amountType = AmountType.Negative,
- )
+
TransactionAmountComposable(
label = stringResource(id = R.string.transaction_order_total),
- amount = t.amountRaw,
+ amount = t.amountRaw.withSpec(spec),
amountType = AmountType.Neutral,
)
+
+ val fee = t.amountEffective - t.amountRaw
+ if (!fee.isZero()) {
+ TransactionAmountComposable(
+ label = stringResource(id = R.string.withdraw_fees),
+ amount = fee.withSpec(spec),
+ amountType = AmountType.Negative,
+ )
+ }
+
TransactionAmountComposable(
- label = stringResource(id = R.string.withdraw_fees),
- amount = t.amountEffective - t.amountRaw,
+ label = stringResource(id = R.string.transaction_paid),
+ amount = t.amountEffective.withSpec(spec),
amountType = AmountType.Negative,
)
+
+ if (t.posConfirmation != null) {
+ TransactionInfoComposable(
+ label = stringResource(id = R.string.payment_confirmation_code),
+ info = t.posConfirmation,
+ )
+ }
+
PurchaseDetails(info = t.info) {
onFulfill(t.info.fulfillmentUrl ?: "")
}
- DeleteTransactionComposable(onDelete)
+
+ TransitionsComposable(t, devMode, onTransition)
if (devMode && t.error != null) {
ErrorTransactionButton(error = t.error)
}
@@ -133,7 +154,8 @@ fun TransactionPaymentComposablePreview() {
val t = TransactionPayment(
transactionId = "transactionId",
timestamp = Timestamp.fromMillis(System.currentTimeMillis() - 360 * 60 * 1000),
- extendedStatus = ExtendedStatus.Pending,
+ txState = TransactionState(Pending),
+ txActions = listOf(Retry, Suspend, Abort),
info = TransactionInfo(
orderId = "123",
merchant = ContractMerchant(name = "Taler"),
@@ -142,12 +164,11 @@ fun TransactionPaymentComposablePreview() {
fulfillmentUrl = "https://bank.demo.taler.net/",
products = listOf(),
),
- status = PaymentStatus.Paid,
- amountRaw = Amount.fromDouble("TESTKUDOS", 42.1337),
- amountEffective = Amount.fromDouble("TESTKUDOS", 42.23),
+ amountRaw = Amount.fromString("TESTKUDOS", "42.1337"),
+ amountEffective = Amount.fromString("TESTKUDOS", "42.23"),
error = TalerErrorInfo(code = TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED),
)
TalerSurface {
- TransactionPaymentComposable(t = t, devMode = true, onFulfill = {}) {}
+ TransactionPaymentComposable(t = t, devMode = true, spec = null, onFulfill = {}) {}
}
}