authorizenet 1.8.7 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/lib/app/helpers/authorize_net_helper.rb +23 -23
  3. data/lib/authorize_net.rb +107 -103
  4. data/lib/authorize_net/addresses/address.rb +28 -28
  5. data/lib/authorize_net/addresses/shipping_address.rb +25 -25
  6. data/lib/authorize_net/aim/response.rb +130 -130
  7. data/lib/authorize_net/aim/transaction.rb +190 -190
  8. data/lib/authorize_net/api/api_transaction.rb +103 -102
  9. data/lib/authorize_net/api/schema.rb +4283 -4283
  10. data/lib/authorize_net/api/transaction.rb +240 -240
  11. data/lib/authorize_net/arb/fields.rb +24 -24
  12. data/lib/authorize_net/arb/paging.rb +33 -33
  13. data/lib/authorize_net/arb/response.rb +33 -33
  14. data/lib/authorize_net/arb/sorting.rb +43 -43
  15. data/lib/authorize_net/arb/subscription.rb +71 -71
  16. data/lib/authorize_net/arb/subscription_detail.rb +14 -14
  17. data/lib/authorize_net/arb/subscription_list_response.rb +43 -43
  18. data/lib/authorize_net/arb/transaction.rb +177 -177
  19. data/lib/authorize_net/authorize_net.rb +153 -153
  20. data/lib/authorize_net/cim/customer_profile.rb +18 -18
  21. data/lib/authorize_net/cim/payment_profile.rb +36 -36
  22. data/lib/authorize_net/cim/response.rb +115 -115
  23. data/lib/authorize_net/cim/transaction.rb +727 -727
  24. data/lib/authorize_net/customer.rb +26 -26
  25. data/lib/authorize_net/email_receipt.rb +23 -23
  26. data/lib/authorize_net/fields.rb +779 -779
  27. data/lib/authorize_net/key_value_response.rb +116 -116
  28. data/lib/authorize_net/key_value_transaction.rb +290 -290
  29. data/lib/authorize_net/line_item.rb +24 -24
  30. data/lib/authorize_net/order.rb +41 -41
  31. data/lib/authorize_net/payment_methods/credit_card.rb +62 -62
  32. data/lib/authorize_net/payment_methods/echeck.rb +71 -71
  33. data/lib/authorize_net/reporting/batch.rb +18 -18
  34. data/lib/authorize_net/reporting/batch_statistics.rb +18 -18
  35. data/lib/authorize_net/reporting/fds_filter.rb +10 -10
  36. data/lib/authorize_net/reporting/response.rb +162 -162
  37. data/lib/authorize_net/reporting/returned_item.rb +46 -46
  38. data/lib/authorize_net/reporting/transaction.rb +133 -133
  39. data/lib/authorize_net/reporting/transaction_details.rb +24 -24
  40. data/lib/authorize_net/response.rb +26 -26
  41. data/lib/authorize_net/sim/hosted_payment_form.rb +37 -37
  42. data/lib/authorize_net/sim/hosted_receipt_page.rb +36 -36
  43. data/lib/authorize_net/sim/response.rb +141 -141
  44. data/lib/authorize_net/sim/transaction.rb +137 -137
  45. data/lib/authorize_net/transaction.rb +65 -65
  46. data/lib/authorize_net/xml_response.rb +171 -171
  47. data/lib/authorize_net/xml_transaction.rb +280 -280
  48. data/lib/authorizenet.rb +4 -4
  49. data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +53 -53
  50. data/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +48 -48
  51. data/lib/generators/authorize_net/direct_post/templates/config.yml.erb +8 -8
  52. data/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +8 -8
  53. data/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +30 -30
  54. data/lib/generators/authorize_net/direct_post/templates/initializer.rb +4 -4
  55. data/lib/generators/authorize_net/direct_post/templates/layout.erb +17 -17
  56. data/lib/generators/authorize_net/direct_post/templates/payment.erb +9 -9
  57. data/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +9 -9
  58. data/lib/generators/authorize_net/sim/sim_generator.rb +47 -47
  59. data/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +51 -51
  60. data/lib/generators/authorize_net/sim/templates/config.yml.erb +8 -8
  61. data/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +8 -8
  62. data/lib/generators/authorize_net/sim/templates/controller.rb.erb +20 -20
  63. data/lib/generators/authorize_net/sim/templates/initializer.rb +4 -4
  64. data/lib/generators/authorize_net/sim/templates/layout.erb +17 -17
  65. data/lib/generators/authorize_net/sim/templates/payment.erb +5 -5
  66. data/lib/generators/authorize_net/sim/templates/payment.rails3.erb +5 -5
  67. data/lib/generators/generator_extensions.rb +74 -74
  68. metadata +4 -3
@@ -1,117 +1,117 @@
1
- module AuthorizeNet
2
-
3
- # The core, key/value response class. You shouldn't instantiate this one.
4
- # Instead you should use AuthorizeNet::AIM::Response or AuthorizeNet::SIM::Response.
5
- class KeyValueResponse < AuthorizeNet::Response
6
-
7
- # Defines constants for each response code.
8
- module ResponseCode
9
- APPROVED = '1'
10
- DECLINED = '2'
11
- ERROR = '3'
12
- HELD = '4'
13
- end
14
-
15
- # Defines constants for each address verification response code.
16
- module AVSResponseCode
17
- ADDRESS_MATCH_NOT_ZIP = 'A'
18
- NO_INFO = 'B'
19
- ERROR = 'E'
20
- NON_US = 'G'
21
- NO_MATCH = 'N'
22
- NOT_APPLICABLE = 'P'
23
- RETRY = 'R'
24
- NOT_SUPPOPRTED = 'S'
25
- UNAVAILABLE = 'U'
26
- ZIP9_MATCH_NOT_ADDRESS = 'W'
27
- ADDRESS_AND_ZIP9_MATCH = 'X'
28
- ADDRESS_AND_ZIP5_MATCH = 'Y'
29
- ZIP5_MATCH_NOT_ADDRESS = 'Z'
30
- end
31
-
32
- # Defines constants for each supported credit card type.
33
- module CardType
34
- VISA = 'Visa'
35
- MASTER_CARD = 'MasterCard'
36
- AMEX = 'American Express'
37
- DISCOVER = 'Discover'
38
- DINERS_CLUB = 'Diners Club'
39
- JCB = 'JCB'
40
- end
41
-
42
- # Defines constants for CCV code validation responses.
43
- module CCVResponseCode
44
- MATCH = 'M'
45
- NO_MATCH = 'N'
46
- NOT_PROCESSED = 'P'
47
- SHOULD_HAVE_BEEN_PRESENT = 'S'
48
- UNABLE_TO_PROCESS = 'U'
49
- end
50
-
51
- # Defines constants for CAVV code validation responses.
52
- module CAVVResponseCode
53
- ERRONEOUS_DATA = '0'
54
- FAILED_VALIDATION = '1'
55
- PASSED_VALIDATION = '2'
56
- ISSUER_ATTEMPT_INCOMPLETE = '3'
57
- ISSUER_SYSTEM_ERROR = '4'
58
- FAILED_ISSUER_AVAILABLE = '7'
59
- PASSED_ISSUER_AVAILABLE = '8'
60
- FAILED_ISSUER_UNAVAILABLE = '9'
61
- PASSED_ISSUER_UNAVAILABLE = 'A'
62
- PASSED_NO_LIABILITY_SHIFT = 'B'
63
- end
64
-
65
- # Check to see if the transaction was approved.
66
- def approved?
67
- @fields[:response_code] == ResponseCode::APPROVED
68
- end
69
-
70
- # Check to see if the transaction was declined.
71
- def declined?
72
- @fields[:response_code] == ResponseCode::DECLINED
73
- end
74
-
75
- # Check to see if the transaction was returned with an error.
76
- def error?
77
- @fields[:response_code] == ResponseCode::ERROR
78
- end
79
-
80
- # Check to see if the transaction was held for review by Authorize.Net.
81
- def held?
82
- @fields[:response_code] == ResponseCode::HELD
83
- end
84
-
85
- # Returns the response code received from the gateway. Note: its better to use
86
- # success?, approved?, etc. to check the response code.
87
- def response_code
88
- @fields[:response_code]
89
- end
90
-
91
- # Returns the response reason code received from the gateway. This code can be used
92
- # to identify why something failed by referencing the AIM documentation.
93
- def response_reason_code
94
- @fields[:response_reason_code]
95
- end
96
-
97
- # Returns the response reason text received from the gateway. This is a brief, human readable
98
- # explanation of why you got the response code that you got. Note that these strings tend to be
99
- # a bit vague. More detail can be gleaned from the response_reason_code.
100
- def response_reason_text
101
- @fields[:response_reason_text]
102
- end
103
-
104
- # Returns all the fields returned in the response, keyed by their API name. Custom fields are NOT
105
- # included (see custom_fields).
106
- def fields
107
- @fields
108
- end
109
-
110
- # Returns all the custom fields returned in the response, keyed by their field name.
111
- def custom_fields
112
- @custom_fields
113
- end
114
-
115
- end
116
-
1
+ module AuthorizeNet
2
+
3
+ # The core, key/value response class. You shouldn't instantiate this one.
4
+ # Instead you should use AuthorizeNet::AIM::Response or AuthorizeNet::SIM::Response.
5
+ class KeyValueResponse < AuthorizeNet::Response
6
+
7
+ # Defines constants for each response code.
8
+ module ResponseCode
9
+ APPROVED = '1'
10
+ DECLINED = '2'
11
+ ERROR = '3'
12
+ HELD = '4'
13
+ end
14
+
15
+ # Defines constants for each address verification response code.
16
+ module AVSResponseCode
17
+ ADDRESS_MATCH_NOT_ZIP = 'A'
18
+ NO_INFO = 'B'
19
+ ERROR = 'E'
20
+ NON_US = 'G'
21
+ NO_MATCH = 'N'
22
+ NOT_APPLICABLE = 'P'
23
+ RETRY = 'R'
24
+ NOT_SUPPOPRTED = 'S'
25
+ UNAVAILABLE = 'U'
26
+ ZIP9_MATCH_NOT_ADDRESS = 'W'
27
+ ADDRESS_AND_ZIP9_MATCH = 'X'
28
+ ADDRESS_AND_ZIP5_MATCH = 'Y'
29
+ ZIP5_MATCH_NOT_ADDRESS = 'Z'
30
+ end
31
+
32
+ # Defines constants for each supported credit card type.
33
+ module CardType
34
+ VISA = 'Visa'
35
+ MASTER_CARD = 'MasterCard'
36
+ AMEX = 'American Express'
37
+ DISCOVER = 'Discover'
38
+ DINERS_CLUB = 'Diners Club'
39
+ JCB = 'JCB'
40
+ end
41
+
42
+ # Defines constants for CCV code validation responses.
43
+ module CCVResponseCode
44
+ MATCH = 'M'
45
+ NO_MATCH = 'N'
46
+ NOT_PROCESSED = 'P'
47
+ SHOULD_HAVE_BEEN_PRESENT = 'S'
48
+ UNABLE_TO_PROCESS = 'U'
49
+ end
50
+
51
+ # Defines constants for CAVV code validation responses.
52
+ module CAVVResponseCode
53
+ ERRONEOUS_DATA = '0'
54
+ FAILED_VALIDATION = '1'
55
+ PASSED_VALIDATION = '2'
56
+ ISSUER_ATTEMPT_INCOMPLETE = '3'
57
+ ISSUER_SYSTEM_ERROR = '4'
58
+ FAILED_ISSUER_AVAILABLE = '7'
59
+ PASSED_ISSUER_AVAILABLE = '8'
60
+ FAILED_ISSUER_UNAVAILABLE = '9'
61
+ PASSED_ISSUER_UNAVAILABLE = 'A'
62
+ PASSED_NO_LIABILITY_SHIFT = 'B'
63
+ end
64
+
65
+ # Check to see if the transaction was approved.
66
+ def approved?
67
+ @fields[:response_code] == ResponseCode::APPROVED
68
+ end
69
+
70
+ # Check to see if the transaction was declined.
71
+ def declined?
72
+ @fields[:response_code] == ResponseCode::DECLINED
73
+ end
74
+
75
+ # Check to see if the transaction was returned with an error.
76
+ def error?
77
+ @fields[:response_code] == ResponseCode::ERROR
78
+ end
79
+
80
+ # Check to see if the transaction was held for review by Authorize.Net.
81
+ def held?
82
+ @fields[:response_code] == ResponseCode::HELD
83
+ end
84
+
85
+ # Returns the response code received from the gateway. Note: its better to use
86
+ # success?, approved?, etc. to check the response code.
87
+ def response_code
88
+ @fields[:response_code]
89
+ end
90
+
91
+ # Returns the response reason code received from the gateway. This code can be used
92
+ # to identify why something failed by referencing the AIM documentation.
93
+ def response_reason_code
94
+ @fields[:response_reason_code]
95
+ end
96
+
97
+ # Returns the response reason text received from the gateway. This is a brief, human readable
98
+ # explanation of why you got the response code that you got. Note that these strings tend to be
99
+ # a bit vague. More detail can be gleaned from the response_reason_code.
100
+ def response_reason_text
101
+ @fields[:response_reason_text]
102
+ end
103
+
104
+ # Returns all the fields returned in the response, keyed by their API name. Custom fields are NOT
105
+ # included (see custom_fields).
106
+ def fields
107
+ @fields
108
+ end
109
+
110
+ # Returns all the custom fields returned in the response, keyed by their field name.
111
+ def custom_fields
112
+ @custom_fields
113
+ end
114
+
115
+ end
116
+
117
117
  end
@@ -1,291 +1,291 @@
1
- module AuthorizeNet
2
-
3
- # The core, key/value transaction class. You shouldn't instantiate this one.
4
- # Instead you should use AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction.
5
- class KeyValueTransaction < AuthorizeNet::Transaction
6
-
7
- # Constants for both the various Authorize.Net payment gateways are defined here.
8
- module Gateway
9
- LIVE = 'https://secure2.authorize.net/gateway/transact.dll'
10
- TEST = 'https://test.authorize.net/gateway/transact.dll'
11
- CARD_PRESENT_LIVE = 'https://cardpresent.authorize.net/gateway/transact.dll'
12
- CARD_PRESENT_TEST = 'https://test.authorize.net/gateway/transact.dll'
13
- end
14
-
15
- # Constants for both the various Authorize.Net payment transaction types are defined here.
16
- module Type
17
- AUTHORIZE_AND_CAPTURE = "AUTH_CAPTURE"
18
- AUTHORIZE_ONLY = "AUTH_ONLY"
19
- CAPTURE_ONLY = "CAPTURE_ONLY"
20
- CREDIT = "CREDIT"
21
- PRIOR_AUTHORIZATION_AND_CAPTURE = "PRIOR_AUTH_CAPTURE"
22
- VOID = "VOID"
23
- end
24
-
25
- # Constants for the various device types used in card present transactions.
26
- module DeviceType
27
- UNKNOWN = 1
28
- UNATTENDED = 2
29
- SELF_SERVICE = 3
30
- CASH_REGISTER = 4
31
- PC_TERMINAL = 5
32
- AIRPAY = 6
33
- WIRELESS_POS = 7
34
- WEBSITE_TERMINAL = 8
35
- DIAL_TERMINAL = 9
36
- VIRTUAL_TERMINAL = 10
37
- end
38
-
39
- # Constants for the various market types used in card present transactions.
40
- module MarketType
41
- RETAIL = 2
42
- end
43
-
44
- # The default options for purchase.
45
- @@purchase_option_defaults = {
46
- :cardholder_auth_value => nil,
47
- :cardholder_auth_indicator => nil
48
- }
49
-
50
- # The default options for authorize.
51
- @@authorize_option_defaults = {
52
- :cardholder_auth_value => nil,
53
- :cardholder_auth_indicator => nil
54
- }
55
-
56
- # Fields to convert to/from booleans.
57
- @@boolean_fields = []
58
-
59
- # Fields to convert to/from BigDecimal.
60
- @@decimal_fields = []
61
-
62
- # DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction instead.
63
- def initialize()
64
- super
65
- @custom_fields ||= {}
66
- @test_mode ||= false
67
- @version = '3.1'
68
- end
69
-
70
- # Checks if the transaction has been configured for test mode or not. Return TRUE if the
71
- # transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
72
- # are considered test transactions.
73
- def test?
74
- !!@test_mode
75
- end
76
-
77
- # Returns the current API version that we are adhering to
78
- def version
79
- @version
80
- end
81
-
82
- # Sets arbitrary custom fields, overwriting existing values if they exist. Takes a hash of key/value pairs,
83
- # where the keys are the field names. You can set a field to Nil to unset it.
84
- def set_custom_fields(fields = {})
85
- @custom_fields.merge!(fields)
86
- end
87
-
88
- # Returns the current hash of custom fields.
89
- def custom_fields
90
- @custom_fields
91
- end
92
-
93
- # Convenience method for adding line items to a transaction.
94
- def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil)
95
- line_item = "#{id}<|>#{name}<|>#{description}<|>#{quantity}<|>#{price}<|>#{taxable}"
96
- if @fields.has_key?(:line_item)
97
- @fields[:line_item] = @fields[:line_item].to_a << line_item
98
- else
99
- @fields[:line_item] = [line_item]
100
- end
101
- end
102
-
103
- # Takes an instance of AuthorizeNet::EmailReceipt and adds it to the transaction.
104
- def set_email_receipt(email)
105
- @fields.merge!(email.to_hash)
106
- end
107
-
108
- # Returns the type of transaction.
109
- def type
110
- @type
111
- end
112
-
113
- # Sets the type of transaction.
114
- def type=(type)
115
- case type
116
- when :authorize, :auth_only
117
- @type = Type::AUTHORIZE_ONLY
118
- when :purchase, :auth_and_capture
119
- @type = Type::AUTHORIZE_AND_CAPTURE
120
- when :refund, :credit
121
- @type = Type::CREDIT
122
- when :void
123
- @type = Type::VOID
124
- when :capture, :capture_only
125
- @type = Type::CAPTURE_ONLY
126
- when :prior_auth_capture
127
- @type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE
128
- else
129
- @type = type
130
- end
131
- end
132
-
133
- # Sets up and submits a standard purchase (AUTHORIZE_AND_CAPTURE) transaction. Returns a response object. If the transaction
134
- # has already been run, it will return nil.
135
- #
136
- # +amount+:: The amount to charge. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
137
- # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields).
138
- # +options+:: A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases.
139
- #
140
- #
141
- # Typical usage:
142
- #
143
- # credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
144
- # response = transaction.purchase(10.0, credit_card)
145
- #
146
- def purchase(amount, credit_card, options = {})
147
- handle_payment_argument(credit_card)
148
- options = @@purchase_option_defaults.merge(options)
149
- handle_cavv_options(options)
150
- set_fields(:amount => amount)
151
- self.type = Type::AUTHORIZE_AND_CAPTURE
152
- run
153
- end
154
-
155
- # Sets up and submits a refund (CREDIT) transaction. Returns a response object. If the transaction
156
- # has already been run, it will return nil.
157
- #
158
- # +amount+:: The amount to refund. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
159
- # +transaction+:: The transaction ID to apply the refund to. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
160
- # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits. In many cases you only need the last 4 digits of the credit card here.
161
- #
162
- #
163
- # Typical usage:
164
- #
165
- # response = transaction.refund(10.0, '123456789', '1212')
166
- #
167
- def refund(amount, transaction, credit_card)
168
- handle_payment_argument(credit_card)
169
- handle_transaction_argument(transaction)
170
- set_fields(:amount => amount)
171
- self.type = Type::CREDIT
172
- run
173
- end
174
-
175
- # Sets up and submits a refund (CREDIT) transaction for a transaction that was not originally
176
- # submitted via the payment gateway. Note that this is a special feature which requires your
177
- # account to support ECC (expanded credits capability) transactions.
178
- #
179
- # +amount+:: The amount to refund. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
180
- # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits.
181
- #
182
- # Typical usage:
183
- #
184
- # response = transaction.unlinked_credit(10.0, '4111111111111111')
185
- #
186
- def unlinked_credit(amount, credit_card)
187
- handle_payment_argument(credit_card)
188
- set_fields(:amount => amount)
189
- self.type = Type::CREDIT
190
- run
191
- end
192
-
193
- # Sets up and submits a void (VOID) transaction. Returns a response object. If the transaction
194
- # has already been run, it will return nil. Note that you can only void unsettled transactions.
195
- #
196
- # +transaction+:: The transaction ID of the transaction to void. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
197
- #
198
- #
199
- # Typical usage:
200
- #
201
- # response = transaction.void('123456789')
202
- #
203
- def void(transaction)
204
- handle_transaction_argument(transaction)
205
- self.type = Type::VOID
206
- run
207
- end
208
-
209
- # Sets up and submits an authorize (AUTH_ONLY) transaction. Returns a response object. If the transaction
210
- # has already been run, it will return nil. Use this to put a hold on funds, but don't actually charge
211
- # the card yet.
212
- #
213
- # +amount+:: The amount to authorize. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
214
- # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields).
215
- # +options+:: A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases.
216
- #
217
- #
218
- # Typical usage:
219
- #
220
- # credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
221
- # response = transaction.authorize(10.0, credit_card)
222
- #
223
- def authorize(amount, credit_card, options = {})
224
- handle_payment_argument(credit_card)
225
- options = @@authorize_option_defaults.merge(options)
226
- handle_cavv_options(options)
227
- set_fields(:amount => amount)
228
- self.type = Type::AUTHORIZE_ONLY
229
- run
230
- end
231
-
232
- # Sets up and submits a capture (CAPTURE_ONLY) transaction. Returns a response object. If the transaction
233
- # has already been run, it will return nil. Note that you can not capture a transaction that was made
234
- # though the AIM API using this method. Use prior_auth_capture instead.
235
- #
236
- # +amount+:: The amount to capture. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
237
- # +authorization_code+:: The authorization code of the transaction to capture. Accepts a string.
238
- #
239
- #
240
- # Typical usage:
241
- #
242
- # response = transaction.capture(10.0, '123FAKE')
243
- #
244
- def capture(amount, authorization_code)
245
- set_fields(:amount => amount, :auth_code => authorization_code)
246
- self.type = Type::CAPTURE_ONLY
247
- run
248
- end
249
-
250
- # Sets up and submits a capture (PRIOR_AUTH_CAPTURE) transaction. Returns a response object. Use this method
251
- # to actually charge a card that you previously put a hold on (using authorize).
252
- #
253
- # +transaction+:: The transaction ID to capture. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
254
- # +amount+:: The amount to capture (only if less than the amount originally authorized, otherwise leave as Nil). Accepts a string in the format "%0.2f", a Float, a BigDecimal or Nil.
255
- #
256
- #
257
- # Typical usage:
258
- #
259
- # response = transaction.prior_auth_capture('123456789')
260
- #
261
- def prior_auth_capture(transaction, amount = nil)
262
- handle_transaction_argument(transaction)
263
- set_fields(:amount => amount)
264
- self.type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE
265
- run
266
- end
267
-
268
- #:enddoc:
269
- protected
270
-
271
- # Internal method to handle multiple types of transaction arguments.
272
- def handle_transaction_argument(transaction)
273
- case transaction
274
- when Transaction
275
- set_fields(:trans_id => transaction.response.transaction_id)
276
- when Response
277
- set_fields(:trans_id => transaction.transaction_id)
278
- else
279
- set_fields(:trans_id => transaction)
280
- end
281
- end
282
-
283
- # Internal method to handle CAVV options.
284
- def handle_cavv_options(options)
285
- set_fields(:authentication_indicator => options[:cardholder_auth_indicator]) unless options[:cardholder_auth_indicator].nil?
286
- set_fields(:cardholder_authentication_value => options[:cardholder_auth_value]) unless options[:cardholder_auth_value].nil?
287
- end
288
-
289
- end
290
-
1
+ module AuthorizeNet
2
+
3
+ # The core, key/value transaction class. You shouldn't instantiate this one.
4
+ # Instead you should use AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction.
5
+ class KeyValueTransaction < AuthorizeNet::Transaction
6
+
7
+ # Constants for both the various Authorize.Net payment gateways are defined here.
8
+ module Gateway
9
+ LIVE = 'https://secure2.authorize.net/gateway/transact.dll'
10
+ TEST = 'https://test.authorize.net/gateway/transact.dll'
11
+ CARD_PRESENT_LIVE = 'https://cardpresent.authorize.net/gateway/transact.dll'
12
+ CARD_PRESENT_TEST = 'https://test.authorize.net/gateway/transact.dll'
13
+ end
14
+
15
+ # Constants for both the various Authorize.Net payment transaction types are defined here.
16
+ module Type
17
+ AUTHORIZE_AND_CAPTURE = "AUTH_CAPTURE"
18
+ AUTHORIZE_ONLY = "AUTH_ONLY"
19
+ CAPTURE_ONLY = "CAPTURE_ONLY"
20
+ CREDIT = "CREDIT"
21
+ PRIOR_AUTHORIZATION_AND_CAPTURE = "PRIOR_AUTH_CAPTURE"
22
+ VOID = "VOID"
23
+ end
24
+
25
+ # Constants for the various device types used in card present transactions.
26
+ module DeviceType
27
+ UNKNOWN = 1
28
+ UNATTENDED = 2
29
+ SELF_SERVICE = 3
30
+ CASH_REGISTER = 4
31
+ PC_TERMINAL = 5
32
+ AIRPAY = 6
33
+ WIRELESS_POS = 7
34
+ WEBSITE_TERMINAL = 8
35
+ DIAL_TERMINAL = 9
36
+ VIRTUAL_TERMINAL = 10
37
+ end
38
+
39
+ # Constants for the various market types used in card present transactions.
40
+ module MarketType
41
+ RETAIL = 2
42
+ end
43
+
44
+ # The default options for purchase.
45
+ @@purchase_option_defaults = {
46
+ :cardholder_auth_value => nil,
47
+ :cardholder_auth_indicator => nil
48
+ }
49
+
50
+ # The default options for authorize.
51
+ @@authorize_option_defaults = {
52
+ :cardholder_auth_value => nil,
53
+ :cardholder_auth_indicator => nil
54
+ }
55
+
56
+ # Fields to convert to/from booleans.
57
+ @@boolean_fields = []
58
+
59
+ # Fields to convert to/from BigDecimal.
60
+ @@decimal_fields = []
61
+
62
+ # DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction instead.
63
+ def initialize()
64
+ super
65
+ @custom_fields ||= {}
66
+ @test_mode ||= false
67
+ @version = '3.1'
68
+ end
69
+
70
+ # Checks if the transaction has been configured for test mode or not. Return TRUE if the
71
+ # transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
72
+ # are considered test transactions.
73
+ def test?
74
+ !!@test_mode
75
+ end
76
+
77
+ # Returns the current API version that we are adhering to
78
+ def version
79
+ @version
80
+ end
81
+
82
+ # Sets arbitrary custom fields, overwriting existing values if they exist. Takes a hash of key/value pairs,
83
+ # where the keys are the field names. You can set a field to Nil to unset it.
84
+ def set_custom_fields(fields = {})
85
+ @custom_fields.merge!(fields)
86
+ end
87
+
88
+ # Returns the current hash of custom fields.
89
+ def custom_fields
90
+ @custom_fields
91
+ end
92
+
93
+ # Convenience method for adding line items to a transaction.
94
+ def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil)
95
+ line_item = "#{id}<|>#{name}<|>#{description}<|>#{quantity}<|>#{price}<|>#{taxable}"
96
+ if @fields.has_key?(:line_item)
97
+ @fields[:line_item] = @fields[:line_item].to_a << line_item
98
+ else
99
+ @fields[:line_item] = [line_item]
100
+ end
101
+ end
102
+
103
+ # Takes an instance of AuthorizeNet::EmailReceipt and adds it to the transaction.
104
+ def set_email_receipt(email)
105
+ @fields.merge!(email.to_hash)
106
+ end
107
+
108
+ # Returns the type of transaction.
109
+ def type
110
+ @type
111
+ end
112
+
113
+ # Sets the type of transaction.
114
+ def type=(type)
115
+ case type
116
+ when :authorize, :auth_only
117
+ @type = Type::AUTHORIZE_ONLY
118
+ when :purchase, :auth_and_capture
119
+ @type = Type::AUTHORIZE_AND_CAPTURE
120
+ when :refund, :credit
121
+ @type = Type::CREDIT
122
+ when :void
123
+ @type = Type::VOID
124
+ when :capture, :capture_only
125
+ @type = Type::CAPTURE_ONLY
126
+ when :prior_auth_capture
127
+ @type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE
128
+ else
129
+ @type = type
130
+ end
131
+ end
132
+
133
+ # Sets up and submits a standard purchase (AUTHORIZE_AND_CAPTURE) transaction. Returns a response object. If the transaction
134
+ # has already been run, it will return nil.
135
+ #
136
+ # +amount+:: The amount to charge. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
137
+ # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields).
138
+ # +options+:: A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases.
139
+ #
140
+ #
141
+ # Typical usage:
142
+ #
143
+ # credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
144
+ # response = transaction.purchase(10.0, credit_card)
145
+ #
146
+ def purchase(amount, credit_card, options = {})
147
+ handle_payment_argument(credit_card)
148
+ options = @@purchase_option_defaults.merge(options)
149
+ handle_cavv_options(options)
150
+ set_fields(:amount => amount)
151
+ self.type = Type::AUTHORIZE_AND_CAPTURE
152
+ run
153
+ end
154
+
155
+ # Sets up and submits a refund (CREDIT) transaction. Returns a response object. If the transaction
156
+ # has already been run, it will return nil.
157
+ #
158
+ # +amount+:: The amount to refund. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
159
+ # +transaction+:: The transaction ID to apply the refund to. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
160
+ # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits. In many cases you only need the last 4 digits of the credit card here.
161
+ #
162
+ #
163
+ # Typical usage:
164
+ #
165
+ # response = transaction.refund(10.0, '123456789', '1212')
166
+ #
167
+ def refund(amount, transaction, credit_card)
168
+ handle_payment_argument(credit_card)
169
+ handle_transaction_argument(transaction)
170
+ set_fields(:amount => amount)
171
+ self.type = Type::CREDIT
172
+ run
173
+ end
174
+
175
+ # Sets up and submits a refund (CREDIT) transaction for a transaction that was not originally
176
+ # submitted via the payment gateway. Note that this is a special feature which requires your
177
+ # account to support ECC (expanded credits capability) transactions.
178
+ #
179
+ # +amount+:: The amount to refund. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
180
+ # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits.
181
+ #
182
+ # Typical usage:
183
+ #
184
+ # response = transaction.unlinked_credit(10.0, '4111111111111111')
185
+ #
186
+ def unlinked_credit(amount, credit_card)
187
+ handle_payment_argument(credit_card)
188
+ set_fields(:amount => amount)
189
+ self.type = Type::CREDIT
190
+ run
191
+ end
192
+
193
+ # Sets up and submits a void (VOID) transaction. Returns a response object. If the transaction
194
+ # has already been run, it will return nil. Note that you can only void unsettled transactions.
195
+ #
196
+ # +transaction+:: The transaction ID of the transaction to void. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
197
+ #
198
+ #
199
+ # Typical usage:
200
+ #
201
+ # response = transaction.void('123456789')
202
+ #
203
+ def void(transaction)
204
+ handle_transaction_argument(transaction)
205
+ self.type = Type::VOID
206
+ run
207
+ end
208
+
209
+ # Sets up and submits an authorize (AUTH_ONLY) transaction. Returns a response object. If the transaction
210
+ # has already been run, it will return nil. Use this to put a hold on funds, but don't actually charge
211
+ # the card yet.
212
+ #
213
+ # +amount+:: The amount to authorize. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
214
+ # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields).
215
+ # +options+:: A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases.
216
+ #
217
+ #
218
+ # Typical usage:
219
+ #
220
+ # credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
221
+ # response = transaction.authorize(10.0, credit_card)
222
+ #
223
+ def authorize(amount, credit_card, options = {})
224
+ handle_payment_argument(credit_card)
225
+ options = @@authorize_option_defaults.merge(options)
226
+ handle_cavv_options(options)
227
+ set_fields(:amount => amount)
228
+ self.type = Type::AUTHORIZE_ONLY
229
+ run
230
+ end
231
+
232
+ # Sets up and submits a capture (CAPTURE_ONLY) transaction. Returns a response object. If the transaction
233
+ # has already been run, it will return nil. Note that you can not capture a transaction that was made
234
+ # though the AIM API using this method. Use prior_auth_capture instead.
235
+ #
236
+ # +amount+:: The amount to capture. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
237
+ # +authorization_code+:: The authorization code of the transaction to capture. Accepts a string.
238
+ #
239
+ #
240
+ # Typical usage:
241
+ #
242
+ # response = transaction.capture(10.0, '123FAKE')
243
+ #
244
+ def capture(amount, authorization_code)
245
+ set_fields(:amount => amount, :auth_code => authorization_code)
246
+ self.type = Type::CAPTURE_ONLY
247
+ run
248
+ end
249
+
250
+ # Sets up and submits a capture (PRIOR_AUTH_CAPTURE) transaction. Returns a response object. Use this method
251
+ # to actually charge a card that you previously put a hold on (using authorize).
252
+ #
253
+ # +transaction+:: The transaction ID to capture. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
254
+ # +amount+:: The amount to capture (only if less than the amount originally authorized, otherwise leave as Nil). Accepts a string in the format "%0.2f", a Float, a BigDecimal or Nil.
255
+ #
256
+ #
257
+ # Typical usage:
258
+ #
259
+ # response = transaction.prior_auth_capture('123456789')
260
+ #
261
+ def prior_auth_capture(transaction, amount = nil)
262
+ handle_transaction_argument(transaction)
263
+ set_fields(:amount => amount)
264
+ self.type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE
265
+ run
266
+ end
267
+
268
+ #:enddoc:
269
+ protected
270
+
271
+ # Internal method to handle multiple types of transaction arguments.
272
+ def handle_transaction_argument(transaction)
273
+ case transaction
274
+ when Transaction
275
+ set_fields(:trans_id => transaction.response.transaction_id)
276
+ when Response
277
+ set_fields(:trans_id => transaction.transaction_id)
278
+ else
279
+ set_fields(:trans_id => transaction)
280
+ end
281
+ end
282
+
283
+ # Internal method to handle CAVV options.
284
+ def handle_cavv_options(options)
285
+ set_fields(:authentication_indicator => options[:cardholder_auth_indicator]) unless options[:cardholder_auth_indicator].nil?
286
+ set_fields(:cardholder_authentication_value => options[:cardholder_auth_value]) unless options[:cardholder_auth_value].nil?
287
+ end
288
+
289
+ end
290
+
291
291
  end