public void validateCardNumber(Context context, PaymentMethod paymentMethod) throws Exception { // Empty field if (TextUtils.isEmpty(cardNumber)) { throw new Exception(context.getString(R.string.mpsdk_invalid_empty_card)); } Setting setting = Setting.getSettingByBin( paymentMethod.getSettings(), (cardNumber.length() >= MercadoPago.BIN_LENGTH ? cardNumber.substring(0, MercadoPago.BIN_LENGTH) : "")); if (setting == null) { // Invalid bin throw new Exception(context.getString(R.string.mpsdk_invalid_card_bin)); } else { // Validate card length int cardLength = setting.getCardNumber().getLength(); if (cardNumber.trim().length() != cardLength) { throw new Exception(context.getString(R.string.mpsdk_invalid_card_length, cardLength)); } // Validate luhn String luhnAlgorithm = setting.getCardNumber().getValidation(); if (("standard".equals(luhnAlgorithm)) && (!checkLuhn(cardNumber))) { throw new Exception(context.getString(R.string.mpsdk_invalid_card_luhn)); } } }
public static void validateSecurityCode( Context context, String securityCode, PaymentMethod paymentMethod, String bin) throws Exception { if (paymentMethod != null) { Setting setting = Setting.getSettingByBin(paymentMethod.getSettings(), bin); // Validate security code length if (setting != null) { int cvvLength = setting.getSecurityCode().getLength(); if ((cvvLength != 0) && (securityCode.trim().length() != cvvLength)) { throw new Exception(context.getString(R.string.mpsdk_invalid_cvv_length, cvvLength)); } } else { throw new Exception(context.getString(R.string.mpsdk_invalid_field)); } } }