Search in sources :

Example 1 with ValidationErrorMessage

use of com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationErrorMessage in project connect-sdk-client-android by Ingenico-ePayments.

the class PaymentProductField method validateValue.

/**
 * Gets all errormessagecodes for this field's value.
 * This list is filled after doing isValid() on this field
 * @param paymentRequest, The fully filled PaymentRequest, that holds all the values that the payment
 *                        will be made with.
 * @return A list of error messages that apply to this field. If the list is empty you can
 * assume that the field value is a valid value.
 */
public List<ValidationErrorMessage> validateValue(PaymentRequest paymentRequest) {
    // Get the value from the paymentRequest
    String value = paymentRequest.getValue(id);
    // Remove possible existing errors
    errorMessageIds.clear();
    // check required first
    if (dataRestrictions.isRequired() && valueNullOrEmpty(value)) {
        // If field is required, but has no value, add to the the errormessage list
        errorMessageIds.add(new ValidationErrorMessage("required", id, null));
    } else {
        // BoletoBancarioRequiredness validator do need to be validated.
        if (!valueNullOrEmpty(value) || containsBoletoBancarioRequirednessValidator()) {
            for (AbstractValidationRule rule : dataRestrictions.getValidationRules()) {
                if (!rule.validate(paymentRequest, id)) {
                    // If an invalid fieldvalue is found, add to the the errormessage list
                    errorMessageIds.add(new ValidationErrorMessage(rule.getMessageId(), id, rule));
                }
            }
        }
    }
    return errorMessageIds;
}
Also used : AbstractValidationRule(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.AbstractValidationRule) ValidationErrorMessage(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationErrorMessage)

Aggregations

AbstractValidationRule (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.AbstractValidationRule)1 ValidationErrorMessage (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationErrorMessage)1