authorizenet 1.9.4 → 1.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/lib/app/helpers/authorize_net_helper.rb +2 -3
  2. data/lib/authorize_net.rb +5 -5
  3. data/lib/authorize_net/addresses/address.rb +15 -19
  4. data/lib/authorize_net/addresses/shipping_address.rb +12 -16
  5. data/lib/authorize_net/aim/response.rb +27 -38
  6. data/lib/authorize_net/aim/transaction.rb +46 -65
  7. data/lib/authorize_net/api/api_transaction.rb +85 -90
  8. data/lib/authorize_net/api/constants.yml +1 -1
  9. data/lib/authorize_net/api/schema.rb +968 -936
  10. data/lib/authorize_net/api/transaction.rb +100 -102
  11. data/lib/authorize_net/arb/fields.rb +21 -21
  12. data/lib/authorize_net/arb/paging.rb +7 -11
  13. data/lib/authorize_net/arb/response.rb +7 -15
  14. data/lib/authorize_net/arb/sorting.rb +6 -10
  15. data/lib/authorize_net/arb/subscription.rb +27 -31
  16. data/lib/authorize_net/arb/subscription_detail.rb +1 -5
  17. data/lib/authorize_net/arb/subscription_list_response.rb +13 -20
  18. data/lib/authorize_net/arb/transaction.rb +50 -56
  19. data/lib/authorize_net/authorize_net.rb +20 -27
  20. data/lib/authorize_net/cim/customer_profile.rb +4 -8
  21. data/lib/authorize_net/cim/payment_profile.rb +10 -12
  22. data/lib/authorize_net/cim/response.rb +19 -24
  23. data/lib/authorize_net/cim/transaction.rb +168 -174
  24. data/lib/authorize_net/customer.rb +11 -14
  25. data/lib/authorize_net/email_receipt.rb +8 -12
  26. data/lib/authorize_net/fields.rb +483 -502
  27. data/lib/authorize_net/key_value_response.rb +54 -62
  28. data/lib/authorize_net/key_value_transaction.rb +87 -97
  29. data/lib/authorize_net/line_item.rb +10 -14
  30. data/lib/authorize_net/order.rb +21 -25
  31. data/lib/authorize_net/payment_methods/credit_card.rb +6 -7
  32. data/lib/authorize_net/payment_methods/echeck.rb +29 -31
  33. data/lib/authorize_net/reporting/batch.rb +4 -7
  34. data/lib/authorize_net/reporting/batch_statistics.rb +2 -6
  35. data/lib/authorize_net/reporting/fds_filter.rb +2 -5
  36. data/lib/authorize_net/reporting/response.rb +54 -60
  37. data/lib/authorize_net/reporting/returned_item.rb +11 -12
  38. data/lib/authorize_net/reporting/transaction.rb +27 -29
  39. data/lib/authorize_net/reporting/transaction_details.rb +3 -6
  40. data/lib/authorize_net/response.rb +6 -10
  41. data/lib/authorize_net/sim/hosted_payment_form.rb +16 -20
  42. data/lib/authorize_net/sim/hosted_receipt_page.rb +18 -23
  43. data/lib/authorize_net/sim/response.rb +24 -33
  44. data/lib/authorize_net/sim/transaction.rb +33 -43
  45. data/lib/authorize_net/transaction.rb +15 -21
  46. data/lib/authorize_net/xml_response.rb +36 -54
  47. data/lib/authorize_net/xml_transaction.rb +115 -134
  48. data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +5 -6
  49. data/lib/generators/authorize_net/sim/sim_generator.rb +6 -7
  50. data/lib/generators/generator_extensions.rb +23 -25
  51. metadata +127 -81
  52. checksums.yaml +0 -7
@@ -1,37 +1,35 @@
1
1
  module AuthorizeNet::SIM
2
-
3
2
  # The SIM transaction class. Handles building the transaction payload and
4
3
  # generating a set of hidden form fields to be POSTed to the gateway.
5
4
  class Transaction < AuthorizeNet::KeyValueTransaction
6
-
7
5
  RANDOM_SEQUENCE_MAX = (1 << 32) - 1
8
-
6
+
9
7
  # Our MD5 digest generator.
10
- @@digest = OpenSSL::Digest.new('md5')
8
+ @@digest = OpenSSL::Digest.new('md5')
11
9
 
12
10
  # The default options for the constructor.
13
11
  @@option_defaults = {
14
- :sequence => nil,
15
- :timestamp => nil,
16
- :test => false,
17
- :hosted_payment_form => false,
18
- :relay_response => true,
19
- :relay_url => nil,
20
- :transaction_type => Type::AUTHORIZE_AND_CAPTURE
12
+ sequence: nil,
13
+ timestamp: nil,
14
+ test: false,
15
+ hosted_payment_form: false,
16
+ relay_response: true,
17
+ relay_url: nil,
18
+ transaction_type: Type::AUTHORIZE_AND_CAPTURE
21
19
  }
22
-
20
+
23
21
  # Constructs a SIM transaction. You can use the new SIM transaction object
24
22
  # to build the hidden field payload needed to process a SIM transaction with
25
23
  # the gateway. In particular, this class handles generating the MD5 fingerprint
26
24
  # used to authenticate transactions at the gateway. Since the fingerprint includes
27
25
  # the amount to charge, you should not construct this object until you know EXACTLY
28
26
  # how much you want to charge (or authorize).
29
- #
27
+ #
30
28
  # +api_login_id+:: Your API login ID, as a string.
31
29
  # +api_transaction_key+:: Your API transaction key, as a string.
32
30
  # +amount+:: The amount of the transaction, as a string, Float or BigDecimal.
33
31
  # +options+:: A hash of options. See below for values.
34
- #
32
+ #
35
33
  # Options
36
34
  # +sequence+:: The sequence number of the transaction as a string or Integer. This is usually something like an invoice number. If none is provided, the SDK generates one at random.
37
35
  # +timestamp+:: The time the transaction was initiated as a string or Integer. This needs to be within 15 minutes of when the gateway receives the transaction. If no value is provided, the SDK defaults it to Time.now().
@@ -40,8 +38,9 @@ module AuthorizeNet::SIM
40
38
  # +relay_response+:: A boolean indicating if the transaction should use the relay response feature to return a receipt to the customer (defaults to true). Direct Post Method requires using a relay response.
41
39
  # +relay_url+:: A string of the URL that the gateway should hit to get the relay response (defaults to nil).
42
40
  # +transaction_type+:: The type of transaction to perform. Defaults to AuthorizeNet::Type::AUTHORIZE_AND_CAPTURE. This value is only used if run is called directly.
43
- #
41
+ #
44
42
  def initialize(api_login_id, api_transaction_key, amount, options = {})
43
+ ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction"
45
44
  super()
46
45
  @api_transaction_key = api_transaction_key
47
46
  @api_login_id = api_login_id
@@ -53,52 +52,46 @@ module AuthorizeNet::SIM
53
52
  @hosted_payment_form = options[:hosted_payment_form]
54
53
  @relay_url = options[:relay_url]
55
54
  @type = options[:transaction_type]
56
- unless @relay_url.nil?
57
- @relay_response = true
58
- else
55
+ if @relay_url.nil?
59
56
  @relay_response = !!options[:relay_response]
57
+ else
58
+ @relay_response = true
60
59
  end
61
60
  @delim_data = !@relay_response
62
61
  end
63
-
62
+
64
63
  # Calculates and returns the HMAC-MD5 fingerprint needed to authenticate the transaction
65
64
  # with the SIM gateway.
66
65
  def fingerprint
67
- if @timestamp.nil?
68
- @timestamp = Time.now.to_i
69
- end
70
-
71
- if @sequence.nil?
72
- @sequence = rand(RANDOM_SEQUENCE_MAX)
73
- end
66
+ @timestamp = Time.now.to_i if @timestamp.nil?
67
+
68
+ @sequence = rand(RANDOM_SEQUENCE_MAX) if @sequence.nil?
74
69
  OpenSSL::HMAC.hexdigest(@@digest, @api_transaction_key, "#{@api_login_id.to_s.rstrip}^#{@sequence.to_s.rstrip}^#{@timestamp.to_s.rstrip}^#{@amount.to_s.rstrip}^")
75
70
  end
76
-
71
+
77
72
  # Returns all the fields needed for the fingerprint. These must all be passed to the SIM
78
73
  # exactly as returned. And these values are time sensitive.
79
74
  def fingerprint_fields
80
75
  {
81
- :login => @api_login_id,
82
- :fp_hash => fingerprint,
83
- :fp_sequence => @sequence,
84
- :fp_timestamp => @timestamp,
85
- :amount => @amount
76
+ login: @api_login_id,
77
+ fp_hash: fingerprint,
78
+ fp_sequence: @sequence,
79
+ fp_timestamp: @timestamp,
80
+ amount: @amount
86
81
  }
87
82
  end
88
-
83
+
89
84
  # Returns all the fields (including custom) exactly as they should be named
90
85
  # in the SIM form. Fields with multiple values are returned with an array
91
86
  # for the key's value.
92
87
  def form_fields
93
88
  form_fields = {}
94
89
  form_fields[:x_test_request] = boolean_to_value(@test_mode)
95
- if @hosted_payment_form
96
- form_fields[:x_show_form] = 'PAYMENT_FORM'
97
- end
90
+ form_fields[:x_show_form] = 'PAYMENT_FORM' if @hosted_payment_form
98
91
  if @relay_response && !@relay_url.nil?
99
92
  form_fields[:x_relay_url] = @relay_url
100
93
  end
101
- fields.merge(:type => @type, :version => @version, :delim_data => boolean_to_value(@delim_data), :relay_response => boolean_to_value(@relay_response)).each do |k, v|
94
+ fields.merge(type: @type, version: @version, delim_data: boolean_to_value(@delim_data), relay_response: boolean_to_value(@relay_response)).each do |k, v|
102
95
  form_fields[to_external_field(k)] = v
103
96
  end
104
97
  fingerprint_fields.each do |k, v|
@@ -106,8 +99,7 @@ module AuthorizeNet::SIM
106
99
  end
107
100
  form_fields.merge(custom_fields)
108
101
  end
109
-
110
-
102
+
111
103
  # Takes an instance of AuthorizeNet::SIM::HostedPaymentForm and adds it to the transaction. Note that
112
104
  # many of the fields in AuthorizeNet::SIM::HostedPaymentForm are shared with those in
113
105
  # AuthorizeNet::SIM::HostedReceiptPage. For the duplicate fields, which ever value
@@ -116,7 +108,7 @@ module AuthorizeNet::SIM
116
108
  @fields.merge!(form.to_hash)
117
109
  @hosted_payment_form = true
118
110
  end
119
-
111
+
120
112
  # Takes an instance of AuthorizeNet::SIM::HostedReceiptPage and adds it to the transaction. Note that
121
113
  # many of the fields in AuthorizeNet::SIM::HostedReceiptPage are shared with those in
122
114
  # AuthorizeNet::SIM::HostedPaymentForm. For the duplicate fields, which ever value
@@ -127,12 +119,10 @@ module AuthorizeNet::SIM
127
119
  @relay_response = false
128
120
  @delim_data = true
129
121
  end
130
-
122
+
131
123
  # An alias for form_fields.
132
124
  def run
133
125
  form_fields
134
126
  end
135
-
136
127
  end
137
-
138
128
  end
@@ -1,24 +1,22 @@
1
1
  module AuthorizeNet
2
-
3
2
  # The core, API agnostic transaction class. You shouldn't instantiate this one.
4
3
  # Instead you should use AuthorizeNet::AIM::Transaction,
5
4
  # AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction.
6
5
  class Transaction
7
-
8
6
  include AuthorizeNet::TypeConversions
9
-
7
+
10
8
  # Fields to convert to/from booleans.
11
9
  @@boolean_fields = []
12
-
10
+
13
11
  # Fields to convert to/from BigDecimal.
14
12
  @@decimal_fields = []
15
-
13
+
16
14
  # DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction,
17
15
  # AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction instead.
18
- def initialize()
16
+ def initialize
19
17
  @fields ||= {}
20
18
  end
21
-
19
+
22
20
  # Sets arbitrary API fields, overwriting existing values if they exist.
23
21
  # Takes a hash of key/value pairs, where the keys are the field names
24
22
  # without the "x_" prefix. You can set a field to Nil to unset it. If the
@@ -29,44 +27,40 @@ module AuthorizeNet
29
27
  # each value in the array.
30
28
  def set_fields(fields = {})
31
29
  @fields.merge!(fields)
32
- @fields.reject! {|k, v| v.nil?}
30
+ @fields.reject! { |_k, v| v.nil? }
33
31
  @fields
34
32
  end
35
-
33
+
36
34
  # Returns the current hash of API fields.
37
- def fields
38
- @fields
39
- end
40
-
35
+ attr_reader :fields
36
+
41
37
  # Takes an instance of AuthorizeNet::Address and adds it to the transaction.
42
38
  def set_address(address)
43
39
  @fields.merge!(address.to_hash)
44
40
  end
45
-
41
+
46
42
  # Takes an instance of AuthorizeNet::ShippingAddress and adds it to the
47
43
  # transaction.
48
44
  def set_shipping_address(address)
49
45
  @fields.merge!(address.to_hash)
50
46
  end
51
-
47
+
52
48
  # Takes an instance of AuthorizeNet::Customer and adds it to the transaction.
53
49
  def set_customer(customer)
54
50
  @fields.merge!(customer.to_hash)
55
51
  end
56
-
52
+
57
53
  #:enddoc:
58
54
  protected
59
-
55
+
60
56
  # Internal method to handle multiple types of payment arguments.
61
57
  def handle_payment_argument(payment)
62
58
  case payment
63
59
  when AuthorizeNet::CreditCard, AuthorizeNet::ECheck
64
60
  set_fields(payment.to_hash)
65
61
  else
66
- set_fields(:card_num => payment)
62
+ set_fields(card_num: payment)
67
63
  end
68
64
  end
69
-
70
65
  end
71
-
72
- end
66
+ end
@@ -1,9 +1,7 @@
1
1
  module AuthorizeNet
2
-
3
2
  # The core, xml response class. You shouldn't instantiate this one.
4
3
  # Instead you should use AuthorizeNet::ARB::Response.
5
4
  class XmlResponse < AuthorizeNet::Response
6
-
7
5
  # DO NOT USE. Instantiate AuthorizeNet::ARB::Response or AuthorizeNet::CIM::Response instead.
8
6
  def initialize(raw_response, transaction)
9
7
  @raw_response = raw_response
@@ -19,23 +17,23 @@ module AuthorizeNet
19
17
  @message_code = node_content_unless_nil(@root.at_css('messages message code'))
20
18
  @message_text = node_content_unless_nil(@root.at_css('messages message text'))
21
19
  @reference_id = node_content_unless_nil(@root.at_css('refId'))
22
- rescue
23
- @raw_response = $!
20
+ rescue StandardError
21
+ @raw_response = $ERROR_INFO
24
22
  end
25
23
  end
26
24
  end
27
-
25
+
28
26
  # Check to see if the response indicated success. Success is defined as a 200 OK response with a resultCode
29
27
  # of 'Ok'.
30
28
  def success?
31
29
  !connection_failure? && @result_code == 'Ok'
32
30
  end
33
-
31
+
34
32
  # Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
35
33
  def connection_failure?
36
- !@raw_response.kind_of?(Net::HTTPOK)
34
+ !@raw_response.is_a?(Net::HTTPOK)
37
35
  end
38
-
36
+
39
37
  # Returns the underlying Net::HTTPResponse object. This has the original response body along with
40
38
  # headers and such. Note that if an exception is generated while making the request (which happens
41
39
  # if there is no internet connection for example), you will get the exception object here instead of
@@ -43,51 +41,43 @@ module AuthorizeNet
43
41
  def raw
44
42
  @raw_response
45
43
  end
46
-
44
+
47
45
  # Returns a deep-copy of the XML object received from the payment gateway. Or nil if there was no XML payload.
48
46
  def xml
49
47
  @root.dup unless @root.nil?
50
48
  end
51
-
49
+
52
50
  # Returns the resultCode from the XML response. resultCode will be either 'Ok' or 'Error'.
53
- def result_code
54
- @result_code
55
- end
56
-
51
+ attr_reader :result_code
52
+
57
53
  # Returns the messageCode from the XML response. This is a code indicating the details of an error
58
54
  # or success.
59
- def message_code
60
- @message_code
61
- end
62
-
55
+ attr_reader :message_code
56
+
63
57
  # Returns the messageText from the XML response. This is a text description of the message_code.
64
- def message_text
65
- @message_text
66
- end
67
-
58
+ attr_reader :message_text
59
+
68
60
  # Alias for result_code.
69
61
  def response_code
70
62
  result_code
71
63
  end
72
-
64
+
73
65
  # Alias for message_code.
74
66
  def response_reason_code
75
67
  message_code
76
68
  end
77
-
69
+
78
70
  # Alias for message_text.
79
71
  def response_reason_text
80
72
  message_text
81
73
  end
82
-
74
+
83
75
  # Returns the refId from the response if there is one. Otherwise returns nil.
84
- def reference_id
85
- @reference_id
86
- end
87
-
76
+ attr_reader :reference_id
77
+
88
78
  #:enddoc:
89
79
  protected
90
-
80
+
91
81
  def node_content_unless_nil(node)
92
82
  if node.nil?
93
83
  nil
@@ -95,31 +85,25 @@ module AuthorizeNet
95
85
  node.content
96
86
  end
97
87
  end
98
-
88
+
99
89
  def node_child_content_unless_nil(node)
100
90
  if node.nil?
101
91
  nil
102
92
  else
103
- if node.children.length > 0
104
- node.children.collect(&:content)
105
- else
106
- nil
107
- end
93
+ node.children.collect(&:content) unless node.children.empty?
108
94
  end
109
95
  end
110
-
96
+
111
97
  # Transforms a block of XML into a model Object defined by entity_desc.
112
98
  def build_entity(xml, entity_desc)
113
99
  args = {}
114
100
  entity_desc.node_structure.each do |node_desc|
115
- node_name = (node_desc.keys.reject {|k| k.to_s[0..0] == '_' }).first
101
+ node_name = (node_desc.keys.reject { |k| k.to_s[0..0] == '_' }).first
116
102
  args.merge!(handle_node_type(xml, node_desc, node_name, args, ''))
117
103
  end
118
-
119
- if args.length == 0
120
- return nil
121
- end
122
-
104
+
105
+ return nil if args.empty?
106
+
123
107
  if entity_desc.arg_mapping.nil?
124
108
  return entity_desc.entity_class.new(args)
125
109
  else
@@ -132,7 +116,7 @@ module AuthorizeNet
132
116
  return entity_desc.entity_class.new(*args_list)
133
117
  end
134
118
  end
135
-
119
+
136
120
  # Parses an XML fragment into an internal representation.
137
121
  def handle_node_type(xml, node_desc, node_name, args, base_name)
138
122
  case node_desc[node_name]
@@ -144,29 +128,27 @@ module AuthorizeNet
144
128
  when Method, Proc
145
129
  content = node_desc[:_converter].call(content)
146
130
  when Symbol
147
- content = self.send(node_desc[:_converter], content)
131
+ content = send(node_desc[:_converter], content)
148
132
  end
149
133
  args[node_desc[node_name]] = content unless content.nil?
150
134
  end
151
135
  when AuthorizeNet::EntityDescription
152
- unless node_desc[:_multivalue].nil?
136
+ if node_desc[:_multivalue].nil?
137
+ entity = build_entity(xml.css(base_name + node_name.to_s), node_desc[node_name])
138
+ args[node_desc[:_value]] = entity unless entity.nil?
139
+ else
153
140
  xml.css(base_name + node_name.to_s).each do |node|
154
141
  entity = build_entity(node, node_desc[node_name])
155
142
  args[node_desc[:_multivalue]] = args[node_desc[:_multivalue]].to_a + entity.to_a unless entity.nil?
156
143
  end
157
- else
158
- entity = build_entity(xml.css(base_name + node_name.to_s), node_desc[node_name])
159
- args[node_desc[:_value]] = entity unless entity.nil?
160
144
  end
161
145
  when Array
162
146
  node_desc[node_name].each do |inner_node|
163
- inner_node_name = (inner_node.keys.reject {|k| k.to_s[0..0] == '_' }).first
147
+ inner_node_name = (inner_node.keys.reject { |k| k.to_s[0..0] == '_' }).first
164
148
  args.merge!(handle_node_type(xml, inner_node, inner_node_name, args, node_name.to_s + ' '))
165
149
  end
166
150
  end
167
- return args
151
+ args
168
152
  end
169
-
170
153
  end
171
-
172
- end
154
+ end
@@ -1,163 +1,151 @@
1
1
  module AuthorizeNet
2
-
3
2
  # The ARB transaction class.
4
3
  class XmlTransaction < AuthorizeNet::Transaction
5
-
6
4
  # The XML namespace used by the ARB API.
7
- XML_NAMESPACE = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'
8
-
5
+ XML_NAMESPACE = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.freeze
6
+
9
7
  # Constants for both the various Authorize.Net subscription gateways are defined here.
10
8
  module Gateway
11
- LIVE = 'https://api2.authorize.net/xml/v1/request.api'
12
- TEST = 'https://apitest.authorize.net/xml/v1/request.api'
9
+ LIVE = 'https://api2.authorize.net/xml/v1/request.api'.freeze
10
+ TEST = 'https://apitest.authorize.net/xml/v1/request.api'.freeze
13
11
  end
14
-
12
+
15
13
  # Constants for both the various Authorize.Net transaction types are defined here.
16
14
  module Type
17
- ARB_CREATE = "ARBCreateSubscriptionRequest"
18
- ARB_UPDATE = "ARBUpdateSubscriptionRequest"
19
- ARB_GET_STATUS = "ARBGetSubscriptionStatusRequest"
20
- ARB_CANCEL = "ARBCancelSubscriptionRequest"
21
- ARB_GET_SUBSCRIPTION_LIST = "ARBGetSubscriptionListRequest"
22
- CIM_CREATE_PROFILE = "createCustomerProfileRequest"
23
- CIM_CREATE_PAYMENT = "createCustomerPaymentProfileRequest"
24
- CIM_CREATE_ADDRESS = "createCustomerShippingAddressRequest"
25
- CIM_CREATE_TRANSACTION = "createCustomerProfileTransactionRequest"
26
- CIM_DELETE_PROFILE = "deleteCustomerProfileRequest"
27
- CIM_DELETE_PAYMENT = "deleteCustomerPaymentProfileRequest"
28
- CIM_DELETE_ADDRESS = "deleteCustomerShippingAddressRequest"
29
- CIM_GET_PROFILE_IDS = "getCustomerProfileIdsRequest"
30
- CIM_GET_PROFILE = "getCustomerProfileRequest"
31
- CIM_GET_PAYMENT = "getCustomerPaymentProfileRequest"
32
- CIM_GET_ADDRESS = "getCustomerShippingAddressRequest"
33
- CIM_GET_HOSTED_PROFILE = "getHostedProfilePageRequest"
34
- CIM_UPDATE_PROFILE = "updateCustomerProfileRequest"
35
- CIM_UPDATE_PAYMENT = "updateCustomerPaymentProfileRequest"
36
- CIM_UPDATE_ADDRESS = "updateCustomerShippingAddressRequest"
37
- CIM_UPDATE_SPLIT = "updateSplitTenderGroupRequest"
38
- CIM_VALIDATE_PAYMENT = "validateCustomerPaymentProfileRequest"
39
- REPORT_GET_BATCH_LIST = "getSettledBatchListRequest"
40
- REPORT_GET_TRANSACTION_LIST = "getTransactionListRequest"
41
- REPORT_GET_UNSETTLED_TRANSACTION_LIST = "getUnsettledTransactionListRequest"
42
- REPORT_GET_TRANSACTION_DETAILS = "getTransactionDetailsRequest"
15
+ ARB_CREATE = "ARBCreateSubscriptionRequest".freeze
16
+ ARB_UPDATE = "ARBUpdateSubscriptionRequest".freeze
17
+ ARB_GET_STATUS = "ARBGetSubscriptionStatusRequest".freeze
18
+ ARB_CANCEL = "ARBCancelSubscriptionRequest".freeze
19
+ ARB_GET_SUBSCRIPTION_LIST = "ARBGetSubscriptionListRequest".freeze
20
+ CIM_CREATE_PROFILE = "createCustomerProfileRequest".freeze
21
+ CIM_CREATE_PAYMENT = "createCustomerPaymentProfileRequest".freeze
22
+ CIM_CREATE_ADDRESS = "createCustomerShippingAddressRequest".freeze
23
+ CIM_CREATE_TRANSACTION = "createCustomerProfileTransactionRequest".freeze
24
+ CIM_DELETE_PROFILE = "deleteCustomerProfileRequest".freeze
25
+ CIM_DELETE_PAYMENT = "deleteCustomerPaymentProfileRequest".freeze
26
+ CIM_DELETE_ADDRESS = "deleteCustomerShippingAddressRequest".freeze
27
+ CIM_GET_PROFILE_IDS = "getCustomerProfileIdsRequest".freeze
28
+ CIM_GET_PROFILE = "getCustomerProfileRequest".freeze
29
+ CIM_GET_PAYMENT = "getCustomerPaymentProfileRequest".freeze
30
+ CIM_GET_ADDRESS = "getCustomerShippingAddressRequest".freeze
31
+ CIM_GET_HOSTED_PROFILE = "getHostedProfilePageRequest".freeze
32
+ CIM_UPDATE_PROFILE = "updateCustomerProfileRequest".freeze
33
+ CIM_UPDATE_PAYMENT = "updateCustomerPaymentProfileRequest".freeze
34
+ CIM_UPDATE_ADDRESS = "updateCustomerShippingAddressRequest".freeze
35
+ CIM_UPDATE_SPLIT = "updateSplitTenderGroupRequest".freeze
36
+ CIM_VALIDATE_PAYMENT = "validateCustomerPaymentProfileRequest".freeze
37
+ REPORT_GET_BATCH_LIST = "getSettledBatchListRequest".freeze
38
+ REPORT_GET_TRANSACTION_LIST = "getTransactionListRequest".freeze
39
+ REPORT_GET_UNSETTLED_TRANSACTION_LIST = "getUnsettledTransactionListRequest".freeze
40
+ REPORT_GET_TRANSACTION_DETAILS = "getTransactionDetailsRequest".freeze
43
41
  end
44
-
42
+
45
43
  # Fields to convert to/from booleans.
46
44
  @@boolean_fields = []
47
-
45
+
48
46
  # Fields to convert to/from BigDecimal.
49
47
  @@decimal_fields = []
50
-
48
+
51
49
  # Fields to convert to/from Date.
52
50
  @@date_fields = []
53
-
51
+
54
52
  # Fields to convert to/from DateTime.
55
53
  @@datetime_fields = []
56
-
54
+
57
55
  # The class to wrap our response in.
58
56
  @response_class = AuthorizeNet::XmlResponse
59
-
57
+
60
58
  # The default options for the constructor.
61
59
  @@option_defaults = {
62
- :gateway => :production,
63
- :verify_ssl => true,
64
- :reference_id => nil
60
+ gateway: :production,
61
+ verify_ssl: true,
62
+ reference_id: nil
65
63
  }
66
-
64
+
67
65
  # DO NOT USE. Instantiate AuthorizeNet::ARB::Transaction or AuthorizeNet::CIM::Transaction instead.
68
66
  def initialize(api_login_id, api_transaction_key, options = {})
69
67
  super()
70
68
  @api_login_id = api_login_id
71
69
  @api_transaction_key = api_transaction_key
72
-
70
+
73
71
  @response ||= nil
74
72
  @type ||= nil
75
-
73
+
76
74
  options = @@option_defaults.merge(options)
77
75
  @verify_ssl = options[:verify_ssl]
78
76
  @reference_id = options[:reference_id]
79
77
  @gateway = case options[:gateway].to_s
80
- when 'sandbox', 'test'
81
- Gateway::TEST
82
- when 'production', 'live'
83
- Gateway::LIVE
84
- else
85
- @gateway = options[:gateway]
86
- options[:gateway]
78
+ when 'sandbox', 'test'
79
+ Gateway::TEST
80
+ when 'production', 'live'
81
+ Gateway::LIVE
82
+ else
83
+ @gateway = options[:gateway]
84
+ options[:gateway]
87
85
  end
88
86
  end
89
-
90
- def setOAuthOptions()
91
- if !@options_OAuth.blank?
92
- @options_OAuth = @@option_defaults.merge(@options_OAuth)
93
- @verify_ssl = options_OAuth[:verify_ssl]
94
- @reference_id = options_OAuth[:reference_id]
95
-
96
- @gateway = case options_OAuth[:gateway].to_s
97
- when 'sandbox', 'test'
98
- Gateway::TEST
99
- when 'production', 'live'
100
- Gateway::LIVE
101
- else
102
- @gateway = options_OAuth[:gateway]
103
- options_OAuth[:gateway]
104
- end
105
- end
106
- end
107
-
87
+
88
+ def setOAuthOptions
89
+ unless @options_OAuth.blank?
90
+ @options_OAuth = @@option_defaults.merge(@options_OAuth)
91
+ @verify_ssl = options_OAuth[:verify_ssl]
92
+ @reference_id = options_OAuth[:reference_id]
93
+
94
+ @gateway = case options_OAuth[:gateway].to_s
95
+ when 'sandbox', 'test'
96
+ Gateway::TEST
97
+ when 'production', 'live'
98
+ Gateway::LIVE
99
+ else
100
+ @gateway = options_OAuth[:gateway]
101
+ options_OAuth[:gateway]
102
+ end
103
+ end
104
+ end
105
+
108
106
  # Checks if the transaction has been configured for the sandbox or not. Return FALSE if the
109
107
  # transaction is running against the production, TRUE otherwise.
110
108
  def test?
111
109
  @gateway != Gateway::LIVE
112
110
  end
113
-
111
+
114
112
  # Checks to see if the transaction has a response (meaning it has been submitted to the gateway).
115
113
  # Returns TRUE if a response is present, FALSE otherwise.
116
114
  def has_response?
117
115
  !@response.nil?
118
116
  end
119
-
117
+
120
118
  # Retrieve the response object (or Nil if transaction hasn't been sent to the gateway).
121
- def response
122
- @response
123
- end
124
-
119
+ attr_reader :response
120
+
125
121
  # Submits the transaction to the gateway for processing. Returns a response object. If the transaction
126
122
  # has already been run, it will return nil.
127
123
  def run
128
124
  make_request
129
125
  end
130
-
126
+
131
127
  # Returns a deep-copy of the XML object sent to the payment gateway. Or nil if there was no XML payload.
132
- def xml
133
- @xml
134
- end
135
-
128
+ attr_reader :xml
129
+
136
130
  #:enddoc:
137
131
  protected
138
-
132
+
139
133
  # Takes a list of nodes (a Hash is a node, and Array is a list) and returns True if any nodes
140
134
  # would be built by build_nodes. False if no new nodes would be generated.
141
135
  def has_content(nodeList, data)
142
136
  nodeList.each do |node|
143
- nodeName = (node.keys.reject {|k| nodeName.to_s[0..0] == '_' }).first
137
+ nodeName = (node.keys.reject { |_k| nodeName.to_s[0..0] == '_' }).first
144
138
  multivalue = node[:_multivalue]
145
139
  conditional = node[:_conditional]
146
140
  value = node[nodeName]
147
- unless conditional.nil?
148
- value = self.send(conditional, nodeName)
149
- end
141
+ value = send(conditional, nodeName) unless conditional.nil?
150
142
  case value
151
143
  when Array
152
144
  if multivalue.nil?
153
- if has_content(value, data)
154
- return true
155
- end
145
+ return true if has_content(value, data)
156
146
  else
157
147
  data[multivalue].each do |v|
158
- if has_content(value, v)
159
- return true
160
- end
148
+ return true if has_content(value, v)
161
149
  end
162
150
  end
163
151
  when Symbol
@@ -169,33 +157,31 @@ module AuthorizeNet
169
157
  end
170
158
  false
171
159
  end
172
-
160
+
173
161
  # Takes a list of nodes (a Hash is a node, and Array is a list) and recursively builds the XML by pulling
174
162
  # values as needed from data.
175
163
  def build_nodes(builder, nodeList, data)
176
164
  nodeList.each do |node|
177
- # TODO - ADD COMMENTS HERE
178
- nodeName = (node.keys.reject {|k| k.to_s[0..0] == '_' }).first
165
+ # TODO: - ADD COMMENTS HERE
166
+ nodeName = (node.keys.reject { |k| k.to_s[0..0] == '_' }).first
179
167
  multivalue = node[:_multivalue]
180
168
  conditional = node[:_conditional]
181
169
  value = node[nodeName]
182
170
 
183
- unless conditional.nil?
184
- value = self.send(conditional, nodeName)
185
- end
171
+ value = send(conditional, nodeName) unless conditional.nil?
186
172
  case value
187
173
  when Array # node containing other nodes
188
174
  if multivalue.nil?
189
- proc = Proc.new { build_nodes(builder, value, data) }
175
+ proc = proc { build_nodes(builder, value, data) }
190
176
  builder.send(nodeName, &proc) if has_content(value, data)
191
177
  else
192
178
  data[multivalue].to_a.each do |v|
193
- proc = Proc.new { build_nodes(builder, value, v) }
179
+ proc = proc { build_nodes(builder, value, v) }
194
180
  builder.send(nodeName, &proc) if has_content(value, v)
195
181
  end
196
182
  end
197
183
  when Symbol # node containing actual data
198
- if data[value].kind_of?(Array)
184
+ if data[value].is_a?(Array)
199
185
  data[value].each do |v|
200
186
  converted = convert_field(value, v)
201
187
  builder.send(nodeName, converted) unless converted.nil?
@@ -209,32 +195,30 @@ module AuthorizeNet
209
195
  end
210
196
  end
211
197
  end
212
-
198
+
213
199
  def convert_field(field, value)
214
- if @@boolean_fields.include?(field) and !value.nil?
200
+ if @@boolean_fields.include?(field) && !value.nil?
215
201
  return boolean_to_value(value)
216
- elsif @@decimal_fields.include?(field) and !value.nil?
202
+ elsif @@decimal_fields.include?(field) && !value.nil?
217
203
  return decimal_to_value(value)
218
- elsif @@date_fields.include?(field) and !value.nil?
204
+ elsif @@date_fields.include?(field) && !value.nil?
219
205
  return date_to_value(value)
220
- elsif @@datetime_fields.include?(field) and !value.nil?
206
+ elsif @@datetime_fields.include?(field) && !value.nil?
221
207
  return datetime_to_value(value)
222
208
  elsif field == :extra_options
223
209
  # handle converting extra options
224
210
  options = []
225
- unless value.nil?
226
- value.each_pair{|k,v| options <<= self.to_param(k, v)}
227
- end
211
+ value.each_pair { |k, v| options <<= to_param(k, v) } unless value.nil?
228
212
  unless @custom_fields.nil?
229
213
  # special sort to maintain compatibility with AIM custom field ordering
230
214
  # FIXME - This should be DRY'd up.
231
215
  custom_field_keys = @custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
232
216
  for key in custom_field_keys
233
- options <<= self.to_param(key, @custom_fields[key.to_sym], '')
217
+ options <<= to_param(key, @custom_fields[key.to_sym], '')
234
218
  end
235
219
  end
236
-
237
- if options.length > 0
220
+
221
+ if !options.empty?
238
222
  return options.join('&')
239
223
  else
240
224
  return nil
@@ -243,38 +227,36 @@ module AuthorizeNet
243
227
  # convert MMYY expiration dates into the XML equivalent
244
228
  unless value.nil?
245
229
  begin
246
- return value.to_s.downcase == 'xxxx' ? 'XXXX' : Date.strptime(value.to_s, '%m%y').strftime('%Y-%m')
247
- rescue
230
+ return value.to_s.casecmp('xxxx').zero? ? 'XXXX' : Date.strptime(value.to_s, '%m%y').strftime('%Y-%m')
231
+ rescue StandardError
248
232
  # If we didn't get the exp_date in MMYY format, try our best to convert it
249
233
  return Date.parse(value.to_s).strftime('%Y-%m')
250
234
  end
251
235
  end
252
236
  end
253
-
237
+
254
238
  value
255
239
  end
256
-
240
+
257
241
  # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
258
242
  def make_request
259
- if has_response?
260
- return nil
261
- end
262
-
243
+ return nil if has_response?
244
+
263
245
  fields = @fields
264
-
265
- builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |x|
266
- x.send(@type.to_sym, :xmlns => XML_NAMESPACE) {
267
- x.merchantAuthentication {
246
+
247
+ builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |x|
248
+ x.send(@type.to_sym, xmlns: XML_NAMESPACE) do
249
+ x.merchantAuthentication do
268
250
  x.name @api_login_id
269
251
  x.transactionKey @api_transaction_key
270
- }
252
+ end
271
253
  build_nodes(x, self.class.const_get(:FIELDS)[@type], fields)
272
- }
254
+ end
273
255
  end
274
- @xml = builder.to_xml
256
+ @xml = builder.to_xml
275
257
 
276
258
  url = URI.parse(@gateway)
277
-
259
+
278
260
  request = Net::HTTP::Post.new(url.path)
279
261
  request.content_type = 'text/xml'
280
262
  request.body = @xml
@@ -285,14 +267,13 @@ module AuthorizeNet
285
267
  else
286
268
  connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
287
269
  end
288
-
270
+
289
271
  # Use our Class's @response_class variable to find the Response class we are supposed to use.
290
272
  begin
291
- @response = self.class.instance_variable_get(:@response_class).new((connection.start {|http| http.request(request)}), self)
292
- rescue
293
- @response = self.class.instance_variable_get(:@response_class).new($!, self)
273
+ @response = self.class.instance_variable_get(:@response_class).new((connection.start { |http| http.request(request) }), self)
274
+ rescue StandardError
275
+ @response = self.class.instance_variable_get(:@response_class).new($ERROR_INFO, self)
294
276
  end
295
277
  end
296
-
297
278
  end
298
279
  end