| 1 |  |  | module AuthorizeNet::API | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |   class ApiTransaction < AuthorizeNet::XmlTransaction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |     module Type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |       API_CREATE_TRANSACTION = "createTransactionRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |       API_UPDATE_SPLIT_TENDER_GROUP = "updateSplitTenderGroupRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |       API_CREATE_SUBSCRIPTION = "ARBCreateSubscriptionRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |       API_UPDATE_SUBSCRIPTION = "ARBUpdateSubscriptionRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |       API_CANCEL_SUBSCRIPTION = "ARBCancelSubscriptionRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |       API_GET_SUBSCRIPTION_STATUS = "ARBGetSubscriptionStatusRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |       API_GET_SUBSCRIPTION_LIST = "ARBGetSubscriptionListRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |       API_GET_CUSTOMER_PROFILE_IDS = "getCustomerProfileIdsRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |       API_CREATE_CUSTOMER_PROFILE = "createCustomerProfileRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |       API_GET_CUSTOMER_PROFILE = "getCustomerProfileRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |       API_UPDATE_CUSTOMER_PROFILE = "updateCustomerProfileRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |       API_DELETE_CUSTOMER_PROFILE = "deleteCustomerProfileRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |       API_CREATE_CUSTOMER_PAYMENT_PROFILE = "createCustomerPaymentProfileRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |       API_GET_CUSTOMER_PAYMENT_PROFILE = "getCustomerPaymentProfileRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |       API_UPDATE_CUSTOMER_PAYMENT_PROFILE = "updateCustomerPaymentProfileRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |       API_VALIDATE_CUSTOMER_PAYMENT_PROFILE = "validateCustomerPaymentProfileRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |       API_DELETE_CUSTOMER_PAYMENT_PROFILE = "deleteCustomerPaymentProfileRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |       API_CREATE_CUSTOMER_SHIPPING_PROFILE = "createCustomerShippingAddressRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |       API_GET_CUSTOMER_SHIPPING_PROFILE = "getCustomerShippingAddressRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |       API_UPDATE_CUSTOMER_SHIPPING_PROFILE = "updateCustomerShippingAddressRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |       API_DELETE_CUSTOMER_SHIPPING_PROFILE = "deleteCustomerShippingAddressRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |       API_CREATE_CUSTOMER_PROFILE_FROM_TRANSACTION = "createCustomerProfileFromTransactionRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |       API_GET_SETTLED_BATCH_LIST = "getSettledBatchListRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |       API_GET_TRANSACTION_LIST = "getTransactionListRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |       API_GET_TRANSACTION_DETAILS = "getTransactionDetailsRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |       API_GET_UNSETTLED_TRANSACTION_LIST = "getUnsettledTransactionListRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |       API_GET_BATCH_STATISTICS = "getBatchStatisticsRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	  API_GET_TRANSACTION_LIST_FOR_CUSTOMER = "getTransactionListForCustomerRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	   | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |       API_GET_HOSTED_PROFILE_PAGE = "getHostedProfilePageRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |       API_DECRYPT_PAYMENT_DATA = "decryptPaymentDataRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |       API_AUTHENTICATE_TEST_REQUEST = "authenticateTestRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |       API_GET_CUSTOMER_PAYMENT_PROFILE_LIST = "getCustomerPaymentProfileListRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |       API_ARB_GET_SUBSCRIPTION_REQUEST = "ARBGetSubscriptionRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |       API_GET_MERCHANT_DETAILS = "getMerchantDetailsRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |       API_GET_HOSTED_PAYMENT_PAGE = "getHostedPaymentPageRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |       API_UDPATE_HELD_TRANSACTION = "updateHeldTransactionRequest" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     end | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     def initialize(api_login_id = nil, api_transaction_key = nil, options = {}) | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |        super | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |     end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     def setOAuthOptions() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	   super | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     def make_request(request,responseClass,type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 setOAuthOptions() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 unless responseClass.nil? or request.nil? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |        begin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         @xml = serialize(request,type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         respXml = send_request(@xml) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         @response = deserialize(respXml.body,responseClass)  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |        rescue Exception => ex   | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |           ex   | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |        end  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     def serialize(object,type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |       doc = Nokogiri::XML::Document.new | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |       doc.root = object.to_xml | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |       constants = YAML.load_file(File.dirname(__FILE__) + "/constants.yml") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |       clientId = constants['clientId'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |       builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |x| | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         x.send(type.to_sym, :xmlns => XML_NAMESPACE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |           x.merchantAuthentication { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 			if !@access_token.blank? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 				x.accessToken @access_token | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 			end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			if !@api_login_id.blank? || (@access_token.blank? && @api_login_id.blank?) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 				x.name @api_login_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 				x.transactionKey @api_transaction_key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 			end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |           x.clientId clientId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |          x.send:insert, doc.root.element_children | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |       } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |       end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |       builder.to_xml  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     def send_request(xml) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |       url = URI.parse(@gateway) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |       httpRequest = Net::HTTP::Post.new(url.path) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |       httpRequest.content_type = 'text/xml' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |       httpRequest.body = xml | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |       connection = Net::HTTP.new(url.host, url.port) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |       connection.use_ssl = true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |       if @verify_ssl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         connection.verify_mode = OpenSSL::SSL::VERIFY_PEER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |       else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         connection.verify_mode = OpenSSL::SSL::VERIFY_NONE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |       end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |       response = connection.start {|http| http.request(httpRequest)} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     def deserialize(xml,responseClass) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |       responseClass.from_xml(xml) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     end | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |   end | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 123 |  |  | end | 
            
                                                        
            
                                    
            
            
                | 124 |  |  |  |