authorizenet 1.8.7 → 1.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/app/helpers/authorize_net_helper.rb +23 -23
 - data/lib/authorize_net.rb +107 -103
 - data/lib/authorize_net/addresses/address.rb +28 -28
 - data/lib/authorize_net/addresses/shipping_address.rb +25 -25
 - data/lib/authorize_net/aim/response.rb +130 -130
 - data/lib/authorize_net/aim/transaction.rb +190 -190
 - data/lib/authorize_net/api/api_transaction.rb +103 -102
 - data/lib/authorize_net/api/schema.rb +4283 -4283
 - data/lib/authorize_net/api/transaction.rb +240 -240
 - data/lib/authorize_net/arb/fields.rb +24 -24
 - data/lib/authorize_net/arb/paging.rb +33 -33
 - data/lib/authorize_net/arb/response.rb +33 -33
 - data/lib/authorize_net/arb/sorting.rb +43 -43
 - data/lib/authorize_net/arb/subscription.rb +71 -71
 - data/lib/authorize_net/arb/subscription_detail.rb +14 -14
 - data/lib/authorize_net/arb/subscription_list_response.rb +43 -43
 - data/lib/authorize_net/arb/transaction.rb +177 -177
 - data/lib/authorize_net/authorize_net.rb +153 -153
 - data/lib/authorize_net/cim/customer_profile.rb +18 -18
 - data/lib/authorize_net/cim/payment_profile.rb +36 -36
 - data/lib/authorize_net/cim/response.rb +115 -115
 - data/lib/authorize_net/cim/transaction.rb +727 -727
 - data/lib/authorize_net/customer.rb +26 -26
 - data/lib/authorize_net/email_receipt.rb +23 -23
 - data/lib/authorize_net/fields.rb +779 -779
 - data/lib/authorize_net/key_value_response.rb +116 -116
 - data/lib/authorize_net/key_value_transaction.rb +290 -290
 - data/lib/authorize_net/line_item.rb +24 -24
 - data/lib/authorize_net/order.rb +41 -41
 - data/lib/authorize_net/payment_methods/credit_card.rb +62 -62
 - data/lib/authorize_net/payment_methods/echeck.rb +71 -71
 - data/lib/authorize_net/reporting/batch.rb +18 -18
 - data/lib/authorize_net/reporting/batch_statistics.rb +18 -18
 - data/lib/authorize_net/reporting/fds_filter.rb +10 -10
 - data/lib/authorize_net/reporting/response.rb +162 -162
 - data/lib/authorize_net/reporting/returned_item.rb +46 -46
 - data/lib/authorize_net/reporting/transaction.rb +133 -133
 - data/lib/authorize_net/reporting/transaction_details.rb +24 -24
 - data/lib/authorize_net/response.rb +26 -26
 - data/lib/authorize_net/sim/hosted_payment_form.rb +37 -37
 - data/lib/authorize_net/sim/hosted_receipt_page.rb +36 -36
 - data/lib/authorize_net/sim/response.rb +141 -141
 - data/lib/authorize_net/sim/transaction.rb +137 -137
 - data/lib/authorize_net/transaction.rb +65 -65
 - data/lib/authorize_net/xml_response.rb +171 -171
 - data/lib/authorize_net/xml_transaction.rb +280 -280
 - data/lib/authorizenet.rb +4 -4
 - data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +53 -53
 - data/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +48 -48
 - data/lib/generators/authorize_net/direct_post/templates/config.yml.erb +8 -8
 - data/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +8 -8
 - data/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +30 -30
 - data/lib/generators/authorize_net/direct_post/templates/initializer.rb +4 -4
 - data/lib/generators/authorize_net/direct_post/templates/layout.erb +17 -17
 - data/lib/generators/authorize_net/direct_post/templates/payment.erb +9 -9
 - data/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +9 -9
 - data/lib/generators/authorize_net/sim/sim_generator.rb +47 -47
 - data/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +51 -51
 - data/lib/generators/authorize_net/sim/templates/config.yml.erb +8 -8
 - data/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +8 -8
 - data/lib/generators/authorize_net/sim/templates/controller.rb.erb +20 -20
 - data/lib/generators/authorize_net/sim/templates/initializer.rb +4 -4
 - data/lib/generators/authorize_net/sim/templates/layout.erb +17 -17
 - data/lib/generators/authorize_net/sim/templates/payment.erb +5 -5
 - data/lib/generators/authorize_net/sim/templates/payment.rails3.erb +5 -5
 - data/lib/generators/generator_extensions.rb +74 -74
 - metadata +4 -3
 
| 
         @@ -1,190 +1,190 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module AuthorizeNet::AIM
         
     | 
| 
       2 
     | 
    
         
            -
              
         
     | 
| 
       3 
     | 
    
         
            -
              # The AIM transaction class. Handles building the transaction payload and
         
     | 
| 
       4 
     | 
    
         
            -
              # transmitting it to the gateway.
         
     | 
| 
       5 
     | 
    
         
            -
              class Transaction < AuthorizeNet::KeyValueTransaction
         
     | 
| 
       6 
     | 
    
         
            -
                
         
     | 
| 
       7 
     | 
    
         
            -
                # The default options for the constructor.
         
     | 
| 
       8 
     | 
    
         
            -
                @@option_defaults = {
         
     | 
| 
       9 
     | 
    
         
            -
                  :transaction_type => Type::AUTHORIZE_AND_CAPTURE,
         
     | 
| 
       10 
     | 
    
         
            -
                  :gateway => :production,
         
     | 
| 
       11 
     | 
    
         
            -
                  :test => false,
         
     | 
| 
       12 
     | 
    
         
            -
                  :allow_split => false,
         
     | 
| 
       13 
     | 
    
         
            -
                  :delimiter => ',',
         
     | 
| 
       14 
     | 
    
         
            -
                  :encapsulation_character => nil,
         
     | 
| 
       15 
     | 
    
         
            -
                  :verify_ssl => true,
         
     | 
| 
       16 
     | 
    
         
            -
                  :device_type => DeviceType::UNKNOWN,
         
     | 
| 
       17 
     | 
    
         
            -
                  :market_type => MarketType::RETAIL
         
     | 
| 
       18 
     | 
    
         
            -
                }
         
     | 
| 
       19 
     | 
    
         
            -
                
         
     | 
| 
       20 
     | 
    
         
            -
                # Fields to convert to/from booleans.
         
     | 
| 
       21 
     | 
    
         
            -
                @@boolean_fields = [:tax_exempt, :test_request, :recurring_billing, :allow_partial_auth, :delim_data, :email_customer, :relay_response]
         
     | 
| 
       22 
     | 
    
         
            -
                
         
     | 
| 
       23 
     | 
    
         
            -
                # Fields to convert to/from BigDecimal.
         
     | 
| 
       24 
     | 
    
         
            -
                @@decimal_fields = [:amount]
         
     | 
| 
       25 
     | 
    
         
            -
                
         
     | 
| 
       26 
     | 
    
         
            -
                # Constructs an AIM transaction. You can use the new AIM transaction object
         
     | 
| 
       27 
     | 
    
         
            -
                # to issue a request to the payment gateway and parse the response into a new
         
     | 
| 
       28 
     | 
    
         
            -
                # AuthorizeNet::AIM::Response object.
         
     | 
| 
       29 
     | 
    
         
            -
                # 
         
     | 
| 
       30 
     | 
    
         
            -
                # +api_login_id+:: Your API login ID, as a string.
         
     | 
| 
       31 
     | 
    
         
            -
                # +api_transaction_key+:: Your API transaction key, as a string.
         
     | 
| 
       32 
     | 
    
         
            -
                # +options+:: A hash of options. See below for values.
         
     | 
| 
       33 
     | 
    
         
            -
                # 
         
     | 
| 
       34 
     | 
    
         
            -
                # Options
         
     | 
| 
       35 
     | 
    
         
            -
                # +transaction_type+:: The type of transaction to perform. Defaults to AuthorizeNet::Type::AUTHORIZE_AND_CAPTURE. This value is only used if run is called directly.
         
     | 
| 
       36 
     | 
    
         
            -
                # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::AIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :card_present_test, :card_present_live, :card_present_sandbox, :card_present_production, :production, or :live (:test is an alias for :sandbox, :card_present_test is an alias for :card_present_sandbox, :card_present_production is an alias for :card_present_live, and :live is an alias for :production). 
         
     | 
| 
       37 
     | 
    
         
            -
                # +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false).
         
     | 
| 
       38 
     | 
    
         
            -
                # +allow_split+:: A boolean indicating if split transactions should be allowed (defaults to false).
         
     | 
| 
       39 
     | 
    
         
            -
                # +delimiter+:: A single character (as a string) that will be used to delimit the response from the gateway. Defaults to ','.
         
     | 
| 
       40 
     | 
    
         
            -
                # +encapsulation_character+:: A single character (as a string) that will be used to encapsulate each field in the response from the gateway. Defaults to nil.
         
     | 
| 
       41 
     | 
    
         
            -
                # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to true.
         
     | 
| 
       42 
     | 
    
         
            -
                # +device_type+:: A constant from DeviceType indicating the type of POS device used in a card present transaction. Defaults to DeviceType::UNKNOWN.
         
     | 
| 
       43 
     | 
    
         
            -
                # +market_type+:: A constant from MarketType indicating your industry. Used for card present transactions. Defaults to MarketType::RETAIL.
         
     | 
| 
       44 
     | 
    
         
            -
                #
         
     | 
| 
       45 
     | 
    
         
            -
                def initialize(api_login_id, api_transaction_key, options = {})
         
     | 
| 
       46 
     | 
    
         
            -
                  super()
         
     | 
| 
       47 
     | 
    
         
            -
                  options = @@option_defaults.merge(options)
         
     | 
| 
       48 
     | 
    
         
            -
                  @api_login_id = api_login_id
         
     | 
| 
       49 
     | 
    
         
            -
                  @api_transaction_key = api_transaction_key
         
     | 
| 
       50 
     | 
    
         
            -
                  @test_mode = options[:test]
         
     | 
| 
       51 
     | 
    
         
            -
                  @response ||= nil
         
     | 
| 
       52 
     | 
    
         
            -
                  @delimiter = options[:delimiter]
         
     | 
| 
       53 
     | 
    
         
            -
                  @type = options[:transaction_type]
         
     | 
| 
       54 
     | 
    
         
            -
                  @cp_version = nil
         
     | 
| 
       55 
     | 
    
         
            -
                  case options[:gateway]
         
     | 
| 
       56 
     | 
    
         
            -
                  when :sandbox, :test
         
     | 
| 
       57 
     | 
    
         
            -
                    @gateway = Gateway::TEST
         
     | 
| 
       58 
     | 
    
         
            -
                  when :production, :live
         
     | 
| 
       59 
     | 
    
         
            -
                    @gateway = Gateway::LIVE
         
     | 
| 
       60 
     | 
    
         
            -
                  when :card_present_live, :card_present_production
         
     | 
| 
       61 
     | 
    
         
            -
                    @gateway = Gateway::CARD_PRESENT_LIVE
         
     | 
| 
       62 
     | 
    
         
            -
                    @cp_version = '1.0'
         
     | 
| 
       63 
     | 
    
         
            -
                  when :card_present_test, :card_present_sandbox
         
     | 
| 
       64 
     | 
    
         
            -
                    @gateway = Gateway::CARD_PRESENT_TEST
         
     | 
| 
       65 
     | 
    
         
            -
                    @cp_version = '1.0'
         
     | 
| 
       66 
     | 
    
         
            -
                  else
         
     | 
| 
       67 
     | 
    
         
            -
                    @gateway = options[:gateway]
         
     | 
| 
       68 
     | 
    
         
            -
                  end
         
     | 
| 
       69 
     | 
    
         
            -
                  @allow_split_transaction = options[:allow_split]
         
     | 
| 
       70 
     | 
    
         
            -
                  @encapsulation_character = options[:encapsulation_character]
         
     | 
| 
       71 
     | 
    
         
            -
                  @verify_ssl = options[:verify_ssl]
         
     | 
| 
       72 
     | 
    
         
            -
                  @market_type = options[:market_type]
         
     | 
| 
       73 
     | 
    
         
            -
                  @device_type = options[:device_type]
         
     | 
| 
       74 
     | 
    
         
            -
                  @solution_id = options[:solution_id]
         
     | 
| 
       75 
     | 
    
         
            -
                end
         
     | 
| 
       76 
     | 
    
         
            -
                
         
     | 
| 
       77 
     | 
    
         
            -
                # Checks if the transaction has been configured for test mode or not. Return TRUE if the
         
     | 
| 
       78 
     | 
    
         
            -
                # transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
         
     | 
| 
       79 
     | 
    
         
            -
                # are considered test transactions.
         
     | 
| 
       80 
     | 
    
         
            -
                def test?
         
     | 
| 
       81 
     | 
    
         
            -
                  super || @gateway == Gateway::TEST
         
     | 
| 
       82 
     | 
    
         
            -
                end
         
     | 
| 
       83 
     | 
    
         
            -
                
         
     | 
| 
       84 
     | 
    
         
            -
                # Returns TRUE if split transactions are allowed, FALSE otherwise.
         
     | 
| 
       85 
     | 
    
         
            -
                def split_transaction_allowed?
         
     | 
| 
       86 
     | 
    
         
            -
                  !!@allow_split_transaction
         
     | 
| 
       87 
     | 
    
         
            -
                end
         
     | 
| 
       88 
     | 
    
         
            -
                
         
     | 
| 
       89 
     | 
    
         
            -
                # Returns the current encapsulation character unless there is none, in which case Nil is returned.
         
     | 
| 
       90 
     | 
    
         
            -
                def encapsulation_character
         
     | 
| 
       91 
     | 
    
         
            -
                  @encapsulation_character
         
     | 
| 
       92 
     | 
    
         
            -
                end
         
     | 
| 
       93 
     | 
    
         
            -
                
         
     | 
| 
       94 
     | 
    
         
            -
                # Returns the gateway to be used for this transaction.
         
     | 
| 
       95 
     | 
    
         
            -
                def gateway
         
     | 
| 
       96 
     | 
    
         
            -
                  @gateway
         
     | 
| 
       97 
     | 
    
         
            -
                end
         
     | 
| 
       98 
     | 
    
         
            -
                
         
     | 
| 
       99 
     | 
    
         
            -
                # Checks to see if the transaction has a response (meaning it has been submitted to the gateway).
         
     | 
| 
       100 
     | 
    
         
            -
                # Returns TRUE if a response is present, FALSE otherwise.
         
     | 
| 
       101 
     | 
    
         
            -
                def has_response?
         
     | 
| 
       102 
     | 
    
         
            -
                  !@response.nil?
         
     | 
| 
       103 
     | 
    
         
            -
                end
         
     | 
| 
       104 
     | 
    
         
            -
                
         
     | 
| 
       105 
     | 
    
         
            -
                # Retrieve the response object (or Nil if transaction hasn't been sent to the gateway).
         
     | 
| 
       106 
     | 
    
         
            -
                def response
         
     | 
| 
       107 
     | 
    
         
            -
                  @response
         
     | 
| 
       108 
     | 
    
         
            -
                end
         
     | 
| 
       109 
     | 
    
         
            -
                
         
     | 
| 
       110 
     | 
    
         
            -
                # Returns the current delimiter we are using to parse the fields returned by the
         
     | 
| 
       111 
     | 
    
         
            -
                # gateway.
         
     | 
| 
       112 
     | 
    
         
            -
                def delimiter
         
     | 
| 
       113 
     | 
    
         
            -
                  @delimiter
         
     | 
| 
       114 
     | 
    
         
            -
                end
         
     | 
| 
       115 
     | 
    
         
            -
                
         
     | 
| 
       116 
     | 
    
         
            -
                # Sets the delimiter used to parse the response from the gateway.
         
     | 
| 
       117 
     | 
    
         
            -
                def delimiter=(delimiter)
         
     | 
| 
       118 
     | 
    
         
            -
                  @delimiter = delimiter
         
     | 
| 
       119 
     | 
    
         
            -
                end
         
     | 
| 
       120 
     | 
    
         
            -
                
         
     | 
| 
       121 
     | 
    
         
            -
                # Submits the transaction to the gateway for processing. Returns a response object. If the transaction
         
     | 
| 
       122 
     | 
    
         
            -
                # has already been run, it will return nil.
         
     | 
| 
       123 
     | 
    
         
            -
                def run
         
     | 
| 
       124 
     | 
    
         
            -
                  make_request
         
     | 
| 
       125 
     | 
    
         
            -
                end
         
     | 
| 
       126 
     | 
    
         
            -
                
         
     | 
| 
       127 
     | 
    
         
            -
                # Returns the current card present API version that we are adhering to.
         
     | 
| 
       128 
     | 
    
         
            -
                def cp_version
         
     | 
| 
       129 
     | 
    
         
            -
                  @cp_version
         
     | 
| 
       130 
     | 
    
         
            -
                end
         
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
                def solution_id
         
     | 
| 
       133 
     | 
    
         
            -
                  @solution_id
         
     | 
| 
       134 
     | 
    
         
            -
                end
         
     | 
| 
       135 
     | 
    
         
            -
                
         
     | 
| 
       136 
     | 
    
         
            -
                #:enddoc:
         
     | 
| 
       137 
     | 
    
         
            -
                protected
         
     | 
| 
       138 
     | 
    
         
            -
                
         
     | 
| 
       139 
     | 
    
         
            -
                # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
         
     | 
| 
       140 
     | 
    
         
            -
                def make_request
         
     | 
| 
       141 
     | 
    
         
            -
                  if has_response?
         
     | 
| 
       142 
     | 
    
         
            -
                    return nil
         
     | 
| 
       143 
     | 
    
         
            -
                  end
         
     | 
| 
       144 
     | 
    
         
            -
                  url = URI.parse(@gateway)
         
     | 
| 
       145 
     | 
    
         
            -
                  fields = @fields.merge(:type => @type, :delim_char => @delimiter, :delim_data => "TRUE", :login => @api_login_id, :tran_key => @api_transaction_key, :relay_response => "FALSE")
         
     | 
| 
       146 
     | 
    
         
            -
                  
         
     | 
| 
       147 
     | 
    
         
            -
                  if @cp_version.nil?
         
     | 
| 
       148 
     | 
    
         
            -
                    fields.merge!(:version => @version)
         
     | 
| 
       149 
     | 
    
         
            -
                  else
         
     | 
| 
       150 
     | 
    
         
            -
                    fields.merge!(:cp_version => @cp_version, :market_type => @market_type, :device_type => @device_type, :response_format => "1")
         
     | 
| 
       151 
     | 
    
         
            -
                  end
         
     | 
| 
       152 
     | 
    
         
            -
                  fields[:test_request] = boolean_to_value(@test_mode)
         
     | 
| 
       153 
     | 
    
         
            -
                  fields[:allow_partial_auth] = 'TRUE' if @allow_split_transaction
         
     | 
| 
       154 
     | 
    
         
            -
                  fields[:encap_char] = @encapsulation_character unless @encapsulation_character.nil?
         
     | 
| 
       155 
     | 
    
         
            -
                  fields[:solution_id] = @solution_id unless @solution_id.nil?
         
     | 
| 
       156 
     | 
    
         
            -
                  fields.each do |k, v|
         
     | 
| 
       157 
     | 
    
         
            -
                    if @@boolean_fields.include?(k)
         
     | 
| 
       158 
     | 
    
         
            -
                      fields[k] = boolean_to_value(v)
         
     | 
| 
       159 
     | 
    
         
            -
                    elsif @@decimal_fields.include?(k)
         
     | 
| 
       160 
     | 
    
         
            -
                      fields[k] = decimal_to_value(v)
         
     | 
| 
       161 
     | 
    
         
            -
                    end
         
     | 
| 
       162 
     | 
    
         
            -
                  end
         
     | 
| 
       163 
     | 
    
         
            -
                  data = fields.collect do |key, val|
         
     | 
| 
       164 
     | 
    
         
            -
                    self.to_param(key, val)
         
     | 
| 
       165 
     | 
    
         
            -
                  end
         
     | 
| 
       166 
     | 
    
         
            -
                  custom_field_keys = @custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
         
     | 
| 
       167 
     | 
    
         
            -
                  for key in custom_field_keys
         
     | 
| 
       168 
     | 
    
         
            -
                    data += [self.to_param(key, @custom_fields[key.to_sym], '')]
         
     | 
| 
       169 
     | 
    
         
            -
                  end
         
     | 
| 
       170 
     | 
    
         
            -
                  data.flatten!
         
     | 
| 
       171 
     | 
    
         
            -
                  request = Net::HTTP::Post.new(url.path)
         
     | 
| 
       172 
     | 
    
         
            -
                  request.content_type = 'application/x-www-form-urlencoded'
         
     | 
| 
       173 
     | 
    
         
            -
                  request.body = data.join("&")
         
     | 
| 
       174 
     | 
    
         
            -
                  connection = Net::HTTP.new(url.host, url.port)
         
     | 
| 
       175 
     | 
    
         
            -
                  connection.use_ssl = true
         
     | 
| 
       176 
     | 
    
         
            -
                  if @verify_ssl
         
     | 
| 
       177 
     | 
    
         
            -
                    connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
         
     | 
| 
       178 
     | 
    
         
            -
                  else
         
     | 
| 
       179 
     | 
    
         
            -
                    connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
       180 
     | 
    
         
            -
                  end
         
     | 
| 
       181 
     | 
    
         
            -
                  begin
         
     | 
| 
       182 
     | 
    
         
            -
                    @response = AuthorizeNet::AIM::Response.new((connection.start {|http| http.request(request)}), self)
         
     | 
| 
       183 
     | 
    
         
            -
                  rescue
         
     | 
| 
       184 
     | 
    
         
            -
                    @response = AuthorizeNet::AIM::Response.new($!, self)
         
     | 
| 
       185 
     | 
    
         
            -
                  end
         
     | 
| 
       186 
     | 
    
         
            -
                end
         
     | 
| 
       187 
     | 
    
         
            -
                
         
     | 
| 
       188 
     | 
    
         
            -
              end
         
     | 
| 
       189 
     | 
    
         
            -
              
         
     | 
| 
       190 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            module AuthorizeNet::AIM
         
     | 
| 
      
 2 
     | 
    
         
            +
              
         
     | 
| 
      
 3 
     | 
    
         
            +
              # The AIM transaction class. Handles building the transaction payload and
         
     | 
| 
      
 4 
     | 
    
         
            +
              # transmitting it to the gateway.
         
     | 
| 
      
 5 
     | 
    
         
            +
              class Transaction < AuthorizeNet::KeyValueTransaction
         
     | 
| 
      
 6 
     | 
    
         
            +
                
         
     | 
| 
      
 7 
     | 
    
         
            +
                # The default options for the constructor.
         
     | 
| 
      
 8 
     | 
    
         
            +
                @@option_defaults = {
         
     | 
| 
      
 9 
     | 
    
         
            +
                  :transaction_type => Type::AUTHORIZE_AND_CAPTURE,
         
     | 
| 
      
 10 
     | 
    
         
            +
                  :gateway => :production,
         
     | 
| 
      
 11 
     | 
    
         
            +
                  :test => false,
         
     | 
| 
      
 12 
     | 
    
         
            +
                  :allow_split => false,
         
     | 
| 
      
 13 
     | 
    
         
            +
                  :delimiter => ',',
         
     | 
| 
      
 14 
     | 
    
         
            +
                  :encapsulation_character => nil,
         
     | 
| 
      
 15 
     | 
    
         
            +
                  :verify_ssl => true,
         
     | 
| 
      
 16 
     | 
    
         
            +
                  :device_type => DeviceType::UNKNOWN,
         
     | 
| 
      
 17 
     | 
    
         
            +
                  :market_type => MarketType::RETAIL
         
     | 
| 
      
 18 
     | 
    
         
            +
                }
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
                # Fields to convert to/from booleans.
         
     | 
| 
      
 21 
     | 
    
         
            +
                @@boolean_fields = [:tax_exempt, :test_request, :recurring_billing, :allow_partial_auth, :delim_data, :email_customer, :relay_response]
         
     | 
| 
      
 22 
     | 
    
         
            +
                
         
     | 
| 
      
 23 
     | 
    
         
            +
                # Fields to convert to/from BigDecimal.
         
     | 
| 
      
 24 
     | 
    
         
            +
                @@decimal_fields = [:amount]
         
     | 
| 
      
 25 
     | 
    
         
            +
                
         
     | 
| 
      
 26 
     | 
    
         
            +
                # Constructs an AIM transaction. You can use the new AIM transaction object
         
     | 
| 
      
 27 
     | 
    
         
            +
                # to issue a request to the payment gateway and parse the response into a new
         
     | 
| 
      
 28 
     | 
    
         
            +
                # AuthorizeNet::AIM::Response object.
         
     | 
| 
      
 29 
     | 
    
         
            +
                # 
         
     | 
| 
      
 30 
     | 
    
         
            +
                # +api_login_id+:: Your API login ID, as a string.
         
     | 
| 
      
 31 
     | 
    
         
            +
                # +api_transaction_key+:: Your API transaction key, as a string.
         
     | 
| 
      
 32 
     | 
    
         
            +
                # +options+:: A hash of options. See below for values.
         
     | 
| 
      
 33 
     | 
    
         
            +
                # 
         
     | 
| 
      
 34 
     | 
    
         
            +
                # Options
         
     | 
| 
      
 35 
     | 
    
         
            +
                # +transaction_type+:: The type of transaction to perform. Defaults to AuthorizeNet::Type::AUTHORIZE_AND_CAPTURE. This value is only used if run is called directly.
         
     | 
| 
      
 36 
     | 
    
         
            +
                # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::AIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :card_present_test, :card_present_live, :card_present_sandbox, :card_present_production, :production, or :live (:test is an alias for :sandbox, :card_present_test is an alias for :card_present_sandbox, :card_present_production is an alias for :card_present_live, and :live is an alias for :production). 
         
     | 
| 
      
 37 
     | 
    
         
            +
                # +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false).
         
     | 
| 
      
 38 
     | 
    
         
            +
                # +allow_split+:: A boolean indicating if split transactions should be allowed (defaults to false).
         
     | 
| 
      
 39 
     | 
    
         
            +
                # +delimiter+:: A single character (as a string) that will be used to delimit the response from the gateway. Defaults to ','.
         
     | 
| 
      
 40 
     | 
    
         
            +
                # +encapsulation_character+:: A single character (as a string) that will be used to encapsulate each field in the response from the gateway. Defaults to nil.
         
     | 
| 
      
 41 
     | 
    
         
            +
                # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to true.
         
     | 
| 
      
 42 
     | 
    
         
            +
                # +device_type+:: A constant from DeviceType indicating the type of POS device used in a card present transaction. Defaults to DeviceType::UNKNOWN.
         
     | 
| 
      
 43 
     | 
    
         
            +
                # +market_type+:: A constant from MarketType indicating your industry. Used for card present transactions. Defaults to MarketType::RETAIL.
         
     | 
| 
      
 44 
     | 
    
         
            +
                #
         
     | 
| 
      
 45 
     | 
    
         
            +
                def initialize(api_login_id, api_transaction_key, options = {})
         
     | 
| 
      
 46 
     | 
    
         
            +
                  super()
         
     | 
| 
      
 47 
     | 
    
         
            +
                  options = @@option_defaults.merge(options)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  @api_login_id = api_login_id
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @api_transaction_key = api_transaction_key
         
     | 
| 
      
 50 
     | 
    
         
            +
                  @test_mode = options[:test]
         
     | 
| 
      
 51 
     | 
    
         
            +
                  @response ||= nil
         
     | 
| 
      
 52 
     | 
    
         
            +
                  @delimiter = options[:delimiter]
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @type = options[:transaction_type]
         
     | 
| 
      
 54 
     | 
    
         
            +
                  @cp_version = nil
         
     | 
| 
      
 55 
     | 
    
         
            +
                  case options[:gateway]
         
     | 
| 
      
 56 
     | 
    
         
            +
                  when :sandbox, :test
         
     | 
| 
      
 57 
     | 
    
         
            +
                    @gateway = Gateway::TEST
         
     | 
| 
      
 58 
     | 
    
         
            +
                  when :production, :live
         
     | 
| 
      
 59 
     | 
    
         
            +
                    @gateway = Gateway::LIVE
         
     | 
| 
      
 60 
     | 
    
         
            +
                  when :card_present_live, :card_present_production
         
     | 
| 
      
 61 
     | 
    
         
            +
                    @gateway = Gateway::CARD_PRESENT_LIVE
         
     | 
| 
      
 62 
     | 
    
         
            +
                    @cp_version = '1.0'
         
     | 
| 
      
 63 
     | 
    
         
            +
                  when :card_present_test, :card_present_sandbox
         
     | 
| 
      
 64 
     | 
    
         
            +
                    @gateway = Gateway::CARD_PRESENT_TEST
         
     | 
| 
      
 65 
     | 
    
         
            +
                    @cp_version = '1.0'
         
     | 
| 
      
 66 
     | 
    
         
            +
                  else
         
     | 
| 
      
 67 
     | 
    
         
            +
                    @gateway = options[:gateway]
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
                  @allow_split_transaction = options[:allow_split]
         
     | 
| 
      
 70 
     | 
    
         
            +
                  @encapsulation_character = options[:encapsulation_character]
         
     | 
| 
      
 71 
     | 
    
         
            +
                  @verify_ssl = options[:verify_ssl]
         
     | 
| 
      
 72 
     | 
    
         
            +
                  @market_type = options[:market_type]
         
     | 
| 
      
 73 
     | 
    
         
            +
                  @device_type = options[:device_type]
         
     | 
| 
      
 74 
     | 
    
         
            +
                  @solution_id = options[:solution_id]
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
                
         
     | 
| 
      
 77 
     | 
    
         
            +
                # Checks if the transaction has been configured for test mode or not. Return TRUE if the
         
     | 
| 
      
 78 
     | 
    
         
            +
                # transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
         
     | 
| 
      
 79 
     | 
    
         
            +
                # are considered test transactions.
         
     | 
| 
      
 80 
     | 
    
         
            +
                def test?
         
     | 
| 
      
 81 
     | 
    
         
            +
                  super || @gateway == Gateway::TEST
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
      
 83 
     | 
    
         
            +
                
         
     | 
| 
      
 84 
     | 
    
         
            +
                # Returns TRUE if split transactions are allowed, FALSE otherwise.
         
     | 
| 
      
 85 
     | 
    
         
            +
                def split_transaction_allowed?
         
     | 
| 
      
 86 
     | 
    
         
            +
                  !!@allow_split_transaction
         
     | 
| 
      
 87 
     | 
    
         
            +
                end
         
     | 
| 
      
 88 
     | 
    
         
            +
                
         
     | 
| 
      
 89 
     | 
    
         
            +
                # Returns the current encapsulation character unless there is none, in which case Nil is returned.
         
     | 
| 
      
 90 
     | 
    
         
            +
                def encapsulation_character
         
     | 
| 
      
 91 
     | 
    
         
            +
                  @encapsulation_character
         
     | 
| 
      
 92 
     | 
    
         
            +
                end
         
     | 
| 
      
 93 
     | 
    
         
            +
                
         
     | 
| 
      
 94 
     | 
    
         
            +
                # Returns the gateway to be used for this transaction.
         
     | 
| 
      
 95 
     | 
    
         
            +
                def gateway
         
     | 
| 
      
 96 
     | 
    
         
            +
                  @gateway
         
     | 
| 
      
 97 
     | 
    
         
            +
                end
         
     | 
| 
      
 98 
     | 
    
         
            +
                
         
     | 
| 
      
 99 
     | 
    
         
            +
                # Checks to see if the transaction has a response (meaning it has been submitted to the gateway).
         
     | 
| 
      
 100 
     | 
    
         
            +
                # Returns TRUE if a response is present, FALSE otherwise.
         
     | 
| 
      
 101 
     | 
    
         
            +
                def has_response?
         
     | 
| 
      
 102 
     | 
    
         
            +
                  !@response.nil?
         
     | 
| 
      
 103 
     | 
    
         
            +
                end
         
     | 
| 
      
 104 
     | 
    
         
            +
                
         
     | 
| 
      
 105 
     | 
    
         
            +
                # Retrieve the response object (or Nil if transaction hasn't been sent to the gateway).
         
     | 
| 
      
 106 
     | 
    
         
            +
                def response
         
     | 
| 
      
 107 
     | 
    
         
            +
                  @response
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
                
         
     | 
| 
      
 110 
     | 
    
         
            +
                # Returns the current delimiter we are using to parse the fields returned by the
         
     | 
| 
      
 111 
     | 
    
         
            +
                # gateway.
         
     | 
| 
      
 112 
     | 
    
         
            +
                def delimiter
         
     | 
| 
      
 113 
     | 
    
         
            +
                  @delimiter
         
     | 
| 
      
 114 
     | 
    
         
            +
                end
         
     | 
| 
      
 115 
     | 
    
         
            +
                
         
     | 
| 
      
 116 
     | 
    
         
            +
                # Sets the delimiter used to parse the response from the gateway.
         
     | 
| 
      
 117 
     | 
    
         
            +
                def delimiter=(delimiter)
         
     | 
| 
      
 118 
     | 
    
         
            +
                  @delimiter = delimiter
         
     | 
| 
      
 119 
     | 
    
         
            +
                end
         
     | 
| 
      
 120 
     | 
    
         
            +
                
         
     | 
| 
      
 121 
     | 
    
         
            +
                # Submits the transaction to the gateway for processing. Returns a response object. If the transaction
         
     | 
| 
      
 122 
     | 
    
         
            +
                # has already been run, it will return nil.
         
     | 
| 
      
 123 
     | 
    
         
            +
                def run
         
     | 
| 
      
 124 
     | 
    
         
            +
                  make_request
         
     | 
| 
      
 125 
     | 
    
         
            +
                end
         
     | 
| 
      
 126 
     | 
    
         
            +
                
         
     | 
| 
      
 127 
     | 
    
         
            +
                # Returns the current card present API version that we are adhering to.
         
     | 
| 
      
 128 
     | 
    
         
            +
                def cp_version
         
     | 
| 
      
 129 
     | 
    
         
            +
                  @cp_version
         
     | 
| 
      
 130 
     | 
    
         
            +
                end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                def solution_id
         
     | 
| 
      
 133 
     | 
    
         
            +
                  @solution_id
         
     | 
| 
      
 134 
     | 
    
         
            +
                end
         
     | 
| 
      
 135 
     | 
    
         
            +
                
         
     | 
| 
      
 136 
     | 
    
         
            +
                #:enddoc:
         
     | 
| 
      
 137 
     | 
    
         
            +
                protected
         
     | 
| 
      
 138 
     | 
    
         
            +
                
         
     | 
| 
      
 139 
     | 
    
         
            +
                # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
         
     | 
| 
      
 140 
     | 
    
         
            +
                def make_request
         
     | 
| 
      
 141 
     | 
    
         
            +
                  if has_response?
         
     | 
| 
      
 142 
     | 
    
         
            +
                    return nil
         
     | 
| 
      
 143 
     | 
    
         
            +
                  end
         
     | 
| 
      
 144 
     | 
    
         
            +
                  url = URI.parse(@gateway)
         
     | 
| 
      
 145 
     | 
    
         
            +
                  fields = @fields.merge(:type => @type, :delim_char => @delimiter, :delim_data => "TRUE", :login => @api_login_id, :tran_key => @api_transaction_key, :relay_response => "FALSE")
         
     | 
| 
      
 146 
     | 
    
         
            +
                  
         
     | 
| 
      
 147 
     | 
    
         
            +
                  if @cp_version.nil?
         
     | 
| 
      
 148 
     | 
    
         
            +
                    fields.merge!(:version => @version)
         
     | 
| 
      
 149 
     | 
    
         
            +
                  else
         
     | 
| 
      
 150 
     | 
    
         
            +
                    fields.merge!(:cp_version => @cp_version, :market_type => @market_type, :device_type => @device_type, :response_format => "1")
         
     | 
| 
      
 151 
     | 
    
         
            +
                  end
         
     | 
| 
      
 152 
     | 
    
         
            +
                  fields[:test_request] = boolean_to_value(@test_mode)
         
     | 
| 
      
 153 
     | 
    
         
            +
                  fields[:allow_partial_auth] = 'TRUE' if @allow_split_transaction
         
     | 
| 
      
 154 
     | 
    
         
            +
                  fields[:encap_char] = @encapsulation_character unless @encapsulation_character.nil?
         
     | 
| 
      
 155 
     | 
    
         
            +
                  fields[:solution_id] = @solution_id unless @solution_id.nil?
         
     | 
| 
      
 156 
     | 
    
         
            +
                  fields.each do |k, v|
         
     | 
| 
      
 157 
     | 
    
         
            +
                    if @@boolean_fields.include?(k)
         
     | 
| 
      
 158 
     | 
    
         
            +
                      fields[k] = boolean_to_value(v)
         
     | 
| 
      
 159 
     | 
    
         
            +
                    elsif @@decimal_fields.include?(k)
         
     | 
| 
      
 160 
     | 
    
         
            +
                      fields[k] = decimal_to_value(v)
         
     | 
| 
      
 161 
     | 
    
         
            +
                    end
         
     | 
| 
      
 162 
     | 
    
         
            +
                  end
         
     | 
| 
      
 163 
     | 
    
         
            +
                  data = fields.collect do |key, val|
         
     | 
| 
      
 164 
     | 
    
         
            +
                    self.to_param(key, val)
         
     | 
| 
      
 165 
     | 
    
         
            +
                  end
         
     | 
| 
      
 166 
     | 
    
         
            +
                  custom_field_keys = @custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
         
     | 
| 
      
 167 
     | 
    
         
            +
                  for key in custom_field_keys
         
     | 
| 
      
 168 
     | 
    
         
            +
                    data += [self.to_param(key, @custom_fields[key.to_sym], '')]
         
     | 
| 
      
 169 
     | 
    
         
            +
                  end
         
     | 
| 
      
 170 
     | 
    
         
            +
                  data.flatten!
         
     | 
| 
      
 171 
     | 
    
         
            +
                  request = Net::HTTP::Post.new(url.path)
         
     | 
| 
      
 172 
     | 
    
         
            +
                  request.content_type = 'application/x-www-form-urlencoded'
         
     | 
| 
      
 173 
     | 
    
         
            +
                  request.body = data.join("&")
         
     | 
| 
      
 174 
     | 
    
         
            +
                  connection = Net::HTTP.new(url.host, url.port)
         
     | 
| 
      
 175 
     | 
    
         
            +
                  connection.use_ssl = true
         
     | 
| 
      
 176 
     | 
    
         
            +
                  if @verify_ssl
         
     | 
| 
      
 177 
     | 
    
         
            +
                    connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
         
     | 
| 
      
 178 
     | 
    
         
            +
                  else
         
     | 
| 
      
 179 
     | 
    
         
            +
                    connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
      
 180 
     | 
    
         
            +
                  end
         
     | 
| 
      
 181 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 182 
     | 
    
         
            +
                    @response = AuthorizeNet::AIM::Response.new((connection.start {|http| http.request(request)}), self)
         
     | 
| 
      
 183 
     | 
    
         
            +
                  rescue
         
     | 
| 
      
 184 
     | 
    
         
            +
                    @response = AuthorizeNet::AIM::Response.new($!, self)
         
     | 
| 
      
 185 
     | 
    
         
            +
                  end
         
     | 
| 
      
 186 
     | 
    
         
            +
                end
         
     | 
| 
      
 187 
     | 
    
         
            +
                
         
     | 
| 
      
 188 
     | 
    
         
            +
              end
         
     | 
| 
      
 189 
     | 
    
         
            +
              
         
     | 
| 
      
 190 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,103 +1,104 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
                   
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                   
     | 
| 
       28 
     | 
    
         
            -
                   
     | 
| 
       29 
     | 
    
         
            -
                   
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                   
     | 
| 
       35 
     | 
    
         
            -
                   
     | 
| 
       36 
     | 
    
         
            -
                   
     | 
| 
       37 
     | 
    
         
            -
                   
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                   
     | 
| 
       44 
     | 
    
         
            -
                  
         
     | 
| 
       45 
     | 
    
         
            -
                   
     | 
| 
       46 
     | 
    
         
            -
                  
         
     | 
| 
       47 
     | 
    
         
            -
                   
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                
         
     | 
| 
       50 
     | 
    
         
            -
                 
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                
         
     | 
| 
       54 
     | 
    
         
            -
                 
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
                     
     | 
| 
       59 
     | 
    
         
            -
                     
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                
         
     | 
| 
       66 
     | 
    
         
            -
                 
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                  doc 
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
                        x. 
     | 
| 
       75 
     | 
    
         
            -
                         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                   
     | 
| 
       79 
     | 
    
         
            -
                   
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                
         
     | 
| 
       82 
     | 
    
         
            -
                 
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                  httpRequest 
     | 
| 
       87 
     | 
    
         
            -
                  httpRequest. 
     | 
| 
       88 
     | 
    
         
            -
                   
     | 
| 
       89 
     | 
    
         
            -
                  connection 
     | 
| 
       90 
     | 
    
         
            -
                   
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                  
         
     | 
| 
       96 
     | 
    
         
            -
                   
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
                
         
     | 
| 
       99 
     | 
    
         
            -
                 
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            +
            	  
         
     | 
| 
      
 40 
     | 
    
         
            +
                  API_GET_HOSTED_PROFILE_PAGE = "getHostedProfilePageRequest"
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  API_DECRYPT_PAYMENT_DATA = "decryptPaymentDataRequest"
         
     | 
| 
      
 44 
     | 
    
         
            +
                  API_AUTHENTICATE_TEST_REQUEST = "authenticateTestRequest"
         
     | 
| 
      
 45 
     | 
    
         
            +
                  
         
     | 
| 
      
 46 
     | 
    
         
            +
                  API_GET_CUSTOMER_PAYMENT_PROFILE_LIST = "getCustomerPaymentProfileListRequest"
         
     | 
| 
      
 47 
     | 
    
         
            +
                  
         
     | 
| 
      
 48 
     | 
    
         
            +
                  API_ARB_GET_SUBSCRIPTION_REQUEST = "ARBGetSubscriptionRequest"
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
                
         
     | 
| 
      
 51 
     | 
    
         
            +
                def initialize(api_login_id, api_transaction_key, options = {})
         
     | 
| 
      
 52 
     | 
    
         
            +
                   super
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
                
         
     | 
| 
      
 55 
     | 
    
         
            +
                def make_request(request,responseClass,type)
         
     | 
| 
      
 56 
     | 
    
         
            +
                 unless responseClass.nil? or request.nil?
         
     | 
| 
      
 57 
     | 
    
         
            +
                   begin
         
     | 
| 
      
 58 
     | 
    
         
            +
                    @xml = serialize(request,type)
         
     | 
| 
      
 59 
     | 
    
         
            +
                    respXml = send_request(@xml)
         
     | 
| 
      
 60 
     | 
    
         
            +
                    @response = deserialize(respXml.body,responseClass) 
         
     | 
| 
      
 61 
     | 
    
         
            +
                   rescue Exception => ex  
         
     | 
| 
      
 62 
     | 
    
         
            +
                      ex  
         
     | 
| 
      
 63 
     | 
    
         
            +
                   end 
         
     | 
| 
      
 64 
     | 
    
         
            +
                 end
         
     | 
| 
      
 65 
     | 
    
         
            +
                end
         
     | 
| 
      
 66 
     | 
    
         
            +
                
         
     | 
| 
      
 67 
     | 
    
         
            +
                def serialize(object,type)
         
     | 
| 
      
 68 
     | 
    
         
            +
                  doc = Nokogiri::XML::Document.new
         
     | 
| 
      
 69 
     | 
    
         
            +
                  doc.root = object.to_xml     
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                  builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |x|
         
     | 
| 
      
 72 
     | 
    
         
            +
                    x.send(type.to_sym, :xmlns => XML_NAMESPACE) {
         
     | 
| 
      
 73 
     | 
    
         
            +
                      x.merchantAuthentication {
         
     | 
| 
      
 74 
     | 
    
         
            +
                        x.name @api_login_id
         
     | 
| 
      
 75 
     | 
    
         
            +
                        x.transactionKey @api_transaction_key
         
     | 
| 
      
 76 
     | 
    
         
            +
                        }
         
     | 
| 
      
 77 
     | 
    
         
            +
                     x.send:insert, doc.root.element_children
         
     | 
| 
      
 78 
     | 
    
         
            +
                  }
         
     | 
| 
      
 79 
     | 
    
         
            +
                  end
         
     | 
| 
      
 80 
     | 
    
         
            +
                  builder.to_xml 
         
     | 
| 
      
 81 
     | 
    
         
            +
                end
         
     | 
| 
      
 82 
     | 
    
         
            +
                
         
     | 
| 
      
 83 
     | 
    
         
            +
                def send_request(xml)
         
     | 
| 
      
 84 
     | 
    
         
            +
                  url = URI.parse(@gateway)
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                  httpRequest = Net::HTTP::Post.new(url.path)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  httpRequest.content_type = 'text/xml'
         
     | 
| 
      
 88 
     | 
    
         
            +
                  httpRequest.body = xml
         
     | 
| 
      
 89 
     | 
    
         
            +
                  connection = Net::HTTP.new(url.host, url.port)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  connection.use_ssl = true
         
     | 
| 
      
 91 
     | 
    
         
            +
                  if @verify_ssl
         
     | 
| 
      
 92 
     | 
    
         
            +
                    connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
         
     | 
| 
      
 93 
     | 
    
         
            +
                  else
         
     | 
| 
      
 94 
     | 
    
         
            +
                    connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
      
 95 
     | 
    
         
            +
                  end
         
     | 
| 
      
 96 
     | 
    
         
            +
                  
         
     | 
| 
      
 97 
     | 
    
         
            +
                  response = connection.start {|http| http.request(httpRequest)}
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
                
         
     | 
| 
      
 100 
     | 
    
         
            +
                def deserialize(xml,responseClass)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  responseClass.from_xml(xml)
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
              end
         
     | 
| 
       103 
104 
     | 
    
         
             
            end
         
     |