class AuthorizeNet::AIM::Transaction

The AIM transaction class. Handles building the transaction payload and transmitting it to the gateway.

Public Class Methods

new(api_login_id, api_transaction_key, options = {}) click to toggle source

Constructs an AIM transaction. You can use the new AIM transaction object to issue a request to the payment gateway and parse the response into a new AuthorizeNet::AIM::Response object.

api_login_id

Your API login ID, as a string.

api_transaction_key

Your API transaction key, as a string.

options

A hash of options. See below for values.

Options

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.

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).

test

A boolean indicating if the transaction should be run in test mode or not (defaults to false).

allow_split

A boolean indicating if split transactions should be allowed (defaults to false).

delimiter

A single character (as a string) that will be used to delimit the response from the gateway. Defaults to ','.

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.

verify_ssl

A boolean indicating if the SSL certificate of the gateway should be verified. Defaults to true.

device_type

A constant from DeviceType indicating the type of POS device used in a card present transaction. Defaults to DeviceType::UNKNOWN.

market_type

A constant from MarketType indicating your industry. Used for card present transactions. Defaults to MarketType::RETAIL.

Calls superclass method AuthorizeNet::KeyValueTransaction::new
# File lib/authorize_net/aim/transaction.rb, line 45
def initialize(api_login_id, api_transaction_key, options = {})
  super()
  options = @@option_defaults.merge(options)
  @api_login_id = api_login_id
  @api_transaction_key = api_transaction_key
  @test_mode = options[:test]
  @response ||= nil
  @delimiter = options[:delimiter]
  @type = options[:transaction_type]
  @cp_version = nil
  case options[:gateway]
  when :sandbox, :test
    @gateway = Gateway::TEST
  when :production, :live
    @gateway = Gateway::LIVE
  when :card_present_live, :card_present_production
    @gateway = Gateway::CARD_PRESENT_LIVE
    @cp_version = '1.0'
  when :card_present_test, :card_present_sandbox
    @gateway = Gateway::CARD_PRESENT_TEST
    @cp_version = '1.0'
  else
    @gateway = options[:gateway]
  end
  @allow_split_transaction = options[:allow_split]
  @encapsulation_character = options[:encapsulation_character]
  @verify_ssl = options[:verify_ssl]
  @market_type = options[:market_type]
  @device_type = options[:device_type]
  @solution_id = options[:solution_id]
end

Public Instance Methods

cp_version() click to toggle source

Returns the current card present API version that we are adhering to.

# File lib/authorize_net/aim/transaction.rb, line 128
def cp_version
  @cp_version
end
delimiter() click to toggle source

Returns the current delimiter we are using to parse the fields returned by the gateway.

# File lib/authorize_net/aim/transaction.rb, line 112
def delimiter
  @delimiter
end
delimiter=(delimiter) click to toggle source

Sets the delimiter used to parse the response from the gateway.

# File lib/authorize_net/aim/transaction.rb, line 117
def delimiter=(delimiter)
  @delimiter = delimiter
end
encapsulation_character() click to toggle source

Returns the current encapsulation character unless there is none, in which case Nil is returned.

# File lib/authorize_net/aim/transaction.rb, line 90
def encapsulation_character
  @encapsulation_character
end
gateway() click to toggle source

Returns the gateway to be used for this transaction.

# File lib/authorize_net/aim/transaction.rb, line 95
def gateway
  @gateway
end
has_response?() click to toggle source

Checks to see if the transaction has a response (meaning it has been submitted to the gateway). Returns TRUE if a response is present, FALSE otherwise.

# File lib/authorize_net/aim/transaction.rb, line 101
def has_response?
  !@response.nil?
end
response() click to toggle source

Retrieve the response object (or Nil if transaction hasn't been sent to the gateway).

# File lib/authorize_net/aim/transaction.rb, line 106
def response
  @response
end
run() click to toggle source

Submits the transaction to the gateway for processing. Returns a response object. If the transaction has already been run, it will return nil.

# File lib/authorize_net/aim/transaction.rb, line 123
def run
  make_request
end
solution_id() click to toggle source
# File lib/authorize_net/aim/transaction.rb, line 132
def solution_id
  @solution_id
end
split_transaction_allowed?() click to toggle source

Returns TRUE if split transactions are allowed, FALSE otherwise.

# File lib/authorize_net/aim/transaction.rb, line 85
def split_transaction_allowed?
  !!@allow_split_transaction
end
test?() click to toggle source

Checks if the transaction has been configured for test mode or not. Return TRUE if the transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox are considered test transactions.

Calls superclass method AuthorizeNet::KeyValueTransaction#test?
# File lib/authorize_net/aim/transaction.rb, line 80
def test?
  super || @gateway == Gateway::TEST
end