authorizenet_blaq 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/lib/app/helpers/authorize_net_helper.rb +24 -0
  3. data/lib/authorize_net/addresses/address.rb +29 -0
  4. data/lib/authorize_net/addresses/shipping_address.rb +26 -0
  5. data/lib/authorize_net/aim/response.rb +131 -0
  6. data/lib/authorize_net/aim/transaction.rb +190 -0
  7. data/lib/authorize_net/api/api_transaction.rb +123 -0
  8. data/lib/authorize_net/api/constants.yml +1 -0
  9. data/lib/authorize_net/api/schema.rb +4985 -0
  10. data/lib/authorize_net/api/transaction.rb +258 -0
  11. data/lib/authorize_net/arb/fields.rb +24 -0
  12. data/lib/authorize_net/arb/paging.rb +33 -0
  13. data/lib/authorize_net/arb/response.rb +34 -0
  14. data/lib/authorize_net/arb/sorting.rb +43 -0
  15. data/lib/authorize_net/arb/subscription.rb +72 -0
  16. data/lib/authorize_net/arb/subscription_detail.rb +14 -0
  17. data/lib/authorize_net/arb/subscription_list_response.rb +43 -0
  18. data/lib/authorize_net/arb/transaction.rb +177 -0
  19. data/lib/authorize_net/authorize_net.rb +154 -0
  20. data/lib/authorize_net/cim/customer_profile.rb +19 -0
  21. data/lib/authorize_net/cim/payment_profile.rb +37 -0
  22. data/lib/authorize_net/cim/response.rb +116 -0
  23. data/lib/authorize_net/cim/transaction.rb +727 -0
  24. data/lib/authorize_net/customer.rb +27 -0
  25. data/lib/authorize_net/email_receipt.rb +24 -0
  26. data/lib/authorize_net/fields.rb +779 -0
  27. data/lib/authorize_net/key_value_response.rb +117 -0
  28. data/lib/authorize_net/key_value_transaction.rb +291 -0
  29. data/lib/authorize_net/line_item.rb +25 -0
  30. data/lib/authorize_net/order.rb +42 -0
  31. data/lib/authorize_net/payment_methods/credit_card.rb +62 -0
  32. data/lib/authorize_net/payment_methods/echeck.rb +72 -0
  33. data/lib/authorize_net/reporting/batch.rb +19 -0
  34. data/lib/authorize_net/reporting/batch_statistics.rb +19 -0
  35. data/lib/authorize_net/reporting/fds_filter.rb +11 -0
  36. data/lib/authorize_net/reporting/response.rb +163 -0
  37. data/lib/authorize_net/reporting/returned_item.rb +46 -0
  38. data/lib/authorize_net/reporting/transaction.rb +133 -0
  39. data/lib/authorize_net/reporting/transaction_details.rb +25 -0
  40. data/lib/authorize_net/response.rb +27 -0
  41. data/lib/authorize_net/sim/hosted_payment_form.rb +38 -0
  42. data/lib/authorize_net/sim/hosted_receipt_page.rb +37 -0
  43. data/lib/authorize_net/sim/response.rb +142 -0
  44. data/lib/authorize_net/sim/transaction.rb +138 -0
  45. data/lib/authorize_net/transaction.rb +66 -0
  46. data/lib/authorize_net/xml_response.rb +172 -0
  47. data/lib/authorize_net/xml_transaction.rb +298 -0
  48. data/lib/authorize_net.rb +107 -0
  49. data/lib/authorizenet_blaq.rb +4 -0
  50. data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +53 -0
  51. data/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +49 -0
  52. data/lib/generators/authorize_net/direct_post/templates/config.yml.erb +8 -0
  53. data/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +8 -0
  54. data/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +31 -0
  55. data/lib/generators/authorize_net/direct_post/templates/initializer.rb +4 -0
  56. data/lib/generators/authorize_net/direct_post/templates/layout.erb +18 -0
  57. data/lib/generators/authorize_net/direct_post/templates/payment.erb +10 -0
  58. data/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +10 -0
  59. data/lib/generators/authorize_net/direct_post/templates/receipt.erb +1 -0
  60. data/lib/generators/authorize_net/direct_post/templates/relay_response.erb +1 -0
  61. data/lib/generators/authorize_net/sim/sim_generator.rb +47 -0
  62. data/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +52 -0
  63. data/lib/generators/authorize_net/sim/templates/config.yml.erb +8 -0
  64. data/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +8 -0
  65. data/lib/generators/authorize_net/sim/templates/controller.rb.erb +21 -0
  66. data/lib/generators/authorize_net/sim/templates/initializer.rb +4 -0
  67. data/lib/generators/authorize_net/sim/templates/layout.erb +18 -0
  68. data/lib/generators/authorize_net/sim/templates/payment.erb +6 -0
  69. data/lib/generators/authorize_net/sim/templates/payment.rails3.erb +6 -0
  70. data/lib/generators/authorize_net/sim/templates/thank_you.erb +1 -0
  71. data/lib/generators/generator_extensions.rb +75 -0
  72. metadata +196 -0
@@ -0,0 +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
+
117
+ end
@@ -0,0 +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
+
291
+ end
@@ -0,0 +1,25 @@
1
+ module AuthorizeNet
2
+
3
+ # Models an line item.
4
+ class LineItem
5
+
6
+ include AuthorizeNet::Model
7
+
8
+ attr_accessor :id, :name, :description, :quantity, :price, :taxable
9
+
10
+ def to_hash
11
+ hash = {
12
+ :line_item_id => @id,
13
+ :line_item_name => @name,
14
+ :line_item_description => @description,
15
+ :line_item_quantity => @quantity,
16
+ :line_item_unit_price => @price,
17
+ :line_item_taxable => @taxable
18
+ }
19
+ hash.delete_if {|k, v| v.nil?}
20
+ hash
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,42 @@
1
+ module AuthorizeNet
2
+
3
+ # Models an order.
4
+ class Order
5
+
6
+ include AuthorizeNet::Model
7
+
8
+ attr_accessor :invoice_num, :description, :tax, :tax_name, :tax_description, :freight, :freight_name, :freight_description, :duty, :duty_name, :duty_description, :tax_exempt, :po_num, :line_items
9
+
10
+ def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil)
11
+ if id.kind_of?(AuthorizeNet::LineItem)
12
+ line_item = id
13
+ else
14
+ line_item = AuthorizeNet::LineItem.new({:id => id, :name => name, :description => description, :quantity => quantity, :price => price, :taxable => taxable})
15
+ end
16
+ @line_items = @line_items.to_a << line_item
17
+ end
18
+
19
+ def to_hash
20
+ hash = {
21
+ :invoice_num => @invoice_num,
22
+ :description => @description,
23
+ :tax => @tax,
24
+ :tax_name => @tax_name,
25
+ :tax_description => @tax_description,
26
+ :freight => @freight,
27
+ :freight_name => @freight_name,
28
+ :freight_description => @freight_description,
29
+ :duty => @duty,
30
+ :duty_name => @duty_name,
31
+ :duty_description => @duty_description,
32
+ :tax_exempt => @tax_exempt,
33
+ :po_num => @po_num,
34
+ :line_items => handle_multivalue_hashing(@line_items)
35
+ }
36
+ hash.delete_if {|k, v| v.nil?}
37
+ hash
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,62 @@
1
+ module AuthorizeNet
2
+
3
+ # Defines constants for each payment method type.
4
+ module PaymentMethodType
5
+ CREDIT_CARD = 'CC'
6
+ end
7
+
8
+ # Models a credit card.
9
+ class CreditCard
10
+ PAYMENT_METHOD_CODE = AuthorizeNet::PaymentMethodType::CREDIT_CARD
11
+
12
+ # The option defaults for the constructor.
13
+ @@option_defaults = {
14
+ :card_code => nil,
15
+ :card_type => nil
16
+ }
17
+
18
+ attr_accessor :card_number, :expiration, :card_code, :card_type, :track_1, :track_2
19
+
20
+ # Constructs a new credit card object. Takes a credit card number
21
+ # and an expiration date. The CCV code can be passed as an option. So can
22
+ # the data tracks (1 & 2). When passing in data tracks, please pass the
23
+ # whole track. Sentinels and the LRC will be removed by the SDK. Track data
24
+ # must be passed along as ASCII. The raw bit stream from the card is not acceptable.
25
+ #
26
+ # Field separators on
27
+ #
28
+ # +card_number+:: The credit card number as a string.
29
+ # +expiration+:: The credit card expiration date as a string with format MMYY.
30
+ # +options+:: A hash of options.
31
+ #
32
+ # Options
33
+ # +card_code+:: Sets the CCV code for the credit card.
34
+ # +card_type+:: Sets the type of card (Visa, MasterCard, Dinners Club, etc.)
35
+ # +track_1+:: Sets the track 1 data. Either track 1 or track 2 data needs to be included for card present transactions (otherwise fee structure will change).
36
+ # +track_2+:: Sets the track 2 data. Either track 1 or track 2 data needs to be included for card present transactions (otherwise fee structure will change).
37
+ #
38
+ #
39
+ def initialize(card_number, expiration, options = {})
40
+ @card_number = card_number
41
+ @expiration = expiration
42
+ options = @@option_defaults.merge(options)
43
+ @card_code = options[:card_code]
44
+ @card_type = options[:card_type]
45
+ @track_1 = options[:track_1]
46
+ @track_2 = options[:track_2]
47
+ end
48
+
49
+ def to_hash
50
+ Hash.new.tap do |ch|
51
+ ch[:method] = PAYMENT_METHOD_CODE
52
+ ch[:card_num] = @card_number
53
+ ch[:exp_date] = @expiration
54
+ ch[:card_code] = @card_code if @card_code
55
+ ch[:track1] = @track_1.match(/(%|^)(.*?)(\?|$)/)[2] if @track_1
56
+ ch[:track2] = @track_2.match(/(;|^)(.*?)(\?|$)/)[2] if @track_2
57
+ #ch[:track1] = @track_1.match(/^%(?<fc>.)(?<p>[\d]{1,19}+)\^(?<n>.{2,26})\^(?<e>[\d]{0,4}|\^)(?<sc>[\d]{0,3}|\^)(?<dd>.*)\?\Z/) if @track_1
58
+ #ch[:track2] = @track_2.match(/\A;(?<pan>[\d]{1,19}+)=(?<expiration>[\d]{0,4}|=)(?<service_code>[\d]{0,3}|=)(?<discretionary_data>.*)\?\Z/) if @track_2
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,72 @@
1
+ module AuthorizeNet
2
+
3
+ # Defines constants for each payment method type.
4
+ module PaymentMethodType
5
+ ECHECK = 'ECHECK'
6
+ end
7
+
8
+ # Models an eCheck.
9
+ class ECheck
10
+ PAYMENT_METHOD_CODE = AuthorizeNet::PaymentMethodType::ECHECK
11
+
12
+ # Defines constants for each bank account type.
13
+ module AccountType
14
+ CHECKING = 'CHECKING'
15
+ SAVINGS = 'SAVINGS'
16
+ BUSINESS_CHECKING = 'BUSINESSCHECKING'
17
+ end
18
+
19
+ # Defines constants for each check type.
20
+ module CheckType
21
+ ACCOUNTS_RECEIVABLE_CONVERSION = 'ARC'
22
+ BACK_OFFICE_CONVERSION = 'BOC'
23
+ CASH_CONCENTRATION_DISBURSEMENT = 'CCD'
24
+ PREARRANGED_PAYMENT_DEPOSIT = 'PPD'
25
+ TELEPHONE_INITIATED = 'TEL'
26
+ INTERNET_INITIATED = 'WEB'
27
+ end
28
+
29
+ # The option defaults for the constructor.
30
+ @@option_defaults = {
31
+ :echeck_type => CheckType::INTERNET_INITIATED,
32
+ :check_number => nil,
33
+ :account_type => AccountType::CHECKING
34
+ }
35
+
36
+ attr_accessor :routing_number, :account_number, :bank_name, :account_holder_name, :echeck_type, :check_number, :account_type
37
+
38
+ # Constructs a new eCheck object.
39
+ #
40
+ # +routing_number+:: The bank routing number as a string.
41
+ # +account_number+:: The bank account number as a string.
42
+ # +bank_name+:: The legal name of the bank. This should match the name associated with the +routing_number+.
43
+ # +account_holder_name+:: The full name on the bank account represented by +account_number+.
44
+ # +options+:: A hash of options. Accepts +echeck_type+ (the type of check, can usually be ignored), +check_number+ (the number on the check, only needed for some check types), and +account_type+ (the type of bank account the check draws from). All values should be passed as strings.
45
+ #
46
+ def initialize(routing_number, account_number, bank_name, account_holder_name, options = {})
47
+ @routing_number = routing_number
48
+ @account_number = account_number
49
+ @bank_name = bank_name
50
+ @account_holder_name = account_holder_name
51
+ options = @@option_defaults.merge(options)
52
+ @echeck_type = options[:echeck_type]
53
+ @check_number = options[:check_number]
54
+ @account_type = options[:account_type]
55
+ end
56
+
57
+ def to_hash
58
+ hash = {
59
+ :method => PAYMENT_METHOD_CODE,
60
+ :bank_aba_code => @routing_number,
61
+ :bank_acct_num => @account_number,
62
+ :bank_acct_type => @account_type,
63
+ :bank_name => @bank_name,
64
+ :bank_acct_name => @account_holder_name,
65
+ :echeck_type => @echeck_type
66
+ }
67
+ hash[:bank_check_number] = @check_number unless @check_number.nil?
68
+ hash
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,19 @@
1
+ module AuthorizeNet::Reporting
2
+
3
+ # Models a batch of credit cards.
4
+ class Batch
5
+
6
+ include AuthorizeNet::Model
7
+
8
+ attr_accessor :id, :settled_at, :state, :statistics, :payment_method
9
+
10
+ def settled_at=(time)
11
+ if time.kind_of?(DateTime)
12
+ @settled_at = time
13
+ else
14
+ @settled_at = DateTime.parse(time.to_s)
15
+ end
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ module AuthorizeNet::Reporting
2
+
3
+ # Models a batch of credit cards.
4
+ class BatchStatistics
5
+
6
+ include AuthorizeNet::Model
7
+
8
+ attr_accessor :account_type, :charge_count, :charge_amount, :refund_count,
9
+ :refund_amount, :void_count, :decline_count, :error_count,
10
+ :returned_item_amount, :returned_item_count, :chargeback_count,
11
+ :chargeback_amount, :correction_notice_count, :charge_chageback_count,
12
+ :charge_chargeback_amount, :refund_chargeback_amount,
13
+ :refund_chargeback_count, :charge_returned_items_amount,
14
+ :charge_returned_items_count, :refund_returned_items_amount,
15
+ :refund_returned_items_count
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,11 @@
1
+ module AuthorizeNet::Reporting
2
+
3
+ # Models a fraud detection filter.
4
+ class FDSFilter
5
+
6
+ include AuthorizeNet::Model
7
+
8
+ attr_accessor :name, :action
9
+ end
10
+
11
+ end