<s> from billing import CreditCard <EOL> from billing import Gateway , GatewayNotConfigured <EOL> from billing . signals import transaction_was_successful , transaction_was_unsuccessful <EOL> from billing . utils . credit_card import Visa , MasterCard , DinersClub , JCB , AmericanExpress , InvalidCard <EOL> from eway_api . client import RebillEwayClient , DirectPaymentClient <EOL> from eway_api . client import REBILL_TEST_URL , REBILL_LIVE_URL , HOSTED_TEST_URL , HOSTED_LIVE_URL , DIRECT_PAYMENT_TEST_URL , DIRECT_PAYMENT_LIVE_URL <EOL> from django . conf import settings <EOL> class EwayGateway ( Gateway ) : <EOL> default_currency = "<STR_LIT>" <EOL> supported_countries = [ "<STR_LIT>" ] <EOL> supported_cardtypes = [ Visa , MasterCard , AmericanExpress , DinersClub , JCB ] <EOL> homepage_url = "<STR_LIT>" <EOL> display_name = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> self . test_mode = getattr ( settings , '<STR_LIT>' , True ) <EOL> merchant_settings = getattr ( settings , "<STR_LIT>" ) <EOL> if not merchant_settings or not merchant_settings . get ( "<STR_LIT>" ) : <EOL> raise GatewayNotConfigured ( "<STR_LIT>" <EOL> "<STR_LIT>" % self . display_name ) <EOL> eway_settings = merchant_settings [ "<STR_LIT>" ] <EOL> self . customer_id = eway_settings [ '<STR_LIT>' ] <EOL> if self . test_mode : <EOL> self . rebill_url = REBILL_TEST_URL <EOL> self . hosted_url = HOSTED_TEST_URL <EOL> self . direct_payment_url = DIRECT_PAYMENT_TEST_URL <EOL> else : <EOL> self . rebill_url = REBILL_LIVE_URL <EOL> self . hosted_url = HOSTED_LIVE_URL <EOL> self . direct_payment_url = DIRECT_PAYMENT_LIVE_URL <EOL> self . eway_username = eway_settings [ '<STR_LIT>' ] <EOL> self . eway_password = eway_settings [ '<STR_LIT>' ] <EOL> def add_creditcard ( self , hosted_customer , credit_card ) : <EOL> """<STR_LIT>""" <EOL> hosted_customer . CCNumber = credit_card . number <EOL> hosted_customer . CCNameOnCard = credit_card . name <EOL> hosted_customer . CCExpiryMonth = '<STR_LIT>' % ( credit_card . month ) <EOL> hosted_customer . CCExpiryYear = str ( credit_card . year ) [ - <NUM_LIT:2> : ] <EOL> hosted_customer . FirstName = credit_card . first_name <EOL> hosted_customer . LastName = credit_card . last_name <EOL> def add_address ( self , hosted_customer , options = None ) : <EOL> """<STR_LIT>""" <EOL> if not options : <EOL> options = { } <EOL> address = options . get ( "<STR_LIT>" , { } ) <EOL> hosted_customer . Title = address . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> hosted_customer . Address = address . get ( "<STR_LIT>" , '<STR_LIT>' ) + address . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> hosted_customer . Suburb = address . get ( "<STR_LIT>" ) <EOL> hosted_customer . State = address . get ( "<STR_LIT:state>" ) <EOL> hosted_customer . Company = address . get ( "<STR_LIT>" ) <EOL> hosted_customer . PostCode = address . get ( "<STR_LIT>" ) <EOL> hosted_customer . Country = address . get ( "<STR_LIT>" ) <EOL> hosted_customer . Email = address . get ( "<STR_LIT:email>" ) <EOL> hosted_customer . Fax = address . get ( "<STR_LIT>" ) <EOL> hosted_customer . Phone = address . get ( "<STR_LIT>" ) <EOL> hosted_customer . Mobile = address . get ( "<STR_LIT>" ) <EOL> hosted_customer . CustomerRef = address . get ( "<STR_LIT>" ) <EOL> hosted_customer . JobDesc = address . get ( "<STR_LIT>" ) <EOL> hosted_customer . Comments = address . get ( "<STR_LIT>" ) <EOL> hosted_customer . URL = address . get ( "<STR_LIT:url>" ) <EOL> def add_customer_details ( self , credit_card , customer_detail , options = None ) : <EOL> """<STR_LIT>""" <EOL> if not options : <EOL> options = { } <EOL> customer = options . get ( "<STR_LIT>" , { } ) <EOL> customer_detail . CustomerRef = customer . get ( "<STR_LIT>" ) <EOL> customer_detail . CustomerTitle = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerFirstName = credit_card . first_name <EOL> customer_detail . CustomerLastName = credit_card . last_name <EOL> customer_detail . CustomerCompany = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerJobDesc = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerEmail = customer . get ( "<STR_LIT>" ) <EOL> customer_detail . CustomerAddress = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) + customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerSuburb = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerState = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerPostCode = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerCountry = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerPhone1 = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerPhone2 = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerFax = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> customer_detail . CustomerURL = customer . get ( "<STR_LIT>" ) <EOL> customer_detail . CustomerComments = customer . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def add_rebill_details ( self , rebill_detail , rebile_customer_id , credit_card , rebill_profile ) : <EOL> """<STR_LIT>""" <EOL> rebill_detail . RebillCustomerID = rebile_customer_id <EOL> rebill_detail . RebillInvRef = rebill_profile . get ( "<STR_LIT>" ) <EOL> rebill_detail . RebillInvDesc = rebill_profile . get ( "<STR_LIT>" ) <EOL> rebill_detail . RebillCCName = credit_card . name <EOL> rebill_detail . RebillCCNumber = credit_card . number <EOL> rebill_detail . RebillCCExpMonth = '<STR_LIT>' % ( credit_card . month ) <EOL> rebill_detail . RebillCCExpYear = str ( credit_card . year ) [ - <NUM_LIT:2> : ] <EOL> rebill_detail . RebillInitAmt = rebill_profile . get ( "<STR_LIT>" ) <EOL> rebill_detail . RebillInitDate = rebill_profile . get ( "<STR_LIT>" ) <EOL> rebill_detail . RebillRecurAmt = rebill_profile . get ( "<STR_LIT>" ) <EOL> rebill_detail . RebillStartDate = rebill_profile . get ( "<STR_LIT>" ) <EOL> rebill_detail . RebillInterval = rebill_profile . get ( "<STR_LIT>" ) <EOL> rebill_detail . RebillIntervalType = rebill_profile . get ( "<STR_LIT>" ) <EOL> rebill_detail . RebillEndDate = rebill_profile . get ( "<STR_LIT>" ) <EOL> def add_direct_payment_details ( self , credit_card , customer_details , payment_details ) : <EOL> direct_payment_details = { } <EOL> direct_payment_details [ '<STR_LIT>' ] = self . customer_id <EOL> direct_payment_details [ '<STR_LIT>' ] = customer_details . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> direct_payment_details [ '<STR_LIT>' ] = customer_details . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> direct_payment_details [ '<STR_LIT>' ] = customer_details . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> direct_payment_details [ '<STR_LIT>' ] = customer_details . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> direct_payment_details [ '<STR_LIT>' ] = customer_details . get ( '<STR_LIT>' , None ) <EOL> direct_payment_details [ '<STR_LIT>' ] = credit_card . number <EOL> direct_payment_details [ '<STR_LIT>' ] = credit_card . name <EOL> direct_payment_details [ '<STR_LIT>' ] = '<STR_LIT>' % ( credit_card . month ) <EOL> direct_payment_details [ '<STR_LIT>' ] = str ( credit_card . year ) [ - <NUM_LIT:2> : ] <EOL> direct_payment_details [ '<STR_LIT>' ] = credit_card . verification_value <EOL> direct_payment_details [ '<STR_LIT>' ] = '<STR_LIT>' , <EOL> direct_payment_details [ '<STR_LIT>' ] = '<STR_LIT>' , <EOL> direct_payment_details [ '<STR_LIT>' ] = '<STR_LIT>' , <EOL> direct_payment_details [ '<STR_LIT>' ] = payment_details . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> direct_payment_details [ '<STR_LIT>' ] = payment_details [ '<STR_LIT>' ] <EOL> direct_payment_details [ '<STR_LIT>' ] = payment_details . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> direct_payment_details [ '<STR_LIT>' ] = payment_details . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return direct_payment_details <EOL> @ property <EOL> def service_url ( self ) : <EOL> if self . test_mode : <EOL> return HOSTED_TEST_URL <EOL> return HOSTED_LIVE_URL <EOL> def purchase ( self , money , credit_card , options = None ) : <EOL> """<STR_LIT>""" <EOL> if not options : <EOL> options = { } <EOL> if not self . validate_card ( credit_card ) : <EOL> raise InvalidCard ( "<STR_LIT>" ) <EOL> client = RebillEwayClient ( customer_id = self . customer_id , <EOL> username = self . eway_username , <EOL> password = self . eway_password , <EOL> url = self . service_url , <EOL> ) <EOL> hosted_customer = client . client . factory . create ( "<STR_LIT>" ) <EOL> self . add_creditcard ( hosted_customer , credit_card ) <EOL> self . add_address ( hosted_customer , options ) <EOL> customer_id = client . create_hosted_customer ( hosted_customer ) <EOL> pymt_response = client . process_payment ( <EOL> customer_id , <EOL> money , <EOL> options . get ( "<STR_LIT>" , '<STR_LIT:test>' ) , <EOL> options . get ( "<STR_LIT:description>" , '<STR_LIT:test>' ) <EOL> ) <EOL> if not hasattr ( pymt_response , "<STR_LIT>" ) : <EOL> transaction_was_unsuccessful . send ( sender = self , <EOL> type = "<STR_LIT>" , <EOL> response = pymt_response ) <EOL> return { "<STR_LIT:status>" : "<STR_LIT>" , "<STR_LIT>" : pymt_response } <EOL> if pymt_response . ewayTrxnStatus == "<STR_LIT:False>" : <EOL> transaction_was_unsuccessful . send ( sender = self , <EOL> type = "<STR_LIT>" , <EOL> response = pymt_response ) <EOL> return { "<STR_LIT:status>" : "<STR_LIT>" , "<STR_LIT>" : pymt_response } <EOL> transaction_was_successful . send ( sender = self , <EOL> type = "<STR_LIT>" , <EOL> response = pymt_response ) <EOL> return { "<STR_LIT:status>" : "<STR_LIT>" , "<STR_LIT>" : pymt_response } <EOL> def authorize ( self , money , credit_card , options = None ) : <EOL> raise NotImplementedError <EOL> def capture ( self , money , authorization , options = None ) : <EOL> raise NotImplementedError <EOL> def void ( self , identification , options = None ) : <EOL> raise NotImplementedError <EOL> def credit ( self , money , identification , options = None ) : <EOL> raise NotImplementedError <EOL> def direct_payment ( self , credit_card_details , options = None ) : <EOL> """<STR_LIT>""" <EOL> error_response = { } <EOL> try : <EOL> if ( options and options . get ( '<STR_LIT>' , False ) and <EOL> options . get ( '<STR_LIT>' , False ) ) : <EOL> customer_details = options . get ( '<STR_LIT>' ) <EOL> payment_details = options . get ( '<STR_LIT>' ) <EOL> else : <EOL> error_response = { "<STR_LIT>" : "<STR_LIT>" } <EOL> raise <EOL> """<STR_LIT>""" <EOL> credit_card = CreditCard ( ** credit_card_details ) <EOL> is_valid = self . validate_card ( credit_card ) <EOL> if not is_valid : <EOL> raise InvalidCard ( "<STR_LIT>" ) <EOL> """<STR_LIT>""" <EOL> direct_payment_details = self . add_direct_payment_details ( credit_card , customer_details , payment_details ) <EOL> """<STR_LIT>""" <EOL> dpObj = DirectPaymentClient ( self . direct_payment_url ) <EOL> response = dpObj . process_direct_payment ( direct_payment_details ) <EOL> """<STR_LIT>""" <EOL> eway_response = response . get ( '<STR_LIT>' , None ) <EOL> if eway_response and eway_response . get ( '<STR_LIT>' , '<STR_LIT:false>' ) . lower ( ) == '<STR_LIT:true>' : <EOL> status = "<STR_LIT>" <EOL> else : <EOL> status = "<STR_LIT>" <EOL> except Exception as e : <EOL> error_response [ '<STR_LIT>' ] = e <EOL> return { "<STR_LIT:status>" : "<STR_LIT>" , "<STR_LIT>" : error_response } <EOL> return { "<STR_LIT:status>" : status , "<STR_LIT>" : response } <EOL> def recurring ( self , credit_card_details , options = None ) : <EOL> """<STR_LIT>""" <EOL> error_response = { } <EOL> try : <EOL> if not options : <EOL> error_response = { "<STR_LIT>" : "<STR_LIT>" } <EOL> raise <EOL> """<STR_LIT>""" <EOL> credit_card = CreditCard ( ** credit_card_details ) <EOL> if not self . validate_card ( credit_card ) : <EOL> raise InvalidCard ( "<STR_LIT>" ) <EOL> rebillClient = RebillEwayClient ( <EOL> customer_id = self . customer_id , <EOL> username = self . eway_username , <EOL> password = self . eway_password , <EOL> url = self . rebill_url , <EOL> ) <EOL> customer_detail = rebillClient . client . factory . create ( "<STR_LIT>" ) <EOL> self . add_customer_details ( credit_card , customer_detail , options ) <EOL> """<STR_LIT>""" <EOL> rebill_customer_response = rebillClient . create_rebill_customer ( customer_detail ) <EOL> if rebill_customer_response . ErrorSeverity : <EOL> transaction_was_unsuccessful . send ( sender = self , <EOL> type = "<STR_LIT>" , <EOL> response = rebill_customer_response ) <EOL> error_response = rebill_customer_response <EOL> raise <EOL> rebile_customer_id = rebill_customer_response . RebillCustomerID <EOL> """<STR_LIT>""" <EOL> rebill_event_response_list = [ ] <EOL> for each_rebill_profile in options . get ( "<STR_LIT>" , [ ] ) : <EOL> rebill_detail = rebillClient . client . factory . create ( "<STR_LIT>" ) <EOL> self . add_rebill_details ( rebill_detail , rebile_customer_id , credit_card , each_rebill_profile ) <EOL> rebill_event_response = rebillClient . create_rebill_event ( rebill_detail ) <EOL> if rebill_event_response . ErrorSeverity : <EOL> transaction_was_unsuccessful . send ( sender = self , <EOL> type = "<STR_LIT>" , <EOL> response = rebill_event_response ) <EOL> error_response = rebill_event_response <EOL> raise <EOL> rebill_event_response_list . append ( rebill_event_response ) <EOL> transaction_was_successful . send ( sender = self , <EOL> type = "<STR_LIT>" , <EOL> response = rebill_event_response_list ) <EOL> except Exception as e : <EOL> error_response [ '<STR_LIT>' ] = e <EOL> return { "<STR_LIT:status>" : "<STR_LIT>" , "<STR_LIT>" : error_response } <EOL> return { "<STR_LIT:status>" : "<STR_LIT>" , "<STR_LIT>" : rebill_event_response_list } <EOL> def recurring_cancel ( self , rebill_customer_id , rebill_id ) : <EOL> """<STR_LIT>""" <EOL> rebillDeleteClient = RebillEwayClient ( <EOL> customer_id = self . customer_id , <EOL> username = self . eway_username , <EOL> password = self . eway_password , <EOL> url = self . rebill_url , <EOL> ) <EOL> """<STR_LIT>""" <EOL> delete_rebill_response = rebillDeleteClient . delete_rebill_event ( rebill_customer_id , rebill_id ) <EOL> if delete_rebill_response . ErrorSeverity : <EOL> transaction_was_unsuccessful . send ( sender = self , <EOL> type = "<STR_LIT>" , <EOL> response = delete_rebill_response ) <EOL> return { "<STR_LIT:status>" : "<STR_LIT>" , "<STR_LIT>" : delete_rebill_response } <EOL> transaction_was_successful . send ( sender = self , <EOL> type = "<STR_LIT>" , <EOL> response = delete_rebill_response ) <EOL> return { "<STR_LIT:status>" : "<STR_LIT>" , "<STR_LIT>" : delete_rebill_response } <EOL> def store ( self , creditcard , options = None ) : <EOL> raise NotImplementedError <EOL> def unstore ( self , identification , options = None ) : <EOL> raise NotImplementedError </s>
