Class: AuthorizeNet::API::ApiTransaction

Inherits:
XmlTransaction show all
Defined in:
lib/authorize_net/api/api_transaction.rb

Direct Known Subclasses

Transaction

Defined Under Namespace

Modules: Type

Constant Summary

Constants inherited from XmlTransaction

XmlTransaction::XML_NAMESPACE

Constants included from TypeConversions

TypeConversions::API_FIELD_PREFIX

Instance Attribute Summary

Attributes inherited from XmlTransaction

#response, #xml

Attributes inherited from Transaction

#fields

Instance Method Summary collapse

Methods inherited from XmlTransaction

#has_response?, #run, #test?

Methods inherited from Transaction

#set_address, #set_customer, #set_fields, #set_shipping_address

Methods included from TypeConversions

#boolean_to_value, #date_to_value, #datetime_to_value, #decimal_to_value, #integer_to_value, #to_external_field, #to_internal_field, #to_param, #value_to_boolean, #value_to_date, #value_to_datetime, #value_to_decimal, #value_to_integer

Constructor Details

#initialize(api_login_id = nil, api_transaction_key = nil, options = {}) ⇒ ApiTransaction

Returns a new instance of ApiTransaction.



59
60
61
# File 'lib/authorize_net/api/api_transaction.rb', line 59

def initialize( = nil, api_transaction_key = nil, options = {})
  super
end

Instance Method Details

#deserialize(xml, responseClass) ⇒ Object



125
126
127
# File 'lib/authorize_net/api/api_transaction.rb', line 125

def deserialize(xml, responseClass)
  responseClass.from_xml(xml)
end

#make_request(request, responseClass, type) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/authorize_net/api/api_transaction.rb', line 67

def make_request(request, responseClass, type)
  setOAuthOptions
  unless responseClass.nil? || request.nil?
    begin
      @xml = serialize(request, type)
      LogHelper.log.debug(@xml)
      respXml = send_request(@xml)
      @response = deserialize(respXml.body, responseClass)
      LogHelper.log.debug(respXml.body)
	  return @response
    rescue Exception => ex
  LogHelper.log.error(ex.message)
  ex.backtrace.each {|line| LogHelper.log.error(line)}
      ex
    end
    end
end

#send_request(xml) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/authorize_net/api/api_transaction.rb', line 108

def send_request(xml)
  url = URI.parse(@gateway)

  httpRequest = Net::HTTP::Post.new(url.path)
  httpRequest.content_type = 'text/xml'
  httpRequest.body = xml
  connection = Net::HTTP.new(url.host, url.port)
  connection.use_ssl = true
  if @verify_ssl
    connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
  else
    connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

  response = connection.start { |http| http.request(httpRequest) }
end

#serialize(object, type) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/authorize_net/api/api_transaction.rb', line 85

def serialize(object, type)
  doc = Nokogiri::XML::Document.new
  doc.root = object.to_xml
  constants = YAML.load_file(File.dirname(__FILE__) + "/constants.yml")
  clientId = constants['clientId']

  builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |x|
    x.send(type.to_sym, xmlns: XML_NAMESPACE) do
      x.merchantAuthentication do
        x.accessToken @access_token unless @access_token.blank?
        if !@api_login_id.blank? || (@access_token.blank? && @api_login_id.blank?)
          x.name @api_login_id
          x.transactionKey @api_transaction_key
        end
      end
      x.clientId clientId
      x.send :insert, doc.root.element_children
    end
  end
  builder.to_xml
end

#setOAuthOptionsObject



63
64
65
# File 'lib/authorize_net/api/api_transaction.rb', line 63

def setOAuthOptions
    super
end