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.



51
52
53
# File 'lib/authorize_net/api/api_transaction.rb', line 51

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

Instance Method Details

#deserialize(xml, responseClass) ⇒ Object



100
101
102
# File 'lib/authorize_net/api/api_transaction.rb', line 100

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

#make_request(request, responseClass, type) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/authorize_net/api/api_transaction.rb', line 55

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



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/authorize_net/api/api_transaction.rb', line 83

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



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

def serialize(object,type)
  doc = Nokogiri::XML::Document.new
  doc.root = object.to_xml     

  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.send:insert, doc.root.element_children
  }
  end
  builder.to_xml 
end