authorizenet 1.8.2 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,131 +0,0 @@
1
- module AuthorizeNet::AIM
2
-
3
- # The AIM response class. Handles parsing the response from the gateway.
4
- class Response < AuthorizeNet::KeyValueResponse
5
-
6
- # Our MD5 digest generator.
7
- @@digest = OpenSSL::Digest.new('md5')
8
-
9
- include AuthorizeNet::AIM::Fields
10
-
11
- # Fields to convert to/from booleans.
12
- @@boolean_fields = [:tax_exempt]
13
-
14
- # Fields to convert to/from BigDecimal.
15
- @@decimal_fields = [:amount, :tax, :freight, :duty, :requested, :balance_on_card]
16
-
17
-
18
- # Constructs a new response object from a +raw_response+ and the +transaction+ that generated
19
- # the +raw_response+. You don't typically construct this object yourself, as AuthorizeNet::AIM::Transaction
20
- # will build one for you when it makes the request to the gateway.
21
- def initialize(raw_response, transaction)
22
- @version = transaction.version
23
- raise "AuthorizeNet gem only supports AIM version 3.1" unless @version.to_s == '3.1'
24
- @raw_response = raw_response
25
- @fields = {}
26
- @transaction = transaction
27
- custom_field_names = transaction.custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
28
- @custom_fields = {}
29
- split_on = transaction.delimiter
30
- if @raw_response.kind_of?(Net::HTTPOK) || @raw_response.kind_of?(Nokogiri::XML::Element)
31
- if @raw_response.kind_of?(Net::HTTPOK)
32
- raw_data = @raw_response.body
33
- else
34
- raw_data = @raw_response.text
35
- end
36
- unless transaction.encapsulation_character.nil?
37
- split_on = transaction.encapsulation_character + split_on + transaction.encapsulation_character
38
- raw_data = raw_data[1..raw_data.length - 2]
39
- end
40
- raw_data.split(split_on).each_with_index do |field, index|
41
- if transaction.cp_version.nil?
42
- field_desc = FIELDS
43
- else
44
- field_desc = CP_FIELDS
45
- end
46
- if index < field_desc.length
47
- @fields[field_desc[index]] = field
48
- else
49
- @custom_fields[custom_field_names[index - field_desc.length]] = field
50
- end
51
- end
52
- @fields.delete(nil)
53
- @fields.each do |k, v|
54
- if @@boolean_fields.include?(k)
55
- @fields[k] = value_to_boolean(v)
56
- elsif @@decimal_fields.include?(k)
57
- @fields[k] = value_to_decimal(v)
58
- end
59
- end
60
- end
61
- end
62
-
63
- # Returns True if the MD5 hash found in the response payload validates using
64
- # the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY).
65
- def valid_md5?(api_login, merchant_value)
66
- if @fields[:md5_hash].nil?
67
- return false
68
- end
69
- @@digest.hexdigest("#{merchant_value}#{api_login}#{@fields[:transaction_id]}#{@transaction.fields[:amount]}").downcase == @fields[:md5_hash].downcase
70
- end
71
-
72
- # Returns the current API version that we are adhering to.
73
- def version
74
- @version
75
- end
76
-
77
- # Check to see if the response indicated success. Success is defined as a 200 OK response indicating
78
- # that the transaction was approved.
79
- def success?
80
- !connection_failure? && approved?
81
- end
82
-
83
- # Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
84
- def connection_failure?
85
- !@raw_response.kind_of?(Net::HTTPOK) && !@raw_response.kind_of?(Nokogiri::XML::Element)
86
- end
87
-
88
- # Returns the underlying Net::HTTPResponse object. This has the original response body along with
89
- # headers and such. Note that if an exception is generated while making the request (which happens
90
- # if there is no internet connection for example), you will get the exception object here instead of
91
- # a Net::HTTPResponse object.
92
- def raw
93
- @raw_response
94
- end
95
-
96
- # Returns the AuthorizeNet::Transaction instance that owns this response.
97
- def transaction
98
- @transaction
99
- end
100
-
101
- # Returns the transaction's authorization code. This should be shown to the
102
- # end user.
103
- def authorization_code
104
- @fields[:authorization_code]
105
- end
106
-
107
- # Returns the transaction's authorization id. You will need this for future void, refund
108
- # and prior authorization capture requests.
109
- def transaction_id
110
- @fields[:transaction_id]
111
- end
112
-
113
- # Returns the customer id from the response.
114
- def customer_id
115
- @fields[:customer_id]
116
- end
117
-
118
- # Returns a response code (from AVSResponseCode) indicating the result of any Address Verification
119
- # Service checks.
120
- def avs_response
121
- @fields[:avs_response]
122
- end
123
-
124
- # Returns the credit card type used in the transaction. The values returned can be found in CardType.
125
- def card_type
126
- @fields[:card_type]
127
- end
128
-
129
- end
130
-
131
- end
@@ -1,13 +0,0 @@
1
- module AuthorizeNet::ARB
2
- module Fields
3
- EntityDescription = Struct.new(:node_structure, :entity_class, :arg_mapping)
4
-
5
- SUBSCRIPTION_DETAIL_ENTITY_DESCRIPTION = EntityDescription.new(
6
- [
7
- {:id => :id},
8
- {:name => :name}
9
- ],
10
- AuthorizeNet::ARB::SubscriptionDetail
11
- )
12
- end
13
- end
@@ -1,25 +0,0 @@
1
- module AuthorizeNet::ARB
2
-
3
- class Paging
4
-
5
- # Models Paging
6
- include AuthorizeNet::Model
7
-
8
- attr_accessor :offset,:limit
9
-
10
- def initialize(offset,limit)
11
- @offset = offset
12
- @limit = limit
13
- end
14
-
15
- def to_hash
16
- hash = {
17
- :offset => @offset,
18
- :limit => @limit
19
- }
20
- hash.delete_if {|k, v| v.nil?}
21
- end
22
-
23
- end
24
-
25
- end
@@ -1,68 +0,0 @@
1
- module AuthorizeNet::ARB
2
-
3
- # The ARB response class.
4
- class Response < AuthorizeNet::XmlResponse
5
- # Constructs a new response object from a +raw_response. You don't typically
6
- # construct this object yourself, as AuthorizeNet::ARB::Transaction will
7
- # build one for you when it makes the request to the gateway.
8
- def initialize(raw_response, transaction)
9
- super
10
- unless connection_failure?
11
- begin
12
- @subscription_id = node_content_unless_nil(@root.at_css('subscriptionId'))
13
- @subscription_status = node_content_unless_nil(@root.at_css('Status'))
14
-
15
- rescue
16
- @raw_response = $!
17
- end
18
- end
19
- end
20
-
21
- # Returns the subscriptionId from the response if there is one. Otherwise returns nil.
22
- def subscription_id
23
- @subscription_id
24
- end
25
-
26
- # Returns the status of the Subscription from the response if there is one. Otherwise returns nil. This value
27
- # is only returned in response to a get_status transaction.
28
- def subscription_status
29
- @subscription_status
30
- end
31
-
32
- end #Response
33
-
34
- class SubscriptionListResponse < AuthorizeNet::XmlResponse
35
- def initialize(raw_response, transaction)
36
- super
37
- unless connection_failure?
38
- begin
39
- @subscription_details = @root.at_css('subscriptionDetails')
40
- @subscription_detail = @root.at_css('subscriptionDetail')
41
- @total_num_in_resultset = node_content_unless_nil(@root.at_css('totalNumInResultSet'))
42
-
43
- rescue
44
- @raw_response = $!
45
- end
46
- end
47
- end
48
-
49
- def total_num_in_resultset
50
- @total_num_in_resultset
51
- end
52
-
53
- # Returns an Array of SubscriptionDetail objects built from the entities returned in the response. Returns nil if no subscriptions were returned.
54
- def subscription_details
55
- unless @subscription_details.nil?
56
- subscription_details = []
57
- @subscription_details.element_children.each do |child|
58
- unless child.nil?
59
- subscription_detail = build_entity(child, Fields::SUBSCRIPTION_DETAIL_ENTITY_DESCRIPTION)
60
-
61
- subscription_details <<= subscription_detail
62
- end
63
- end
64
- return subscription_details unless subscription_details.length == 0
65
- end
66
- end
67
- end #SubscriptionListResponse
68
- end
@@ -1,43 +0,0 @@
1
- module AuthorizeNet::ARB
2
-
3
- class Sorting
4
-
5
- # Models Sorting
6
- include AuthorizeNet::Model
7
-
8
- attr_accessor :order_by, :order_descending
9
-
10
- # Initializes Sorting object.
11
- #
12
- # Typical usage:
13
- # sorting = AuthorizeNet::ARB::Sorting.new('name',true)
14
- #
15
- # Valid values for order_by values of the AuthorizeNet::ARB::Sorting:
16
- # id
17
- # name
18
- # status
19
- # createTimeStampUTC
20
- # lastName
21
- # firstName
22
- # accountNumber
23
- # amount
24
- # pastOccurrences
25
- #
26
- # Valid values for order_descending: true, false, 1,0
27
- #
28
- def initialize(order_by, order_descending)
29
- @order_by = order_by
30
- @order_descending = order_descending
31
- end
32
-
33
- def to_hash
34
- hash = {
35
- :order_by => @order_by,
36
- :order_descending => @order_descending
37
- }
38
- hash.delete_if {|k, v| v.nil?}
39
- end
40
-
41
- end
42
-
43
- end
@@ -1,56 +0,0 @@
1
- module AuthorizeNet::ARB
2
-
3
- # Models Subscription Detail.
4
- class SubscriptionDetail
5
-
6
- include AuthorizeNet::Model
7
-
8
- attr_accessor :id, :name, :status, :create_time_stamp_utc, :first_name,
9
- :last_name, :total_occurrences, :past_occurrences,
10
- :payment_method, :account_number, :invoice, :amount, :currency_id
11
-
12
- end
13
-
14
- class Sorting
15
-
16
- include AuthorizeNet::Model
17
-
18
- attr_accessor :order_by, :order_descending
19
-
20
- def initialize(order_by, order_descending)
21
- @order_by = order_by
22
- @order_descending = order_descending
23
- end
24
-
25
- def to_hash
26
- hash = {
27
- :order_by => @order_by,
28
- :order_descending => @order_descending
29
- }
30
- hash.delete_if {|k, v| v.nil?}
31
- end
32
-
33
- end
34
-
35
- class Paging
36
-
37
- include AuthorizeNet::Model
38
-
39
- attr_accessor :offset,:limit
40
-
41
- def initialize(offset,limit)
42
- @offset = offset
43
- @limit = limit
44
- end
45
-
46
- def to_hash
47
- hash = {
48
- :offset => @offset,
49
- :limit => @limit
50
- }
51
- hash.delete_if {|k, v| v.nil?}
52
- end
53
-
54
- end
55
-
56
- end
@@ -1,45 +0,0 @@
1
- module AuthorizeNet::ARB
2
-
3
- class SubscriptionListResponse < AuthorizeNet::XmlResponse
4
- # Constructs a new response object from a +raw_response. You don't typically
5
- # construct this object yourself, as AuthorizeNet::ARB::Transaction will
6
- # build one for you when it makes the request to the gateway.
7
- def initialize(raw_response, transaction)
8
- super
9
- unless connection_failure?
10
- begin
11
- @subscription_details = @root.at_css('subscriptionDetails')
12
- @subscription_detail = @root.at_css('subscriptionDetail')
13
- @total_num_in_resultset = node_content_unless_nil(@root.at_css('totalNumInResultSet'))
14
-
15
- puts "bla bla"
16
-
17
- rescue
18
- @raw_response = $!
19
- end
20
- end
21
- end
22
-
23
- # Returns total number of subscriptions matching the search criteria
24
- def total_num_in_resultset
25
- @total_num_in_resultset
26
- end
27
-
28
- # Returns an Array of SubscriptionDetail objects built from the entities returned in the response. Returns nil if no subscriptions were returned.
29
- def subscription_details
30
- unless @subscription_details.nil?
31
- subscription_details = []
32
- @subscription_details.element_children.each do |child|
33
- unless child.nil?
34
- subscription_detail = build_entity(child, Fields::SUBSCRIPTION_DETAIL_ENTITY_DESCRIPTION)
35
-
36
- subscription_details <<= subscription_detail
37
- end
38
- end
39
- return subscription_details unless subscription_details.length == 0
40
- end
41
- end
42
-
43
- end
44
-
45
- end
@@ -1,176 +0,0 @@
1
- module AuthorizeNet::ARB
2
-
3
- # The ARB transaction class.
4
- class Transaction < AuthorizeNet::XmlTransaction
5
-
6
- include AuthorizeNet::ARB::Fields
7
-
8
- # The default options for the constructor.
9
- @@option_defaults = {
10
- :gateway => :production,
11
- :verify_ssl => false,
12
- :reference_id => nil
13
- }
14
-
15
- # Fields to convert to/from booleans.
16
- @@boolean_fields = []
17
-
18
- # Fields to convert to/from BigDecimal.
19
- @@decimal_fields = [:amount, :trial_amount]
20
-
21
- # Fields to convert to/from Date.
22
- @@date_fields = [:subscription_start_date]
23
-
24
- # The class to wrap our response in.
25
- @response_class = AuthorizeNet::ARB::Response
26
-
27
- # Constructs an ARB transaction. You can use the new ARB transaction object
28
- # to issue a request to the payment gateway and parse the response into a new
29
- # AuthorizeNet::ARB::Response object.
30
- #
31
- # +api_login_id+:: Your API login ID, as a string.
32
- # +api_transaction_key+:: Your API transaction key, as a string.
33
- # +options+:: A hash of options. See below for values.
34
- #
35
- # Options
36
- # +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).
37
- # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to false.
38
- # +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.
39
- #
40
- def initialize(api_login_id, api_transaction_key, options = {})
41
- super
42
- end
43
-
44
- # Sets up and submits a start of subscription (ARBCreateSubscriptionRequest) transaction. Returns a response object. If the transaction
45
- # has already been run, it will return nil.
46
- #
47
- # +subscription+:: An instance of AuthorizeNet::ARB::Subscription describing the recurring payment you would like to create.
48
- #
49
- #
50
- # Typical usage:
51
- #
52
- # subscription = AuthorizeNet::ARB::Subscription.new(
53
- # :name => "Monthly Gift Basket",
54
- # :length => 1,
55
- # :unit => :month,
56
- # :start_date => Date.today,
57
- # :total_occurrences => :unlimited,
58
- # :amount => 100.00,
59
- # :invoice_number => '1234567',
60
- # :description => "John Doe's Monthly Gift Basket",
61
- # :credit_card => AuthorizeNet::CreditCard.new('4111111111111111', '1120'),
62
- # :billing_address => AuthorizeNet::Address.new(:first_name => 'John', :last_name => 'Doe')
63
- # )
64
- # response = transaction.create(subscription)
65
- #
66
- def create(subscription)
67
- @type = Type::ARB_CREATE
68
- set_fields(subscription.to_hash)
69
- run
70
- end
71
-
72
- # Sets up and submits a subscription update (ARBUpdateSubscriptionRequest) transaction. Returns a response object. If the transaction
73
- # has already been run, it will return nil.
74
- #
75
- # +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.
76
- #
77
- #
78
- # Typical usage:
79
- #
80
- # subscription = AuthorizeNet::ARB::Subscription.new(
81
- # :billing_address => AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe'),
82
- # :subscription_id => '123456'
83
- # )
84
- # response = transaction.update(subscription)
85
- #
86
- def update(subscription)
87
- @type = Type::ARB_UPDATE
88
- set_fields(subscription.to_hash)
89
- run
90
- end
91
-
92
- # Sets up and submits a subscription status query (ARBGetSubscriptionStatusRequest) transaction. Returns a response object (which contains the subscription status). If the transaction
93
- # has already been run, it will return nil.
94
- #
95
- # +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.
96
- #
97
- #
98
- # Typical usage:
99
- #
100
- # response = transaction.get_status('123456')
101
- # response.subscription_status # A value from AuthorizeNet::ARB::Subscription::Status
102
- #
103
- def get_status(subscription_id)
104
- @type = Type::ARB_GET_STATUS
105
- handle_subscription_id(subscription_id)
106
- run
107
- end
108
-
109
- # Sets up and submits a subscription list query (ARBGetSubscriptionListRequest). Returns a response object
110
- # which contains the list of subscription details and the total number of subscriptions matching the search
111
- # criteria. Sorting and Paging are optional parameters.
112
- #
113
- # Valid values for search type parameter:
114
- # cardExpiringThisMonth
115
- # subscriptionActive
116
- # subscriptionExpiringThisMonth
117
- # subscriptionInactive
118
- #
119
- # Typical usage:
120
- #
121
- # sorting = AuthorizeNet::ARB::Sorting.new('name',true)
122
- # paging = AuthorizeNet::ARB::Paging.new(1,1000)
123
- # response = transaction.get_subscription_list('subscriptionActive',sorting,paging)
124
- #
125
- def get_subscription_list(search_type, sorting = nil, paging = nil)
126
- unless search_type.nil?
127
- self.class.instance_variable_set(:@response_class,SubscriptionListResponse)
128
- @type = Type::ARB_GET_SUBSCRIPTION_LIST
129
- set_fields(:search_type => search_type.to_s)
130
- unless sorting.nil?
131
- set_fields(sorting.to_hash)
132
- end
133
- unless paging.nil?
134
- set_fields(paging.to_hash)
135
- end
136
- run
137
- end
138
- end
139
-
140
- # Sets up and submits a subscription cancelation (ARBCancelSubscriptionRequest) transaction. Returns a response object. If the transaction
141
- # has already been run, it will return nil.
142
- #
143
- # +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.
144
- #
145
- #
146
- # Typical usage:
147
- #
148
- # response = transaction.cancel('123456')
149
- #
150
- def cancel(subscription_id)
151
- @type = Type::ARB_CANCEL
152
- handle_subscription_id(subscription_id)
153
- run
154
- end
155
-
156
- #:enddoc:
157
- protected
158
-
159
- # Internal method to handle multiple types of subscription id arguments.
160
- def handle_subscription_id(subscription_id)
161
- case subscription_id
162
- when Subscription
163
- set_fields(:subscription_id => subscription_id.subscription_id.to_s)
164
- else
165
- set_fields(:subscription_id => subscription_id.to_s)
166
- end
167
- end
168
-
169
- # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
170
- def make_request
171
- set_fields(:reference_id => @reference_id)
172
- super
173
- end
174
-
175
- end
176
- end