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 Method Summary collapse

Methods inherited from XmlTransaction

#has_response?, #response, #run, #test?, #xml

Methods inherited from Transaction

#fields, #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, api_transaction_key, options = {}) ⇒ ApiTransaction

Returns a new instance of ApiTransaction.



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

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

Instance Method Details

#deserialize(xml, responseClass) ⇒ Object



108
109
110
# File 'lib/authorize_net/api/api_transaction.rb', line 108

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

#make_request(request, responseClass, type) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/authorize_net/api/api_transaction.rb', line 60

def make_request(request,responseClass,type)
 unless responseClass.nil? or 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



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/authorize_net/api/api_transaction.rb', line 91

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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/authorize_net/api/api_transaction.rb', line 72

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) {
      x.merchantAuthentication {
        x.name @api_login_id
        x.transactionKey @api_transaction_key
        }
      x.clientId clientId
     x.send:insert, doc.root.element_children
  }
  end
  builder.to_xml 
end