braintree 1.0.1 → 1.1.0
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.
- data/lib/braintree.rb +36 -46
- data/lib/braintree/address.rb +14 -14
- data/lib/braintree/base_module.rb +3 -3
- data/lib/braintree/configuration.rb +16 -16
- data/lib/braintree/credit_card.rb +39 -30
- data/lib/braintree/credit_card_verification.rb +4 -3
- data/lib/braintree/customer.rb +22 -22
- data/lib/braintree/digest.rb +2 -8
- data/lib/braintree/error_codes.rb +16 -3
- data/lib/braintree/error_result.rb +5 -5
- data/lib/braintree/exceptions.rb +58 -0
- data/lib/braintree/http.rb +7 -7
- data/lib/braintree/paged_collection.rb +14 -14
- data/lib/braintree/ssl_expiration_check.rb +5 -1
- data/lib/braintree/subscription.rb +110 -0
- data/lib/braintree/successful_result.rb +3 -3
- data/lib/braintree/test/credit_card_numbers.rb +1 -1
- data/lib/braintree/test/transaction_amounts.rb +18 -0
- data/lib/braintree/transaction.rb +52 -25
- data/lib/braintree/transaction/address_details.rb +2 -2
- data/lib/braintree/transaction/credit_card_details.rb +12 -4
- data/lib/braintree/transaction/customer_details.rb +9 -1
- data/lib/braintree/transaction/status_details.rb +1 -1
- data/lib/braintree/transparent_redirect.rb +15 -15
- data/lib/braintree/util.rb +7 -7
- data/lib/braintree/validation_error.rb +1 -1
- data/lib/braintree/validation_error_collection.rb +6 -6
- data/lib/braintree/version.rb +3 -3
- data/lib/braintree/xml/generator.rb +2 -2
- data/lib/braintree/xml/libxml.rb +1 -1
- data/lib/braintree/xml/parser.rb +1 -1
- data/spec/integration/braintree/address_spec.rb +12 -12
- data/spec/integration/braintree/credit_card_spec.rb +189 -37
- data/spec/integration/braintree/customer_spec.rb +35 -35
- data/spec/integration/braintree/http_spec.rb +3 -3
- data/spec/integration/braintree/subscription_spec.rb +362 -0
- data/spec/integration/braintree/transaction_spec.rb +130 -58
- data/spec/integration/spec_helper.rb +1 -1
- data/spec/spec_helper.rb +4 -4
- data/spec/unit/braintree/address_spec.rb +6 -6
- data/spec/unit/braintree/base_module_spec.rb +18 -0
- data/spec/unit/braintree/configuration_spec.rb +10 -10
- data/spec/unit/braintree/credit_card_spec.rb +15 -15
- data/spec/unit/braintree/credit_card_verification_spec.rb +4 -2
- data/spec/unit/braintree/customer_spec.rb +8 -8
- data/spec/unit/braintree/digest_spec.rb +4 -0
- data/spec/unit/braintree/http_spec.rb +2 -2
- data/spec/unit/braintree/paged_collection_spec.rb +12 -12
- data/spec/unit/braintree/ssl_expiration_check_spec.rb +18 -9
- data/spec/unit/braintree/transaction/credit_card_details_spec.rb +15 -0
- data/spec/unit/braintree/transaction/customer_details_spec.rb +19 -0
- data/spec/unit/braintree/transaction_spec.rb +14 -14
- data/spec/unit/braintree/transparent_redirect_spec.rb +11 -11
- data/spec/unit/braintree/util_spec.rb +8 -8
- data/spec/unit/braintree/validation_error_collection_spec.rb +6 -6
- data/spec/unit/braintree/validation_error_spec.rb +2 -2
- data/spec/unit/braintree/xml/libxml_spec.rb +5 -5
- data/spec/unit/braintree/xml_spec.rb +16 -16
- data/spec/unit/braintree_spec.rb +11 -0
- metadata +8 -2
@@ -14,12 +14,30 @@ describe Braintree::Transaction do
|
|
14
14
|
result.success?.should == true
|
15
15
|
result.transaction.id.should =~ /^\w{6}$/
|
16
16
|
result.transaction.type.should == "sale"
|
17
|
-
result.transaction.amount.should == Braintree::Test::TransactionAmounts::Authorize
|
17
|
+
result.transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
|
18
18
|
result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
19
19
|
result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
20
20
|
result.transaction.credit_card_details.expiration_date.should == "05/2009"
|
21
|
+
result.transaction.credit_card_details.customer_location.should == "US"
|
21
22
|
end
|
22
|
-
|
23
|
+
|
24
|
+
it "returns processor response code and text if declined" do
|
25
|
+
result = Braintree::Transaction.create(
|
26
|
+
:type => "sale",
|
27
|
+
:amount => Braintree::Test::TransactionAmounts::Decline,
|
28
|
+
:credit_card => {
|
29
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
30
|
+
:expiration_date => "05/2009"
|
31
|
+
}
|
32
|
+
)
|
33
|
+
result.success?.should == true
|
34
|
+
result.transaction.id.should =~ /^\w{6}$/
|
35
|
+
result.transaction.type.should == "sale"
|
36
|
+
result.transaction.status.should == "processor_declined"
|
37
|
+
result.transaction.processor_response_code.should == "2000"
|
38
|
+
result.transaction.processor_response_text.should == "Do Not Honor"
|
39
|
+
end
|
40
|
+
|
23
41
|
it "can create custom fields" do
|
24
42
|
result = Braintree::Transaction.create(
|
25
43
|
:type => "sale",
|
@@ -67,7 +85,7 @@ describe Braintree::Transaction do
|
|
67
85
|
result.success?.should == false
|
68
86
|
result.params.should == {:transaction => {:type => 'sale', :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
|
69
87
|
end
|
70
|
-
|
88
|
+
|
71
89
|
it "returns errors if validations fail (tests many errors at once for spec speed)" do
|
72
90
|
params = {
|
73
91
|
:transaction => {
|
@@ -91,9 +109,8 @@ describe Braintree::Transaction do
|
|
91
109
|
result.errors.for(:transaction).on(:order_id)[0].code.should == Braintree::ErrorCodes::Transaction::OrderIdIsTooLong
|
92
110
|
result.errors.for(:transaction).on(:payment_method_token)[0].code.should == Braintree::ErrorCodes::Transaction::PaymentMethodTokenIsInvalid
|
93
111
|
result.errors.for(:transaction).on(:type)[0].code.should == Braintree::ErrorCodes::Transaction::TypeIsInvalid
|
94
|
-
|
95
112
|
end
|
96
|
-
|
113
|
+
|
97
114
|
it "returns an error if amount is negative" do
|
98
115
|
params = {
|
99
116
|
:transaction => {
|
@@ -117,7 +134,7 @@ describe Braintree::Transaction do
|
|
117
134
|
result.success?.should == false
|
118
135
|
result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsInvalid
|
119
136
|
end
|
120
|
-
|
137
|
+
|
121
138
|
it "returns an error if type is not given" do
|
122
139
|
params = {
|
123
140
|
:transaction => {
|
@@ -128,7 +145,7 @@ describe Braintree::Transaction do
|
|
128
145
|
result.success?.should == false
|
129
146
|
result.errors.for(:transaction).on(:type)[0].code.should == Braintree::ErrorCodes::Transaction::TypeIsRequired
|
130
147
|
end
|
131
|
-
|
148
|
+
|
132
149
|
it "returns an error if no credit card is given" do
|
133
150
|
params = {
|
134
151
|
:transaction => {
|
@@ -138,7 +155,7 @@ describe Braintree::Transaction do
|
|
138
155
|
result.success?.should == false
|
139
156
|
result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CreditCardIsRequired
|
140
157
|
end
|
141
|
-
|
158
|
+
|
142
159
|
it "returns an error if the given payment method token doesn't belong to the customer" do
|
143
160
|
customer = Braintree::Customer.create!(
|
144
161
|
:credit_card => {
|
@@ -169,12 +186,12 @@ describe Braintree::Transaction do
|
|
169
186
|
)
|
170
187
|
transaction.id.should =~ /^\w{6}$/
|
171
188
|
transaction.type.should == "sale"
|
172
|
-
transaction.amount.should == Braintree::Test::TransactionAmounts::Authorize
|
189
|
+
transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
|
173
190
|
transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
174
191
|
transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
175
192
|
transaction.credit_card_details.expiration_date.should == "05/2009"
|
176
193
|
end
|
177
|
-
|
194
|
+
|
178
195
|
it "raises a ValidationsFailed if invalid" do
|
179
196
|
expect do
|
180
197
|
Braintree::Transaction.create!(
|
@@ -201,7 +218,7 @@ describe Braintree::Transaction do
|
|
201
218
|
result.success?.should == true
|
202
219
|
result.transaction.id.should =~ /^\w{6}$/
|
203
220
|
result.transaction.type.should == "sale"
|
204
|
-
result.transaction.amount.should == Braintree::Test::TransactionAmounts::Authorize
|
221
|
+
result.transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
|
205
222
|
result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
206
223
|
result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
207
224
|
result.transaction.credit_card_details.expiration_date.should == "05/2009"
|
@@ -253,7 +270,7 @@ describe Braintree::Transaction do
|
|
253
270
|
transaction.id.should =~ /\A\w{6}\z/
|
254
271
|
transaction.type.should == "sale"
|
255
272
|
transaction.status.should == "authorized"
|
256
|
-
transaction.amount.should == "100.00"
|
273
|
+
transaction.amount.should == BigDecimal.new("100.00")
|
257
274
|
transaction.order_id.should == "123"
|
258
275
|
transaction.processor_response_code.should == "1000"
|
259
276
|
transaction.created_at.between?(Time.now - 5, Time.now).should == true
|
@@ -291,7 +308,7 @@ describe Braintree::Transaction do
|
|
291
308
|
transaction.shipping_details.postal_code.should == "60103"
|
292
309
|
transaction.shipping_details.country_name.should == "United States of America"
|
293
310
|
end
|
294
|
-
|
311
|
+
|
295
312
|
it "can store customer and credit card in the vault" do
|
296
313
|
result = Braintree::Transaction.sale(
|
297
314
|
:amount => "100",
|
@@ -347,6 +364,8 @@ describe Braintree::Transaction do
|
|
347
364
|
transaction.customer_details.id.should =~ /\A\d{6,7}\z/
|
348
365
|
transaction.vault_customer.id.should == transaction.customer_details.id
|
349
366
|
credit_card = Braintree::CreditCard.find(transaction.vault_credit_card.token)
|
367
|
+
transaction.billing_details.id.should == credit_card.billing_address.id
|
368
|
+
transaction.vault_billing_address.id.should == credit_card.billing_address.id
|
350
369
|
credit_card.billing_address.first_name.should == "Carl"
|
351
370
|
credit_card.billing_address.last_name.should == "Jones"
|
352
371
|
credit_card.billing_address.company.should == "Braintree"
|
@@ -358,6 +377,50 @@ describe Braintree::Transaction do
|
|
358
377
|
credit_card.billing_address.country_name.should == "United States of America"
|
359
378
|
end
|
360
379
|
|
380
|
+
it "can store the shipping address in the vault" do
|
381
|
+
result = Braintree::Transaction.sale(
|
382
|
+
:amount => "100",
|
383
|
+
:customer => {
|
384
|
+
:first_name => "Adam",
|
385
|
+
:last_name => "Williams"
|
386
|
+
},
|
387
|
+
:credit_card => {
|
388
|
+
:number => "5105105105105100",
|
389
|
+
:expiration_date => "05/2012"
|
390
|
+
},
|
391
|
+
:shipping => {
|
392
|
+
:first_name => "Carl",
|
393
|
+
:last_name => "Jones",
|
394
|
+
:company => "Braintree",
|
395
|
+
:street_address => "123 E Main St",
|
396
|
+
:extended_address => "Suite 403",
|
397
|
+
:locality => "Chicago",
|
398
|
+
:region => "IL",
|
399
|
+
:postal_code => "60622",
|
400
|
+
:country_name => "United States of America"
|
401
|
+
},
|
402
|
+
:options => {
|
403
|
+
:store_in_vault => true,
|
404
|
+
:store_shipping_address_in_vault => true,
|
405
|
+
}
|
406
|
+
)
|
407
|
+
result.success?.should == true
|
408
|
+
transaction = result.transaction
|
409
|
+
transaction.customer_details.id.should =~ /\A\d{6,7}\z/
|
410
|
+
transaction.vault_customer.id.should == transaction.customer_details.id
|
411
|
+
transaction.vault_shipping_address.id.should == transaction.vault_customer.addresses[0].id
|
412
|
+
shipping_address = transaction.vault_customer.addresses[0]
|
413
|
+
shipping_address.first_name.should == "Carl"
|
414
|
+
shipping_address.last_name.should == "Jones"
|
415
|
+
shipping_address.company.should == "Braintree"
|
416
|
+
shipping_address.street_address.should == "123 E Main St"
|
417
|
+
shipping_address.extended_address.should == "Suite 403"
|
418
|
+
shipping_address.locality.should == "Chicago"
|
419
|
+
shipping_address.region.should == "IL"
|
420
|
+
shipping_address.postal_code.should == "60622"
|
421
|
+
shipping_address.country_name.should == "United States of America"
|
422
|
+
end
|
423
|
+
|
361
424
|
it "submits for settlement if given transaction[options][submit_for_settlement]" do
|
362
425
|
result = Braintree::Transaction.sale(
|
363
426
|
:amount => "100",
|
@@ -372,7 +435,7 @@ describe Braintree::Transaction do
|
|
372
435
|
result.success?.should == true
|
373
436
|
result.transaction.status.should == "submitted_for_settlement"
|
374
437
|
end
|
375
|
-
|
438
|
+
|
376
439
|
it "can specify the customer id and payment method token" do
|
377
440
|
customer_id = "customer_#{rand(1000000)}"
|
378
441
|
payment_mehtod_token = "credit_card_#{rand(1000000)}"
|
@@ -399,7 +462,7 @@ describe Braintree::Transaction do
|
|
399
462
|
transaction.credit_card_details.token.should == payment_mehtod_token
|
400
463
|
transaction.vault_credit_card.token.should == payment_mehtod_token
|
401
464
|
end
|
402
|
-
|
465
|
+
|
403
466
|
it "returns an error result if validations fail" do
|
404
467
|
params = {
|
405
468
|
:transaction => {
|
@@ -428,12 +491,12 @@ describe Braintree::Transaction do
|
|
428
491
|
)
|
429
492
|
transaction.id.should =~ /^\w{6}$/
|
430
493
|
transaction.type.should == "sale"
|
431
|
-
transaction.amount.should == Braintree::Test::TransactionAmounts::Authorize
|
494
|
+
transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
|
432
495
|
transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
433
496
|
transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
434
497
|
transaction.credit_card_details.expiration_date.should == "05/2009"
|
435
498
|
end
|
436
|
-
|
499
|
+
|
437
500
|
it "raises a ValidationsFailed if invalid" do
|
438
501
|
expect do
|
439
502
|
Braintree::Transaction.sale!(
|
@@ -468,10 +531,10 @@ describe Braintree::Transaction do
|
|
468
531
|
:expiration_date => "06/2009"
|
469
532
|
}
|
470
533
|
)
|
471
|
-
transaction.amount.should == "1000.00"
|
534
|
+
transaction.amount.should == BigDecimal.new("1000.00")
|
472
535
|
result = Braintree::Transaction.submit_for_settlement(transaction.id, "999.99")
|
473
536
|
result.success?.should == true
|
474
|
-
result.transaction.amount.should == "999.99"
|
537
|
+
result.transaction.amount.should == BigDecimal.new("999.99")
|
475
538
|
result.transaction.status.should == "submitted_for_settlement"
|
476
539
|
result.transaction.updated_at.between?(Time.now - 5, Time.now).should == true
|
477
540
|
end
|
@@ -484,7 +547,7 @@ describe Braintree::Transaction do
|
|
484
547
|
:expiration_date => "06/2009"
|
485
548
|
}
|
486
549
|
)
|
487
|
-
transaction.amount.should == "1000.00"
|
550
|
+
transaction.amount.should == BigDecimal.new("1000.00")
|
488
551
|
result = Braintree::Transaction.submit_for_settlement(transaction.id, "1000.01")
|
489
552
|
result.success?.should == false
|
490
553
|
result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::SettlementAmountIsTooLarge
|
@@ -527,13 +590,13 @@ describe Braintree::Transaction do
|
|
527
590
|
:expiration_date => "06/2009"
|
528
591
|
}
|
529
592
|
)
|
530
|
-
transaction.amount.should == "1000.00"
|
593
|
+
transaction.amount.should == BigDecimal.new("1000.00")
|
531
594
|
expect do
|
532
595
|
Braintree::Transaction.submit_for_settlement!(transaction.id, "1000.01")
|
533
596
|
end.to raise_error(Braintree::ValidationsFailed)
|
534
597
|
end
|
535
598
|
end
|
536
|
-
|
599
|
+
|
537
600
|
describe "self.credit" do
|
538
601
|
it "returns a successful result with type=credit if successful" do
|
539
602
|
result = Braintree::Transaction.credit(
|
@@ -546,12 +609,12 @@ describe Braintree::Transaction do
|
|
546
609
|
result.success?.should == true
|
547
610
|
result.transaction.id.should =~ /^\w{6}$/
|
548
611
|
result.transaction.type.should == "credit"
|
549
|
-
result.transaction.amount.should == Braintree::Test::TransactionAmounts::Authorize
|
612
|
+
result.transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
|
550
613
|
result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
551
614
|
result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
552
615
|
result.transaction.credit_card_details.expiration_date.should == "05/2009"
|
553
616
|
end
|
554
|
-
|
617
|
+
|
555
618
|
it "returns an error result if validations fail" do
|
556
619
|
params = {
|
557
620
|
:transaction => {
|
@@ -568,7 +631,7 @@ describe Braintree::Transaction do
|
|
568
631
|
result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
|
569
632
|
end
|
570
633
|
end
|
571
|
-
|
634
|
+
|
572
635
|
describe "self.credit!" do
|
573
636
|
it "returns the transaction if valid" do
|
574
637
|
transaction = Braintree::Transaction.credit!(
|
@@ -580,12 +643,12 @@ describe Braintree::Transaction do
|
|
580
643
|
)
|
581
644
|
transaction.id.should =~ /^\w{6}$/
|
582
645
|
transaction.type.should == "credit"
|
583
|
-
transaction.amount.should == Braintree::Test::TransactionAmounts::Authorize
|
646
|
+
transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
|
584
647
|
transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
585
648
|
transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
586
649
|
transaction.credit_card_details.expiration_date.should == "05/2009"
|
587
650
|
end
|
588
|
-
|
651
|
+
|
589
652
|
it "raises a ValidationsFailed if invalid" do
|
590
653
|
expect do
|
591
654
|
Braintree::Transaction.credit!(
|
@@ -598,7 +661,7 @@ describe Braintree::Transaction do
|
|
598
661
|
end.to raise_error(Braintree::ValidationsFailed)
|
599
662
|
end
|
600
663
|
end
|
601
|
-
|
664
|
+
|
602
665
|
describe "self.create_from_transparent_redirect" do
|
603
666
|
it "returns a successful result if successful" do
|
604
667
|
params = {
|
@@ -620,15 +683,15 @@ describe Braintree::Transaction do
|
|
620
683
|
result.success?.should == true
|
621
684
|
transaction = result.transaction
|
622
685
|
transaction.type.should == "sale"
|
623
|
-
transaction.amount.should == "1000.00"
|
686
|
+
transaction.amount.should == BigDecimal.new("1000.00")
|
624
687
|
transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
625
688
|
transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
626
689
|
transaction.credit_card_details.expiration_date.should == "05/2009"
|
627
690
|
end
|
628
|
-
|
691
|
+
|
629
692
|
it "can put any param in tr_data" do
|
630
693
|
params = {
|
631
|
-
|
694
|
+
|
632
695
|
}
|
633
696
|
tr_data_params = {
|
634
697
|
:transaction => {
|
@@ -679,7 +742,7 @@ describe Braintree::Transaction do
|
|
679
742
|
transaction.id.should =~ /\A\w{6}\z/
|
680
743
|
transaction.type.should == "sale"
|
681
744
|
transaction.status.should == "authorized"
|
682
|
-
transaction.amount.should == "100.00"
|
745
|
+
transaction.amount.should == BigDecimal.new("100.00")
|
683
746
|
transaction.order_id.should == "123"
|
684
747
|
transaction.processor_response_code.should == "1000"
|
685
748
|
transaction.created_at.between?(Time.now - 5, Time.now).should == true
|
@@ -717,7 +780,7 @@ describe Braintree::Transaction do
|
|
717
780
|
transaction.shipping_details.postal_code.should == "60103"
|
718
781
|
transaction.shipping_details.country_name.should == "United States of America"
|
719
782
|
end
|
720
|
-
|
783
|
+
|
721
784
|
it "returns an error result if validations fail" do
|
722
785
|
params = {
|
723
786
|
:transaction => {
|
@@ -740,7 +803,7 @@ describe Braintree::Transaction do
|
|
740
803
|
result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
|
741
804
|
end
|
742
805
|
end
|
743
|
-
|
806
|
+
|
744
807
|
describe "self.find" do
|
745
808
|
it "finds the transaction with the given id" do
|
746
809
|
result = Braintree::Transaction.create(
|
@@ -793,7 +856,7 @@ describe Braintree::Transaction do
|
|
793
856
|
end
|
794
857
|
end
|
795
858
|
|
796
|
-
describe "void!" do
|
859
|
+
describe "self.void!" do
|
797
860
|
it "returns the transaction if successful" do
|
798
861
|
transaction = Braintree::Transaction.sale!(
|
799
862
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
@@ -820,17 +883,18 @@ describe Braintree::Transaction do
|
|
820
883
|
end.to raise_error(Braintree::ValidationsFailed)
|
821
884
|
end
|
822
885
|
end
|
823
|
-
|
886
|
+
|
824
887
|
describe "refund" do
|
825
888
|
it "returns a successful result if successful" do
|
826
|
-
transaction =
|
889
|
+
transaction = create_transaction_to_refund
|
890
|
+
transaction.status.should == "settled"
|
827
891
|
result = transaction.refund
|
828
892
|
result.success?.should == true
|
829
893
|
result.new_transaction.type.should == "credit"
|
830
894
|
end
|
831
895
|
|
832
896
|
it "returns an error if already refunded" do
|
833
|
-
transaction =
|
897
|
+
transaction = create_transaction_to_refund
|
834
898
|
result = transaction.refund
|
835
899
|
result.success?.should == true
|
836
900
|
result = transaction.refund
|
@@ -874,10 +938,10 @@ describe Braintree::Transaction do
|
|
874
938
|
:expiration_date => "06/2009"
|
875
939
|
}
|
876
940
|
)
|
877
|
-
transaction.amount.should == "1000.00"
|
941
|
+
transaction.amount.should == BigDecimal.new("1000.00")
|
878
942
|
result = transaction.submit_for_settlement("999.99")
|
879
943
|
result.success?.should == true
|
880
|
-
transaction.amount.should == "999.99"
|
944
|
+
transaction.amount.should == BigDecimal.new("999.99")
|
881
945
|
end
|
882
946
|
|
883
947
|
it "updates the transaction attributes" do
|
@@ -888,10 +952,10 @@ describe Braintree::Transaction do
|
|
888
952
|
:expiration_date => "06/2009"
|
889
953
|
}
|
890
954
|
)
|
891
|
-
transaction.amount.should == "1000.00"
|
955
|
+
transaction.amount.should == BigDecimal.new("1000.00")
|
892
956
|
result = transaction.submit_for_settlement("999.99")
|
893
957
|
result.success?.should == true
|
894
|
-
transaction.amount.should == "999.99"
|
958
|
+
transaction.amount.should == BigDecimal.new("999.99")
|
895
959
|
transaction.status.should == "submitted_for_settlement"
|
896
960
|
transaction.updated_at.between?(Time.now - 5, Time.now).should == true
|
897
961
|
end
|
@@ -904,7 +968,7 @@ describe Braintree::Transaction do
|
|
904
968
|
:expiration_date => "06/2009"
|
905
969
|
}
|
906
970
|
)
|
907
|
-
transaction.amount.should == "1000.00"
|
971
|
+
transaction.amount.should == BigDecimal.new("1000.00")
|
908
972
|
result = transaction.submit_for_settlement("1000.01")
|
909
973
|
result.success?.should == false
|
910
974
|
result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::SettlementAmountIsTooLarge
|
@@ -934,13 +998,13 @@ describe Braintree::Transaction do
|
|
934
998
|
:expiration_date => "06/2009"
|
935
999
|
}
|
936
1000
|
)
|
937
|
-
transaction.amount.should == "1000.00"
|
1001
|
+
transaction.amount.should == BigDecimal.new("1000.00")
|
938
1002
|
expect do
|
939
1003
|
transaction.submit_for_settlement!("1000.01")
|
940
1004
|
end.to raise_error(Braintree::ValidationsFailed)
|
941
1005
|
end
|
942
1006
|
end
|
943
|
-
|
1007
|
+
|
944
1008
|
describe "search" do
|
945
1009
|
describe "advanced" do
|
946
1010
|
it "pretty much works in one big fell swoop/hash" do
|
@@ -1026,12 +1090,12 @@ describe Braintree::Transaction do
|
|
1026
1090
|
transactions = Braintree::Transaction.search "1111"
|
1027
1091
|
transactions.total_items.should > 0
|
1028
1092
|
end
|
1029
|
-
|
1093
|
+
|
1030
1094
|
it "is paged" do
|
1031
1095
|
transactions = Braintree::Transaction.search "1111", :page => 2
|
1032
1096
|
transactions.current_page_number.should == 2
|
1033
1097
|
end
|
1034
|
-
|
1098
|
+
|
1035
1099
|
it "can traverse pages" do
|
1036
1100
|
transactions = Braintree::Transaction.search "1111", :page => 1
|
1037
1101
|
transactions.next_page.current_page_number.should == 2
|
@@ -1054,7 +1118,7 @@ describe Braintree::Transaction do
|
|
1054
1118
|
transaction.status_history[1].status.should == "submitted_for_settlement"
|
1055
1119
|
end
|
1056
1120
|
end
|
1057
|
-
|
1121
|
+
|
1058
1122
|
describe "vault_credit_card" do
|
1059
1123
|
it "returns the Braintree::CreditCard if the transaction credit card is stored in the vault" do
|
1060
1124
|
customer = Braintree::Customer.create!(
|
@@ -1066,7 +1130,7 @@ describe Braintree::Transaction do
|
|
1066
1130
|
transaction = customer.credit_cards[0].sale(:amount => "100.00").transaction
|
1067
1131
|
transaction.vault_credit_card.should == customer.credit_cards[0]
|
1068
1132
|
end
|
1069
|
-
|
1133
|
+
|
1070
1134
|
it "returns nil if the transaction credit card is not stored in the vault" do
|
1071
1135
|
transaction = Braintree::Transaction.create!(
|
1072
1136
|
:amount => "100.00",
|
@@ -1091,7 +1155,7 @@ describe Braintree::Transaction do
|
|
1091
1155
|
transaction = customer.credit_cards[0].sale(:amount => "100.00").transaction
|
1092
1156
|
transaction.vault_customer.should == customer
|
1093
1157
|
end
|
1094
|
-
|
1158
|
+
|
1095
1159
|
it "returns nil if the transaction customer is not stored in the vault" do
|
1096
1160
|
transaction = Braintree::Transaction.create!(
|
1097
1161
|
:amount => "100.00",
|
@@ -1104,7 +1168,7 @@ describe Braintree::Transaction do
|
|
1104
1168
|
transaction.vault_customer.should == nil
|
1105
1169
|
end
|
1106
1170
|
end
|
1107
|
-
|
1171
|
+
|
1108
1172
|
describe "void" do
|
1109
1173
|
it "returns a successful result if successful" do
|
1110
1174
|
result = Braintree::Transaction.create(
|
@@ -1178,15 +1242,23 @@ describe Braintree::Transaction do
|
|
1178
1242
|
request.body = Braintree::Util.hash_to_query_string(params)
|
1179
1243
|
response = http.request(request)
|
1180
1244
|
end
|
1181
|
-
query_string = response["Location"].split("?", 2).last
|
1245
|
+
query_string = response["Location"].split("?", 2).last
|
1182
1246
|
query_string
|
1183
1247
|
end
|
1184
1248
|
|
1185
|
-
def
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1249
|
+
def create_transaction_to_refund
|
1250
|
+
transaction = Braintree::Transaction.sale!(
|
1251
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
1252
|
+
:credit_card => {
|
1253
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1254
|
+
:expiration_date => "05/2009"
|
1255
|
+
},
|
1256
|
+
:options => {
|
1257
|
+
:submit_for_settlement => true
|
1258
|
+
}
|
1259
|
+
)
|
1260
|
+
|
1261
|
+
response = Braintree::Http.put "/transactions/#{transaction.id}/settle"
|
1262
|
+
Braintree::Transaction.find(transaction.id)
|
1191
1263
|
end
|
1192
1264
|
end
|