<s> from django import forms <EOL> from billing . utils . credit_card import CreditCard , CardNotSupported <EOL> class CreditCardFormBase ( forms . Form ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . gateway = kwargs . pop ( '<STR_LIT>' , None ) <EOL> super ( CreditCardFormBase , self ) . __init__ ( * args , ** kwargs ) <EOL> def get_credit_card ( self ) : <EOL> """<STR_LIT>""" <EOL> card = CreditCard ( ** self . cleaned_data ) <EOL> if self . gateway is not None : <EOL> self . gateway . validate_card ( card ) <EOL> return card <EOL> def clean ( self ) : <EOL> cleaned_data = super ( CreditCardFormBase , self ) . clean ( ) <EOL> if self . errors : <EOL> return cleaned_data <EOL> try : <EOL> credit_card = self . get_credit_card ( ) <EOL> if not credit_card . is_valid ( ) : <EOL> raise forms . ValidationError ( "<STR_LIT>" ) <EOL> except CardNotSupported : <EOL> raise forms . ValidationError ( "<STR_LIT>" ) <EOL> return cleaned_data </s>
