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 Attribute Summary collapse

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 Attribute Details

#fieldsObject (readonly)

Returns the current hash of API fields.



35
36
37
# File 'lib/authorize_net/transaction.rb', line 35

def fields
  @fields
end

Instance Method Details

#set_address(address) ⇒ Object

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



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

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.



49
50
51
# File 'lib/authorize_net/transaction.rb', line 49

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.



28
29
30
31
32
# File 'lib/authorize_net/transaction.rb', line 28

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.



44
45
46
# File 'lib/authorize_net/transaction.rb', line 44

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