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.



55
56
57
# File 'lib/authorize_net/api/api_transaction.rb', line 55

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

Instance Method Details

#deserialize(xml, responseClass) ⇒ Object



115
116
117
# File 'lib/authorize_net/api/api_transaction.rb', line 115

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

#make_request(request, responseClass, type) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/authorize_net/api/api_transaction.rb', line 63

def make_request(request, responseClass, type)
  setOAuthOptions
  unless responseClass.nil? || request.nil?
    begin
      @xml = serialize(request, type)
      respXml = send_request(@xml)
      @response = deserialize(respXml.body, responseClass)
    rescue Exception => ex
      ex
    end
    end
end

#send_request(xml) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/authorize_net/api/api_transaction.rb', line 98

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/authorize_net/api/api_transaction.rb', line 76

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



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

def setOAuthOptions
    super
end