Class: AuthorizeNet::ARB::Transaction
- Inherits:
-
XmlTransaction
- Object
- Transaction
- XmlTransaction
- AuthorizeNet::ARB::Transaction
- 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.
[: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
Constants included from TypeConversions
TypeConversions::API_FIELD_PREFIX
Instance Method Summary collapse
-
#cancel(subscription_id) ⇒ Object
Sets up and submits a subscription cancelation (ARBCancelSubscriptionRequest) transaction.
-
#create(subscription) ⇒ Object
Sets up and submits a start of subscription (ARBCreateSubscriptionRequest) transaction.
-
#get_status(subscription_id) ⇒ Object
Sets up and submits a subscription status query (ARBGetSubscriptionStatusRequest) transaction.
-
#get_subscription_list(search_type, sorting = nil, paging = nil) ⇒ Object
Sets up and submits a subscription list query (ARBGetSubscriptionListRequest).
-
#initialize(api_login_id, api_transaction_key, options = {}) ⇒ Transaction
constructor
Constructs an ARB transaction.
-
#update(subscription) ⇒ Object
Sets up and submits a subscription update (ARBUpdateSubscriptionRequest) transaction.
Methods inherited from XmlTransaction
#has_response?, #response, #run, #setOAuthOptions, #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 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.
40 41 42 |
# File 'lib/authorize_net/arb/transaction.rb', line 40 def initialize(api_login_id, api_transaction_key, = {}) 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')
151 152 153 154 155 |
# File 'lib/authorize_net/arb/transaction.rb', line 151 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)
66 67 68 69 70 |
# File 'lib/authorize_net/arb/transaction.rb', line 66 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
103 104 105 106 107 |
# File 'lib/authorize_net/arb/transaction.rb', line 103 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)
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/authorize_net/arb/transaction.rb', line 125 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) unless sorting.nil? set_fields(sorting.to_hash) end unless paging.nil? set_fields(paging.to_hash) end run end return 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)
86 87 88 89 90 |
# File 'lib/authorize_net/arb/transaction.rb', line 86 def update(subscription) @type = Type::ARB_UPDATE set_fields(subscription.to_hash) run end |