braintree 2.101.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +6 -3
  4. data/lib/braintree.rb +3 -17
  5. data/lib/braintree/address.rb +0 -22
  6. data/lib/braintree/address_gateway.rb +2 -2
  7. data/lib/braintree/base_module.rb +6 -0
  8. data/lib/braintree/configuration.rb +1 -1
  9. data/lib/braintree/credit_card.rb +5 -76
  10. data/lib/braintree/credit_card_gateway.rb +16 -32
  11. data/lib/braintree/credit_card_verification.rb +14 -0
  12. data/lib/braintree/customer.rb +3 -72
  13. data/lib/braintree/customer_gateway.rb +0 -23
  14. data/lib/braintree/dispute.rb +1 -7
  15. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  16. data/lib/braintree/dispute/transaction.rb +2 -0
  17. data/lib/braintree/dispute_gateway.rb +2 -7
  18. data/lib/braintree/error_codes.rb +162 -157
  19. data/lib/braintree/exceptions.rb +5 -3
  20. data/lib/braintree/gateway.rb +0 -14
  21. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -1
  22. data/lib/braintree/local_payment_completed.rb +1 -1
  23. data/lib/braintree/merchant_account_gateway.rb +2 -0
  24. data/lib/braintree/payment_instrument_type.rb +1 -4
  25. data/lib/braintree/payment_method_gateway.rb +16 -8
  26. data/lib/braintree/payment_method_nonce.rb +2 -0
  27. data/lib/braintree/payment_method_nonce_gateway.rb +13 -2
  28. data/lib/braintree/payment_method_parser.rb +1 -7
  29. data/lib/braintree/risk_data.rb +4 -1
  30. data/lib/braintree/subscription.rb +5 -5
  31. data/lib/braintree/successful_result.rb +0 -1
  32. data/lib/braintree/test/authentication_id.rb +21 -0
  33. data/lib/braintree/test/credit_card.rb +1 -0
  34. data/lib/braintree/test/nonce.rb +19 -20
  35. data/lib/braintree/transaction.rb +8 -72
  36. data/lib/braintree/transaction/address_details.rb +11 -0
  37. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  38. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  39. data/lib/braintree/transaction/paypal_details.rb +2 -0
  40. data/lib/braintree/transaction/subscription_details.rb +2 -0
  41. data/lib/braintree/transaction_gateway.rb +14 -21
  42. data/lib/braintree/transaction_search.rb +0 -1
  43. data/lib/braintree/util.rb +17 -2
  44. data/lib/braintree/version.rb +3 -3
  45. data/lib/braintree/webhook_notification.rb +3 -10
  46. data/lib/braintree/webhook_testing_gateway.rb +243 -43
  47. data/lib/braintree/xml/libxml.rb +1 -0
  48. data/lib/braintree/xml/parser.rb +11 -34
  49. data/spec/integration/braintree/address_spec.rb +2 -89
  50. data/spec/integration/braintree/client_api/spec_helper.rb +100 -67
  51. data/spec/integration/braintree/credit_card_spec.rb +119 -467
  52. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -0
  53. data/spec/integration/braintree/customer_spec.rb +135 -362
  54. data/spec/integration/braintree/dispute_search_spec.rb +2 -2
  55. data/spec/integration/braintree/dispute_spec.rb +1 -2
  56. data/spec/integration/braintree/document_upload_spec.rb +12 -0
  57. data/spec/integration/braintree/merchant_spec.rb +2 -2
  58. data/spec/integration/braintree/payment_method_nonce_spec.rb +77 -0
  59. data/spec/integration/braintree/payment_method_spec.rb +186 -120
  60. data/spec/integration/braintree/paypal_account_spec.rb +1 -1
  61. data/spec/integration/braintree/subscription_spec.rb +11 -16
  62. data/spec/integration/braintree/transaction_search_spec.rb +3 -3
  63. data/spec/integration/braintree/transaction_spec.rb +252 -524
  64. data/spec/integration/spec_helper.rb +1 -4
  65. data/spec/spec_helper.rb +1 -11
  66. data/spec/unit/braintree/address_spec.rb +0 -8
  67. data/spec/unit/braintree/credit_card_spec.rb +50 -23
  68. data/spec/unit/braintree/credit_card_verification_spec.rb +7 -0
  69. data/spec/unit/braintree/customer_spec.rb +26 -14
  70. data/spec/unit/braintree/dispute_spec.rb +4 -12
  71. data/spec/unit/braintree/http_spec.rb +3 -3
  72. data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
  73. data/spec/unit/braintree/transaction/paypal_details_spec.rb +57 -0
  74. data/spec/unit/braintree/transaction_spec.rb +17 -37
  75. data/spec/unit/braintree/util_spec.rb +37 -3
  76. data/spec/unit/braintree/webhook_notification_spec.rb +49 -1
  77. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  78. metadata +29 -31
  79. data/lib/braintree/amex_express_checkout_card.rb +0 -38
  80. data/lib/braintree/coinbase_account.rb +0 -34
  81. data/lib/braintree/europe_bank_account.rb +0 -36
  82. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  83. data/lib/braintree/ideal_payment.rb +0 -61
  84. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  85. data/lib/braintree/masterpass_card.rb +0 -81
  86. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  87. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  88. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  89. data/lib/braintree/transaction/masterpass_card_details.rb +0 -47
  90. data/lib/braintree/transparent_redirect.rb +0 -40
  91. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  92. data/lib/braintree/xml/rexml.rb +0 -71
  93. data/spec/hacks/tcp_socket.rb +0 -18
  94. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  95. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  96. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  97. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  98. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -131,7 +131,7 @@ describe Braintree::PayPalAccount do
131
131
  )
132
132
 
133
133
  result.success?.should == false
134
- result.errors.first.code.should == "82902"
134
+ result.errors.map(&:code).should include("82902")
135
135
  end
136
136
  end
137
137
 
@@ -19,23 +19,21 @@ describe Braintree::Subscription do
19
19
  :plan_id => SpecHelper::TriallessPlan[:id]
20
20
  )
21
21
 
22
- date_format = /^\d{4}\D\d{1,2}\D\d{1,2}$/
23
22
  result.success?.should == true
24
23
  result.subscription.id.should =~ /^\w{6}$/
25
24
  result.subscription.status.should == Braintree::Subscription::Status::Active
26
25
  result.subscription.plan_id.should == "integration_trialless_plan"
27
26
 
28
- result.subscription.first_billing_date.should match(date_format)
29
- result.subscription.next_billing_date.should match(date_format)
30
- result.subscription.billing_period_start_date.should match(date_format)
31
- result.subscription.billing_period_end_date.should match(date_format)
32
- result.subscription.paid_through_date.should match(date_format)
27
+ expect(result.subscription.first_billing_date).to be_a Date
28
+ expect(result.subscription.next_billing_date).to be_a Date
29
+ expect(result.subscription.billing_period_start_date).to be_a Date
30
+ expect(result.subscription.billing_period_end_date).to be_a Date
31
+ expect(result.subscription.paid_through_date).to be_a Date
33
32
 
34
33
  result.subscription.created_at.between?(Time.now - 60, Time.now).should == true
35
34
  result.subscription.updated_at.between?(Time.now - 60, Time.now).should == true
36
35
 
37
36
  result.subscription.failure_count.should == 0
38
- result.subscription.next_bill_amount.should == "12.34"
39
37
  result.subscription.next_billing_period_amount.should == "12.34"
40
38
  result.subscription.payment_method_token.should == @credit_card.token
41
39
 
@@ -68,7 +66,6 @@ describe Braintree::Subscription do
68
66
  :id => new_id
69
67
  )
70
68
 
71
- date_format = /^\d{4}\D\d{1,2}\D\d{1,2}$/
72
69
  result.success?.should == true
73
70
  result.subscription.id.should == new_id
74
71
  end
@@ -195,7 +192,7 @@ describe Braintree::Subscription do
195
192
  )
196
193
 
197
194
  result.success?.should == true
198
- result.subscription.first_billing_date.should == (Date.today + 3).to_s
195
+ result.subscription.first_billing_date.should == Date.today + 3
199
196
  result.subscription.status.should == Braintree::Subscription::Status::Pending
200
197
  end
201
198
 
@@ -678,20 +675,18 @@ describe Braintree::Subscription do
678
675
  :plan_id => SpecHelper::TriallessPlan[:id]
679
676
  )
680
677
 
681
- date_format = /^\d{4}\D\d{1,2}\D\d{1,2}$/
682
678
  subscription.id.should =~ /^\w{6}$/
683
679
  subscription.status.should == Braintree::Subscription::Status::Active
684
680
  subscription.plan_id.should == "integration_trialless_plan"
685
681
 
686
- subscription.first_billing_date.should match(date_format)
687
- subscription.next_billing_date.should match(date_format)
688
- subscription.billing_period_start_date.should match(date_format)
689
- subscription.billing_period_end_date.should match(date_format)
690
- subscription.paid_through_date.should match(date_format)
682
+ expect(subscription.first_billing_date).to be_a Date
683
+ expect(subscription.next_billing_date).to be_a Date
684
+ expect(subscription.billing_period_start_date).to be_a Date
685
+ expect(subscription.billing_period_end_date).to be_a Date
686
+ expect(subscription.paid_through_date).to be_a Date
691
687
 
692
688
  subscription.failure_count.should == 0
693
689
  subscription.current_billing_cycle.should == 1
694
- subscription.next_bill_amount.should == "12.34"
695
690
  subscription.next_billing_period_amount.should == "12.34"
696
691
  subscription.payment_method_token.should == @credit_card.token
697
692
  end
@@ -468,7 +468,7 @@ describe Braintree::Transaction, "search" do
468
468
  )
469
469
  SpecHelper.settle_transaction transaction.id
470
470
 
471
- refund_transaction = transaction.refund.new_transaction
471
+ refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
472
472
 
473
473
  collection = Braintree::Transaction.search do |search|
474
474
  search.credit_card_cardholder_name.is cardholder_name
@@ -1316,12 +1316,12 @@ describe Braintree::Transaction, "search" do
1316
1316
  end
1317
1317
 
1318
1318
  context "when the search times out" do
1319
- it "raises a Down for Maintenance Error" do
1319
+ it "raises a UnexpectedError" do
1320
1320
  expect {
1321
1321
  collection = Braintree::Transaction.search do |search|
1322
1322
  search.amount.is -10
1323
1323
  end
1324
- }.to raise_error(Braintree::DownForMaintenanceError)
1324
+ }.to raise_error(Braintree::UnexpectedError)
1325
1325
  end
1326
1326
  end
1327
1327
  end
@@ -140,6 +140,31 @@ describe Braintree::Transaction do
140
140
  result.transaction.risk_data.should respond_to(:fraud_service_provider)
141
141
  end
142
142
  end
143
+
144
+ it "handles validation errors for invalid risk data attributes" do
145
+ with_advanced_fraud_integration_merchant do
146
+ result = Braintree::Transaction.create(
147
+ :type => "sale",
148
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
149
+ :credit_card => {
150
+ :number => Braintree::Test::CreditCardNumbers::Visa,
151
+ :expiration_date => "05/2009"
152
+ },
153
+ :risk_data => {
154
+ :customer_browser => "#{"1" * 300}",
155
+ :customer_device_id => "customer_device_id_0#{"1" * 300}",
156
+ :customer_ip => "192.168.0.1",
157
+ :customer_location_zip => "not-a-$#phone",
158
+ :customer_tenure => "20#{"0" * 500}"
159
+ }
160
+ )
161
+ result.success?.should == false
162
+ result.errors.for(:transaction).for(:risk_data).on(:customer_browser).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerBrowserIsTooLong
163
+ result.errors.for(:transaction).for(:risk_data).on(:customer_device_id).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerDeviceIdIsTooLong
164
+ result.errors.for(:transaction).for(:risk_data).on(:customer_location_zip).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerLocationZipInvalidCharacters
165
+ result.errors.for(:transaction).for(:risk_data).on(:customer_tenure).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerTenureIsTooLong
166
+ end
167
+ end
143
168
  end
144
169
 
145
170
  describe "card type indicators" do
@@ -419,6 +444,7 @@ describe Braintree::Transaction do
419
444
  result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
420
445
  result.transaction.credit_card_details.expiration_date.should == "05/2009"
421
446
  result.transaction.credit_card_details.customer_location.should == "US"
447
+ result.transaction.retrieval_reference_number.should_not be_nil
422
448
  end
423
449
 
424
450
  it "returns a successful network response code if successful" do
@@ -483,7 +509,7 @@ describe Braintree::Transaction do
483
509
  result.transaction.credit_card_details.customer_location.should == "US"
484
510
  end
485
511
 
486
- it "accepts additional security parameters: device_session_id and fraud_merchant_id" do
512
+ it "accepts additional security parameters: device_data" do
487
513
  result = Braintree::Transaction.create(
488
514
  :type => "sale",
489
515
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -491,14 +517,13 @@ describe Braintree::Transaction do
491
517
  :number => Braintree::Test::CreditCardNumbers::Visa,
492
518
  :expiration_date => "05/2009"
493
519
  },
494
- :device_session_id => "abc123",
495
- :fraud_merchant_id => "7"
520
+ :device_data => "device_data",
496
521
  )
497
522
 
498
523
  result.success?.should == true
499
524
  end
500
525
 
501
- it "accepts additional security parameters: risk data with customer_browser and customer_ip" do
526
+ it "accepts additional security parameters: risk data" do
502
527
  result = Braintree::Transaction.create(
503
528
  :type => "sale",
504
529
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -508,7 +533,10 @@ describe Braintree::Transaction do
508
533
  },
509
534
  :risk_data => {
510
535
  :customer_browser => "IE6",
511
- :customer_ip => "192.168.0.1"
536
+ :customer_device_id => "customer_device_id_012",
537
+ :customer_ip => "192.168.0.1",
538
+ :customer_location_zip => "91244",
539
+ :customer_tenure => "20",
512
540
  }
513
541
  )
514
542
 
@@ -687,6 +715,68 @@ describe Braintree::Transaction do
687
715
  codes.should include(Braintree::ErrorCodes::Address::CountryCodeNumericIsNotAccepted)
688
716
  end
689
717
 
718
+ it "returns an error if provided product sku is invalid" do
719
+ result = Braintree::Transaction.sale(
720
+ :amount => "100",
721
+ :credit_card => {
722
+ :number => "5105105105105100",
723
+ :expiration_date => "05/2012"
724
+ },
725
+ :product_sku => "product$ku!",
726
+ )
727
+
728
+ result.success?.should == false
729
+ result.errors.for(:transaction).on(:product_sku).map { |e| e.code }.should include(Braintree::ErrorCodes::Transaction::ProductSkuIsInvalid)
730
+ end
731
+
732
+ it "returns an error if provided shipping phone number is invalid" do
733
+ result = Braintree::Transaction.sale(
734
+ :amount => "100",
735
+ :credit_card => {
736
+ :number => "5105105105105100",
737
+ :expiration_date => "05/2012"
738
+ },
739
+ :shipping => {
740
+ :phone_number => "123-234-3456=098765"
741
+ }
742
+ )
743
+
744
+ result.success?.should == false
745
+ result.errors.for(:transaction).for(:shipping).on(:phone_number).map { |e| e.code }.should include(Braintree::ErrorCodes::Transaction::ShippingPhoneNumberIsInvalid)
746
+ end
747
+
748
+ it "returns an error if provided shipping method is invalid" do
749
+ result = Braintree::Transaction.sale(
750
+ :amount => "100",
751
+ :credit_card => {
752
+ :number => "5105105105105100",
753
+ :expiration_date => "05/2012"
754
+ },
755
+ :shipping => {
756
+ :shipping_method => "urgent"
757
+ }
758
+ )
759
+
760
+ result.success?.should == false
761
+ result.errors.for(:transaction).for(:shipping).on(:shipping_method).map { |e| e.code }.should include(Braintree::ErrorCodes::Transaction::ShippingMethodIsInvalid)
762
+ end
763
+
764
+ it "returns an error if provided billing phone number is invalid" do
765
+ result = Braintree::Transaction.sale(
766
+ :amount => "100",
767
+ :credit_card => {
768
+ :number => "5105105105105100",
769
+ :expiration_date => "05/2012"
770
+ },
771
+ :billing => {
772
+ :phone_number => "123-234-3456=098765"
773
+ }
774
+ )
775
+
776
+ result.success?.should == false
777
+ result.errors.for(:transaction).for(:billing).on(:phone_number).map { |e| e.code }.should include(Braintree::ErrorCodes::Transaction::BillingPhoneNumberIsInvalid)
778
+ end
779
+
690
780
  context "gateway rejection reason" do
691
781
  it "exposes the cvv gateway rejection reason" do
692
782
  old_merchant = Braintree::Configuration.merchant_id
@@ -804,16 +894,44 @@ describe Braintree::Transaction do
804
894
  end
805
895
 
806
896
  it "exposes the fraud gateway rejection reason" do
807
- result = Braintree::Transaction.sale(
808
- :amount => Braintree::Test::TransactionAmounts::Authorize,
809
- :credit_card => {
810
- :number => Braintree::Test::CreditCardNumbers::Fraud,
811
- :expiration_date => "05/2017",
812
- :cvv => "333"
813
- }
814
- )
815
- result.success?.should == false
816
- result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::Fraud
897
+ with_advanced_fraud_integration_merchant do
898
+ result = Braintree::Transaction.sale(
899
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
900
+ :credit_card => {
901
+ :number => Braintree::Test::CreditCardNumbers::Fraud,
902
+ :expiration_date => "05/2017",
903
+ :cvv => "333"
904
+ }
905
+ )
906
+ result.success?.should == false
907
+ result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::Fraud
908
+ end
909
+ end
910
+
911
+ it "exposes the risk_threshold gateway rejection reason (via test cc num)" do
912
+ with_advanced_fraud_integration_merchant do
913
+ result = Braintree::Transaction.sale(
914
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
915
+ :credit_card => {
916
+ :number => Braintree::Test::CreditCardNumbers::RiskThreshold,
917
+ :expiration_date => "05/2017",
918
+ :cvv => "333"
919
+ }
920
+ )
921
+ result.success?.should == false
922
+ result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::RiskThreshold
923
+ end
924
+ end
925
+
926
+ it "exposes the risk_threshold gateway rejection reason (via test test nonce)" do
927
+ with_advanced_fraud_integration_merchant do
928
+ result = Braintree::Transaction.sale(
929
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
930
+ :payment_method_nonce => Braintree::Test::Nonce::GatewayRejectedRiskThresholds,
931
+ )
932
+ result.success?.should == false
933
+ result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::RiskThreshold
934
+ end
817
935
  end
818
936
 
819
937
  it "exposes the token issuance gateway rejection reason" do
@@ -1253,22 +1371,6 @@ describe Braintree::Transaction do
1253
1371
  end
1254
1372
  end
1255
1373
 
1256
- context "recurring" do
1257
- it "marks a transaction as recurring" do
1258
- result = Braintree::Transaction.create(
1259
- :type => "sale",
1260
- :amount => Braintree::Test::TransactionAmounts::Authorize,
1261
- :credit_card => {
1262
- :number => Braintree::Test::CreditCardNumbers::Visa,
1263
- :expiration_date => "12/12",
1264
- },
1265
- :recurring => true
1266
- )
1267
- result.success?.should == true
1268
- result.transaction.recurring.should == true
1269
- end
1270
- end
1271
-
1272
1374
  context "transaction_source" do
1273
1375
  it "marks a transactions as recurring_first" do
1274
1376
  result = Braintree::Transaction.create(
@@ -1685,106 +1787,83 @@ describe Braintree::Transaction do
1685
1787
  apple_pay_details.token.should_not be_nil
1686
1788
  end
1687
1789
 
1688
- it "can create a transaction with a fake android pay proxy card nonce" do
1790
+ it "can create a transaction with a fake google pay proxy card nonce" do
1689
1791
  customer = Braintree::Customer.create!
1690
1792
  result = Braintree::Transaction.create(
1691
1793
  :type => "sale",
1692
1794
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1693
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover
1795
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover
1694
1796
  )
1695
1797
  result.success?.should == true
1696
1798
  result.transaction.should_not be_nil
1697
- android_pay_details = result.transaction.android_pay_details
1698
- android_pay_details.should_not be_nil
1699
- android_pay_details.bin.should_not be_nil
1700
- android_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1701
- android_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1702
- android_pay_details.last_4.should == "1117"
1703
- android_pay_details.virtual_card_last_4.should == "1117"
1704
- android_pay_details.source_description.should == "Discover 1111"
1705
- android_pay_details.expiration_month.to_i.should > 0
1706
- android_pay_details.expiration_year.to_i.should > 0
1707
- android_pay_details.google_transaction_id.should == "google_transaction_id"
1708
- android_pay_details.image_url.should_not be_nil
1709
- android_pay_details.is_network_tokenized?.should == false
1710
- android_pay_details.token.should be_nil
1711
- android_pay_details.prepaid.should_not be_nil
1712
- android_pay_details.healthcare.should_not be_nil
1713
- android_pay_details.debit.should_not be_nil
1714
- android_pay_details.durbin_regulated.should_not be_nil
1715
- android_pay_details.commercial.should_not be_nil
1716
- android_pay_details.payroll.should_not be_nil
1717
- android_pay_details.product_id.should_not be_nil
1718
- end
1719
-
1720
- it "can create a vaulted transaction with a fake android pay proxy card nonce" do
1799
+ google_pay_details = result.transaction.google_pay_details
1800
+ google_pay_details.should_not be_nil
1801
+ google_pay_details.bin.should_not be_nil
1802
+ google_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1803
+ google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1804
+ google_pay_details.last_4.should == "1117"
1805
+ google_pay_details.virtual_card_last_4.should == "1117"
1806
+ google_pay_details.source_description.should == "Discover 1111"
1807
+ google_pay_details.expiration_month.to_i.should > 0
1808
+ google_pay_details.expiration_year.to_i.should > 0
1809
+ google_pay_details.google_transaction_id.should == "google_transaction_id"
1810
+ google_pay_details.image_url.should_not be_nil
1811
+ google_pay_details.is_network_tokenized?.should == false
1812
+ google_pay_details.token.should be_nil
1813
+ google_pay_details.prepaid.should_not be_nil
1814
+ google_pay_details.healthcare.should_not be_nil
1815
+ google_pay_details.debit.should_not be_nil
1816
+ google_pay_details.durbin_regulated.should_not be_nil
1817
+ google_pay_details.commercial.should_not be_nil
1818
+ google_pay_details.payroll.should_not be_nil
1819
+ google_pay_details.product_id.should_not be_nil
1820
+ end
1821
+
1822
+ it "can create a vaulted transaction with a fake google pay proxy card nonce" do
1721
1823
  customer = Braintree::Customer.create!
1722
1824
  result = Braintree::Transaction.create(
1723
1825
  :type => "sale",
1724
1826
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1725
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
1827
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1726
1828
  :options => { :store_in_vault_on_success => true }
1727
1829
  )
1728
1830
  result.success?.should == true
1729
1831
  result.transaction.should_not be_nil
1730
- android_pay_details = result.transaction.android_pay_details
1731
- android_pay_details.should_not be_nil
1732
- android_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1733
- android_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1734
- android_pay_details.last_4.should == "1117"
1735
- android_pay_details.virtual_card_last_4.should == "1117"
1736
- android_pay_details.source_description.should == "Discover 1111"
1737
- android_pay_details.expiration_month.to_i.should > 0
1738
- android_pay_details.expiration_year.to_i.should > 0
1739
- android_pay_details.google_transaction_id.should == "google_transaction_id"
1740
- android_pay_details.image_url.should_not be_nil
1741
- android_pay_details.is_network_tokenized?.should == false
1742
- android_pay_details.token.should_not be_nil
1743
- end
1744
-
1745
- it "can create a transaction with a fake android pay network token nonce" do
1832
+ google_pay_details = result.transaction.google_pay_details
1833
+ google_pay_details.should_not be_nil
1834
+ google_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1835
+ google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1836
+ google_pay_details.last_4.should == "1117"
1837
+ google_pay_details.virtual_card_last_4.should == "1117"
1838
+ google_pay_details.source_description.should == "Discover 1111"
1839
+ google_pay_details.expiration_month.to_i.should > 0
1840
+ google_pay_details.expiration_year.to_i.should > 0
1841
+ google_pay_details.google_transaction_id.should == "google_transaction_id"
1842
+ google_pay_details.image_url.should_not be_nil
1843
+ google_pay_details.is_network_tokenized?.should == false
1844
+ google_pay_details.token.should_not be_nil
1845
+ end
1846
+
1847
+ it "can create a transaction with a fake google pay network token nonce" do
1746
1848
  customer = Braintree::Customer.create!
1747
1849
  result = Braintree::Transaction.create(
1748
1850
  :type => "sale",
1749
1851
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1750
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard
1852
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard
1751
1853
  )
1752
1854
  result.success?.should == true
1753
1855
  result.transaction.should_not be_nil
1754
- android_pay_details = result.transaction.android_pay_details
1755
- android_pay_details.should_not be_nil
1756
- android_pay_details.card_type.should == Braintree::CreditCard::CardType::MasterCard
1757
- android_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1758
- android_pay_details.last_4.should == "4444"
1759
- android_pay_details.virtual_card_last_4.should == "4444"
1760
- android_pay_details.source_description.should == "MasterCard 4444"
1761
- android_pay_details.expiration_month.to_i.should > 0
1762
- android_pay_details.expiration_year.to_i.should > 0
1763
- android_pay_details.google_transaction_id.should == "google_transaction_id"
1764
- android_pay_details.is_network_tokenized?.should == true
1765
- end
1766
-
1767
- it "can create a transaction with a fake amex express checkout card nonce" do
1768
- result = Braintree::Transaction.create(
1769
- :type => "sale",
1770
- :merchant_account_id => SpecHelper::FakeAmexDirectMerchantAccountId,
1771
- :amount => Braintree::Test::TransactionAmounts::Authorize,
1772
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout,
1773
- :options => {:store_in_vault => true}
1774
- )
1775
- result.success?.should == true
1776
- result.transaction.should_not be_nil
1777
- checkout_details = result.transaction.amex_express_checkout_details
1778
- checkout_details.should_not be_nil
1779
- checkout_details.card_type.should == "American Express"
1780
- checkout_details.token.should respond_to(:to_str)
1781
- checkout_details.bin.should =~ /\A\d{6}\z/
1782
- checkout_details.expiration_month.should =~ /\A\d{2}\z/
1783
- checkout_details.expiration_year.should =~ /\A\d{4}\z/
1784
- checkout_details.card_member_number.should =~ /\A\d{4}\z/
1785
- checkout_details.card_member_expiry_date.should =~ /\A\d{2}\/\d{2}\z/
1786
- checkout_details.image_url.should include(".png")
1787
- checkout_details.source_description.should =~ /\AAmEx \d{4}\z/
1856
+ google_pay_details = result.transaction.google_pay_details
1857
+ google_pay_details.should_not be_nil
1858
+ google_pay_details.card_type.should == Braintree::CreditCard::CardType::MasterCard
1859
+ google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1860
+ google_pay_details.last_4.should == "4444"
1861
+ google_pay_details.virtual_card_last_4.should == "4444"
1862
+ google_pay_details.source_description.should == "MasterCard 4444"
1863
+ google_pay_details.expiration_month.to_i.should > 0
1864
+ google_pay_details.expiration_year.to_i.should > 0
1865
+ google_pay_details.google_transaction_id.should == "google_transaction_id"
1866
+ google_pay_details.is_network_tokenized?.should == true
1788
1867
  end
1789
1868
 
1790
1869
  it "can create a transaction with a fake venmo account nonce" do
@@ -2746,14 +2825,6 @@ describe Braintree::Transaction do
2746
2825
  }.to raise_error(ArgumentError)
2747
2826
  end
2748
2827
 
2749
- it "assigns the refund_id on the original transaction" do
2750
- transaction = create_paypal_transaction_for_refund
2751
- refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
2752
- transaction = Braintree::Transaction.find(transaction.id)
2753
-
2754
- transaction.refund_id.should == refund_transaction.id
2755
- end
2756
-
2757
2828
  it "assigns the refunded_transaction_id to the original transaction" do
2758
2829
  transaction = create_paypal_transaction_for_refund
2759
2830
  refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
@@ -2783,7 +2854,13 @@ describe Braintree::Transaction do
2783
2854
  response = config.http.put("#{config.base_merchant_path}/transactions/#{transaction.id}/settle")
2784
2855
  result = Braintree::Transaction.refund(transaction.id, :amount => "2046.00")
2785
2856
  result.success?.should == false
2786
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::RefundAuthSoftDeclined
2857
+ result.transaction.id.should =~ /^\w{6,}$/
2858
+ result.transaction.type.should == "credit"
2859
+ result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
2860
+ result.transaction.processor_response_code.should == "2046"
2861
+ result.transaction.processor_response_text.should == "Declined"
2862
+ result.transaction.processor_response_type.should == Braintree::ProcessorResponseTypes::SoftDeclined
2863
+ result.transaction.additional_processor_response.should == "2046 : Declined"
2787
2864
  end
2788
2865
 
2789
2866
  it "handles hard declined refund authorizations" do
@@ -2798,7 +2875,13 @@ describe Braintree::Transaction do
2798
2875
  response = config.http.put("#{config.base_merchant_path}/transactions/#{transaction.id}/settle")
2799
2876
  result = Braintree::Transaction.refund(transaction.id, :amount => "2009.00")
2800
2877
  result.success?.should == false
2801
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::RefundAuthHardDeclined
2878
+ result.transaction.id.should =~ /^\w{6,}$/
2879
+ result.transaction.type.should == "credit"
2880
+ result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
2881
+ result.transaction.processor_response_code.should == "2009"
2882
+ result.transaction.processor_response_text.should == "No Such Issuer"
2883
+ result.transaction.processor_response_type.should == Braintree::ProcessorResponseTypes::HardDeclined
2884
+ result.transaction.additional_processor_response.should == "2009 : No Such Issuer"
2802
2885
  end
2803
2886
  end
2804
2887
 
@@ -4452,14 +4535,6 @@ describe Braintree::Transaction do
4452
4535
  result.transaction.type.should == "credit"
4453
4536
  end
4454
4537
 
4455
- it "assigns the refund_id on the original transaction" do
4456
- transaction = create_transaction_to_refund
4457
- refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
4458
- transaction = Braintree::Transaction.find(transaction.id)
4459
-
4460
- transaction.refund_id.should == refund_transaction.id
4461
- end
4462
-
4463
4538
  it "assigns the refunded_transaction_id to the original transaction" do
4464
4539
  transaction = create_transaction_to_refund
4465
4540
  refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
@@ -4535,6 +4610,7 @@ describe Braintree::Transaction do
4535
4610
  result = Braintree::Transaction.sale(
4536
4611
  :amount => "100.00",
4537
4612
  :order_id => "123",
4613
+ :product_sku => "productsku01",
4538
4614
  :channel => "MyShoppingCartProvider",
4539
4615
  :credit_card => {
4540
4616
  :cardholder_name => "The Cardholder",
@@ -4559,6 +4635,7 @@ describe Braintree::Transaction do
4559
4635
  :extended_address => "Suite 403",
4560
4636
  :locality => "Chicago",
4561
4637
  :region => "IL",
4638
+ :phone_number => "122-555-1237",
4562
4639
  :postal_code => "60622",
4563
4640
  :country_name => "United States of America"
4564
4641
  },
@@ -4570,8 +4647,10 @@ describe Braintree::Transaction do
4570
4647
  :extended_address => "Apt 2F",
4571
4648
  :locality => "Bartlett",
4572
4649
  :region => "IL",
4650
+ :phone_number => "122-555-1236",
4573
4651
  :postal_code => "60103",
4574
- :country_name => "United States of America"
4652
+ :country_name => "United States of America",
4653
+ :shipping_method => Braintree::Transaction::AddressDetails::ShippingMethod::Electronic
4575
4654
  }
4576
4655
  )
4577
4656
  result.success?.should == true
@@ -4897,11 +4976,11 @@ describe Braintree::Transaction do
4897
4976
  result.transaction.status.should == Braintree::Transaction::Status::Authorized
4898
4977
  end
4899
4978
 
4900
- context "Android Pay params" do
4979
+ context "Google Pay params" do
4901
4980
  it "works with full params" do
4902
4981
  params = {
4903
4982
  :amount => "3.12",
4904
- :android_pay_card => {
4983
+ :google_pay_card => {
4905
4984
  :number => "4012888888881881",
4906
4985
  :cryptogram => "AAAAAAAA/COBt84dnIEcwAA3gAAGhgEDoLABAAhAgAABAAAALnNCLw==",
4907
4986
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
@@ -4920,7 +4999,7 @@ describe Braintree::Transaction do
4920
4999
  it "works with only number, cryptogram, expiration and transaction ID (network tokenized card)" do
4921
5000
  params = {
4922
5001
  :amount => "3.12",
4923
- :android_pay_card => {
5002
+ :google_pay_card => {
4924
5003
  :number => "4012888888881881",
4925
5004
  :cryptogram => "AAAAAAAA/COBt84dnIEcwAA3gAAGhgEDoLABAAhAgAABAAAALnNCLw==",
4926
5005
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
@@ -4936,7 +5015,7 @@ describe Braintree::Transaction do
4936
5015
  it "works with only number, expiration and transaction ID (non-tokenized card)" do
4937
5016
  params = {
4938
5017
  :amount => "3.12",
4939
- :android_pay_card => {
5018
+ :google_pay_card => {
4940
5019
  :number => "4012888888881881",
4941
5020
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
4942
5021
  :expiration_month => "10",
@@ -5925,184 +6004,6 @@ describe Braintree::Transaction do
5925
6004
  end
5926
6005
  end
5927
6006
 
5928
- describe "self.create_from_transparent_redirect" do
5929
- it "returns a successful result if successful" do
5930
- params = {
5931
- :transaction => {
5932
- :amount => Braintree::Test::TransactionAmounts::Authorize,
5933
- :credit_card => {
5934
- :number => Braintree::Test::CreditCardNumbers::Visa,
5935
- :expiration_date => "05/2009"
5936
- }
5937
- }
5938
- }
5939
- tr_data_params = {
5940
- :transaction => {
5941
- :type => "sale"
5942
- }
5943
- }
5944
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
5945
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
5946
- result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
5947
-
5948
- result.success?.should == true
5949
- transaction = result.transaction
5950
- transaction.type.should == "sale"
5951
- transaction.amount.should == BigDecimal("1000.00")
5952
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
5953
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
5954
- transaction.credit_card_details.expiration_date.should == "05/2009"
5955
- end
5956
-
5957
- it "raises an error with a message if given invalid params" do
5958
- params = {
5959
- :transaction => {
5960
- :bad => "value",
5961
- :amount => Braintree::Test::TransactionAmounts::Authorize,
5962
- :credit_card => {
5963
- :number => Braintree::Test::CreditCardNumbers::Visa,
5964
- :expiration_date => "05/2009"
5965
- }
5966
- }
5967
- }
5968
- tr_data_params = {
5969
- :transaction => {
5970
- :type => "sale"
5971
- }
5972
- }
5973
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
5974
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
5975
-
5976
- expect do
5977
- Braintree::Transaction.create_from_transparent_redirect(query_string_response)
5978
- end.to raise_error(Braintree::AuthorizationError, "Invalid params: transaction[bad]")
5979
- end
5980
-
5981
- it "can put any param in tr_data" do
5982
- params = {
5983
-
5984
- }
5985
- tr_data_params = {
5986
- :transaction => {
5987
- :amount => "100.00",
5988
- :order_id => "123",
5989
- :channel => "MyShoppingCartProvider",
5990
- :type => "sale",
5991
- :credit_card => {
5992
- :cardholder_name => "The Cardholder",
5993
- :number => "5105105105105100",
5994
- :expiration_date => "05/2011",
5995
- :cvv => "123"
5996
- },
5997
- :customer => {
5998
- :first_name => "Dan",
5999
- :last_name => "Smith",
6000
- :company => "Braintree",
6001
- :email => "dan@example.com",
6002
- :phone => "419-555-1234",
6003
- :fax => "419-555-1235",
6004
- :website => "http://braintreepayments.com"
6005
- },
6006
- :billing => {
6007
- :first_name => "Carl",
6008
- :last_name => "Jones",
6009
- :company => "Braintree",
6010
- :street_address => "123 E Main St",
6011
- :extended_address => "Suite 403",
6012
- :locality => "Chicago",
6013
- :region => "IL",
6014
- :postal_code => "60622",
6015
- :country_name => "United States of America"
6016
- },
6017
- :shipping => {
6018
- :first_name => "Andrew",
6019
- :last_name => "Mason",
6020
- :company => "Braintree",
6021
- :street_address => "456 W Main St",
6022
- :extended_address => "Apt 2F",
6023
- :locality => "Bartlett",
6024
- :region => "IL",
6025
- :postal_code => "60103",
6026
- :country_name => "United States of America"
6027
- }
6028
- }
6029
- }
6030
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
6031
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
6032
- result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
6033
-
6034
- transaction = result.transaction
6035
- transaction.id.should =~ /\A\w{6,}\z/
6036
- transaction.type.should == "sale"
6037
- transaction.status.should == Braintree::Transaction::Status::Authorized
6038
- transaction.amount.should == BigDecimal("100.00")
6039
- transaction.order_id.should == "123"
6040
- transaction.channel.should == "MyShoppingCartProvider"
6041
- transaction.processor_response_code.should == "1000"
6042
- transaction.authorization_expires_at.between?(Time.now, Time.now + (60 * 60 * 24 * 60)).should == true
6043
- transaction.created_at.between?(Time.now - 60, Time.now).should == true
6044
- transaction.updated_at.between?(Time.now - 60, Time.now).should == true
6045
- transaction.credit_card_details.bin.should == "510510"
6046
- transaction.credit_card_details.last_4.should == "5100"
6047
- transaction.credit_card_details.cardholder_name.should == "The Cardholder"
6048
- transaction.credit_card_details.masked_number.should == "510510******5100"
6049
- transaction.credit_card_details.card_type.should == "MasterCard"
6050
- transaction.avs_error_response_code.should == nil
6051
- transaction.avs_postal_code_response_code.should == "M"
6052
- transaction.avs_street_address_response_code.should == "M"
6053
- transaction.cvv_response_code.should == "M"
6054
- transaction.customer_details.first_name.should == "Dan"
6055
- transaction.customer_details.last_name.should == "Smith"
6056
- transaction.customer_details.company.should == "Braintree"
6057
- transaction.customer_details.email.should == "dan@example.com"
6058
- transaction.customer_details.phone.should == "419-555-1234"
6059
- transaction.customer_details.fax.should == "419-555-1235"
6060
- transaction.customer_details.website.should == "http://braintreepayments.com"
6061
- transaction.billing_details.first_name.should == "Carl"
6062
- transaction.billing_details.last_name.should == "Jones"
6063
- transaction.billing_details.company.should == "Braintree"
6064
- transaction.billing_details.street_address.should == "123 E Main St"
6065
- transaction.billing_details.extended_address.should == "Suite 403"
6066
- transaction.billing_details.locality.should == "Chicago"
6067
- transaction.billing_details.region.should == "IL"
6068
- transaction.billing_details.postal_code.should == "60622"
6069
- transaction.billing_details.country_name.should == "United States of America"
6070
- transaction.shipping_details.first_name.should == "Andrew"
6071
- transaction.shipping_details.last_name.should == "Mason"
6072
- transaction.shipping_details.company.should == "Braintree"
6073
- transaction.shipping_details.street_address.should == "456 W Main St"
6074
- transaction.shipping_details.extended_address.should == "Apt 2F"
6075
- transaction.shipping_details.locality.should == "Bartlett"
6076
- transaction.shipping_details.region.should == "IL"
6077
- transaction.shipping_details.postal_code.should == "60103"
6078
- transaction.shipping_details.country_name.should == "United States of America"
6079
- end
6080
-
6081
- it "returns an error result if validations fail" do
6082
- params = {
6083
- :transaction => {
6084
- :amount => "",
6085
- :credit_card => {
6086
- :number => Braintree::Test::CreditCardNumbers::Visa,
6087
- :expiration_date => "05/2009"
6088
- }
6089
- }
6090
- }
6091
- tr_data_params = {
6092
- :transaction => {
6093
- :type => "sale"
6094
- }
6095
- }
6096
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
6097
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
6098
- result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
6099
-
6100
- result.success?.should == false
6101
- result.params[:transaction].should == {:amount => "", :type => "sale", :credit_card => {:expiration_date => "05/2009"}}
6102
- result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
6103
- end
6104
- end
6105
-
6106
6007
  describe "self.find" do
6107
6008
  it "finds the transaction with the given id" do
6108
6009
  result = Braintree::Transaction.create(
@@ -6151,7 +6052,8 @@ describe Braintree::Transaction do
6151
6052
  found_transaction.disbursed?.should == true
6152
6053
  disbursement = found_transaction.disbursement_details
6153
6054
 
6154
- disbursement.disbursement_date.should == "2013-04-10"
6055
+ expect(disbursement.disbursement_date).to be_a Date
6056
+ expect(disbursement.disbursement_date).to eq Date.parse("2013-04-10")
6155
6057
  disbursement.settlement_amount.should == "100.00"
6156
6058
  disbursement.settlement_currency_iso_code.should == "USD"
6157
6059
  disbursement.settlement_currency_exchange_rate.should == "1"
@@ -6396,151 +6298,6 @@ describe Braintree::Transaction do
6396
6298
  end
6397
6299
  end
6398
6300
 
6399
- describe "refund" do
6400
- context "partial refunds" do
6401
- it "allows partial refunds" do
6402
- transaction = create_transaction_to_refund
6403
- result = transaction.refund(transaction.amount / 2)
6404
- result.success?.should == true
6405
- result.new_transaction.type.should == "credit"
6406
- end
6407
- end
6408
-
6409
- it "returns a successful result if successful" do
6410
- transaction = create_transaction_to_refund
6411
- transaction.status.should == Braintree::Transaction::Status::Settled
6412
- result = transaction.refund
6413
- result.success?.should == true
6414
- result.new_transaction.type.should == "credit"
6415
- end
6416
-
6417
- it "assigns the refund_id on the original transaction" do
6418
- transaction = create_transaction_to_refund
6419
- refund_transaction = transaction.refund.new_transaction
6420
- transaction = Braintree::Transaction.find(transaction.id)
6421
-
6422
- transaction.refund_id.should == refund_transaction.id
6423
- end
6424
-
6425
- it "assigns the refunded_transaction_id to the original transaction" do
6426
- transaction = create_transaction_to_refund
6427
- refund_transaction = transaction.refund.new_transaction
6428
-
6429
- refund_transaction.refunded_transaction_id.should == transaction.id
6430
- end
6431
-
6432
- it "returns an error if already refunded" do
6433
- transaction = create_transaction_to_refund
6434
- result = transaction.refund
6435
- result.success?.should == true
6436
- result = transaction.refund
6437
- result.success?.should == false
6438
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::HasAlreadyBeenRefunded
6439
- end
6440
-
6441
- it "returns an error result if unsettled" do
6442
- transaction = Braintree::Transaction.create!(
6443
- :type => "sale",
6444
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6445
- :credit_card => {
6446
- :number => Braintree::Test::CreditCardNumbers::Visa,
6447
- :expiration_date => "05/2009"
6448
- }
6449
- )
6450
- result = transaction.refund
6451
- result.success?.should == false
6452
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CannotRefundUnlessSettled
6453
- end
6454
- end
6455
-
6456
- describe "submit_for_settlement" do
6457
- it "returns a successful result if successful" do
6458
- transaction = Braintree::Transaction.sale!(
6459
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6460
- :credit_card => {
6461
- :number => Braintree::Test::CreditCardNumbers::Visa,
6462
- :expiration_date => "06/2009"
6463
- }
6464
- )
6465
- result = transaction.submit_for_settlement
6466
- result.success?.should == true
6467
- end
6468
-
6469
- it "can submit a specific amount for settlement" do
6470
- transaction = Braintree::Transaction.sale!(
6471
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6472
- :credit_card => {
6473
- :number => Braintree::Test::CreditCardNumbers::Visa,
6474
- :expiration_date => "06/2009"
6475
- }
6476
- )
6477
- transaction.amount.should == BigDecimal("1000.00")
6478
- result = transaction.submit_for_settlement("999.99")
6479
- result.success?.should == true
6480
- transaction.amount.should == BigDecimal("999.99")
6481
- end
6482
-
6483
- it "updates the transaction attributes" do
6484
- transaction = Braintree::Transaction.sale!(
6485
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6486
- :credit_card => {
6487
- :number => Braintree::Test::CreditCardNumbers::Visa,
6488
- :expiration_date => "06/2009"
6489
- }
6490
- )
6491
- transaction.amount.should == BigDecimal("1000.00")
6492
- result = transaction.submit_for_settlement("999.99")
6493
- result.success?.should == true
6494
- transaction.amount.should == BigDecimal("999.99")
6495
- transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
6496
- transaction.updated_at.between?(Time.now - 60, Time.now).should == true
6497
- end
6498
-
6499
- it "returns an error result if unsuccessful" do
6500
- transaction = Braintree::Transaction.sale!(
6501
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6502
- :credit_card => {
6503
- :number => Braintree::Test::CreditCardNumbers::Visa,
6504
- :expiration_date => "06/2009"
6505
- }
6506
- )
6507
- transaction.amount.should == BigDecimal("1000.00")
6508
- result = transaction.submit_for_settlement("1000.01")
6509
- result.success?.should == false
6510
- result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::SettlementAmountIsTooLarge
6511
- result.params[:transaction][:amount].should == "1000.01"
6512
- end
6513
- end
6514
-
6515
- describe "submit_for_settlement!" do
6516
- it "returns the transaction if successful" do
6517
- original_transaction = Braintree::Transaction.sale!(
6518
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6519
- :credit_card => {
6520
- :number => Braintree::Test::CreditCardNumbers::Visa,
6521
- :expiration_date => "06/2009"
6522
- }
6523
- )
6524
- transaction = original_transaction.submit_for_settlement!
6525
- transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
6526
- transaction.id.should == original_transaction.id
6527
- end
6528
-
6529
- it "raises a ValidationsFailed if unsuccessful" do
6530
- transaction = Braintree::Transaction.sale!(
6531
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6532
- :credit_card => {
6533
- :number => Braintree::Test::CreditCardNumbers::Visa,
6534
- :expiration_date => "06/2009"
6535
- }
6536
- )
6537
- transaction.amount.should == BigDecimal("1000.00")
6538
- expect do
6539
- transaction.submit_for_settlement!("1000.01")
6540
- end.to raise_error(Braintree::ValidationsFailed)
6541
- end
6542
- end
6543
-
6544
6301
  describe "status_history" do
6545
6302
  it "returns an array of StatusDetail" do
6546
6303
  transaction = Braintree::Transaction.sale!(
@@ -6550,10 +6307,10 @@ describe Braintree::Transaction do
6550
6307
  :expiration_date => "05/2009"
6551
6308
  }
6552
6309
  )
6553
- transaction.submit_for_settlement!
6554
- transaction.status_history.size.should == 2
6555
- transaction.status_history[0].status.should == Braintree::Transaction::Status::Authorized
6556
- transaction.status_history[1].status.should == Braintree::Transaction::Status::SubmittedForSettlement
6310
+ result = Braintree::Transaction.submit_for_settlement!(transaction.id)
6311
+ result.status_history.size.should == 2
6312
+ result.status_history[0].status.should == Braintree::Transaction::Status::Authorized
6313
+ result.status_history[1].status.should == Braintree::Transaction::Status::SubmittedForSettlement
6557
6314
  end
6558
6315
  end
6559
6316
 
@@ -6608,7 +6365,7 @@ describe Braintree::Transaction do
6608
6365
  :expiration_date => "05/2010"
6609
6366
  }
6610
6367
  )
6611
- transaction = customer.credit_cards[0].sale(:amount => "100.00").transaction
6368
+ transaction = Braintree::CreditCard.sale(customer.credit_cards[0].token, {:amount => "100.00"}).transaction
6612
6369
  transaction.vault_credit_card.should == customer.credit_cards[0]
6613
6370
  end
6614
6371
 
@@ -6633,7 +6390,7 @@ describe Braintree::Transaction do
6633
6390
  :expiration_date => "05/2010"
6634
6391
  }
6635
6392
  )
6636
- transaction = customer.credit_cards[0].sale(:amount => "100.00").transaction
6393
+ transaction = Braintree::CreditCard.sale(customer.credit_cards[0].token, :amount => "100.00").transaction
6637
6394
  transaction.vault_customer.should == customer
6638
6395
  end
6639
6396
 
@@ -6650,68 +6407,6 @@ describe Braintree::Transaction do
6650
6407
  end
6651
6408
  end
6652
6409
 
6653
- describe "void" do
6654
- it "returns a successful result if successful" do
6655
- result = Braintree::Transaction.create(
6656
- :type => "sale",
6657
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6658
- :credit_card => {
6659
- :number => Braintree::Test::CreditCardNumbers::Visa,
6660
- :expiration_date => "05/2009"
6661
- }
6662
- )
6663
- result.success?.should == true
6664
- transaction = result.transaction
6665
- transaction.status.should == Braintree::Transaction::Status::Authorized
6666
- void_result = transaction.void
6667
- void_result.success?.should == true
6668
- void_result.transaction.should == transaction
6669
- transaction.status.should == void_result.transaction.status
6670
- end
6671
-
6672
- it "returns an error result if unsuccessful" do
6673
- transaction = Braintree::Transaction.sale(
6674
- :amount => Braintree::Test::TransactionAmounts::Decline,
6675
- :credit_card => {
6676
- :number => Braintree::Test::CreditCardNumbers::Visa,
6677
- :expiration_date => "05/2009"
6678
- }
6679
- ).transaction
6680
- transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
6681
- result = transaction.void
6682
- result.success?.should == false
6683
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CannotBeVoided
6684
- end
6685
- end
6686
-
6687
- describe "void!" do
6688
- it "returns the transaction if successful" do
6689
- transaction = Braintree::Transaction.sale!(
6690
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6691
- :credit_card => {
6692
- :number => Braintree::Test::CreditCardNumbers::Visa,
6693
- :expiration_date => "05/2009"
6694
- }
6695
- )
6696
- transaction.void!.should == transaction
6697
- transaction.status.should == Braintree::Transaction::Status::Voided
6698
- end
6699
-
6700
- it "raises a ValidationsFailed if unsuccessful" do
6701
- transaction = Braintree::Transaction.sale(
6702
- :amount => Braintree::Test::TransactionAmounts::Decline,
6703
- :credit_card => {
6704
- :number => Braintree::Test::CreditCardNumbers::Visa,
6705
- :expiration_date => "05/2009"
6706
- }
6707
- ).transaction
6708
- transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
6709
- expect do
6710
- transaction.void!
6711
- end.to raise_error(Braintree::ValidationsFailed)
6712
- end
6713
- end
6714
-
6715
6410
  def create_transaction_to_refund
6716
6411
  transaction = Braintree::Transaction.sale!(
6717
6412
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -7038,4 +6733,37 @@ describe Braintree::Transaction do
7038
6733
  details.refund_id.should_not be_nil
7039
6734
  end
7040
6735
  end
6736
+
6737
+ describe "card on file network tokenization" do
6738
+ it "creates a transaction with a vaulted, tokenized credit card" do
6739
+ result = Braintree::Transaction.sale(
6740
+ :amount => "112.44",
6741
+ :payment_method_token => "network_tokenized_credit_card",
6742
+ )
6743
+ result.success?.should == true
6744
+ transaction = result.transaction
6745
+
6746
+ transaction.amount.should == BigDecimal("112.44")
6747
+ transaction.processed_with_network_token?.should == true
6748
+ end
6749
+
6750
+ it "creates a transaction with a vaulted, non-tokenized credit card" do
6751
+ customer = Braintree::Customer.create!
6752
+ result = Braintree::PaymentMethod.create(
6753
+ :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
6754
+ :customer_id => customer.id
6755
+ )
6756
+ payment_method_token = result.payment_method.token
6757
+
6758
+ result = Braintree::Transaction.sale(
6759
+ :amount => "112.44",
6760
+ :payment_method_token => payment_method_token,
6761
+ )
6762
+ result.success?.should == true
6763
+ transaction = result.transaction
6764
+
6765
+ transaction.amount.should == BigDecimal("112.44")
6766
+ transaction.processed_with_network_token?.should == false
6767
+ end
6768
+ end
7041
6769
  end