commit 3e58682c6f81da19fe160d2f500fa6d1757c736c
parent 95bc45f1ccad04b36f3079b6c29a5979a2fb0e8a
Author: Iván Ávalos <avalos@disroot.org>
Date: Wed, 6 May 2026 22:59:06 +0200
[wallet] add Paivana support
Diffstat:
4 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateDetails.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateDetails.kt
@@ -22,7 +22,24 @@ import net.taler.common.Amount
import net.taler.common.RelativeTime
@Serializable
+enum class TemplateType {
+ @SerialName("fixed-order")
+ FixedOrder,
+
+ @SerialName("inventory-cart")
+ InventoryCart,
+
+ @SerialName("paivana")
+ Paivana,
+
+ Unknown,
+}
+
+@Serializable
data class TemplateContractDetails(
+ @SerialName("template_type")
+ val templateType: TemplateType? = null,
+
/**
* Human-readable summary for the template.
*/
@@ -45,14 +62,14 @@ data class TemplateContractDetails(
* Minimum age buyer must have (in years). Default is 0.
*/
@SerialName("minimum_age")
- val minimumAge: Int,
+ val minimumAge: Int? = null,
/**
* The time the customer need to pay before his order will be deleted. It
* is deleted if the customer did not pay and if the duration is over.
*/
@SerialName("pay_duration")
- val payDuration: RelativeTime,
+ val payDuration: RelativeTime? = null,
)
@Serializable
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateOrderComposable.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateOrderComposable.kt
@@ -133,6 +133,7 @@ fun PayTemplateOrderComposable(
val defaultTemplateDetails = WalletTemplateDetails(
templateContract = TemplateContractDetails(
+ templateType = TemplateType.FixedOrder,
minimumAge = 18,
payDuration = RelativeTime.forever(),
),
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt
@@ -270,10 +270,14 @@ class PaymentManager(
}.onError {
handleError("checkPayForTemplate", it)
}.onSuccess { response ->
- mPayStatus.value = PayStatus.Checked(
- details = response.templateDetails,
- supportedCurrencies = response.supportedCurrencies,
- )
+ if (response.templateDetails.templateContract.templateType == TemplateType.Paivana) {
+ scope.launch { preparePayForTemplate(url, TemplateParams()) }
+ } else {
+ mPayStatus.value = PayStatus.Checked(
+ details = response.templateDetails,
+ supportedCurrencies = response.supportedCurrencies,
+ )
+ }
}
}
@@ -287,6 +291,8 @@ class PaymentManager(
}.onSuccess { response ->
mPayStatus.value = when (response) {
is PaymentPossibleResponse -> response.toPayStatusPrepared()
+ is PreparePayResponse.ChoiceSelection -> response.toPayStatusPrepared()
+
is InsufficientBalanceResponse -> InsufficientBalance(
transactionId = response.transactionId,
contractTerms = response.contractTerms,
@@ -297,9 +303,6 @@ class PaymentManager(
is AlreadyConfirmedResponse -> AlreadyPaid(
transactionId = response.transactionId,
)
-
- // only applies to regular payments
- is PreparePayResponse.ChoiceSelection -> return@onSuccess
}
}
}
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt
@@ -79,7 +79,12 @@ sealed class PreparePayResponse {
data class ChoiceSelection(
val transactionId: String,
val contractTerms: ContractTerms,
- ) : PreparePayResponse()
+ ) : PreparePayResponse() {
+ fun toPayStatusPrepared() = PayStatus.Prepared(
+ contractTerms = contractTerms,
+ transactionId = transactionId,
+ )
+ }
}
@Serializable