Class: AuthorizeNet::AIM::Transaction

Inherits:
KeyValueTransaction show all
Defined in:
lib/authorize_net/aim/transaction.rb

Overview

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

Constant Summary collapse

@@option_defaults =

The default options for the constructor.

{
  transaction_type: Type::AUTHORIZE_AND_CAPTURE,
  gateway: :production,
  test: false,
  allow_split: false,
  delimiter: ',',
  encapsulation_character: nil,
  verify_ssl: true,
  device_type: DeviceType::UNKNOWN,
  market_type: MarketType::RETAIL
}
@@boolean_fields =

Fields to convert to/from booleans.

%i[tax_exempt test_request recurring_billing allow_partial_auth delim_data email_customer relay_response]
@@decimal_fields =

Fields to convert to/from BigDecimal.

[:amount]

Constants included from TypeConversions

TypeConversions::API_FIELD_PREFIX

Instance Attribute Summary collapse

Attributes inherited from KeyValueTransaction

#custom_fields, #type, #version

Attributes inherited from Transaction

#fields

Instance Method Summary collapse

Methods inherited from KeyValueTransaction

#add_line_item, #authorize, #capture, #prior_auth_capture, #purchase, #refund, #set_custom_fields, #set_email_receipt, #unlinked_credit, #void

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

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.



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
69
70
71
72
73
74
# File 'lib/authorize_net/aim/transaction.rb', line 43

def initialize(, api_transaction_key, options = {})
  ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction"
  super()
  options = @@option_defaults.merge(options)
  @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

Instance Attribute Details

#cp_versionObject (readonly)

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



117
118
119
# File 'lib/authorize_net/aim/transaction.rb', line 117

def cp_version
  @cp_version
end

#delimiterObject

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



105
106
107
# File 'lib/authorize_net/aim/transaction.rb', line 105

def delimiter
  @delimiter
end

#encapsulation_characterObject (readonly)

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



89
90
91
# File 'lib/authorize_net/aim/transaction.rb', line 89

def encapsulation_character
  @encapsulation_character
end

#gatewayObject (readonly)

Returns the gateway to be used for this transaction.



92
93
94
# File 'lib/authorize_net/aim/transaction.rb', line 92

def gateway
  @gateway
end

#responseObject (readonly)

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



101
102
103
# File 'lib/authorize_net/aim/transaction.rb', line 101

def response
  @response
end

#solution_idObject (readonly)

Returns the value of attribute solution_id.



119
120
121
# File 'lib/authorize_net/aim/transaction.rb', line 119

def solution_id
  @solution_id
end

Instance Method Details

#has_response?Boolean

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.

Returns:

  • (Boolean)


96
97
98
# File 'lib/authorize_net/aim/transaction.rb', line 96

def has_response?
  !@response.nil?
end

#runObject

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



112
113
114
# File 'lib/authorize_net/aim/transaction.rb', line 112

def run
  make_request
end

#split_transaction_allowed?Boolean

Returns TRUE if split transactions are allowed, FALSE otherwise.

Returns:

  • (Boolean)


84
85
86
# File 'lib/authorize_net/aim/transaction.rb', line 84

def split_transaction_allowed?
  !!@allow_split_transaction
end

#test?Boolean

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.

Returns:

  • (Boolean)


79
80
81
# File 'lib/authorize_net/aim/transaction.rb', line 79

def test?
  super || @gateway == Gateway::TEST
end