diff options
author | Iván Ávalos <avalos@disroot.org> | 2023-08-11 23:08:46 +0200 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2023-09-26 18:30:51 +0200 |
commit | cb6d8362746481b383d559280c8cfadbed082231 (patch) | |
tree | f5f3d5c0349a646e1148f06a270fe18aac62e4a6 /wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt | |
parent | d7196a07eaaf5ca52906a8c987144c7b9814dfef (diff) | |
download | taler-android-cb6d8362746481b383d559280c8cfadbed082231.tar.gz taler-android-cb6d8362746481b383d559280c8cfadbed082231.tar.bz2 taler-android-cb6d8362746481b383d559280c8cfadbed082231.zip |
[wallet] Initial version of template support
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 | 21 |
1 files changed, 21 insertions, 0 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 c280304..538f2e1 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt @@ -32,6 +32,7 @@ import net.taler.wallet.payment.PayStatus.InsufficientBalance import net.taler.wallet.payment.PreparePayResponse.AlreadyConfirmedResponse import net.taler.wallet.payment.PreparePayResponse.InsufficientBalanceResponse import net.taler.wallet.payment.PreparePayResponse.PaymentPossibleResponse +import org.json.JSONObject val REGEX_PRODUCT_IMAGE = Regex("^data:image/(jpeg|png);base64,([A-Za-z0-9+/=]+)$") @@ -102,6 +103,26 @@ class PaymentManager( resetPayStatus() } + fun preparePayForTemplate(url: String, params: Map<String, String>) = scope.launch { + api.request("preparePayForTemplate", PreparePayResponse.serializer()) { + put("talerPayTemplateUri", url) + put("templateParams", JSONObject().apply { + params.forEach { put(it.key, it.value) } + }) + }.onError { + handleError("preparePayForTemplate", it) + }.onSuccess { response -> + mPayStatus.value = when (response) { + is PaymentPossibleResponse -> response.toPayStatusPrepared() + is InsufficientBalanceResponse -> InsufficientBalance( + response.contractTerms, + response.amountRaw + ) + is AlreadyConfirmedResponse -> AlreadyPaid + } + } + } + internal fun abortProposal(proposalId: String) = scope.launch { Log.i(TAG, "aborting proposal") api.request<Unit>("abortProposal") { |