Skip to content

Commit

Permalink
Feature: Create payment
Browse files Browse the repository at this point in the history
  • Loading branch information
jdsdhp committed Jan 27, 2024
1 parent d125868 commit c2d73fc
Show file tree
Hide file tree
Showing 23 changed files with 714 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.jdsdhp.enzona.payment.embedded.sample

import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
Expand All @@ -13,7 +12,11 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
Expand All @@ -24,7 +27,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand Down Expand Up @@ -56,18 +58,18 @@ internal fun MainScreen(
viewModel: MainViewModel,
) {

val context = LocalContext.current

val uiState by viewModel.uiState.collectAsStateWithLifecycle()

Column(
modifier = modifier.padding(16.dp),
modifier = modifier
.padding(16.dp)
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Spacer(modifier = Modifier.height(16.dp))

Text(
text = stringResource(id = R.string.app_name),
text = stringResource(id = R.string.authenticate),
style = MaterialTheme.typography.titleLarge,
)

Expand Down Expand Up @@ -110,6 +112,136 @@ internal fun MainScreen(

Spacer(modifier = Modifier.height(16.dp))

Text(
text = stringResource(id = R.string.create_payment),
style = MaterialTheme.typography.titleLarge,
)

Spacer(modifier = Modifier.height(16.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Currency") },
value = uiState.createPayment.currency,
onValueChange = { viewModel.onCurrencyChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Cancel Url") },
value = uiState.createPayment.cancelUrl,
onValueChange = { viewModel.onCancelUrlChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Return Url") },
value = uiState.createPayment.returnUrl,
onValueChange = { viewModel.onReturnUrlChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Merchant Op Id (12 digits max)") },
value = uiState.createPayment.merchantOpId,
onValueChange = { viewModel.onMerchantOpIdChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Description (Optional)") },
value = uiState.createPayment.description,
onValueChange = { viewModel.onDescriptionChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Invoice Number (Optional)") },
value = uiState.createPayment.invoiceNumber,
onValueChange = { viewModel.onInvoiceNumberChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Discount (Optional)") },
value = uiState.createPayment.discount.toString(),
onValueChange = { viewModel.onDiscountChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Tip (Optional)") },
value = uiState.createPayment.tip.toString(),
onValueChange = { viewModel.onTipChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Shipping (Optional)") },
value = uiState.createPayment.shipping.toString(),
onValueChange = { viewModel.onShippingChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Buyer Identity Code (Optional)") },
value = uiState.createPayment.buyerIdentityCode,
onValueChange = { viewModel.onBuyerIdentityCodeChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

TextField(
modifier = Modifier.fillMaxWidth(),
label = { Text(text = "Terminal Id (Optional)") },
value = uiState.createPayment.terminalId,
onValueChange = { viewModel.onTerminalIdChanged(it) },
)

Spacer(modifier = Modifier.height(8.dp))

Column(modifier = Modifier.fillMaxWidth()) {
uiState.items.forEach {
Card(modifier = Modifier.fillMaxWidth()) {
Column(modifier = Modifier.padding(8.dp)) {
Text(text = it.name + " (${it.quantity})")
Text(text = it.description)
Text(text = "$${it.price}")
Text(text = "Tax: ${it.tax}")
}
}
Spacer(modifier = Modifier.height(4.dp))
}
}

Spacer(modifier = Modifier.height(16.dp))

Button(onClick = { viewModel.onCreatePaymentClick() }) {
Text(text = stringResource(R.string.create_payment))
}

Spacer(modifier = Modifier.height(16.dp))

HorizontalDivider()

}

if (uiState.isLoading) {
Expand All @@ -124,11 +256,27 @@ internal fun MainScreen(
}

uiState.textMessage?.let {
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
AlertDialog(
text = { Text(text = it) },
onDismissRequest = { viewModel.onDialogClose() },
confirmButton = {
Button(onClick = { viewModel.onDialogClose() }) {
Text(text = stringResource(R.string.accept))
}
},
)
}

uiState.error?.let {
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
AlertDialog(
text = { Text(text = it) },
onDismissRequest = { viewModel.onDialogClose() },
confirmButton = {
Button(onClick = { viewModel.onDialogClose() }) {
Text(text = stringResource(R.string.accept))
}
},
)
}

}
Loading

0 comments on commit c2d73fc

Please sign in to comment.