Beispiel #1
0
    def clean(self):
        """Validates the form"""
        super(CreditCardForm, self).clean()

        cleaned_data = self.cleaned_data

        number = cleaned_data.get('number')
        security_code = cleaned_data.get('security_code')
        exp_month = cleaned_data.get('exp_month')
        exp_year = cleaned_data.get('exp_year')

        if not self.is_valid():
            raise forms.ValidationError("There was a problem processing your payment")

        cc_type = get_card_type(number)
        if not cc_type or not is_valid_cc(number):
            raise forms.ValidationError("Invalid credit card number")

        if not is_valid_cvv(security_code, cc_type):
            raise forms.ValidationError("Invalid security code")

        if not is_valid_exp(exp_month, exp_year):
            raise forms.ValidationError("Invalid expiracy date")

        return cleaned_data
Beispiel #2
0
    def validate(self):
        """
        validates expiration date & card number using util functions
        """
        if not is_valid_cc(self.number):
            raise DataValidationError('The credit card number provided does not pass luhn validation')

        if not is_valid_exp(self.exp_month, self.exp_year):
            raise DataValidationError('The credit card expiration provided is not in the future')

        if self.strict:
            if not is_valid_cvv(self.verification_value):
                raise DataValidationError('The credit card cvv is not valid')

        return True
Beispiel #3
0
    def validate(self):
        """
        validates expiration date & card number using util functions
        """
        if not is_valid_cc(self.number):
            raise DataValidationError(
                'The credit card number provided does not pass luhn validation'
            )

        if not is_valid_exp(self.exp_month, self.exp_year):
            raise DataValidationError(
                'The credit card expiration provided is not in the future')

        if self.strict:
            if not is_valid_cvv(self.verification_value):
                raise DataValidationError('The credit card cvv is not valid')

        return True
Beispiel #4
0
    def clean(self):
        """Validates the form"""
        super(CreditCardForm, self).clean()

        cleaned_data = self.cleaned_data

        number = cleaned_data.get('number')
        security_code = cleaned_data.get('security_code')
        exp_month = cleaned_data.get('exp_month')
        exp_year = cleaned_data.get('exp_year')

        if not self.is_valid():
            raise forms.ValidationError("There was a problem processing your payment")

        if not is_valid_cc(number):
            raise forms.ValidationError("Invalid credit card number")

        if not is_valid_cvv(security_code):
            raise forms.ValidationError("Invalid security code")

        if not is_valid_exp(exp_month, exp_year):
            raise forms.ValidationError("Invalid expiracy date")

        return cleaned_data