Class: AuthorizeNet::KeyValueTransaction
- Inherits:
-
Transaction
- Object
- Transaction
- AuthorizeNet::KeyValueTransaction
- Defined in:
- lib/authorize_net/key_value_transaction.rb
Overview
The core, key/value transaction class. You shouldn’t instantiate this one. Instead you should use AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction.
Direct Known Subclasses
Defined Under Namespace
Modules: DeviceType, Gateway, MarketType, Type
Constant Summary collapse
- @@purchase_option_defaults =
The default options for purchase.
{ cardholder_auth_value: nil, cardholder_auth_indicator: nil }
{ cardholder_auth_value: nil, cardholder_auth_indicator: nil }
- @@boolean_fields =
Fields to convert to/from booleans.
[]
- @@decimal_fields =
Fields to convert to/from BigDecimal.
[]
Constants included from TypeConversions
TypeConversions::API_FIELD_PREFIX
Instance Attribute Summary collapse
-
#custom_fields ⇒ Object
readonly
Returns the current hash of custom fields.
-
#type ⇒ Object
Returns the type of transaction.
-
#version ⇒ Object
readonly
Returns the current API version that we are adhering to.
Attributes inherited from Transaction
Instance Method Summary collapse
-
#add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil) ⇒ Object
Convenience method for adding line items to a transaction.
-
#authorize(amount, credit_card, options = {}) ⇒ Object
Sets up and submits an authorize (AUTH_ONLY) transaction.
-
#capture(amount, authorization_code) ⇒ Object
Sets up and submits a capture (CAPTURE_ONLY) transaction.
-
#initialize ⇒ KeyValueTransaction
constructor
DO NOT USE.
-
#prior_auth_capture(transaction, amount = nil) ⇒ Object
Sets up and submits a capture (PRIOR_AUTH_CAPTURE) transaction.
-
#purchase(amount, credit_card, options = {}) ⇒ Object
Sets up and submits a standard purchase (AUTHORIZE_AND_CAPTURE) transaction.
-
#refund(amount, transaction, credit_card) ⇒ Object
Sets up and submits a refund (CREDIT) transaction.
-
#set_custom_fields(fields = {}) ⇒ Object
Sets arbitrary custom fields, overwriting existing values if they exist.
-
#set_email_receipt(email) ⇒ Object
Takes an instance of AuthorizeNet::EmailReceipt and adds it to the transaction.
-
#test? ⇒ Boolean
Checks if the transaction has been configured for test mode or not.
-
#unlinked_credit(amount, credit_card) ⇒ Object
Sets up and submits a refund (CREDIT) transaction for a transaction that was not originally submitted via the payment gateway.
-
#void(transaction) ⇒ Object
Sets up and submits a void (VOID) transaction.
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 ⇒ KeyValueTransaction
DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction instead.
61 62 63 64 65 66 |
# File 'lib/authorize_net/key_value_transaction.rb', line 61 def initialize super @custom_fields ||= {} @test_mode ||= false @version = '3.1' end |
Instance Attribute Details
#custom_fields ⇒ Object (readonly)
Returns the current hash of custom fields.
85 86 87 |
# File 'lib/authorize_net/key_value_transaction.rb', line 85 def custom_fields @custom_fields end |
#type ⇒ Object
Returns the type of transaction.
103 104 105 |
# File 'lib/authorize_net/key_value_transaction.rb', line 103 def type @type end |
#version ⇒ Object (readonly)
Returns the current API version that we are adhering to
76 77 78 |
# File 'lib/authorize_net/key_value_transaction.rb', line 76 def version @version end |
Instance Method Details
#add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil) ⇒ Object
Convenience method for adding line items to a transaction.
88 89 90 91 92 93 94 95 |
# File 'lib/authorize_net/key_value_transaction.rb', line 88 def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil) line_item = "#{id}<|>#{name}<|>#{description}<|>#{quantity}<|>#{price}<|>#{taxable}" if @fields.key?(:line_item) @fields[:line_item] = @fields[:line_item].to_a << line_item else @fields[:line_item] = [line_item] end end |
#authorize(amount, credit_card, options = {}) ⇒ Object
Sets up and submits an authorize (AUTH_ONLY) transaction. Returns a response object. If the transaction has already been run, it will return nil. Use this to put a hold on funds, but don’t actually charge the card yet.
amount
-
The amount to authorize. Accepts a string in the format “%0.2f”, a Float or a BigDecimal.
credit_card
-
The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields).
options
-
A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases.
Typical usage:
credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
response = transaction.(10.0, credit_card)
215 216 217 218 219 220 221 222 |
# File 'lib/authorize_net/key_value_transaction.rb', line 215 def (amount, credit_card, = {}) handle_payment_argument(credit_card) = @@authorize_option_defaults.merge() () set_fields(amount: amount) self.type = Type::AUTHORIZE_ONLY run end |
#capture(amount, authorization_code) ⇒ Object
Sets up and submits a capture (CAPTURE_ONLY) transaction. Returns a response object. If the transaction has already been run, it will return nil. Note that you can not capture a transaction that was made though the AIM API using this method. Use prior_auth_capture instead.
amount
-
The amount to capture. Accepts a string in the format “%0.2f”, a Float or a BigDecimal.
authorization_code
-
The authorization code of the transaction to capture. Accepts a string.
Typical usage:
response = transaction.capture(10.0, '123FAKE')
236 237 238 239 240 |
# File 'lib/authorize_net/key_value_transaction.rb', line 236 def capture(amount, ) set_fields(amount: amount, auth_code: ) self.type = Type::CAPTURE_ONLY run end |
#prior_auth_capture(transaction, amount = nil) ⇒ Object
Sets up and submits a capture (PRIOR_AUTH_CAPTURE) transaction. Returns a response object. Use this method to actually charge a card that you previously put a hold on (using authorize).
transaction
-
The transaction ID to capture. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
amount
-
The amount to capture (only if less than the amount originally authorized, otherwise leave as Nil). Accepts a string in the format “%0.2f”, a Float, a BigDecimal or Nil.
Typical usage:
response = transaction.prior_auth_capture('123456789')
253 254 255 256 257 258 |
# File 'lib/authorize_net/key_value_transaction.rb', line 253 def prior_auth_capture(transaction, amount = nil) handle_transaction_argument(transaction) set_fields(amount: amount) self.type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE run end |
#purchase(amount, credit_card, options = {}) ⇒ Object
Sets up and submits a standard purchase (AUTHORIZE_AND_CAPTURE) transaction. Returns a response object. If the transaction has already been run, it will return nil.
amount
-
The amount to charge. Accepts a string in the format “%0.2f”, a Float or a BigDecimal.
credit_card
-
The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields).
options
-
A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases.
Typical usage:
credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
response = transaction.purchase(10.0, credit_card)
138 139 140 141 142 143 144 145 |
# File 'lib/authorize_net/key_value_transaction.rb', line 138 def purchase(amount, credit_card, = {}) handle_payment_argument(credit_card) = @@purchase_option_defaults.merge() () set_fields(amount: amount) self.type = Type::AUTHORIZE_AND_CAPTURE run end |
#refund(amount, transaction, credit_card) ⇒ Object
Sets up and submits a refund (CREDIT) transaction. Returns a response object. If the transaction has already been run, it will return nil.
amount
-
The amount to refund. Accepts a string in the format “%0.2f”, a Float or a BigDecimal.
transaction
-
The transaction ID to apply the refund to. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
credit_card
-
The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits. In many cases you only need the last 4 digits of the credit card here.
Typical usage:
response = transaction.refund(10.0, '123456789', '1212')
159 160 161 162 163 164 165 |
# File 'lib/authorize_net/key_value_transaction.rb', line 159 def refund(amount, transaction, credit_card) handle_payment_argument(credit_card) handle_transaction_argument(transaction) set_fields(amount: amount) self.type = Type::CREDIT run end |
#set_custom_fields(fields = {}) ⇒ Object
Sets arbitrary custom fields, overwriting existing values if they exist. Takes a hash of key/value pairs, where the keys are the field names. You can set a field to Nil to unset it.
80 81 82 |
# File 'lib/authorize_net/key_value_transaction.rb', line 80 def set_custom_fields(fields = {}) @custom_fields.merge!(fields) end |
#set_email_receipt(email) ⇒ Object
Takes an instance of AuthorizeNet::EmailReceipt and adds it to the transaction.
98 99 100 |
# File 'lib/authorize_net/key_value_transaction.rb', line 98 def set_email_receipt(email) @fields.merge!(email.to_hash) 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.
71 72 73 |
# File 'lib/authorize_net/key_value_transaction.rb', line 71 def test? !!@test_mode end |
#unlinked_credit(amount, credit_card) ⇒ Object
Sets up and submits a refund (CREDIT) transaction for a transaction that was not originally submitted via the payment gateway. Note that this is a special feature which requires your account to support ECC (expanded credits capability) transactions.
amount
-
The amount to refund. Accepts a string in the format “%0.2f”, a Float or a BigDecimal.
credit_card
-
The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits.
Typical usage:
response = transaction.unlinked_credit(10.0, '4111111111111111')
178 179 180 181 182 183 |
# File 'lib/authorize_net/key_value_transaction.rb', line 178 def unlinked_credit(amount, credit_card) handle_payment_argument(credit_card) set_fields(amount: amount) self.type = Type::CREDIT run end |
#void(transaction) ⇒ Object
Sets up and submits a void (VOID) transaction. Returns a response object. If the transaction has already been run, it will return nil. Note that you can only void unsettled transactions.
transaction
-
The transaction ID of the transaction to void. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
Typical usage:
response = transaction.void('123456789')
195 196 197 198 199 |
# File 'lib/authorize_net/key_value_transaction.rb', line 195 def void(transaction) handle_transaction_argument(transaction) self.type = Type::VOID run end |