<s> """<STR_LIT>""" <EOL> import logging <EOL> from paython . exceptions import DataValidationError , MissingTranslationError <EOL> from paython . lib . utils import is_valid_email <EOL> logger = logging . getLogger ( __name__ ) <EOL> class Gateway ( object ) : <EOL> """<STR_LIT>""" <EOL> REQUEST_FIELDS = { } <EOL> RESPONSE_FIELDS = { } <EOL> debug = False <EOL> def __init__ ( self , set_method , translations , debug ) : <EOL> """<STR_LIT>""" <EOL> self . set = set_method <EOL> self . REQUEST_FIELDS = translations <EOL> self . debug = debug <EOL> def use_credit_card ( self , credit_card ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( credit_card , '<STR_LIT>' ) : <EOL> credit_card . exp_year = credit_card . exp_year [ - <NUM_LIT:2> : ] <EOL> for key , value in credit_card . __dict__ . items ( ) : <EOL> if not key . startswith ( '<STR_LIT:_>' ) : <EOL> try : <EOL> self . set ( self . REQUEST_FIELDS [ key ] , value ) <EOL> except KeyError : <EOL> pass <EOL> def set_billing_info ( self , address = None , address2 = None , city = None , state = None , zipcode = None , country = None , phone = None , email = None , ip = None , first_name = None , last_name = None ) : <EOL> """<STR_LIT>""" <EOL> if address : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT:address>' ] , address ) <EOL> if address2 : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , address2 ) <EOL> if city : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , city ) <EOL> if state : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT:state>' ] , state ) <EOL> if zipcode : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , zipcode ) <EOL> if country : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , country ) <EOL> if phone : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , phone ) <EOL> if ip : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , ip ) <EOL> if first_name : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , first_name ) <EOL> if last_name : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , last_name ) <EOL> if email : <EOL> if is_valid_email ( email ) : <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT:email>' ] , email ) <EOL> else : <EOL> raise DataValidationError ( '<STR_LIT>' ) <EOL> def set_shipping_info ( self , ship_first_name , ship_last_name , ship_address , ship_city , ship_state , ship_zipcode , ship_country = None , ship_to_co = None , ship_phone = None , ship_email = None ) : <EOL> """<STR_LIT>""" <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , ship_first_name ) <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , ship_last_name ) <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , ship_address ) <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , ship_city ) <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , ship_state ) <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , ship_zipcode ) <EOL> optionals = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for optional_var in optionals : <EOL> exec '<STR_LIT>' % ( optional_var , optional_var ) <EOL> if eval ( optional_var ) : <EOL> if optional_var not in self . REQUEST_FIELDS : <EOL> raise MissingTranslationError ( '<STR_LIT>' % optional_var ) <EOL> self . set ( self . REQUEST_FIELDS [ '<STR_LIT>' ] , ship_to_co ) <EOL> def standardize ( self , spec_response , field_mapping , response_time , approved ) : <EOL> """<STR_LIT>""" <EOL> self . RESPONSE_FIELDS [ '<STR_LIT>' ] = response_time <EOL> self . RESPONSE_FIELDS [ '<STR_LIT>' ] = approved <EOL> if isinstance ( spec_response , list ) : <EOL> i = <NUM_LIT:0> <EOL> debug_string = '<STR_LIT>' <EOL> logger . debug ( debug_string . center ( <NUM_LIT> , '<STR_LIT:=>' ) ) <EOL> logger . debug ( '<STR_LIT>' % spec_response ) <EOL> debug_string = '<STR_LIT>' <EOL> logger . debug ( debug_string . center ( <NUM_LIT> , '<STR_LIT:=>' ) ) <EOL> logger . debug ( '<STR_LIT>' % field_mapping ) <EOL> for item in spec_response : <EOL> iteration_key = str ( i ) <EOL> if iteration_key in field_mapping : <EOL> self . RESPONSE_FIELDS [ field_mapping [ iteration_key ] ] = item <EOL> i += <NUM_LIT:1> <EOL> else : <EOL> for key , value in spec_response . items ( ) : <EOL> try : <EOL> self . RESPONSE_FIELDS [ field_mapping [ key ] ] = value <EOL> except KeyError : <EOL> pass <EOL> return self . RESPONSE_FIELDS </s>
