#NEWLINE# def recurring( self , money , credit_card , options ) : #NEWLINE# #INDENT# if ( not options ) : #NEWLINE# #INDENT# options = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( not self . validate_card ( credit_card ) ) : #NEWLINE# #INDENT# raise InvalidCard ( 'Invalid Card' ) #NEWLINE# #UNINDENT# template_vars = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# template_vars [ 'auth_login' ] = xml_response . login #NEWLINE# template_vars [ 'auth_key' ] = self . password #NEWLINE# template_vars [ 'amount' ] = money #NEWLINE# template_vars [ 'card_number' ] = credit_card . number #NEWLINE# template_vars [ 'exp_date' ] = credit_card . expire_date #NEWLINE# template_vars [ 'start_date' ] = ( options . get ( 'start_date' ) or datetime . date . today ( ) . strftime ( '%Y-%m-%d' ) ) #NEWLINE# template_vars [ 'total_occurrences' ] = options . get ( 'total_occurences' , 9999 ) #NEWLINE# template_vars [ 'interval_length' ] = options . get ( 'interval_length' , 1 ) #NEWLINE# template_vars [ 'interval_unit' ] = options . get ( 'interval_unit' , 'months' ) #NEWLINE# template_vars [ 'sub_name' ] = options . get ( 'sub_name' , '' ) #NEWLINE# template_vars [ 'first_name' ] = credit_card . first_name #NEWLINE# template_vars [ 'last_name' ] = credit_card . last_name #NEWLINE# xml = render_to_string ( 'billing/arb/arb_create_subscription.xml' , template_vars ) #NEWLINE# if self . test_mode : #NEWLINE# #INDENT# url = self . arb_test_url #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# url = self . arb_live_url #NEWLINE# #UNINDENT# headers = { #NEWLINE# #INDENT# 'content-type' : 'text/xml' , #NEWLINE# #UNINDENT# } #NEWLINE# conn = Request ( url = url , data = xml , headers = headers ) #NEWLINE# try : #NEWLINE# #INDENT# open_conn = urlopen ( conn ) #NEWLINE# xml_response = open_conn . read ( ) #NEWLINE# #UNINDENT# except URLError as e : #NEWLINE# #INDENT# return MockAuthorizeAIMResponse ( 5 , '1' , str ( e ) ) #NEWLINE# #UNINDENT# response = nodeToDic ( parseString ( xml_response ) ) [ 'ARBCreateSubscriptionResponse' ] #NEWLINE# status = 'SUCCESS' #NEWLINE# if ( response [ 'messages' ] [ 'resultCode' ] . lower ( ) != 'ok' ) : #NEWLINE# #INDENT# status = 'FAILURE' #NEWLINE# transaction_was_unsuccessful . send ( sender = self , type = 'recurring' , response = response ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# transaction_was_successful . send ( sender = self , type = 'recurring' , response = response ) #NEWLINE# #UNINDENT# return { #NEWLINE# #INDENT# 'status' : status , #NEWLINE# 'response' : response , #NEWLINE# #UNINDENT# }