NTP-21114 | Collect request amount handling in case of PN/IAN (#14246)
This commit is contained in:
@@ -53,6 +53,43 @@ class AmountUtilityUnitTest {
|
||||
assertEquals("1.20", "1.2.3".getDisplayableAmount().getDisplayableAmount())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun formatAmount_toPlainAmountFormattedCorrectly() {
|
||||
assertEquals("1.00", "1".toPlainAmount())
|
||||
assertEquals("1.00", "1.00".toPlainAmount())
|
||||
assertEquals("50.00", "50".toPlainAmount())
|
||||
assertEquals("200.00", "200.00".toPlainAmount())
|
||||
assertEquals("1000.00", "1,000".toPlainAmount())
|
||||
assertEquals("1000.00", "1,000.00".toPlainAmount())
|
||||
assertEquals("55973.00", "55,973.00".toPlainAmount())
|
||||
assertEquals("16345.56", "16,345.56".toPlainAmount())
|
||||
assertEquals("12345678.12", "1,23,45,678.1234".toPlainAmount())
|
||||
assertEquals("12345678.00", "1,23,45,678.00".toPlainAmount())
|
||||
assertEquals("123456789.30", "12,34,56,789.30".toPlainAmount())
|
||||
assertEquals("123456789.30", "12,34,56,789.3012".toPlainAmount())
|
||||
assertEquals("0.00", "Hello".toPlainAmount())
|
||||
assertEquals("1.01", "1.01".toPlainAmount())
|
||||
assertEquals("1.10", "1.10".toPlainAmount())
|
||||
assertEquals("-678.16", "-678.16".toPlainAmount())
|
||||
assertEquals("678.16", "678.16".toPlainAmount())
|
||||
assertEquals("-6778.16", "-6,778.16".toPlainAmount())
|
||||
assertEquals("-78.16", "-78.16".toPlainAmount())
|
||||
assertEquals("-123456.10", "-1,23,456.1".toPlainAmount())
|
||||
assertEquals("11223456.10", "1,12,23,456.10".toPlainAmount())
|
||||
assertEquals("0.10", "0.1".toPlainAmount())
|
||||
assertEquals("0.10", "0.1".toPlainAmount())
|
||||
assertEquals("0.00", "".toPlainAmount())
|
||||
assertEquals("123456.00", "1,23,456".toPlainAmount())
|
||||
assertEquals("123456.00", "1,23,456.00".toPlainAmount())
|
||||
assertEquals("123456.11", "1,23,456.11".toPlainAmount())
|
||||
assertEquals("123456.11", "+1,23,456.11".toPlainAmount())
|
||||
assertEquals("-123456.11", "-1,23,456.11".toPlainAmount())
|
||||
assertEquals("-123.11", "-1,23.1111".toPlainAmount())
|
||||
assertEquals("123456.11", "1,23,456.11".toPlainAmount().toPlainAmount())
|
||||
assertEquals("-123456.11", "-1,23,456.11".toPlainAmount().toPlainAmount())
|
||||
assertEquals("123.11", "1,23.1111".toPlainAmount().toPlainAmount())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun formatAmount_isAmountFormattedCorrectly() {
|
||||
assertEquals("1.00", "1".getFormattedAmountWithDecimal())
|
||||
|
||||
@@ -147,7 +147,7 @@ data class ConfigMessage(
|
||||
val maxPaymentAmountMessage: String = "Amount can’t be more than ₹20,00,000",
|
||||
@SerializedName("maxPaymentAmountMessageForGallery")
|
||||
val maxPaymentAmountMessageForGallery: String =
|
||||
"Maximum payment limit is ₹2000 when you upload a QR from your gallery.",
|
||||
"Maximum payment limit is ₹2,000 when you upload a QR from your gallery.",
|
||||
@SerializedName("invalidAmountGenericMessage")
|
||||
val invalidAmountGenericMessage: String = "Invalid amount",
|
||||
@SerializedName("sendMoneyDefaultRemarks")
|
||||
|
||||
@@ -257,7 +257,10 @@ fun MainScreen(
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
if (isWarningOrErrorState.isErrorState) {
|
||||
RenderWarningOrErrorMessage(isWarningOrErrorState = isWarningOrErrorState)
|
||||
RenderWarningOrErrorMessage(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
|
||||
isWarningOrErrorState = isWarningOrErrorState
|
||||
)
|
||||
}
|
||||
NotesSection(
|
||||
note = note,
|
||||
|
||||
@@ -60,6 +60,7 @@ import com.navi.pay.utils.NAVI_PAY_NOTIFICATION_MODIFY_MANDATE
|
||||
import com.navi.pay.utils.REQUEST_TYPE_MANDATE
|
||||
import com.navi.pay.utils.UPI_LITE_MANDATE_EXECUTION_FAILURE
|
||||
import com.navi.pay.utils.UPI_LITE_MANDATE_EXECUTION_SUCCESS
|
||||
import com.navi.pay.utils.toPlainAmount
|
||||
import com.navi.pay.utils.value
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
@@ -529,7 +530,7 @@ constructor(
|
||||
isVerifiedVpa = notificationData["isVerifiedPayee"] as Boolean? ?: false,
|
||||
name = notificationData["payeeName"].toString(),
|
||||
vpa = notificationData["payeeVpa"].toString(),
|
||||
amount = notificationData["amount"].toString(),
|
||||
amount = notificationData["amount"]?.toPlainAmount().orEmpty(),
|
||||
note = notificationData["remarks"] ?: "",
|
||||
mcc = notificationData["payeeMcc"].toString(),
|
||||
refCategory = notificationData["refCategory"].toString(),
|
||||
|
||||
@@ -142,6 +142,19 @@ fun String.getDisplayableAmount(): String {
|
||||
return displayableAmount
|
||||
}
|
||||
|
||||
fun String.toPlainAmount(): String {
|
||||
val cleanedAmount = this.filter { it.isDigit() || it == '.' || it == '-' }
|
||||
if (cleanedAmount.isEmpty() || cleanedAmount == "-") return ZERO_STRING_WITH_DECIMAL
|
||||
|
||||
return try {
|
||||
val parsedAmount = cleanedAmount.toBigDecimal()
|
||||
val formattedAmount = parsedAmount.setScale(2, RoundingMode.DOWN)
|
||||
formattedAmount.toPlainString()
|
||||
} catch (e: Exception) {
|
||||
ZERO_STRING_WITH_DECIMAL
|
||||
}
|
||||
}
|
||||
|
||||
fun Double.roundTo(decimals: Int): Double {
|
||||
return when {
|
||||
this.isInfinite() -> this // Preserve Infinity as-is
|
||||
|
||||
Reference in New Issue
Block a user