Class: AuthorizeNet::ARB::Transaction

Inherits:
XmlTransaction show all
Includes:
Fields
Defined in:
lib/authorize_net/arb/transaction.rb

Overview

The ARB transaction class.

Constant Summary collapse

@@option_defaults =

The default options for the constructor.

{
  gateway: :production,
  verify_ssl: true,
  reference_id: nil
}
@@boolean_fields =

Fields to convert to/from booleans.

[]
@@decimal_fields =

Fields to convert to/from BigDecimal.

%i[amount trial_amount]
@@date_fields =

Fields to convert to/from Date.

[:subscription_start_date]

Constants included from Fields

Fields::CANCEL_FIELDS, Fields::CREATE_FIELDS, Fields::FIELDS, Fields::GET_STATUS_FIELDS, Fields::GET_SUBSCRIPTION_LIST_FIELDS, Fields::SUBSCRIPTION_DETAIL_ENTITY_DESCRIPTION, Fields::SUBSCRIPTION_FIELDS, Fields::UPDATE_FIELDS

Constants inherited from XmlTransaction

XmlTransaction::XML_NAMESPACE

Constants included from TypeConversions

TypeConversions::API_FIELD_PREFIX

Instance Attribute Summary

Attributes inherited from XmlTransaction

#response, #xml

Attributes inherited from Transaction

#fields

Instance Method Summary collapse

Methods inherited from XmlTransaction

#has_response?, #run, #setOAuthOptions, #test?

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(api_login_id, api_transaction_key, options = {}) ⇒ Transaction

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

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.



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

def initialize(, api_transaction_key, options = {})
  ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction"
  super
end

Instance Method Details

#cancel(subscription_id) ⇒ Object

Sets up and submits a subscription cancelation (ARBCancelSubscriptionRequest) transaction. Returns a response object. If the transaction has already been run, it will return nil.

subscription_id

Either the subscription id of the subscription to get the status of as a string, or a Subscription instance with a value for subscription_id set on it.

Typical usage:

response = transaction.cancel('123456')


146
147
148
149
150
# File 'lib/authorize_net/arb/transaction.rb', line 146

def cancel(subscription_id)
  @type = Type::ARB_CANCEL
  handle_subscription_id(subscription_id)
  run
end

#create(subscription) ⇒ Object

Sets up and submits a start of subscription (ARBCreateSubscriptionRequest) transaction. Returns a response object. If the transaction has already been run, it will return nil.

subscription

An instance of AuthorizeNet::ARB::Subscription describing the recurring payment you would like to create.

Typical usage:

subscription = AuthorizeNet::ARB::Subscription.new(
  :name => "Monthly Gift Basket",
  :length => 1,
  :unit => :month,
  :start_date => Date.today,
  :total_occurrences => :unlimited,
  :amount => 100.00,
  :invoice_number => '1234567',
  :description => "John Doe's Monthly Gift Basket",
  :credit_card => AuthorizeNet::CreditCard.new('4111111111111111', '1120'),
  :billing_address => AuthorizeNet::Address.new(:first_name => 'John', :last_name => 'Doe')
)
response = transaction.create(subscription)


65
66
67
68
69
# File 'lib/authorize_net/arb/transaction.rb', line 65

def create(subscription)
  @type = Type::ARB_CREATE
  set_fields(subscription.to_hash)
  run
end

#get_status(subscription_id) ⇒ Object

Sets up and submits a subscription status query (ARBGetSubscriptionStatusRequest) transaction. Returns a response object (which contains the subscription status). If the transaction has already been run, it will return nil.

subscription_id

Either the subscription id of the subscription to get the status of as a string, or a Subscription instance with a value for subscription_id set on it.

Typical usage:

response = transaction.get_status('123456')
response.subscription_status    # A value from AuthorizeNet::ARB::Subscription::Status


102
103
104
105
106
# File 'lib/authorize_net/arb/transaction.rb', line 102

def get_status(subscription_id)
  @type = Type::ARB_GET_STATUS
  handle_subscription_id(subscription_id)
  run
end

#get_subscription_list(search_type, sorting = nil, paging = nil) ⇒ Object

Sets up and submits a subscription list query (ARBGetSubscriptionListRequest). Returns a response object which contains the list of subscription details and the total number of subscriptions matching the search criteria. Sorting and Paging are optional parameters.

Valid values for search type parameter:

cardExpiringThisMonth
subscriptionActive
subscriptionExpiringThisMonth
subscriptionInactive

Typical usage:

sorting = AuthorizeNet::ARB::Sorting.new('name',true)
paging = AuthorizeNet::ARB::Paging.new(1,1000)
response = transaction.get_subscription_list('subscriptionActive',sorting,paging)


124
125
126
127
128
129
130
131
132
133
134
# File 'lib/authorize_net/arb/transaction.rb', line 124

def get_subscription_list(search_type, sorting = nil, paging = nil)
  unless search_type.nil?
    self.class.instance_variable_set(:@response_class, SubscriptionListResponse)
    @type = Type::ARB_GET_SUBSCRIPTION_LIST
    set_fields(search_type: search_type.to_s)
    set_fields(sorting.to_hash) unless sorting.nil?
    set_fields(paging.to_hash) unless paging.nil?
    run
  end
  response
end

#update(subscription) ⇒ Object

Sets up and submits a subscription update (ARBUpdateSubscriptionRequest) transaction. Returns a response object. If the transaction has already been run, it will return nil.

subscription

An instance of AuthorizeNet::ARB::Subscription describing the changes to make. It must have a value for subscription_id so that the API knows what subscription to update. Note that some information (intervals, start dates, etc) can’t be changed. See the ARB guide for more details.

Typical usage:

subscription = AuthorizeNet::ARB::Subscription.new(
  :billing_address => AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe'),
  :subscription_id => '123456'
)
response = transaction.update(subscription)


85
86
87
88
89
# File 'lib/authorize_net/arb/transaction.rb', line 85

def update(subscription)
  @type = Type::ARB_UPDATE
  set_fields(subscription.to_hash)
  run
end