<s> from braintree . credit_card_verification import CreditCardVerification <EOL> from braintree . credit_card_verification_search import CreditCardVerificationSearch <EOL> from braintree . exceptions . not_found_error import NotFoundError <EOL> from braintree . ids_search import IdsSearch <EOL> from braintree . resource_collection import ResourceCollection <EOL> from braintree . error_result import ErrorResult <EOL> from braintree . successful_result import SuccessfulResult <EOL> class CreditCardVerificationGateway ( object ) : <EOL> def __init__ ( self , gateway ) : <EOL> self . gateway = gateway <EOL> self . config = gateway . config <EOL> def find ( self , verification_id ) : <EOL> try : <EOL> if verification_id is None or verification_id . strip ( ) == "<STR_LIT>" : <EOL> raise NotFoundError ( ) <EOL> response = self . config . http ( ) . get ( self . config . base_merchant_path ( ) + "<STR_LIT>" + verification_id ) <EOL> return CreditCardVerification ( self . gateway , response [ "<STR_LIT>" ] ) <EOL> except NotFoundError : <EOL> raise NotFoundError ( "<STR_LIT>" + repr ( verification_id ) + "<STR_LIT>" ) <EOL> def __criteria ( self , query ) : <EOL> criteria = { } <EOL> for term in query : <EOL> if criteria . get ( term . name ) : <EOL> criteria [ term . name ] = dict ( list ( criteria [ term . name ] . items ( ) ) + list ( term . to_param ( ) . items ( ) ) ) <EOL> else : <EOL> criteria [ term . name ] = term . to_param ( ) <EOL> return criteria <EOL> def __fetch ( self , query , ids ) : <EOL> criteria = self . __criteria ( query ) <EOL> criteria [ "<STR_LIT>" ] = CreditCardVerificationSearch . ids . in_list ( ids ) . to_param ( ) <EOL> response = self . config . http ( ) . post ( self . config . base_merchant_path ( ) + "<STR_LIT>" , { "<STR_LIT>" : criteria } ) <EOL> return [ CreditCardVerification ( self . gateway , item ) for item in <EOL> ResourceCollection . _extract_as_array ( response [ "<STR_LIT>" ] , "<STR_LIT>" ) ] <EOL> def search ( self , * query ) : <EOL> if isinstance ( query [ <NUM_LIT:0> ] , list ) : <EOL> query = query [ <NUM_LIT:0> ] <EOL> response = self . config . http ( ) . post ( self . config . base_merchant_path ( ) + "<STR_LIT>" , { "<STR_LIT>" : self . __criteria ( query ) } ) <EOL> return ResourceCollection ( query , response , self . __fetch ) <EOL> def __fetch_verifications ( self , query , verification_ids ) : <EOL> criteria = { } <EOL> criteria [ "<STR_LIT>" ] = IdsSearch . ids . in_list ( verification_ids ) . to_param ( ) <EOL> response = self . config . http ( ) . post ( self . config . base_merchant_path ( ) + "<STR_LIT>" , { "<STR_LIT>" : criteria } ) <EOL> return [ CreditCardVerification ( self . gateway , item ) for item in ResourceCollection . _extract_as_array ( response [ "<STR_LIT>" ] , "<STR_LIT>" ) ] <EOL> def create ( self , params ) : <EOL> response = self . config . http ( ) . post ( self . config . base_merchant_path ( ) + "<STR_LIT>" , { "<STR_LIT>" : params } ) <EOL> if "<STR_LIT>" in response : <EOL> return SuccessfulResult ( { "<STR_LIT>" : CreditCardVerification ( self . gateway , response [ "<STR_LIT>" ] ) } ) <EOL> elif "<STR_LIT>" in response : <EOL> return ErrorResult ( self . gateway , response [ "<STR_LIT>" ] ) </s>
