authorize-net 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/License.pdf +0 -0
  2. data/README.rdoc +124 -0
  3. data/Rakefile +74 -0
  4. data/generators/authorize_net_direct_post/USAGE +20 -0
  5. data/generators/authorize_net_direct_post/authorize_net_direct_post_generator.rb +21 -0
  6. data/generators/authorize_net_direct_post/templates/README-AuthorizeNet +49 -0
  7. data/generators/authorize_net_direct_post/templates/config.yml.erb +8 -0
  8. data/generators/authorize_net_direct_post/templates/config.yml.rails3.erb +8 -0
  9. data/generators/authorize_net_direct_post/templates/controller.rb.erb +31 -0
  10. data/generators/authorize_net_direct_post/templates/initializer.rb +4 -0
  11. data/generators/authorize_net_direct_post/templates/layout.erb +18 -0
  12. data/generators/authorize_net_direct_post/templates/payment.erb +10 -0
  13. data/generators/authorize_net_direct_post/templates/payment.rails3.erb +10 -0
  14. data/generators/authorize_net_direct_post/templates/receipt.erb +1 -0
  15. data/generators/authorize_net_direct_post/templates/relay_response.erb +1 -0
  16. data/generators/authorize_net_sim/USAGE +20 -0
  17. data/generators/authorize_net_sim/authorize_net_sim_generator.rb +19 -0
  18. data/generators/authorize_net_sim/templates/README-AuthorizeNet +52 -0
  19. data/generators/authorize_net_sim/templates/config.yml.erb +8 -0
  20. data/generators/authorize_net_sim/templates/config.yml.rails3.erb +8 -0
  21. data/generators/authorize_net_sim/templates/controller.rb.erb +21 -0
  22. data/generators/authorize_net_sim/templates/initializer.rb +4 -0
  23. data/generators/authorize_net_sim/templates/layout.erb +18 -0
  24. data/generators/authorize_net_sim/templates/payment.erb +6 -0
  25. data/generators/authorize_net_sim/templates/payment.rails3.erb +6 -0
  26. data/generators/authorize_net_sim/templates/thank_you.erb +1 -0
  27. data/generators/generator_extensions.rb +75 -0
  28. data/init.rb +2 -0
  29. data/install.rb +1 -0
  30. data/lib/app/helpers/authorize_net_helper.rb +24 -0
  31. data/lib/authorize-net.rb +4 -0
  32. data/lib/authorize_net.rb +92 -0
  33. data/lib/authorize_net/addresses/address.rb +29 -0
  34. data/lib/authorize_net/addresses/shipping_address.rb +26 -0
  35. data/lib/authorize_net/aim/response.rb +131 -0
  36. data/lib/authorize_net/aim/transaction.rb +184 -0
  37. data/lib/authorize_net/arb/response.rb +34 -0
  38. data/lib/authorize_net/arb/subscription.rb +72 -0
  39. data/lib/authorize_net/arb/transaction.rb +146 -0
  40. data/lib/authorize_net/authorize_net.rb +154 -0
  41. data/lib/authorize_net/cim/customer_profile.rb +19 -0
  42. data/lib/authorize_net/cim/payment_profile.rb +37 -0
  43. data/lib/authorize_net/cim/response.rb +110 -0
  44. data/lib/authorize_net/cim/transaction.rb +678 -0
  45. data/lib/authorize_net/customer.rb +27 -0
  46. data/lib/authorize_net/email_receipt.rb +24 -0
  47. data/lib/authorize_net/fields.rb +736 -0
  48. data/lib/authorize_net/key_value_response.rb +117 -0
  49. data/lib/authorize_net/key_value_transaction.rb +291 -0
  50. data/lib/authorize_net/line_item.rb +25 -0
  51. data/lib/authorize_net/order.rb +42 -0
  52. data/lib/authorize_net/payment_methods/credit_card.rb +74 -0
  53. data/lib/authorize_net/payment_methods/echeck.rb +72 -0
  54. data/lib/authorize_net/reporting/batch.rb +19 -0
  55. data/lib/authorize_net/reporting/batch_statistics.rb +19 -0
  56. data/lib/authorize_net/reporting/fds_filter.rb +11 -0
  57. data/lib/authorize_net/reporting/response.rb +127 -0
  58. data/lib/authorize_net/reporting/transaction.rb +116 -0
  59. data/lib/authorize_net/reporting/transaction_details.rb +25 -0
  60. data/lib/authorize_net/response.rb +27 -0
  61. data/lib/authorize_net/sim/hosted_payment_form.rb +38 -0
  62. data/lib/authorize_net/sim/hosted_receipt_page.rb +37 -0
  63. data/lib/authorize_net/sim/response.rb +142 -0
  64. data/lib/authorize_net/sim/transaction.rb +138 -0
  65. data/lib/authorize_net/transaction.rb +66 -0
  66. data/lib/authorize_net/xml_response.rb +172 -0
  67. data/lib/authorize_net/xml_transaction.rb +275 -0
  68. data/lib/generators/authorize_net/direct_post_generator.rb +51 -0
  69. data/lib/generators/authorize_net/sim_generator.rb +47 -0
  70. data/spec/aim_spec.rb +310 -0
  71. data/spec/arb_spec.rb +191 -0
  72. data/spec/authorize_net_spec.rb +200 -0
  73. data/spec/cim_spec.rb +450 -0
  74. data/spec/reporting_spec.rb +431 -0
  75. data/spec/sim_spec.rb +97 -0
  76. data/spec/spec.opts +5 -0
  77. data/spec/spec_helper.rb +2 -0
  78. data/uninstall.rb +1 -0
  79. metadata +223 -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://secure.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_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({:line_item_id => id, :line_item_name => name, :line_item_description => description, :line_item_quantity => quantity, :line_item_price => price, :line_item_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