Class: AuthorizeNet::Transaction
- Inherits:
-
Object
- Object
- AuthorizeNet::Transaction
- Includes:
- TypeConversions
- Defined in:
- lib/authorize_net/transaction.rb
Overview
The core, API agnostic transaction class. You shouldn’t instantiate this one.
Direct Known Subclasses
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
-
#fields ⇒ Object
readonly
Returns the current hash of API fields.
Instance Method Summary collapse
-
#initialize ⇒ Transaction
constructor
DO NOT USE.
-
#set_address(address) ⇒ Object
Takes an instance of AuthorizeNet::Address and adds it to the transaction.
-
#set_customer(customer) ⇒ Object
Takes an instance of AuthorizeNet::Customer and adds it to the transaction.
-
#set_fields(fields = {}) ⇒ Object
Sets arbitrary API fields, overwriting existing values if they exist.
-
#set_shipping_address(address) ⇒ Object
Takes an instance of AuthorizeNet::ShippingAddress and adds it to the transaction.
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 ⇒ Transaction
DO NOT USE.
14 15 16 |
# File 'lib/authorize_net/transaction.rb', line 14 def initialize @fields ||= {} end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the current hash of API fields.
33 34 35 |
# File 'lib/authorize_net/transaction.rb', line 33 def fields @fields end |
Instance Method Details
#set_address(address) ⇒ Object
Takes an instance of AuthorizeNet::Address and adds it to the transaction.
36 37 38 |
# File 'lib/authorize_net/transaction.rb', line 36 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.
26 27 28 29 30 |
# File 'lib/authorize_net/transaction.rb', line 26 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 |