diff options
Diffstat (limited to 'wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/PaymentActivity.kt')
-rw-r--r-- | wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/PaymentActivity.kt | 127 |
1 files changed, 0 insertions, 127 deletions
diff --git a/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/PaymentActivity.kt b/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/PaymentActivity.kt deleted file mode 100644 index e63552b..0000000 --- a/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/PaymentActivity.kt +++ /dev/null @@ -1,127 +0,0 @@ -package ch.bfh.habej2.wallee_c2ec - -import android.os.Bundle -import androidx.activity.compose.setContent -import androidx.appcompat.app.AppCompatActivity -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material3.Button -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Surface -import androidx.compose.material3.Text -import androidx.compose.material3.TextField -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import ch.bfh.habej2.wallee_c2ec.client.taler.BankIntegrationClient -import ch.bfh.habej2.wallee_c2ec.client.wallee.WalleeResponseHandler -import ch.bfh.habej2.wallee_c2ec.config.TalerBankIntegrationConfig -import ch.bfh.habej2.wallee_c2ec.ui.theme.Walleec2ecTheme -import com.wallee.android.till.sdk.ApiClient -import com.wallee.android.till.sdk.data.LineItem -import com.wallee.android.till.sdk.data.Transaction -import com.wallee.android.till.sdk.data.TransactionProcessingBehavior -import java.math.BigDecimal -import java.util.Currency -import java.util.Optional - -class PaymentActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - // TODO retrieve WithdrawalViewModel here - // maybe something like savedStateRegistry.getSavedStateProvider("current-withdrawal") - val model = WithdrawalViewModel(BankIntegrationClient( - TalerBankIntegrationConfig("TestExchange", "http://localhost:8082/c2ec", "Wallee-1", "secret"))) - val client = ApiClient(WalleeResponseHandler()) - - setContent { - Walleec2ecTheme { - // A surface container using the 'background' color from the theme - Surface( - modifier = Modifier.fillMaxSize(), - color = MaterialTheme.colorScheme.background - ) { - Column( - horizontalAlignment = Alignment.CenterHorizontally - ) { - - Text(text = "present card, trigger payment") - - TextField( - value = "", - onValueChange = { - val optAmount = parseAmount(it) - if (optAmount.isPresent) { - model.updateAmount(optAmount.get()) - } - }, - label = { Text(text = "Enter amount") }, - placeholder = { Text(text = "amount") } - ) - - Button(enabled = false, onClick = { - val withdrawalAmount = LineItem - .ListBuilder( - model.uiState.encodedWopid, - BigDecimal("${model.uiState.amount.value}.${model.uiState.amount.frac}") - ) - .build() - - val transaction = Transaction.Builder(withdrawalAmount) - .setCurrency(Currency.getInstance(model.uiState.currency)) - .setInvoiceReference(model.uiState.encodedWopid) - .setMerchantReference(model.uiState.encodedWopid) - .setTransactionProcessingBehavior(TransactionProcessingBehavior.COMPLETE_IMMEDIATELY) - .build() - - try { - client.authorizeTransaction(transaction) - } catch (e: Exception) { - e.printStackTrace() - } - }) { - Text(text = "") - } - - Button(onClick = { - model.withdrawalOperationFailed(applicationContext) - finish() - }) { - Text(text = "abort") - } - } - } - } - } - } - - /** - * Format expected X[.X], X an integer - */ - private fun parseAmount(inp: String): Optional<Amount> { - - val points = inp.count { it == '.' } - if (points > 1) { - return Optional.empty() - } - - if (points == 1) { - val valueStr = inp.split(".")[0] - val fracStr = inp.split(".")[1] - return try { - val value = valueStr.toInt() - val frac = fracStr.toInt() - Optional.of(Amount(value, frac)) - } catch (ex: NumberFormatException) { - Optional.empty() - } - } - - return try { - val value = inp.toInt() - Optional.of(Amount(value, 0)) - } catch (ex: NumberFormatException) { - Optional.empty() - } - } -} |