add payments support to single bills
This commit is contained in:
@@ -129,8 +129,13 @@ class PayWithoutAccountActivity : AppCompatActivity() {
|
|||||||
if (bill.status == "paid") {
|
if (bill.status == "paid") {
|
||||||
Toast.makeText(this, "This bill has already been paid", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "This bill has already been paid", Toast.LENGTH_SHORT).show()
|
||||||
} else {
|
} else {
|
||||||
// TODO: Navigate to payment flow
|
// Navigate to PaymentReviewActivity for single bill
|
||||||
Toast.makeText(this, "Payment flow coming soon", Toast.LENGTH_SHORT).show()
|
val intent = android.content.Intent(this, PaymentReviewActivity::class.java)
|
||||||
|
intent.putExtra("SINGLE_BILL_ID", bill.id)
|
||||||
|
intent.putExtra("SINGLE_BILL_AMOUNT", bill.billAmount)
|
||||||
|
intent.putExtra("SINGLE_BILL_NUMBER", bill.billNumber)
|
||||||
|
intent.putExtra("SINGLE_BILL_SUBSCRIPTION_ID", bill.subscription.id)
|
||||||
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,15 @@ class PaymentReviewActivity : AppCompatActivity() {
|
|||||||
private lateinit var paymentMethodAdapter: PaymentMethodAdapter
|
private lateinit var paymentMethodAdapter: PaymentMethodAdapter
|
||||||
|
|
||||||
private var outstandingBills: List<OutstandingBill> = emptyList()
|
private var outstandingBills: List<OutstandingBill> = emptyList()
|
||||||
|
private var isSingleBillMode: Boolean = false
|
||||||
|
private var singleBillData: SingleBillData? = null
|
||||||
|
|
||||||
|
data class SingleBillData(
|
||||||
|
val billId: Long,
|
||||||
|
val amount: String,
|
||||||
|
val billNumber: String,
|
||||||
|
val subscriptionId: Long
|
||||||
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "PaymentReviewActivity"
|
private const val TAG = "PaymentReviewActivity"
|
||||||
@@ -50,10 +59,27 @@ class PaymentReviewActivity : AppCompatActivity() {
|
|||||||
secureStorage = SecureStorage(this)
|
secureStorage = SecureStorage(this)
|
||||||
apiService = FenakaApiService()
|
apiService = FenakaApiService()
|
||||||
|
|
||||||
|
// Check if this is single bill mode
|
||||||
|
checkForSingleBillMode()
|
||||||
|
|
||||||
setupViews()
|
setupViews()
|
||||||
loadData()
|
loadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkForSingleBillMode() {
|
||||||
|
val billId = intent.getLongExtra("SINGLE_BILL_ID", -1L)
|
||||||
|
if (billId != -1L) {
|
||||||
|
isSingleBillMode = true
|
||||||
|
singleBillData = SingleBillData(
|
||||||
|
billId = billId,
|
||||||
|
amount = intent.getStringExtra("SINGLE_BILL_AMOUNT") ?: "0.00",
|
||||||
|
billNumber = intent.getStringExtra("SINGLE_BILL_NUMBER") ?: "",
|
||||||
|
subscriptionId = intent.getLongExtra("SINGLE_BILL_SUBSCRIPTION_ID", -1L)
|
||||||
|
)
|
||||||
|
Log.d(TAG, "Single bill mode activated for bill: ${singleBillData?.billNumber}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupViews() {
|
private fun setupViews() {
|
||||||
// Setup bills RecyclerView
|
// Setup bills RecyclerView
|
||||||
billSummaryAdapter = BillSummaryAdapter()
|
billSummaryAdapter = BillSummaryAdapter()
|
||||||
@@ -80,6 +106,49 @@ class PaymentReviewActivity : AppCompatActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isSingleBillMode) {
|
||||||
|
loadSingleBillMode(cookie)
|
||||||
|
} else {
|
||||||
|
loadOutstandingBillsMode(cookie)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadSingleBillMode(cookie: String) {
|
||||||
|
singleBillData?.let { billData ->
|
||||||
|
// Create fake OutstandingBill for single bill mode
|
||||||
|
val fakeOutstandingBill = OutstandingBill(
|
||||||
|
id = billData.billId,
|
||||||
|
branchName = "",
|
||||||
|
subscriptionId = billData.subscriptionId,
|
||||||
|
subscriptionStatus = "active",
|
||||||
|
subscriptionNumber = billData.billNumber,
|
||||||
|
outstandingBillCount = "1",
|
||||||
|
billAmount = billData.amount,
|
||||||
|
paidAmount = "0",
|
||||||
|
outstandingAmount = billData.amount
|
||||||
|
)
|
||||||
|
outstandingBills = listOf(fakeOutstandingBill)
|
||||||
|
updateBillsUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
showLoading(true)
|
||||||
|
lifecycleScope.launch {
|
||||||
|
// Load payment methods
|
||||||
|
when (val gatewaysResult = apiService.getPaymentGateways("connect.sid=$cookie")) {
|
||||||
|
is ApiResult.Success -> {
|
||||||
|
paymentMethodAdapter.updatePaymentMethods(gatewaysResult.data)
|
||||||
|
showLoading(false)
|
||||||
|
}
|
||||||
|
is ApiResult.Error -> {
|
||||||
|
Log.e(TAG, "Failed to load payment gateways: ${gatewaysResult.message}")
|
||||||
|
showLoading(false)
|
||||||
|
Toast.makeText(this@PaymentReviewActivity, "Failed to load payment methods", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadOutstandingBillsMode(cookie: String) {
|
||||||
showLoading(true)
|
showLoading(true)
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
|
@@ -1,13 +1,14 @@
|
|||||||
package sh.sar.gridflow.ui.billhistory
|
package sh.sar.gridflow.ui.billhistory
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
|
import sh.sar.gridflow.PaymentReviewActivity
|
||||||
import sh.sar.gridflow.R
|
import sh.sar.gridflow.R
|
||||||
import sh.sar.gridflow.data.Bill
|
import sh.sar.gridflow.data.Bill
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@@ -67,7 +68,13 @@ class BillCardAdapter(
|
|||||||
payNowButton.visibility = View.VISIBLE
|
payNowButton.visibility = View.VISIBLE
|
||||||
|
|
||||||
payNowButton.setOnClickListener {
|
payNowButton.setOnClickListener {
|
||||||
Toast.makeText(itemView.context, "Coming soon", Toast.LENGTH_SHORT).show()
|
// Navigate to PaymentReviewActivity for this bill
|
||||||
|
val intent = Intent(itemView.context, PaymentReviewActivity::class.java)
|
||||||
|
intent.putExtra("SINGLE_BILL_ID", bill.id)
|
||||||
|
intent.putExtra("SINGLE_BILL_AMOUNT", bill.billAmount)
|
||||||
|
intent.putExtra("SINGLE_BILL_NUMBER", bill.billNumber)
|
||||||
|
intent.putExtra("SINGLE_BILL_SUBSCRIPTION_ID", bill.subscription.id)
|
||||||
|
itemView.context.startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import sh.sar.gridflow.PaymentReviewActivity
|
||||||
import sh.sar.gridflow.R
|
import sh.sar.gridflow.R
|
||||||
import sh.sar.gridflow.data.Bill
|
import sh.sar.gridflow.data.Bill
|
||||||
import sh.sar.gridflow.databinding.ActivityBillDetailsBinding
|
import sh.sar.gridflow.databinding.ActivityBillDetailsBinding
|
||||||
@@ -155,7 +156,15 @@ class BillDetailsActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.payNowButton.setOnClickListener {
|
binding.payNowButton.setOnClickListener {
|
||||||
Toast.makeText(this, "Coming soon", Toast.LENGTH_SHORT).show()
|
currentBill?.let { bill ->
|
||||||
|
// Navigate to PaymentReviewActivity for this bill
|
||||||
|
val intent = Intent(this, PaymentReviewActivity::class.java)
|
||||||
|
intent.putExtra("SINGLE_BILL_ID", bill.id)
|
||||||
|
intent.putExtra("SINGLE_BILL_AMOUNT", bill.billAmount)
|
||||||
|
intent.putExtra("SINGLE_BILL_NUMBER", bill.billNumber)
|
||||||
|
intent.putExtra("SINGLE_BILL_SUBSCRIPTION_ID", bill.subscription.id)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user