diff options
author | Iván Ávalos <avalos@disroot.org> | 2024-01-30 18:55:55 -0600 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2024-02-02 15:56:57 -0300 |
commit | f004af7b746a436e7317d5c27f8f261bd7a407f0 (patch) | |
tree | f9b4ad5b3fa40d4e53d5dd640439f3ae6bc02de8 /wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt | |
parent | 636b11b195cd250b96e7de4bea5fa32fc374d2a2 (diff) | |
download | taler-android-f004af7b746a436e7317d5c27f8f261bd7a407f0.tar.gz taler-android-f004af7b746a436e7317d5c27f8f261bd7a407f0.tar.bz2 taler-android-f004af7b746a436e7317d5c27f8f261bd7a407f0.zip |
[wallet] Redirect to details view after payment, deprecate proposalId, and remove pending op actions
bug 0008297
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt')
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt index 3a3069c..19be280 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt @@ -41,7 +41,7 @@ sealed class PayStatus { object Loading : PayStatus() data class Prepared( val contractTerms: ContractTerms, - val proposalId: String, + val transactionId: String, val amountRaw: Amount, val amountEffective: Amount, ) : PayStatus() @@ -51,10 +51,18 @@ sealed class PayStatus { val amountRaw: Amount, ) : PayStatus() - // TODO bring user to fulfilment URI - object AlreadyPaid : PayStatus() - data class Error(val error: TalerErrorInfo) : PayStatus() - data class Success(val currency: String) : PayStatus() + data class AlreadyPaid( + val transactionId: String, + ) : PayStatus() + + data class Error( + val transactionId: String? = null, + val error: TalerErrorInfo, + ) : PayStatus() + data class Success( + val transactionId: String, + val currency: String, + ) : PayStatus() } class PaymentManager( @@ -76,32 +84,33 @@ class PaymentManager( mPayStatus.value = when (response) { is PaymentPossibleResponse -> response.toPayStatusPrepared() is InsufficientBalanceResponse -> InsufficientBalance( - response.contractTerms, - response.amountRaw + contractTerms = response.contractTerms, + amountRaw = response.amountRaw + ) + is AlreadyConfirmedResponse -> AlreadyPaid( + transactionId = response.transactionId, ) - - is AlreadyConfirmedResponse -> AlreadyPaid } } } - fun confirmPay(proposalId: String, currency: String) = scope.launch { + fun confirmPay(transactionId: String, currency: String) = scope.launch { api.request("confirmPay", ConfirmPayResult.serializer()) { - put("proposalId", proposalId) + put("transactionId", transactionId) }.onError { handleError("confirmPay", it) - }.onSuccess { - mPayStatus.postValue(PayStatus.Success(currency)) - } - } - - @UiThread - fun abortPay() { - val ps = payStatus.value - if (ps is PayStatus.Prepared) { - abortProposal(ps.proposalId) + }.onSuccess { response -> + mPayStatus.postValue(when (response) { + is ConfirmPayResult.Done -> PayStatus.Success( + transactionId = response.transactionId, + currency = currency, + ) + is ConfirmPayResult.Pending -> PayStatus.Error( + transactionId = response.transactionId, + error = response.lastError, + ) + }) } - resetPayStatus() } fun preparePayForTemplate(url: String, summary: String?, amount: Amount?) = scope.launch { @@ -122,23 +131,13 @@ class PaymentManager( amountRaw = response.amountRaw, ) - is AlreadyConfirmedResponse -> AlreadyPaid + is AlreadyConfirmedResponse -> AlreadyPaid( + transactionId = response.transactionId, + ) } } } - internal fun abortProposal(proposalId: String) = scope.launch { - Log.i(TAG, "aborting proposal") - api.request<Unit>("abortProposal") { - put("proposalId", proposalId) - }.onError { - Log.e(TAG, "received error response to abortProposal") - handleError("abortProposal", it) - }.onSuccess { - mPayStatus.postValue(PayStatus.None) - } - } - @UiThread fun resetPayStatus() { mPayStatus.value = PayStatus.None @@ -146,7 +145,7 @@ class PaymentManager( private fun handleError(operation: String, error: TalerErrorInfo) { Log.e(TAG, "got $operation error result $error") - mPayStatus.value = PayStatus.Error(error) + mPayStatus.value = PayStatus.Error(error = error) } } |