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 => false,
  :reference_id => nil
}
@@boolean_fields =

Fields to convert to/from booleans.

[]
@@decimal_fields =

Fields to convert to/from BigDecimal.

[: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::SUBSCRIPTION_FIELDS, Fields::UPDATE_FIELDS

Constants inherited from XmlTransaction

XmlTransaction::XML_NAMESPACE

Constants included from TypeConversions

TypeConversions::API_FIELD_PREFIX

Instance Method Summary collapse

Methods inherited from XmlTransaction

#has_response?, #response, #run, #test?, #xml

Methods inherited from Transaction

#fields, #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 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.



41
42
43
# File 'lib/authorize_net/arb/transaction.rb', line 41

def initialize(, api_transaction_key, options = {})
  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')


120
121
122
123
124
# File 'lib/authorize_net/arb/transaction.rb', line 120

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)


67
68
69
70
71
# File 'lib/authorize_net/arb/transaction.rb', line 67

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


104
105
106
107
108
# File 'lib/authorize_net/arb/transaction.rb', line 104

def get_status(subscription_id)
  @type = Type::ARB_GET_STATUS
  handle_subscription_id(subscription_id)
  run
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)


87
88
89
90
91
# File 'lib/authorize_net/arb/transaction.rb', line 87

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