class AuthorizeNet::CIM::Transaction

The CIM transaction class.

Public Class Methods

new(api_login_id, api_transaction_key, options = {}) click to toggle source

Constructs a CIM transaction. You can use the new CIM transaction object to issue a request to the payment gateway and parse the response into a new AuthorizeNet::CIM::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

gateway

The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::CIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :production, or :live (:test is an alias for :sandbox, and :live is an alias for :production).

verify_ssl

A boolean indicating if the SSL certificate of the gateway should be verified. Defaults to false.

reference_id

A string that can be used to identify a particular transaction with its response. Will be echo’d in the response, only if it was provided in the transaction. Defaults to nil.

Calls superclass method AuthorizeNet::XmlTransaction::new
# File lib/authorize_net/cim/transaction.rb, line 31
def initialize(api_login_id, api_transaction_key, options = {})
  super
  @delim_char = ','
  @encap_char = nil
  @custom_fields = {}
end

Public Instance Methods

create_address(address, profile_id) click to toggle source

Sets up and submits a createCustomerShippingAddressRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The response object will have a address_id if the request was successful.

address

An AuthorizeNet::Address object describing the profile to create.

profile_id

Takes either a String containing the ID of the CustomerProfile who will own this Address, or a CustomerProfile object with the ID populated.

Typical usage:

address = AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe', :address => '123 Fake St', :city => 'Raccoon Junction', :state => 'WY', :zip => '99999')
response = transaction.create_address(address, '123456')
puts response.address_id if response.success?
# File lib/authorize_net/cim/transaction.rb, line 285
def create_address(address, profile_id)
  @type = Type::CIM_CREATE_ADDRESS
  @fields.merge!(address.to_hash)
  handle_profile_id(profile_id)
  make_request
end
create_payment_profile(payment_profile, profile_id, options = {}) click to toggle source

Sets up and submits a createCustomerPaymentProfileRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The response object will have a payment_profile_id if the request was successful.

profile

An AuthorizeNet::CIM::PaymentProfile object describing the profile to create.

profile_id

Takes either a String containing the ID of the CustomerProfile who will own the PaymentProfile, or a CustomerProfile object with the ID populated.

options

An optional hash of options.

Options:

validation_mode

Set to :testMode, :liveMode or :none (the default) to indicate what sort of PaymentProfile validation to do (assuming a PaymentProfile is included with the CustomerProfile)

Typical usage:

credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '0120')
payment_profile = AuthorizeNet::CIM::PaymentProfile.new(:payment_method => credit_card)
response = transaction.create_payment_profile(payment_profile, '123456')
puts response.payment_profile_id if response.success?
# File lib/authorize_net/cim/transaction.rb, line 170
def create_payment_profile(payment_profile, profile_id, options = {})
  options = @@create_payment_profile_option_defaults.merge(options)
  @type = Type::CIM_CREATE_PAYMENT
  @fields.merge!(payment_profile.to_hash)
  set_fields(:validation_mode => options[:validation_mode])
  handle_profile_id(profile_id)
  make_request
end
create_profile(profile, options = {}) click to toggle source

Sets up and submits a createCustomerProfileRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The response object will have a profile_id if the request was successful. If any PaymentProfiles or Addresses were included, you can find their IDs in the response objects payment_profile_ids and address_ids methods.

profile

An AuthorizeNet::CIM::CustomerProfile object describing the profile to create.

options

An optional hash of options.

Options:

validation_mode

Set to :testMode, :liveMode or :none (the default) to indicate what sort of PaymentProfile validation to do (assuming a PaymentProfile is included with the CustomerProfile)

Typical usage:

profile = AuthorizeNet::CIM::CustomerProfile.new(
  :email => 'test@example.com',
  :id => 'userassignedid'
)
response = transaction.create_profile(profile)
puts response.profile_id if response.success?
# File lib/authorize_net/cim/transaction.rb, line 91
def create_profile(profile, options = {})
  options = @@create_profile_option_defaults.merge(options)
  @type = Type::CIM_CREATE_PROFILE
  @fields.merge!(profile.to_hash)
  set_fields(:validation_mode => options[:validation_mode])
  make_request
end
create_transaction(type, amount, profile_id, payment_profile_id, order, options = {}) click to toggle source

Sets up and submits a createCustomerProfileTransactionRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. It is recommend to use the connivence methods for each type of payment transaction rather than this method.

type

The type of payment transaction to run. Can be :auth_capture, :auth_only, :prior_auth_capture, :void, or :refund.

amount

The amount of the transaction. This is required for every transaction type except :void.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be charged, or a CustomerProfile object with the ID populated.

payment_profile_id

Takes either a String containing the ID of the PaymentProfile you want to charge, or a PaymentProfile object with the ID populated.

order

An Order object describing the order that this payment transaction is for. Pass nil for no order.

options

An optional hash of options.

Options:

address_id

Takes either a String containing the ID of the an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil.

split_tender_id

A split tender transaction ID as a string. If the transaction is to be part of a split tender batch, this must be included. Defaults to nil.

aim_options

A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.

custom_fields

A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.

Typical usage:

response = transaction.create_transaction(:auth_capture, 10.00, '123456', '654321', nil)
if response.success?
  puts response.direct_response if direct_response.success?
# File lib/authorize_net/cim/transaction.rb, line 376
def create_transaction(type, amount, profile_id, payment_profile_id, order, options = {})
  @type = Type::CIM_CREATE_TRANSACTION
  options = @@create_transaction_option_defaults.merge(options)
  handle_profile_id(profile_id)
  handle_payment_profile_id(payment_profile_id)
  handle_address_id(options[:address_id]) unless options[:address_id].nil?
  set_fields(:split_tender_id => options[:split_tender_id])
  @transaction_type = type
  @fields.merge!(order.to_hash) unless order.nil?
  set_fields(:amount => amount)
  handle_aim_options(options[:aim_options])
  handle_custom_fields(options[:custom_fields])
  make_request
end
create_transaction_auth_capture(amount, profile_id, payment_profile_id, order = nil, options = {}) click to toggle source

Sets up and submits an AUTHORIZE_AND_CAPTURE transaction using stored payment information. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

amount

The amount of the transaction.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be charged, or a CustomerProfile object with the ID populated.

payment_profile_id

Takes either a String containing the ID of the PaymentProfile you want to charge, or a PaymentProfile object with the ID populated.

order

An Order object describing the order that this payment transaction is for. Pass nil for no order.

options

An optional hash of options.

Options:

address_id

Takes either a String containing the ID of the an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil.

split_tender_id

A split tender transaction ID as a string. If the transaction is to be part of a split tender batch, this must be included. Defaults to nil.

aim_options

A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.

custom_fields

A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.

Typical usage:

response = transaction.create_transaction_auth_capture(10.00, '123456', '654321', nil)
if response.success?
  puts response.direct_response if direct_response.success?
# File lib/authorize_net/cim/transaction.rb, line 414
def create_transaction_auth_capture(amount, profile_id, payment_profile_id, order = nil, options = {})
  create_transaction(:auth_capture, amount, profile_id, payment_profile_id, order, options)
end
create_transaction_auth_only(amount, profile_id, payment_profile_id, order = nil, options = {}) click to toggle source

Sets up and submits an AUTH_ONLY transaction using stored payment information. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

amount

The amount of the transaction.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be charged, or a CustomerProfile object with the ID populated.

payment_profile_id

Takes either a String containing the ID of the PaymentProfile you want to charge, or a PaymentProfile object with the ID populated.

order

An Order object describing the order that this payment transaction is for. Pass nil for no order.

options

An optional hash of options.

Options:

address_id

Takes either a String containing the ID of the an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil.

split_tender_id

A split tender transaction ID as a string. If the transaction is to be part of a split tender batch, this must be included. Defaults to nil.

aim_options

A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.

custom_fields

A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.

Typical usage:

response = transaction.create_transaction_auth_only(10.00, '123456', '654321', nil)
if response.success?
  puts response.direct_response if direct_response.success?
# File lib/authorize_net/cim/transaction.rb, line 440
def create_transaction_auth_only(amount, profile_id, payment_profile_id, order = nil, options = {})
  create_transaction(:auth_only, amount, profile_id, payment_profile_id, order, options)
end
create_transaction_prior_auth_capture(transaction_id, amount, order = nil, options = {}) click to toggle source

Sets up and submits a PRIOR_AUTHORIZATION_AND_CAPTURE transaction using stored payment information. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

transaction_id

A string containing a transaction ID that was generated via an AUTH_ONLY transaction.

amount

The amount to capture. Must be <= the amount authorized via the AUTH_ONLY transaction.

order

An Order object describing the order that this payment transaction is for. Pass nil for no order.

options

An optional hash of options.

Options:

aim_options

A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.

custom_fields

A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.

Typical usage:

response = transaction.create_transaction_prior_auth_capture('111222', 10.00)
if response.success?
  puts response.direct_response if direct_response.success?
# File lib/authorize_net/cim/transaction.rb, line 463
def create_transaction_prior_auth_capture(transaction_id, amount, order = nil, options = {})
  handle_transaction_id(transaction_id)
  create_transaction(:prior_auth_capture, amount, nil, nil, order, options)
end
create_transaction_refund(transaction_id, amount, profile_id, payment_profile_id, order = nil, options = {}) click to toggle source

Sets up and submits a REFUND transaction using stored payment information. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

transaction_id

A string containing a transaction ID to refund. Pass nil for an unlinked refund.

amount

The amount to refund.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be credited, or a CustomerProfile object with the ID populated. Pass nil for an unlinked refund.

payment_profile_id

Takes either a String containing the ID of the PaymentProfile you want to credit, or a PaymentProfile object with the ID populated. Pass nil for an unlinked refund.

order

An Order object describing the order that is being refunded. Pass nil for no order.

options

An optional hash of options.

Options:

aim_options

A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.

custom_fields

A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.

Typical usage:

response = transaction.create_transaction_refund('111222', 10.00, '123456', '654321')
if response.success?
  puts response.direct_response if direct_response.success?
# File lib/authorize_net/cim/transaction.rb, line 511
def create_transaction_refund(transaction_id, amount, profile_id, payment_profile_id, order = nil, options = {})
  handle_transaction_id(transaction_id)
  create_transaction(:refund, amount, profile_id, payment_profile_id, order, options)
end
create_transaction_void(transaction_id, options = {}) click to toggle source

Sets up and submits a VOID transaction using stored payment information. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

transaction_id

A string containing a transaction ID to void.

options

An optional hash of options.

Options:

aim_options

A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.

custom_fields

A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.

Typical usage:

response = transaction.create_transaction_void('111222')
if response.success?
  puts response.direct_response if direct_response.success?
# File lib/authorize_net/cim/transaction.rb, line 485
def create_transaction_void(transaction_id, options = {})
  handle_transaction_id(transaction_id)
  create_transaction(:void, nil, nil, nil, nil, options)
end
delete_address(address_id, profile_id) click to toggle source

Sets up and submits a deleteCustomerShippingAddressRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

address_id

Takes either a String containing the ID of the Address you want to delete, or an Address object with the ID populated.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated.

Typical usage:

response = transaction.delete_address('654321', '123456')
puts response.success?
# File lib/authorize_net/cim/transaction.rb, line 345
def delete_address(address_id, profile_id)
  @type = Type::CIM_DELETE_ADDRESS
  handle_address_id(address_id)
  handle_profile_id(profile_id)
  make_request
end
delete_payment_profile(payment_profile_id, profile_id) click to toggle source

Sets up and submits a deleteCustomerPaymentProfileRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

payment_profile_id

Takes either a String containing the ID of the PaymentProfile you want to retrieve, or a PaymentProfile object with the ID populated.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.

Typical usage:

response = transaction.delete_profile('123456')
puts response.success?
# File lib/authorize_net/cim/transaction.rb, line 236
def delete_payment_profile(payment_profile_id, profile_id)
  @type = Type::CIM_DELETE_PAYMENT
  handle_payment_profile_id(payment_profile_id)
  handle_profile_id(profile_id)
  make_request
end
delete_profile(profile_id) click to toggle source

Sets up and submits a deleteCustomerProfileRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

profile_id

Takes either a String containing the ID of the CustomerProfile you want to delete, or a CustomerProfile object with the ID populated.

Typical usage:

response = transaction.delete_profile('123456')
puts response.success?
# File lib/authorize_net/cim/transaction.rb, line 146
def delete_profile(profile_id)
  @type = Type::CIM_DELETE_PROFILE
  handle_profile_id(profile_id)
  make_request
end
get_address(address_id, profile_id) click to toggle source

Sets up and submits a getCustomerShippingAddressRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The response object will have the Address object requested available via its address method if the request was successful.

address_id

Takes either a String containing the ID of the Address you want to retrieve, or an Address object with the ID populated.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated.

Typical usage:

response = transaction.get_address('654321', '123456')
address = response.address if response.success?
# File lib/authorize_net/cim/transaction.rb, line 306
def get_address(address_id, profile_id)
  @type = Type::CIM_GET_ADDRESS
  handle_address_id(address_id)
  handle_profile_id(profile_id)
  make_request
end
get_payment_profile(payment_profile_id, profile_id) click to toggle source

Sets up and submits a getCustomerPaymentProfileRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The response object will have the PaymentProfile object requested available via its payment_profile method if the request was successful.

payment_profile_id

Takes either a String containing the ID of the PaymentProfile you want to retrieve, or a PaymentProfile object with the ID populated.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.

Typical usage:

response = transaction.get_payment_profile('654321', '123456')
payment_profile = response.payment_profile if response.success?
# File lib/authorize_net/cim/transaction.rb, line 192
def get_payment_profile(payment_profile_id, profile_id)
  @type = Type::CIM_GET_PAYMENT
  handle_payment_profile_id(payment_profile_id)
  handle_profile_id(profile_id)
  make_request
end
get_profile(profile_id) click to toggle source

Sets up and submits a getCustomerProfileRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The response object will have the CustomerProfile object requested available via its profile method if the request was successful.

profile_id

Takes either a String containing the ID of the CustomerProfile you want to retrieve, or a CustomerProfile object with the ID populated.

Typical usage:

response = transaction.get_profile('123456')
profile = response.profile if response.success?
# File lib/authorize_net/cim/transaction.rb, line 111
def get_profile(profile_id)
  @type = Type::CIM_GET_PROFILE
  handle_profile_id(profile_id)
  make_request
end
get_profile_ids() click to toggle source

Sets up and submits a getCustomerProfileIdsRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The response object will have a list of all CustomerProfile IDs available via its profile_ids method on success.

Typical usage:

response = transaction.get_profile_ids()
puts response.profile_ids if response.success?
# File lib/authorize_net/cim/transaction.rb, line 543
def get_profile_ids()
  @type = Type::CIM_GET_PROFILE_IDS
  make_request
end
update_address(address, profile_id) click to toggle source

Sets up and submits a updateCustomerShippingAddressRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

address

An Address object describing the address to update.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated.

Typical usage:

address.city = 'Somewhere Else'
response = transaction.update_address(address, '123456')
puts response.success?
# File lib/authorize_net/cim/transaction.rb, line 326
def update_address(address, profile_id)
  @type = Type::CIM_UPDATE_ADDRESS
  @fields.merge!(address.to_hash)
  handle_profile_id(profile_id)
  make_request
end
update_payment_profile(payment_profile, profile_id, options = {}) click to toggle source

Sets up and submits a updateCustomerPaymentProfileRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

payment_profile

An AuthorizeNet::CIM::PaymentProfile object describing the profile to update.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.

Typical usage:

payment_profile.cust_type = :business
response = transaction.update_payment_profile(payment_profile, '123456')
puts response.success?

Options:

validation_mode

Set to :testMode, :liveMode or :none (the default) to indicate what sort of PaymentProfile validation to do.

# File lib/authorize_net/cim/transaction.rb, line 215
def update_payment_profile(payment_profile, profile_id, options = {})
  options = @@create_payment_profile_option_defaults.merge(options)
  @type = Type::CIM_UPDATE_PAYMENT
  @fields.merge!(payment_profile.to_hash)
  set_fields(:validation_mode => options[:validation_mode])
  handle_profile_id(profile_id)
  make_request
end
update_profile(profile) click to toggle source

Sets up and submits a updateCustomerProfileRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. Note that any PaymentProfiles will NOT be updated using this method. This is a limitation of the CIM API. See update_payment_profile if you need to update a PaymentProfile.

profile

An AuthorizeNet::CIM::CustomerProfile object describing the profile to update. It must contain the customer_profile_id of the record to update.

Typical usage:

profile.fax = '5555551234'
response = transaction.update_profile(profile)
puts response.success?
# File lib/authorize_net/cim/transaction.rb, line 130
def update_profile(profile)
  @type = Type::CIM_UPDATE_PROFILE
  @fields.merge!(profile.to_hash)
  make_request
end
update_split_tender(split_tender_id, status) click to toggle source

Sets up and submits a updateSplitTenderGroupRequest transaction. Use this to end or void a split tender batch. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.

split_tender_id

The split tender batch ID you want to change the status of.

status

The new status to set for the batch. Options are :voided or :completed.

Typical usage:

response = transaction.update_split_tender('1111111', :voided)
puts response if response.success?
# File lib/authorize_net/cim/transaction.rb, line 528
def update_split_tender(split_tender_id, status)
  @type = Type::CIM_UPDATE_SPLIT
  set_fields(:split_tender_id => split_tender_id, :split_tender_status => status.to_s)
  make_request
end
validate_payment_profile(payment_profile_id, profile_id, options = {}) click to toggle source

Sets up and submits a validateCustomerPaymentProfileRequest transaction. If this transaction has already been run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The results of the validation can be obtained via the direct_response method of the response object.

payment_profile_id

Takes either a String containing the ID of the PaymentProfile you want to validate, or a PaymentProfile object with the ID populated.

profile_id

Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.

Typical usage:

response = transaction.validate_payment_profile('654321', '123456')
puts response.direct_response.success? if response.success?

Options:

validation_mode

Set to :testMode (the default) or :liveMode to indicate what sort of PaymentProfile validation to do.

address_id

Set a shipping Address to be part of the validation transaction.

card_code

Set a CCV code if one is needed for validation. Defaults to nil.

# File lib/authorize_net/cim/transaction.rb, line 261
def validate_payment_profile(payment_profile_id, profile_id, options = {})
  @type = Type::CIM_VALIDATE_PAYMENT
  options = @@validate_payment_profile_option_defaults.merge(options)
  handle_payment_profile_id(payment_profile_id)
  handle_profile_id(profile_id)
  handle_address_id(options[:address_id]) unless options[:address_id].nil?
  set_fields(:validation_mode => options[:validation_mode])
  set_fields(:card_code => options[:card_code]) unless options[:card_code].nil?
  make_request
end