cashless2ecash

cashless2ecash: pay with cards for digital cash (experimental)
Log | Files | Refs | README

TestTransactionScreen.kt (2437B)


      1 // This file is part of taler-cashless2ecash.
      2 // Copyright (C) 2024 Joel Häberli
      3 //
      4 // taler-cashless2ecash is free software: you can redistribute it and/or modify it
      5 // under the terms of the GNU Affero General Public License as published
      6 // by the Free Software Foundation, either version 3 of the License,
      7 // or (at your option) any later version.
      8 //
      9 // taler-cashless2ecash is distributed in the hope that it will be useful, but
     10 // WITHOUT ANY WARRANTY; without even the implied warranty of
     11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12 // Affero General Public License for more details.
     13 //
     14 // You should have received a copy of the GNU Affero General Public License
     15 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16 //
     17 // SPDX-License-Identifier: AGPL3.0-or-later
     18 
     19 package ch.bfh.habej2.wallee_c2ec.withdrawal
     20 
     21 import androidx.compose.foundation.layout.Column
     22 import androidx.compose.material3.Button
     23 import androidx.compose.material3.Text
     24 import androidx.compose.runtime.Composable
     25 import com.wallee.android.till.sdk.ApiClient
     26 import com.wallee.android.till.sdk.data.LineItem
     27 import com.wallee.android.till.sdk.data.Transaction
     28 import com.wallee.android.till.sdk.data.TransactionProcessingBehavior
     29 import java.math.BigDecimal
     30 import java.util.Currency
     31 import java.util.UUID
     32 
     33 const val TEST_TRANSACTION_PREFIX = "TEST_TRANSACTION"
     34 
     35 @Composable
     36 fun TestTransactionScreen(walleeClient: ApiClient) {
     37 
     38     val lineitemuuid = UUID.randomUUID().toString()
     39     val merchRef = UUID.randomUUID().toString()
     40     val invRef = UUID.randomUUID().toString()
     41 
     42     val withdrawalAmount = LineItem
     43         .ListBuilder(TEST_TRANSACTION_PREFIX+lineitemuuid, BigDecimal(9.0))
     44         .build()
     45 
     46     val transaction = Transaction.Builder(withdrawalAmount)
     47         .setCurrency(Currency.getInstance("CHF"))
     48         .setInvoiceReference(invRef)
     49         .setMerchantReference(merchRef)
     50         .setTransactionProcessingBehavior(TransactionProcessingBehavior.COMPLETE_IMMEDIATELY)
     51         .build()
     52 
     53     Column {
     54         Button(onClick = {
     55             try {
     56                 walleeClient.authorizeTransaction(transaction)
     57                 //walleeClient.unbind(activity)
     58             } catch (e: Exception) {
     59                 println("FAILED authorizing transaction ${e.message}")
     60                 e.printStackTrace()
     61             }
     62         }) {
     63             Text(text = "Authorize test transaction")
     64         }
     65     }
     66 }