Class: AuthorizeNet::AIM::Transaction
- Inherits:
-
KeyValueTransaction
- Object
- Transaction
- KeyValueTransaction
- AuthorizeNet::AIM::Transaction
- 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.
[: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 Method Summary collapse
-
#cp_version ⇒ Object
Returns the current card present API version that we are adhering to.
-
#delimiter ⇒ Object
Returns the current delimiter we are using to parse the fields returned by the gateway.
-
#delimiter=(delimiter) ⇒ Object
Sets the delimiter used to parse the response from the gateway.
-
#encapsulation_character ⇒ Object
Returns the current encapsulation character unless there is none, in which case Nil is returned.
-
#gateway ⇒ Object
Returns the gateway to be used for this transaction.
-
#has_response? ⇒ Boolean
Checks to see if the transaction has a response (meaning it has been submitted to the gateway).
-
#initialize(api_login_id, api_transaction_key, options = {}) ⇒ Transaction
constructor
Constructs an AIM transaction.
-
#response ⇒ Object
Retrieve the response object (or Nil if transaction hasn’t been sent to the gateway).
-
#run ⇒ Object
Submits the transaction to the gateway for processing.
- #solution_id ⇒ Object
-
#split_transaction_allowed? ⇒ Boolean
Returns TRUE if split transactions are allowed, FALSE otherwise.
-
#test? ⇒ Boolean
Checks if the transaction has been configured for test mode or not.
Methods inherited from KeyValueTransaction
#add_line_item, #authorize, #capture, #custom_fields, #prior_auth_capture, #purchase, #refund, #set_custom_fields, #set_email_receipt, #type, #type=, #unlinked_credit, #version, #void
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 = {}) ⇒ 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.
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 75 |
# File 'lib/authorize_net/aim/transaction.rb', line 45 def initialize(api_login_id, api_transaction_key, = {}) super() = @@option_defaults.merge() @api_login_id = api_login_id @api_transaction_key = api_transaction_key @test_mode = [:test] @response ||= nil @delimiter = [:delimiter] @type = [:transaction_type] @cp_version = nil case [: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 = [:gateway] end @allow_split_transaction = [:allow_split] @encapsulation_character = [:encapsulation_character] @verify_ssl = [:verify_ssl] @market_type = [:market_type] @device_type = [:device_type] @solution_id = [:solution_id] end |
Instance Method Details
#cp_version ⇒ Object
Returns the current card present API version that we are adhering to.
128 129 130 |
# File 'lib/authorize_net/aim/transaction.rb', line 128 def cp_version @cp_version end |
#delimiter ⇒ Object
Returns the current delimiter we are using to parse the fields returned by the gateway.
112 113 114 |
# File 'lib/authorize_net/aim/transaction.rb', line 112 def delimiter @delimiter end |
#delimiter=(delimiter) ⇒ Object
Sets the delimiter used to parse the response from the gateway.
117 118 119 |
# File 'lib/authorize_net/aim/transaction.rb', line 117 def delimiter=(delimiter) @delimiter = delimiter end |
#encapsulation_character ⇒ Object
Returns the current encapsulation character unless there is none, in which case Nil is returned.
90 91 92 |
# File 'lib/authorize_net/aim/transaction.rb', line 90 def encapsulation_character @encapsulation_character end |
#gateway ⇒ Object
Returns the gateway to be used for this transaction.
95 96 97 |
# File 'lib/authorize_net/aim/transaction.rb', line 95 def gateway @gateway end |
#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.
101 102 103 |
# File 'lib/authorize_net/aim/transaction.rb', line 101 def has_response? !@response.nil? end |
#response ⇒ Object
Retrieve the response object (or Nil if transaction hasn’t been sent to the gateway).
106 107 108 |
# File 'lib/authorize_net/aim/transaction.rb', line 106 def response @response end |
#run ⇒ Object
Submits the transaction to the gateway for processing. Returns a response object. If the transaction has already been run, it will return nil.
123 124 125 |
# File 'lib/authorize_net/aim/transaction.rb', line 123 def run make_request end |
#solution_id ⇒ Object
132 133 134 |
# File 'lib/authorize_net/aim/transaction.rb', line 132 def solution_id @solution_id end |
#split_transaction_allowed? ⇒ Boolean
Returns TRUE if split transactions are allowed, FALSE otherwise.
85 86 87 |
# File 'lib/authorize_net/aim/transaction.rb', line 85 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.
80 81 82 |
# File 'lib/authorize_net/aim/transaction.rb', line 80 def test? super || @gateway == Gateway::TEST end |