Skip to content

Commit

Permalink
fix#1252: Display error message if expiry date is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
harshhks2 committed Mar 6, 2021
1 parent 857a4bf commit a2b04ba
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface DebitCardView extends BaseView<DebitCardPresenter> {

void verifyDebitCardSuccess(String otp);

void verifyDebitCardError(String message);
void verifyDebitCardError(String message, int viewNumber);
}

interface UpiPinPresenter extends BasePresenter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@ public void verifyDebitCardSuccess(String otp) {
}

@Override
public void verifyDebitCardError(String message) {
public void verifyDebitCardError(String message, int viewNumber) {
hideProgressDialog();
mEtDebitCardNumber.requestFocusFromTouch();
showToast(message);
if (viewNumber == 1) {
mEtDebitCardNumber.requestFocusFromTouch();
} else if (viewNumber == 2) {
mPeMonth.requestFocusFromTouch();
} else if (viewNumber == 3) {
mPeYear.requestFocusFromTouch();
}
}

public void showToast(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.mifos.mobilewallet.mifospay.bank.BankContract;
import org.mifos.mobilewallet.mifospay.base.BaseView;

import java.util.Calendar;

import javax.inject.Inject;

import static org.mifos.mobilewallet.mifospay.MifosPayApp.getContext;
Expand All @@ -30,9 +32,22 @@ public void attachView(BaseView baseView) {
@Override
public void verifyDebitCard(String s, String s1, String s2) {
String otp = "0000";
int expiryMonth = Integer.parseInt(s1);
int expiryYear = Integer.parseInt(s2);
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
int currentMonth = Calendar.getInstance().get(Calendar.MONTH) + 1;
if ((s.length() < 12) || (s.length() > 19)) {
mDebitCardView.verifyDebitCardError(getContext()
.getString(R.string.debit_card_error_message));
.getString(R.string.debit_card_error_message), 1);
} else if (expiryMonth < 01 || expiryMonth > 12) {
mDebitCardView.verifyDebitCardError(getContext()
.getString(R.string.expiry_month_error_message), 2);
} else if (expiryMonth < currentMonth && expiryYear <= currentYear) {
mDebitCardView.verifyDebitCardError(getContext()
.getString(R.string.expiry_month_error_message), 2);
} else if (expiryYear < currentYear || expiryYear > currentYear + 10) {
mDebitCardView.verifyDebitCardError(getContext()
.getString(R.string.expiry_year_error_message), 3);
} else {
mDebitCardView.verifyDebitCardSuccess(otp);
}
Expand Down
2 changes: 2 additions & 0 deletions mifospay/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
<string name="log_out">Log out</string>
<string name="debit_card_details">Debit Card Details</string>
<string name="debit_card_error_message">Invalid Debit Card Number</string>
<string name="expiry_month_error_message">Invalid Expiry Month</string>
<string name="expiry_year_error_message">Invalid Expiry Year</string>
<string name="one_time_password">One Time Password</string>
<string name="upi_pin_setup">UPI PIN Setup</string>
<string name="all_fields_are_mandatory">All fields are mandatory.</string>
Expand Down

0 comments on commit a2b04ba

Please sign in to comment.