Class: AuthorizeNet::Transaction

Inherits:
Object
  • Object
show all
Includes:
TypeConversions
Defined in:
lib/authorize_net/transaction.rb

Overview

The core, API agnostic transaction class. You shouldn’t instantiate this one. Instead you should use AuthorizeNet::AIM::Transaction, AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction.

Direct Known Subclasses

KeyValueTransaction, XmlTransaction

Constant Summary collapse

@@boolean_fields =

Fields to convert to/from booleans.

[]
@@decimal_fields =

Fields to convert to/from BigDecimal.

[]

Constants included from TypeConversions

AuthorizeNet::TypeConversions::API_FIELD_PREFIX

Instance Method Summary collapse

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

#initializeTransaction

DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction, AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction instead.



16
17
18
# File 'lib/authorize_net/transaction.rb', line 16

def initialize()
  @fields ||= {}
end

Instance Method Details

#fieldsObject

Returns the current hash of API fields.



32
33
34
# File 'lib/authorize_net/transaction.rb', line 32

def fields
  @fields
end

#set_address(address) ⇒ Object

Takes an instance of AuthorizeNet::Address and adds it to the transaction.



37
38
39
# File 'lib/authorize_net/transaction.rb', line 37

def set_address(address)
  @fields.merge!(address.to_hash)
end

#set_customer(customer) ⇒ Object

Takes an instance of AuthorizeNet::Customer and adds it to the transaction.



47
48
49
# File 'lib/authorize_net/transaction.rb', line 47

def set_customer(customer)
  @fields.merge!(customer.to_hash)
end

#set_fields(fields = {}) ⇒ Object

Sets arbitrary API fields, overwriting existing values if they exist. Takes a hash of key/value pairs, where the keys are the field names without the “x_” prefix. You can set a field to Nil to unset it. If the value is an array, each value in the array will be added. For example, set_fields(=> [“item1<|>golf balls<|><|>2<|>18.95<|>Y”, “item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>”]) would generate two x_line_item fields in the transaction. One for each value in the array.



25
26
27
28
29
# File 'lib/authorize_net/transaction.rb', line 25

def set_fields(fields = {})
  @fields.merge!(fields)
  @fields.reject! {|k, v| v.nil?}
  @fields
end

#set_shipping_address(address) ⇒ Object

Takes an instance of AuthorizeNet::ShippingAddress and adds it to the transaction.



42
43
44
# File 'lib/authorize_net/transaction.rb', line 42

def set_shipping_address(address)
  @fields.merge!(address.to_hash)
end