authorizenet 1.9.5 → 1.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/lib/app/helpers/authorize_net_helper.rb +23 -23
  3. data/lib/authorize_net.rb +107 -107
  4. data/lib/authorize_net/addresses/address.rb +25 -25
  5. data/lib/authorize_net/addresses/shipping_address.rb +22 -22
  6. data/lib/authorize_net/aim/response.rb +120 -120
  7. data/lib/authorize_net/aim/transaction.rb +171 -171
  8. data/lib/authorize_net/api/api_transaction.rb +119 -119
  9. data/lib/authorize_net/api/constants.yml +1 -1
  10. data/lib/authorize_net/api/schema.rb +5165 -5153
  11. data/lib/authorize_net/api/transaction.rb +261 -261
  12. data/lib/authorize_net/arb/fields.rb +24 -24
  13. data/lib/authorize_net/arb/paging.rb +29 -29
  14. data/lib/authorize_net/arb/response.rb +26 -26
  15. data/lib/authorize_net/arb/sorting.rb +39 -39
  16. data/lib/authorize_net/arb/subscription.rb +68 -68
  17. data/lib/authorize_net/arb/subscription_detail.rb +10 -10
  18. data/lib/authorize_net/arb/subscription_list_response.rb +36 -36
  19. data/lib/authorize_net/arb/transaction.rb +171 -171
  20. data/lib/authorize_net/authorize_net.rb +154 -154
  21. data/lib/authorize_net/cim/customer_profile.rb +15 -15
  22. data/lib/authorize_net/cim/payment_profile.rb +35 -35
  23. data/lib/authorize_net/cim/response.rb +111 -111
  24. data/lib/authorize_net/cim/transaction.rb +721 -721
  25. data/lib/authorize_net/customer.rb +24 -24
  26. data/lib/authorize_net/email_receipt.rb +20 -20
  27. data/lib/authorize_net/fields.rb +760 -760
  28. data/lib/authorize_net/key_value_response.rb +109 -109
  29. data/lib/authorize_net/key_value_transaction.rb +281 -281
  30. data/lib/authorize_net/line_item.rb +21 -21
  31. data/lib/authorize_net/order.rb +38 -38
  32. data/lib/authorize_net/payment_methods/credit_card.rb +61 -61
  33. data/lib/authorize_net/payment_methods/echeck.rb +70 -70
  34. data/lib/authorize_net/reporting/batch.rb +16 -16
  35. data/lib/authorize_net/reporting/batch_statistics.rb +15 -15
  36. data/lib/authorize_net/reporting/fds_filter.rb +8 -8
  37. data/lib/authorize_net/reporting/response.rb +157 -157
  38. data/lib/authorize_net/reporting/returned_item.rb +45 -45
  39. data/lib/authorize_net/reporting/transaction.rb +131 -131
  40. data/lib/authorize_net/reporting/transaction_details.rb +22 -22
  41. data/lib/authorize_net/response.rb +25 -25
  42. data/lib/authorize_net/sim/hosted_payment_form.rb +34 -34
  43. data/lib/authorize_net/sim/hosted_receipt_page.rb +32 -32
  44. data/lib/authorize_net/sim/response.rb +133 -133
  45. data/lib/authorize_net/sim/transaction.rb +128 -128
  46. data/lib/authorize_net/transaction.rb +66 -66
  47. data/lib/authorize_net/xml_response.rb +154 -154
  48. data/lib/authorize_net/xml_transaction.rb +279 -279
  49. data/lib/authorizenet.rb +4 -4
  50. data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +52 -52
  51. data/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +48 -48
  52. data/lib/generators/authorize_net/direct_post/templates/config.yml.erb +8 -8
  53. data/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +8 -8
  54. data/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +30 -30
  55. data/lib/generators/authorize_net/direct_post/templates/initializer.rb +4 -4
  56. data/lib/generators/authorize_net/direct_post/templates/layout.erb +17 -17
  57. data/lib/generators/authorize_net/direct_post/templates/payment.erb +9 -9
  58. data/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +9 -9
  59. data/lib/generators/authorize_net/sim/sim_generator.rb +46 -46
  60. data/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +51 -51
  61. data/lib/generators/authorize_net/sim/templates/config.yml.erb +8 -8
  62. data/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +8 -8
  63. data/lib/generators/authorize_net/sim/templates/controller.rb.erb +20 -20
  64. data/lib/generators/authorize_net/sim/templates/initializer.rb +4 -4
  65. data/lib/generators/authorize_net/sim/templates/layout.erb +17 -17
  66. data/lib/generators/authorize_net/sim/templates/payment.erb +5 -5
  67. data/lib/generators/authorize_net/sim/templates/payment.rails3.erb +5 -5
  68. data/lib/generators/generator_extensions.rb +73 -73
  69. metadata +84 -102
@@ -1,171 +1,171 @@
1
- module AuthorizeNet::AIM
2
- # The AIM transaction class. Handles building the transaction payload and
3
- # transmitting it to the gateway.
4
- class Transaction < AuthorizeNet::KeyValueTransaction
5
- # The default options for the constructor.
6
- @@option_defaults = {
7
- transaction_type: Type::AUTHORIZE_AND_CAPTURE,
8
- gateway: :production,
9
- test: false,
10
- allow_split: false,
11
- delimiter: ',',
12
- encapsulation_character: nil,
13
- verify_ssl: true,
14
- device_type: DeviceType::UNKNOWN,
15
- market_type: MarketType::RETAIL
16
- }
17
-
18
- # Fields to convert to/from booleans.
19
- @@boolean_fields = %i[tax_exempt test_request recurring_billing allow_partial_auth delim_data email_customer relay_response]
20
-
21
- # Fields to convert to/from BigDecimal.
22
- @@decimal_fields = [:amount]
23
-
24
- # Constructs an AIM transaction. You can use the new AIM transaction object
25
- # to issue a request to the payment gateway and parse the response into a new
26
- # AuthorizeNet::AIM::Response object.
27
- #
28
- # +api_login_id+:: Your API login ID, as a string.
29
- # +api_transaction_key+:: Your API transaction key, as a string.
30
- # +options+:: A hash of options. See below for values.
31
- #
32
- # Options
33
- # +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.
34
- # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::AIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :card_present_test, :card_present_live, :card_present_sandbox, :card_present_production, :production, or :live (:test is an alias for :sandbox, :card_present_test is an alias for :card_present_sandbox, :card_present_production is an alias for :card_present_live, and :live is an alias for :production).
35
- # +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false).
36
- # +allow_split+:: A boolean indicating if split transactions should be allowed (defaults to false).
37
- # +delimiter+:: A single character (as a string) that will be used to delimit the response from the gateway. Defaults to ','.
38
- # +encapsulation_character+:: A single character (as a string) that will be used to encapsulate each field in the response from the gateway. Defaults to nil.
39
- # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to true.
40
- # +device_type+:: A constant from DeviceType indicating the type of POS device used in a card present transaction. Defaults to DeviceType::UNKNOWN.
41
- # +market_type+:: A constant from MarketType indicating your industry. Used for card present transactions. Defaults to MarketType::RETAIL.
42
- #
43
- def initialize(api_login_id, api_transaction_key, options = {})
44
- ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction"
45
- super()
46
- options = @@option_defaults.merge(options)
47
- @api_login_id = api_login_id
48
- @api_transaction_key = api_transaction_key
49
- @test_mode = options[:test]
50
- @response ||= nil
51
- @delimiter = options[:delimiter]
52
- @type = options[:transaction_type]
53
- @cp_version = nil
54
- case options[:gateway]
55
- when :sandbox, :test
56
- @gateway = Gateway::TEST
57
- when :production, :live
58
- @gateway = Gateway::LIVE
59
- when :card_present_live, :card_present_production
60
- @gateway = Gateway::CARD_PRESENT_LIVE
61
- @cp_version = '1.0'
62
- when :card_present_test, :card_present_sandbox
63
- @gateway = Gateway::CARD_PRESENT_TEST
64
- @cp_version = '1.0'
65
- else
66
- @gateway = options[:gateway]
67
- end
68
- @allow_split_transaction = options[:allow_split]
69
- @encapsulation_character = options[:encapsulation_character]
70
- @verify_ssl = options[:verify_ssl]
71
- @market_type = options[:market_type]
72
- @device_type = options[:device_type]
73
- @solution_id = options[:solution_id]
74
- end
75
-
76
- # Checks if the transaction has been configured for test mode or not. Return TRUE if the
77
- # transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
78
- # are considered test transactions.
79
- def test?
80
- super || @gateway == Gateway::TEST
81
- end
82
-
83
- # Returns TRUE if split transactions are allowed, FALSE otherwise.
84
- def split_transaction_allowed?
85
- !!@allow_split_transaction
86
- end
87
-
88
- # Returns the current encapsulation character unless there is none, in which case Nil is returned.
89
- attr_reader :encapsulation_character
90
-
91
- # Returns the gateway to be used for this transaction.
92
- attr_reader :gateway
93
-
94
- # Checks to see if the transaction has a response (meaning it has been submitted to the gateway).
95
- # Returns TRUE if a response is present, FALSE otherwise.
96
- def has_response?
97
- !@response.nil?
98
- end
99
-
100
- # Retrieve the response object (or Nil if transaction hasn't been sent to the gateway).
101
- attr_reader :response
102
-
103
- # Returns the current delimiter we are using to parse the fields returned by the
104
- # gateway.
105
- attr_reader :delimiter
106
-
107
- # Sets the delimiter used to parse the response from the gateway.
108
- attr_writer :delimiter
109
-
110
- # Submits the transaction to the gateway for processing. Returns a response object. If the transaction
111
- # has already been run, it will return nil.
112
- def run
113
- make_request
114
- end
115
-
116
- # Returns the current card present API version that we are adhering to.
117
- attr_reader :cp_version
118
-
119
- attr_reader :solution_id
120
-
121
- #:enddoc:
122
- protected
123
-
124
- # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
125
- def make_request
126
- return nil if has_response?
127
- url = URI.parse(@gateway)
128
- fields = @fields.merge(type: @type, delim_char: @delimiter, delim_data: "TRUE", login: @api_login_id, tran_key: @api_transaction_key, relay_response: "FALSE")
129
-
130
- if @cp_version.nil?
131
- fields[:version] = @version
132
- else
133
- fields.merge!(cp_version: @cp_version, market_type: @market_type, device_type: @device_type, response_format: "1")
134
- end
135
- fields[:test_request] = boolean_to_value(@test_mode)
136
- fields[:allow_partial_auth] = 'TRUE' if @allow_split_transaction
137
- fields[:encap_char] = @encapsulation_character unless @encapsulation_character.nil?
138
- fields[:solution_id] = @solution_id unless @solution_id.nil?
139
- fields.each do |k, v|
140
- if @@boolean_fields.include?(k)
141
- fields[k] = boolean_to_value(v)
142
- elsif @@decimal_fields.include?(k)
143
- fields[k] = decimal_to_value(v)
144
- end
145
- end
146
- data = fields.collect do |key, val|
147
- to_param(key, val)
148
- end
149
- custom_field_keys = @custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
150
- for key in custom_field_keys
151
- data += [to_param(key, @custom_fields[key.to_sym], '')]
152
- end
153
- data.flatten!
154
- request = Net::HTTP::Post.new(url.path)
155
- request.content_type = 'application/x-www-form-urlencoded'
156
- request.body = data.join("&")
157
- connection = Net::HTTP.new(url.host, url.port)
158
- connection.use_ssl = true
159
- if @verify_ssl
160
- connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
161
- else
162
- connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
163
- end
164
- begin
165
- @response = AuthorizeNet::AIM::Response.new((connection.start { |http| http.request(request) }), self)
166
- rescue StandardError
167
- @response = AuthorizeNet::AIM::Response.new($ERROR_INFO, self)
168
- end
169
- end
170
- end
171
- end
1
+ module AuthorizeNet::AIM
2
+ # The AIM transaction class. Handles building the transaction payload and
3
+ # transmitting it to the gateway.
4
+ class Transaction < AuthorizeNet::KeyValueTransaction
5
+ # The default options for the constructor.
6
+ @@option_defaults = {
7
+ transaction_type: Type::AUTHORIZE_AND_CAPTURE,
8
+ gateway: :production,
9
+ test: false,
10
+ allow_split: false,
11
+ delimiter: ',',
12
+ encapsulation_character: nil,
13
+ verify_ssl: true,
14
+ device_type: DeviceType::UNKNOWN,
15
+ market_type: MarketType::RETAIL
16
+ }
17
+
18
+ # Fields to convert to/from booleans.
19
+ @@boolean_fields = %i[tax_exempt test_request recurring_billing allow_partial_auth delim_data email_customer relay_response]
20
+
21
+ # Fields to convert to/from BigDecimal.
22
+ @@decimal_fields = [:amount]
23
+
24
+ # Constructs an AIM transaction. You can use the new AIM transaction object
25
+ # to issue a request to the payment gateway and parse the response into a new
26
+ # AuthorizeNet::AIM::Response object.
27
+ #
28
+ # +api_login_id+:: Your API login ID, as a string.
29
+ # +api_transaction_key+:: Your API transaction key, as a string.
30
+ # +options+:: A hash of options. See below for values.
31
+ #
32
+ # Options
33
+ # +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.
34
+ # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::AIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :card_present_test, :card_present_live, :card_present_sandbox, :card_present_production, :production, or :live (:test is an alias for :sandbox, :card_present_test is an alias for :card_present_sandbox, :card_present_production is an alias for :card_present_live, and :live is an alias for :production).
35
+ # +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false).
36
+ # +allow_split+:: A boolean indicating if split transactions should be allowed (defaults to false).
37
+ # +delimiter+:: A single character (as a string) that will be used to delimit the response from the gateway. Defaults to ','.
38
+ # +encapsulation_character+:: A single character (as a string) that will be used to encapsulate each field in the response from the gateway. Defaults to nil.
39
+ # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to true.
40
+ # +device_type+:: A constant from DeviceType indicating the type of POS device used in a card present transaction. Defaults to DeviceType::UNKNOWN.
41
+ # +market_type+:: A constant from MarketType indicating your industry. Used for card present transactions. Defaults to MarketType::RETAIL.
42
+ #
43
+ def initialize(api_login_id, api_transaction_key, options = {})
44
+ ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction"
45
+ super()
46
+ options = @@option_defaults.merge(options)
47
+ @api_login_id = api_login_id
48
+ @api_transaction_key = api_transaction_key
49
+ @test_mode = options[:test]
50
+ @response ||= nil
51
+ @delimiter = options[:delimiter]
52
+ @type = options[:transaction_type]
53
+ @cp_version = nil
54
+ case options[:gateway]
55
+ when :sandbox, :test
56
+ @gateway = Gateway::TEST
57
+ when :production, :live
58
+ @gateway = Gateway::LIVE
59
+ when :card_present_live, :card_present_production
60
+ @gateway = Gateway::CARD_PRESENT_LIVE
61
+ @cp_version = '1.0'
62
+ when :card_present_test, :card_present_sandbox
63
+ @gateway = Gateway::CARD_PRESENT_TEST
64
+ @cp_version = '1.0'
65
+ else
66
+ @gateway = options[:gateway]
67
+ end
68
+ @allow_split_transaction = options[:allow_split]
69
+ @encapsulation_character = options[:encapsulation_character]
70
+ @verify_ssl = options[:verify_ssl]
71
+ @market_type = options[:market_type]
72
+ @device_type = options[:device_type]
73
+ @solution_id = options[:solution_id]
74
+ end
75
+
76
+ # Checks if the transaction has been configured for test mode or not. Return TRUE if the
77
+ # transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
78
+ # are considered test transactions.
79
+ def test?
80
+ super || @gateway == Gateway::TEST
81
+ end
82
+
83
+ # Returns TRUE if split transactions are allowed, FALSE otherwise.
84
+ def split_transaction_allowed?
85
+ !!@allow_split_transaction
86
+ end
87
+
88
+ # Returns the current encapsulation character unless there is none, in which case Nil is returned.
89
+ attr_reader :encapsulation_character
90
+
91
+ # Returns the gateway to be used for this transaction.
92
+ attr_reader :gateway
93
+
94
+ # Checks to see if the transaction has a response (meaning it has been submitted to the gateway).
95
+ # Returns TRUE if a response is present, FALSE otherwise.
96
+ def has_response?
97
+ !@response.nil?
98
+ end
99
+
100
+ # Retrieve the response object (or Nil if transaction hasn't been sent to the gateway).
101
+ attr_reader :response
102
+
103
+ # Returns the current delimiter we are using to parse the fields returned by the
104
+ # gateway.
105
+ attr_reader :delimiter
106
+
107
+ # Sets the delimiter used to parse the response from the gateway.
108
+ attr_writer :delimiter
109
+
110
+ # Submits the transaction to the gateway for processing. Returns a response object. If the transaction
111
+ # has already been run, it will return nil.
112
+ def run
113
+ make_request
114
+ end
115
+
116
+ # Returns the current card present API version that we are adhering to.
117
+ attr_reader :cp_version
118
+
119
+ attr_reader :solution_id
120
+
121
+ #:enddoc:
122
+ protected
123
+
124
+ # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
125
+ def make_request
126
+ return nil if has_response?
127
+ url = URI.parse(@gateway)
128
+ fields = @fields.merge(type: @type, delim_char: @delimiter, delim_data: "TRUE", login: @api_login_id, tran_key: @api_transaction_key, relay_response: "FALSE")
129
+
130
+ if @cp_version.nil?
131
+ fields[:version] = @version
132
+ else
133
+ fields.merge!(cp_version: @cp_version, market_type: @market_type, device_type: @device_type, response_format: "1")
134
+ end
135
+ fields[:test_request] = boolean_to_value(@test_mode)
136
+ fields[:allow_partial_auth] = 'TRUE' if @allow_split_transaction
137
+ fields[:encap_char] = @encapsulation_character unless @encapsulation_character.nil?
138
+ fields[:solution_id] = @solution_id unless @solution_id.nil?
139
+ fields.each do |k, v|
140
+ if @@boolean_fields.include?(k)
141
+ fields[k] = boolean_to_value(v)
142
+ elsif @@decimal_fields.include?(k)
143
+ fields[k] = decimal_to_value(v)
144
+ end
145
+ end
146
+ data = fields.collect do |key, val|
147
+ to_param(key, val)
148
+ end
149
+ custom_field_keys = @custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
150
+ for key in custom_field_keys
151
+ data += [to_param(key, @custom_fields[key.to_sym], '')]
152
+ end
153
+ data.flatten!
154
+ request = Net::HTTP::Post.new(url.path)
155
+ request.content_type = 'application/x-www-form-urlencoded'
156
+ request.body = data.join("&")
157
+ connection = Net::HTTP.new(url.host, url.port)
158
+ connection.use_ssl = true
159
+ if @verify_ssl
160
+ connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
161
+ else
162
+ connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
163
+ end
164
+ begin
165
+ @response = AuthorizeNet::AIM::Response.new((connection.start { |http| http.request(request) }), self)
166
+ rescue StandardError
167
+ @response = AuthorizeNet::AIM::Response.new($ERROR_INFO, self)
168
+ end
169
+ end
170
+ end
171
+ end
@@ -1,119 +1,119 @@
1
- module AuthorizeNet::API
2
- class ApiTransaction < AuthorizeNet::XmlTransaction
3
- module Type
4
- API_CREATE_TRANSACTION = "createTransactionRequest".freeze
5
- API_UPDATE_SPLIT_TENDER_GROUP = "updateSplitTenderGroupRequest".freeze
6
-
7
- API_CREATE_SUBSCRIPTION = "ARBCreateSubscriptionRequest".freeze
8
- API_UPDATE_SUBSCRIPTION = "ARBUpdateSubscriptionRequest".freeze
9
- API_CANCEL_SUBSCRIPTION = "ARBCancelSubscriptionRequest".freeze
10
- API_GET_SUBSCRIPTION_STATUS = "ARBGetSubscriptionStatusRequest".freeze
11
- API_GET_SUBSCRIPTION_LIST = "ARBGetSubscriptionListRequest".freeze
12
-
13
- API_GET_CUSTOMER_PROFILE_IDS = "getCustomerProfileIdsRequest".freeze
14
-
15
- API_CREATE_CUSTOMER_PROFILE = "createCustomerProfileRequest".freeze
16
- API_GET_CUSTOMER_PROFILE = "getCustomerProfileRequest".freeze
17
- API_UPDATE_CUSTOMER_PROFILE = "updateCustomerProfileRequest".freeze
18
- API_DELETE_CUSTOMER_PROFILE = "deleteCustomerProfileRequest".freeze
19
-
20
- API_CREATE_CUSTOMER_PAYMENT_PROFILE = "createCustomerPaymentProfileRequest".freeze
21
- API_GET_CUSTOMER_PAYMENT_PROFILE = "getCustomerPaymentProfileRequest".freeze
22
- API_UPDATE_CUSTOMER_PAYMENT_PROFILE = "updateCustomerPaymentProfileRequest".freeze
23
- API_VALIDATE_CUSTOMER_PAYMENT_PROFILE = "validateCustomerPaymentProfileRequest".freeze
24
- API_DELETE_CUSTOMER_PAYMENT_PROFILE = "deleteCustomerPaymentProfileRequest".freeze
25
-
26
- API_CREATE_CUSTOMER_SHIPPING_PROFILE = "createCustomerShippingAddressRequest".freeze
27
- API_GET_CUSTOMER_SHIPPING_PROFILE = "getCustomerShippingAddressRequest".freeze
28
- API_UPDATE_CUSTOMER_SHIPPING_PROFILE = "updateCustomerShippingAddressRequest".freeze
29
- API_DELETE_CUSTOMER_SHIPPING_PROFILE = "deleteCustomerShippingAddressRequest".freeze
30
-
31
- API_CREATE_CUSTOMER_PROFILE_FROM_TRANSACTION = "createCustomerProfileFromTransactionRequest".freeze
32
-
33
- API_GET_SETTLED_BATCH_LIST = "getSettledBatchListRequest".freeze
34
- API_GET_TRANSACTION_LIST = "getTransactionListRequest".freeze
35
- API_GET_TRANSACTION_DETAILS = "getTransactionDetailsRequest".freeze
36
- API_GET_UNSETTLED_TRANSACTION_LIST = "getUnsettledTransactionListRequest".freeze
37
- API_GET_BATCH_STATISTICS = "getBatchStatisticsRequest".freeze
38
- API_GET_TRANSACTION_LIST_FOR_CUSTOMER = "getTransactionListForCustomerRequest".freeze
39
-
40
- API_GET_HOSTED_PROFILE_PAGE = "getHostedProfilePageRequest".freeze
41
-
42
- API_DECRYPT_PAYMENT_DATA = "decryptPaymentDataRequest".freeze
43
- API_AUTHENTICATE_TEST_REQUEST = "authenticateTestRequest".freeze
44
-
45
- API_GET_CUSTOMER_PAYMENT_PROFILE_LIST = "getCustomerPaymentProfileListRequest".freeze
46
-
47
- API_ARB_GET_SUBSCRIPTION_REQUEST = "ARBGetSubscriptionRequest".freeze
48
-
49
- API_GET_MERCHANT_DETAILS = "getMerchantDetailsRequest".freeze
50
- API_GET_HOSTED_PAYMENT_PAGE = "getHostedPaymentPageRequest".freeze
51
- API_UDPATE_HELD_TRANSACTION = "updateHeldTransactionRequest".freeze
52
- API_UPDATE_MERCHANT_DETAILS = "updateMerchantDetailsRequest".freeze
53
- end
54
-
55
- def initialize(api_login_id = nil, api_transaction_key = nil, options = {})
56
- super
57
- end
58
-
59
- def setOAuthOptions
60
- super
61
- end
62
-
63
- def make_request(request, responseClass, type)
64
- setOAuthOptions
65
- unless responseClass.nil? || request.nil?
66
- begin
67
- @xml = serialize(request, type)
68
- respXml = send_request(@xml)
69
- @response = deserialize(respXml.body, responseClass)
70
- rescue Exception => ex
71
- ex
72
- end
73
- end
74
- end
75
-
76
- def serialize(object, type)
77
- doc = Nokogiri::XML::Document.new
78
- doc.root = object.to_xml
79
- constants = YAML.load_file(File.dirname(__FILE__) + "/constants.yml")
80
- clientId = constants['clientId']
81
-
82
- builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |x|
83
- x.send(type.to_sym, xmlns: XML_NAMESPACE) do
84
- x.merchantAuthentication do
85
- x.accessToken @access_token unless @access_token.blank?
86
- if !@api_login_id.blank? || (@access_token.blank? && @api_login_id.blank?)
87
- x.name @api_login_id
88
- x.transactionKey @api_transaction_key
89
- end
90
- end
91
- x.clientId clientId
92
- x.send :insert, doc.root.element_children
93
- end
94
- end
95
- builder.to_xml
96
- end
97
-
98
- def send_request(xml)
99
- url = URI.parse(@gateway)
100
-
101
- httpRequest = Net::HTTP::Post.new(url.path)
102
- httpRequest.content_type = 'text/xml'
103
- httpRequest.body = xml
104
- connection = Net::HTTP.new(url.host, url.port)
105
- connection.use_ssl = true
106
- if @verify_ssl
107
- connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
108
- else
109
- connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
110
- end
111
-
112
- response = connection.start { |http| http.request(httpRequest) }
113
- end
114
-
115
- def deserialize(xml, responseClass)
116
- responseClass.from_xml(xml)
117
- end
118
- end
119
- end
1
+ module AuthorizeNet::API
2
+ class ApiTransaction < AuthorizeNet::XmlTransaction
3
+ module Type
4
+ API_CREATE_TRANSACTION = "createTransactionRequest".freeze
5
+ API_UPDATE_SPLIT_TENDER_GROUP = "updateSplitTenderGroupRequest".freeze
6
+
7
+ API_CREATE_SUBSCRIPTION = "ARBCreateSubscriptionRequest".freeze
8
+ API_UPDATE_SUBSCRIPTION = "ARBUpdateSubscriptionRequest".freeze
9
+ API_CANCEL_SUBSCRIPTION = "ARBCancelSubscriptionRequest".freeze
10
+ API_GET_SUBSCRIPTION_STATUS = "ARBGetSubscriptionStatusRequest".freeze
11
+ API_GET_SUBSCRIPTION_LIST = "ARBGetSubscriptionListRequest".freeze
12
+
13
+ API_GET_CUSTOMER_PROFILE_IDS = "getCustomerProfileIdsRequest".freeze
14
+
15
+ API_CREATE_CUSTOMER_PROFILE = "createCustomerProfileRequest".freeze
16
+ API_GET_CUSTOMER_PROFILE = "getCustomerProfileRequest".freeze
17
+ API_UPDATE_CUSTOMER_PROFILE = "updateCustomerProfileRequest".freeze
18
+ API_DELETE_CUSTOMER_PROFILE = "deleteCustomerProfileRequest".freeze
19
+
20
+ API_CREATE_CUSTOMER_PAYMENT_PROFILE = "createCustomerPaymentProfileRequest".freeze
21
+ API_GET_CUSTOMER_PAYMENT_PROFILE = "getCustomerPaymentProfileRequest".freeze
22
+ API_UPDATE_CUSTOMER_PAYMENT_PROFILE = "updateCustomerPaymentProfileRequest".freeze
23
+ API_VALIDATE_CUSTOMER_PAYMENT_PROFILE = "validateCustomerPaymentProfileRequest".freeze
24
+ API_DELETE_CUSTOMER_PAYMENT_PROFILE = "deleteCustomerPaymentProfileRequest".freeze
25
+
26
+ API_CREATE_CUSTOMER_SHIPPING_PROFILE = "createCustomerShippingAddressRequest".freeze
27
+ API_GET_CUSTOMER_SHIPPING_PROFILE = "getCustomerShippingAddressRequest".freeze
28
+ API_UPDATE_CUSTOMER_SHIPPING_PROFILE = "updateCustomerShippingAddressRequest".freeze
29
+ API_DELETE_CUSTOMER_SHIPPING_PROFILE = "deleteCustomerShippingAddressRequest".freeze
30
+
31
+ API_CREATE_CUSTOMER_PROFILE_FROM_TRANSACTION = "createCustomerProfileFromTransactionRequest".freeze
32
+
33
+ API_GET_SETTLED_BATCH_LIST = "getSettledBatchListRequest".freeze
34
+ API_GET_TRANSACTION_LIST = "getTransactionListRequest".freeze
35
+ API_GET_TRANSACTION_DETAILS = "getTransactionDetailsRequest".freeze
36
+ API_GET_UNSETTLED_TRANSACTION_LIST = "getUnsettledTransactionListRequest".freeze
37
+ API_GET_BATCH_STATISTICS = "getBatchStatisticsRequest".freeze
38
+ API_GET_TRANSACTION_LIST_FOR_CUSTOMER = "getTransactionListForCustomerRequest".freeze
39
+
40
+ API_GET_HOSTED_PROFILE_PAGE = "getHostedProfilePageRequest".freeze
41
+
42
+ API_DECRYPT_PAYMENT_DATA = "decryptPaymentDataRequest".freeze
43
+ API_AUTHENTICATE_TEST_REQUEST = "authenticateTestRequest".freeze
44
+
45
+ API_GET_CUSTOMER_PAYMENT_PROFILE_LIST = "getCustomerPaymentProfileListRequest".freeze
46
+
47
+ API_ARB_GET_SUBSCRIPTION_REQUEST = "ARBGetSubscriptionRequest".freeze
48
+
49
+ API_GET_MERCHANT_DETAILS = "getMerchantDetailsRequest".freeze
50
+ API_GET_HOSTED_PAYMENT_PAGE = "getHostedPaymentPageRequest".freeze
51
+ API_UDPATE_HELD_TRANSACTION = "updateHeldTransactionRequest".freeze
52
+ API_UPDATE_MERCHANT_DETAILS = "updateMerchantDetailsRequest".freeze
53
+ end
54
+
55
+ def initialize(api_login_id = nil, api_transaction_key = nil, options = {})
56
+ super
57
+ end
58
+
59
+ def setOAuthOptions
60
+ super
61
+ end
62
+
63
+ def make_request(request, responseClass, type)
64
+ setOAuthOptions
65
+ unless responseClass.nil? || request.nil?
66
+ begin
67
+ @xml = serialize(request, type)
68
+ respXml = send_request(@xml)
69
+ @response = deserialize(respXml.body, responseClass)
70
+ rescue Exception => ex
71
+ ex
72
+ end
73
+ end
74
+ end
75
+
76
+ def serialize(object, type)
77
+ doc = Nokogiri::XML::Document.new
78
+ doc.root = object.to_xml
79
+ constants = YAML.load_file(File.dirname(__FILE__) + "/constants.yml")
80
+ clientId = constants['clientId']
81
+
82
+ builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |x|
83
+ x.send(type.to_sym, xmlns: XML_NAMESPACE) do
84
+ x.merchantAuthentication do
85
+ x.accessToken @access_token unless @access_token.blank?
86
+ if !@api_login_id.blank? || (@access_token.blank? && @api_login_id.blank?)
87
+ x.name @api_login_id
88
+ x.transactionKey @api_transaction_key
89
+ end
90
+ end
91
+ x.clientId clientId
92
+ x.send :insert, doc.root.element_children
93
+ end
94
+ end
95
+ builder.to_xml
96
+ end
97
+
98
+ def send_request(xml)
99
+ url = URI.parse(@gateway)
100
+
101
+ httpRequest = Net::HTTP::Post.new(url.path)
102
+ httpRequest.content_type = 'text/xml'
103
+ httpRequest.body = xml
104
+ connection = Net::HTTP.new(url.host, url.port)
105
+ connection.use_ssl = true
106
+ if @verify_ssl
107
+ connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
108
+ else
109
+ connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
110
+ end
111
+
112
+ response = connection.start { |http| http.request(httpRequest) }
113
+ end
114
+
115
+ def deserialize(xml, responseClass)
116
+ responseClass.from_xml(xml)
117
+ end
118
+ end
119
+ end