authorize-net 1.5.2

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 (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,431 @@
1
+ require "spec_helper"
2
+
3
+ describe AuthorizeNet::Reporting do
4
+ before :all do
5
+ begin
6
+ creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
7
+ @api_key = creds['api_transaction_key']
8
+ @api_login = creds['api_login_id']
9
+ rescue Errno::ENOENT => e
10
+ @api_key = "TEST"
11
+ @api_login = "TEST"
12
+ warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
13
+ end
14
+ end
15
+
16
+ it "should support instantiation" do
17
+ transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
18
+ transaction.should be_kind_of(AuthorizeNet::Reporting::Transaction)
19
+ end
20
+
21
+ it "should be able to fetch a list of settled batches" do
22
+ transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
23
+ transaction.should respond_to(:get_settled_batch_list)
24
+ response = transaction.get_settled_batch_list
25
+ response.success?.should be_true
26
+ response.should respond_to(:batch_list)
27
+ end
28
+
29
+ it "should be able to fetch a list of settled batches with start and end dates" do
30
+ transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
31
+ transaction.should respond_to(:get_settled_batch_list)
32
+ response = transaction.get_settled_batch_list(Time.now() - (1 * 3600 * 12), Time.now())
33
+ response.success?.should be_true
34
+ response.should respond_to(:batch_list)
35
+ end
36
+
37
+ it "should be able to fetch a list of settled batches with statistics" do
38
+ transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
39
+ transaction.should respond_to(:get_settled_batch_list)
40
+ response = transaction.get_settled_batch_list(nil, nil, true)
41
+ response.success?.should be_true
42
+ response.should respond_to(:batch_list)
43
+ end
44
+
45
+ it "should be able to fetch a transaction list" do
46
+ transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
47
+ transaction.should respond_to(:get_transaction_list)
48
+ response = transaction.get_transaction_list('111111')
49
+ response.success?.should be_true
50
+ response.should respond_to(:transactions)
51
+ end
52
+
53
+ it "should be able to fetch transaction details" do
54
+ # create a transaction to fetch
55
+ transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
56
+ credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
57
+ transaction.set_fields(:duplicate_window => 0)
58
+ response = transaction.purchase(10.0, credit_card)
59
+
60
+ # fetch the transaction
61
+ transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
62
+ transaction.should respond_to(:get_transaction_details)
63
+ response = transaction.get_transaction_details(response.transaction_id)
64
+ response.success?.should be_true
65
+ response.should respond_to(:transaction)
66
+ end
67
+
68
+ describe "parsing batch statistics" do
69
+ before do
70
+ @response = '<getSettledBatchListResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
71
+ <messages>
72
+ <resultCode>Ok</resultCode>
73
+ <message>
74
+ <code>I00001</code>
75
+ <text>Successful.</text>
76
+ </message>
77
+ </messages>
78
+ <batchList>
79
+ <batch>
80
+ <batchId>834677</batchId>
81
+ <settlementTimeUTC>2010-12-07T23:57:05Z</settlementTimeUTC>
82
+ <settlementTimeLocal>2010-12-07T15:57:05</settlementTimeLocal>
83
+ <settlementState>settledSuccessfully</settlementState>
84
+ <paymentMethod>creditCard</paymentMethod>
85
+ <statistics>
86
+ <statistic>
87
+ <accountType>Visa</accountType>
88
+ <chargeAmount>799.92</chargeAmount>
89
+ <chargeCount>17</chargeCount>
90
+ <refundAmount>0.00</refundAmount>
91
+ <refundCount>0</refundCount>
92
+ <voidCount>4</voidCount>
93
+ <declineCount>0</declineCount>
94
+ <errorCount>0</errorCount>
95
+ </statistic>
96
+ </statistics>
97
+ </batch>
98
+ <batch>
99
+ <batchId>834801</batchId>
100
+ <settlementTimeUTC>2010-12-08T00:17:57Z</settlementTimeUTC>
101
+ <settlementTimeLocal>2010-12-07T16:17:57</settlementTimeLocal>
102
+ <settlementState>settledSuccessfully</settlementState>
103
+ <paymentMethod>creditCard</paymentMethod>
104
+ <statistics>
105
+ <statistic>
106
+ <accountType>Visa</accountType>
107
+ <chargeAmount>594.77</chargeAmount>
108
+ <chargeCount>16</chargeCount>
109
+ <refundAmount>0.00</refundAmount>
110
+ <refundCount>0</refundCount>
111
+ <voidCount>4</voidCount>
112
+ <declineCount>0</declineCount>
113
+ <errorCount>0</errorCount>
114
+ </statistic>
115
+ </statistics>
116
+ </batch>
117
+ <batch>
118
+ <batchId>835158</batchId>
119
+ <settlementTimeUTC>2010-12-08T00:29:31Z</settlementTimeUTC>
120
+ <settlementTimeLocal>2010-12-07T16:29:31</settlementTimeLocal>
121
+ <settlementState>settledSuccessfully</settlementState>
122
+ <paymentMethod>creditCard</paymentMethod>
123
+ <statistics>
124
+ <statistic>
125
+ <accountType>Visa</accountType>
126
+ <chargeAmount>786.22</chargeAmount>
127
+ <chargeCount>17</chargeCount>
128
+ <refundAmount>0.00</refundAmount>
129
+ <refundCount>0</refundCount>
130
+ <voidCount>4</voidCount>
131
+ <declineCount>0</declineCount>
132
+ <errorCount>0</errorCount>
133
+ </statistic>
134
+ </statistics>
135
+ </batch>
136
+ <batch>
137
+ <batchId>835509</batchId>
138
+ <settlementTimeUTC>2010-12-08T09:40:51Z</settlementTimeUTC>
139
+ <settlementTimeLocal>2010-12-08T01:40:51</settlementTimeLocal>
140
+ <settlementState>settledSuccessfully</settlementState>
141
+ <paymentMethod>creditCard</paymentMethod>
142
+ <statistics>
143
+ <statistic>
144
+ <accountType>Visa</accountType>
145
+ <chargeAmount>180.00</chargeAmount>
146
+ <chargeCount>18</chargeCount>
147
+ <refundAmount>0.00</refundAmount>
148
+ <refundCount>0</refundCount>
149
+ <voidCount>0</voidCount>
150
+ <declineCount>0</declineCount>
151
+ <errorCount>0</errorCount>
152
+ </statistic>
153
+ </statistics>
154
+ </batch>
155
+ <batch>
156
+ <batchId>835896</batchId>
157
+ <settlementTimeUTC>2010-12-08T17:21:43Z</settlementTimeUTC>
158
+ <settlementTimeLocal>2010-12-08T09:21:43</settlementTimeLocal>
159
+ <settlementState>settledSuccessfully</settlementState>
160
+ <paymentMethod>creditCard</paymentMethod>
161
+ <statistics>
162
+ <statistic>
163
+ <accountType>Visa</accountType>
164
+ <chargeAmount>3357.32</chargeAmount>
165
+ <chargeCount>67</chargeCount>
166
+ <refundAmount>0.00</refundAmount>
167
+ <refundCount>0</refundCount>
168
+ <voidCount>16</voidCount>
169
+ <declineCount>1</declineCount>
170
+ <errorCount>0</errorCount>
171
+ </statistic>
172
+ </statistics>
173
+ </batch>
174
+ <batch>
175
+ <batchId>836099</batchId>
176
+ <settlementTimeUTC>2010-12-08T19:52:26Z</settlementTimeUTC>
177
+ <settlementTimeLocal>2010-12-08T11:52:26</settlementTimeLocal>
178
+ <settlementState>settledSuccessfully</settlementState>
179
+ <paymentMethod>creditCard</paymentMethod>
180
+ <statistics>
181
+ <statistic>
182
+ <accountType>Visa</accountType>
183
+ <chargeAmount>973.24</chargeAmount>
184
+ <chargeCount>17</chargeCount>
185
+ <refundAmount>0.00</refundAmount>
186
+ <refundCount>0</refundCount>
187
+ <voidCount>4</voidCount>
188
+ <declineCount>0</declineCount>
189
+ <errorCount>0</errorCount>
190
+ </statistic>
191
+ <statistic>
192
+ <accountType>MasterCard</accountType>
193
+ <chargeAmount>973.24</chargeAmount>
194
+ <chargeCount>17</chargeCount>
195
+ <refundAmount>0.00</refundAmount>
196
+ <refundCount>0</refundCount>
197
+ <voidCount>4</voidCount>
198
+ <declineCount>0</declineCount>
199
+ <errorCount>0</errorCount>
200
+ </statistic>
201
+ </statistics>
202
+ </batch>
203
+ </batchList>
204
+ </getSettledBatchListResponse>'
205
+ end
206
+
207
+ it "should be able to build a batch statistics entity" do
208
+ # stub our connection response
209
+ net_response = Net::HTTPOK.new('1.1', 200, 'OK')
210
+ net_response.stub!(:body).and_return(@response)
211
+ connection = Net::HTTP.new('http://www.example.com')
212
+ connection.stub!(:start).and_return(net_response)
213
+ Net::HTTP.stub!(:new).and_return(connection)
214
+
215
+ transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
216
+ transaction.should respond_to(:get_settled_batch_list)
217
+ response = transaction.get_settled_batch_list(nil, nil, true)
218
+ response.success?.should be_true
219
+ response.should respond_to(:batch_list)
220
+ batches = response.batch_list
221
+ batches.length.should == 6
222
+ batches.each do |batch|
223
+ batch.statistics.should be_kind_of(Array)
224
+ batch.statistics[0].should be_kind_of(AuthorizeNet::Reporting::BatchStatistics)
225
+ if batch.id == '836099'
226
+ batch.statistics.length.should == 2
227
+ batch.statistics[1].account_type.should == 'MasterCard'
228
+ batch.payment_method.should == 'creditCard'
229
+ batch.statistics[1].charge_amount.should == 973.24
230
+ batch.statistics[1].void_count.should == 4
231
+ end
232
+ end
233
+ end
234
+ end
235
+
236
+ describe "parsing transaction details" do
237
+ it "should be able to build a transaction details object from the transaction list response" do
238
+ @response = '<getTransactionListResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
239
+ <messages>
240
+ <resultCode>Ok</resultCode>
241
+ <message>
242
+ <code>I00001</code>
243
+ <text>Successful.</text>
244
+ </message>
245
+ </messages>
246
+ <transactions>
247
+ <transaction>
248
+ <transId>2156238989</transId>
249
+ <submitTimeUTC>2010-12-07T23:50:02Z</submitTimeUTC>
250
+ <submitTimeLocal>2010-12-07T15:50:02</submitTimeLocal>
251
+ <transactionStatus>settledSuccessfully</transactionStatus>
252
+ <accountType>Visa</accountType>
253
+ <accountNumber>XXXX1111</accountNumber>
254
+ <settleAmount>38.37</settleAmount>
255
+ </transaction>
256
+ <transaction>
257
+ <transId>2156238988</transId>
258
+ <submitTimeUTC>2010-12-07T23:50:01Z</submitTimeUTC>
259
+ <submitTimeLocal>2010-12-07T15:50:01</submitTimeLocal>
260
+ <transactionStatus>voided</transactionStatus>
261
+ <accountType>Visa</accountType>
262
+ <accountNumber>XXXX1111</accountNumber>
263
+ <settleAmount>0.00</settleAmount>
264
+ </transaction>
265
+ <transaction>
266
+ <transId>2156246780</transId>
267
+ <submitTimeUTC>2010-12-08T09:31:01Z</submitTimeUTC>
268
+ <submitTimeLocal>2010-12-08T01:31:01</submitTimeLocal>
269
+ <transactionStatus>settledSuccessfully</transactionStatus>
270
+ <invoiceNumber>0.0119129953556076</invoiceNumber>
271
+ <firstName>John</firstName>
272
+ <lastName>Doe</lastName>
273
+ <accountType>Visa</accountType>
274
+ <accountNumber>XXXX1111</accountNumber>
275
+ <settleAmount>10.00</settleAmount>
276
+ </transaction>
277
+ </transactions>
278
+ </getTransactionListResponse>'
279
+
280
+ # stub our connection response
281
+ net_response = Net::HTTPOK.new('1.1', 200, 'OK')
282
+ net_response.stub!(:body).and_return(@response)
283
+ connection = Net::HTTP.new('http://www.example.com')
284
+ connection.stub!(:start).and_return(net_response)
285
+ Net::HTTP.stub!(:new).and_return(connection)
286
+
287
+ transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
288
+ transaction.should respond_to(:get_transaction_list)
289
+ response = transaction.get_settled_batch_list('111111')
290
+ response.success?.should be_true
291
+ response.should respond_to(:transactions)
292
+ transactions = response.transactions
293
+ transactions.length.should == 3
294
+ transactions[0].account_type.should == 'Visa'
295
+ transactions[0].settle_amount.should == 38.37
296
+ transactions[0].submitted_at.should == DateTime.parse('2010-12-07T23:50:02Z')
297
+ transactions[0].status = 'voided'
298
+ customer = transactions[2].customer
299
+ customer.nil?.should be_false
300
+ customer.address.nil?.should be_false
301
+ customer.address.first_name.should == 'John'
302
+ customer.address.last_name.should == 'Doe'
303
+ order = transactions[2].order
304
+ order.nil?.should be_false
305
+ order.invoice_num.should == '0.0119129953556076'
306
+ end
307
+
308
+ it "should be able to build a transaction details object from the transaction details response" do
309
+ @response = '<getTransactionDetailsResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
310
+ <messages>
311
+ <resultCode>Ok</resultCode>
312
+ <message>
313
+ <code>I00001</code>
314
+ <text>Successful.</text>
315
+ </message>
316
+ </messages>
317
+ <transaction>
318
+ <transId>2156246780</transId>
319
+ <submitTimeUTC>2010-12-08T09:31:01.01Z</submitTimeUTC>
320
+ <submitTimeLocal>2010-12-08T01:31:01.01</submitTimeLocal>
321
+ <transactionType>authCaptureTransaction</transactionType>
322
+ <transactionStatus>settledSuccessfully</transactionStatus>
323
+ <responseCode>1</responseCode>
324
+ <responseReasonCode>1</responseReasonCode>
325
+ <responseReasonDescription>Approval</responseReasonDescription>
326
+ <authCode>5N3WKF</authCode>
327
+ <AVSResponse>Y</AVSResponse>
328
+ <batch>
329
+ <batchId>835509</batchId>
330
+ <settlementTimeUTC>2010-12-08T09:40:51.12Z</settlementTimeUTC>
331
+ <settlementTimeLocal>2010-12-08T01:40:51.12</settlementTimeLocal>
332
+ <settlementState>settledSuccessfully</settlementState>
333
+ </batch>
334
+ <order>
335
+ <invoiceNumber>0.0119129953556076</invoiceNumber>
336
+ <description>a test subscription</description>
337
+ </order>
338
+ <authAmount>10.00</authAmount>
339
+ <settleAmount>10.00</settleAmount>
340
+ <lineItems>
341
+ <lineItem>
342
+ <itemId>ITEM00001</itemId>
343
+ <name>name of item sold</name>
344
+ <description>Description of item sold</description>
345
+ <quantity>1</quantity>
346
+ <unitPrice>6.95</unitPrice>
347
+ <taxable>true</taxable>
348
+ </lineItem>
349
+ <lineItem>
350
+ <itemId>ITEM00002</itemId>
351
+ <name>name of item sold</name>
352
+ <description>Description of item sold</description>
353
+ <quantity>1</quantity>
354
+ <unitPrice>7.95</unitPrice>
355
+ <taxable>true</taxable>
356
+ </lineItem>
357
+ </lineItems>
358
+ <taxExempt>false</taxExempt>
359
+ <payment>
360
+ <creditCard>
361
+ <cardNumber>XXXX1111</cardNumber>
362
+ <expirationDate>XXXX</expirationDate>
363
+ <cardType>Visa</cardType>
364
+ </creditCard>
365
+ </payment>
366
+ <customer>
367
+ <type>individual</type>
368
+ <id>ABC00001</id>
369
+ <email>mark@example.com</email>
370
+ </customer>
371
+ <billTo>
372
+ <firstName>John</firstName>
373
+ <lastName>Doe</lastName>
374
+ </billTo>
375
+ <recurringBilling>false</recurringBilling>
376
+ <customerIP>127.0.0.1</customerIP>
377
+ </transaction>
378
+ </getTransactionDetailsResponse>'
379
+
380
+ # stub our connection response
381
+ net_response = Net::HTTPOK.new('1.1', 200, 'OK')
382
+ net_response.stub!(:body).and_return(@response)
383
+ connection = Net::HTTP.new('http://www.example.com')
384
+ connection.stub!(:start).and_return(net_response)
385
+ Net::HTTP.stub!(:new).and_return(connection)
386
+
387
+ transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
388
+ transaction.should respond_to(:get_transaction_details)
389
+ response = transaction.get_transaction_details('2156246780')
390
+ response.success?.should be_true
391
+ response.should respond_to(:transaction)
392
+ transaction = response.transaction
393
+
394
+ transaction.should be_kind_of(AuthorizeNet::Reporting::TransactionDetails)
395
+ transaction.response_code.should == "1"
396
+ transaction.response_reason_code.should == "1"
397
+ transaction.response_reason_description.should == "Approval"
398
+ transaction.auth_code.should == "5N3WKF"
399
+ transaction.avs_response.should == 'Y'
400
+ transaction.auth_amount.should == 10.00
401
+ transaction.settle_amount.should == 10.00
402
+ transaction.recurring_billing.should be_true
403
+
404
+ transaction.order.should be_kind_of(AuthorizeNet::Order)
405
+ transaction.order.line_items.should be_kind_of(Array)
406
+ transaction.order.line_items.length.should == 2
407
+ transaction.order.line_items[0].should be_kind_of(AuthorizeNet::LineItem)
408
+ transaction.order.tax_exempt.should be_false
409
+
410
+ transaction.payment_method.should be_kind_of(AuthorizeNet::CreditCard)
411
+ transaction.payment_method.card_number.should == 'XXXX1111'
412
+
413
+ transaction.batch.should be_kind_of(AuthorizeNet::Reporting::Batch)
414
+ transaction.batch.id.should == '835509'
415
+ transaction.batch.settled_at.should == DateTime.civil(2010, 12, 8, 9, 40, 51)
416
+
417
+ transaction.bill_to.should be_kind_of(AuthorizeNet::Address)
418
+ transaction.bill_to.first_name.should == 'John'
419
+ transaction.bill_to.last_name.should == 'Doe'
420
+
421
+ transaction.customer.should be_kind_of(AuthorizeNet::Customer)
422
+ transaction.customer.ip.should == '127.0.0.1'
423
+ transaction.customer.id.should == 'ABC00001'
424
+ transaction.customer.email.should == 'mark@example.com'
425
+ transaction.customer.payment_profiles.should be_kind_of(Array)
426
+ transaction.customer.payment_profiles.length.should == 1
427
+ transaction.customer.payment_profiles[0].cust_type.should == 'individual'
428
+ end
429
+ end
430
+
431
+ end
@@ -0,0 +1,97 @@
1
+ require "spec_helper"
2
+
3
+ describe AuthorizeNet::SIM::Transaction do
4
+
5
+ before :all do
6
+ begin
7
+ creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
8
+ @api_key = creds['api_transaction_key']
9
+ @api_login = creds['api_login_id']
10
+ rescue Errno::ENOENT => e
11
+ @api_key = "TEST"
12
+ @api_login = "TEST"
13
+ warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
14
+ end
15
+ end
16
+
17
+ before do
18
+ @amount = 10.00
19
+ @fingerprint = 'a8ea7b27729daf76d4a67bdb7d0a2fa3'
20
+ @sequence = '123456789'
21
+ @timestamp = '987654321'
22
+ end
23
+
24
+ it "should support instantiation" do
25
+ AuthorizeNet::SIM::Transaction.new(@api_login, @api_key, @amount).should be_instance_of(AuthorizeNet::SIM::Transaction)
26
+ end
27
+
28
+ it "should generate a correct fingerprint" do
29
+ transaction = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount, :sequence => @sequence, :timestamp => @timestamp)
30
+ transaction.fingerprint.should == @fingerprint
31
+ end
32
+
33
+ it "should provide the actual values used to build the fingerprint" do
34
+ transaction = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount)
35
+ hash = transaction.fingerprint_fields
36
+ transaction2 = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount, :sequence => hash[:fp_sequence], :timestamp => hash[:fp_timestamp])
37
+ hash[:fp_hash].should == transaction2.fingerprint
38
+ end
39
+
40
+ it "should provide a hash of all the form fields, ready for conversion to HTML" do
41
+ transaction = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount)
42
+ transaction.form_fields.should be_kind_of(Hash)
43
+ transaction.form_fields.should have_key(:x_fp_hash)
44
+ end
45
+
46
+ it "should know if its in test mode" do
47
+ transaction = AuthorizeNet::SIM::Transaction.new(@api_login, @api_key, @amount, :test => true)
48
+ transaction.test?.should be_true
49
+ transaction = AuthorizeNet::SIM::Transaction.new(@api_login, @api_key, @amount, :test => false)
50
+ transaction.test?.should be_false
51
+ end
52
+ end
53
+
54
+ describe AuthorizeNet::SIM::Response do
55
+
56
+ before :all do
57
+ begin
58
+ creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
59
+ @api_key = creds['api_transaction_key']
60
+ @api_login = creds['api_login_id']
61
+ rescue Errno::ENOENT => e
62
+ @api_key = "TEST"
63
+ @api_login = "TEST"
64
+ warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
65
+ end
66
+ end
67
+
68
+ before do
69
+ @amount = (rand(10000) + 100) / 100.0
70
+ @fingerprint = 'a8ea7b27729daf76d4a67bdb7d0a2fa3'
71
+ @sequence = '123456789'
72
+ @timestamp = '987654321'
73
+ end
74
+
75
+ it "should support instantiation" do
76
+ AuthorizeNet::SIM::Response.new('').should be_instance_of(AuthorizeNet::SIM::Response)
77
+ end
78
+
79
+ it "should support parsing the response into fields" do
80
+ response = AuthorizeNet::SIM::Response.new('x_first_name=John&x_last_name=Doe')
81
+ response.fields.should have_key(:first_name)
82
+ response.fields.should have_key(:last_name)
83
+ end
84
+
85
+ it "should be able to build a Direct Post Method URL with fields from the response" do
86
+ response = AuthorizeNet::SIM::Response.new('x_first_name=John&x_last_name=Doe')
87
+ response.direct_post_url('http://www.example.com/').should == 'http://www.example.com/?x_first_name=John&x_last_name=Doe'
88
+ end
89
+ end
90
+
91
+ describe AuthorizeNet::SIM::HostedPaymentForm do
92
+ it "should support instantiation" do
93
+ AuthorizeNet::SIM::HostedPaymentForm.new().should be_instance_of(AuthorizeNet::SIM::HostedPaymentForm)
94
+ end
95
+
96
+ end
97
+