braintree 2.103.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +6 -3
  4. data/lib/braintree.rb +5 -17
  5. data/lib/braintree/address.rb +0 -22
  6. data/lib/braintree/base_module.rb +6 -0
  7. data/lib/braintree/bin_data.rb +9 -2
  8. data/lib/braintree/configuration.rb +1 -1
  9. data/lib/braintree/credit_card.rb +0 -75
  10. data/lib/braintree/credit_card_gateway.rb +4 -33
  11. data/lib/braintree/credit_card_verification.rb +13 -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 +1 -0
  17. data/lib/braintree/dispute_gateway.rb +2 -7
  18. data/lib/braintree/error_codes.rb +144 -170
  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 +5 -9
  26. data/lib/braintree/payment_method_parser.rb +1 -7
  27. data/lib/braintree/resource_collection.rb +8 -3
  28. data/lib/braintree/subscription.rb +5 -5
  29. data/lib/braintree/successful_result.rb +0 -1
  30. data/lib/braintree/test/credit_card.rb +1 -0
  31. data/lib/braintree/test/nonce.rb +4 -20
  32. data/lib/braintree/transaction.rb +12 -74
  33. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  34. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  35. data/lib/braintree/transaction/installment.rb +28 -0
  36. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  37. data/lib/braintree/transaction/paypal_details.rb +3 -0
  38. data/lib/braintree/transaction/subscription_details.rb +2 -0
  39. data/lib/braintree/transaction_gateway.rb +14 -20
  40. data/lib/braintree/transaction_search.rb +0 -1
  41. data/lib/braintree/util.rb +17 -2
  42. data/lib/braintree/version.rb +2 -2
  43. data/lib/braintree/webhook_notification.rb +0 -10
  44. data/lib/braintree/webhook_testing_gateway.rb +0 -43
  45. data/lib/braintree/xml/libxml.rb +1 -0
  46. data/lib/braintree/xml/parser.rb +11 -34
  47. data/spec/integration/braintree/address_spec.rb +2 -89
  48. data/spec/integration/braintree/client_api/spec_helper.rb +0 -26
  49. data/spec/integration/braintree/credit_card_spec.rb +6 -471
  50. data/spec/integration/braintree/customer_spec.rb +189 -362
  51. data/spec/integration/braintree/dispute_search_spec.rb +3 -3
  52. data/spec/integration/braintree/dispute_spec.rb +1 -2
  53. data/spec/integration/braintree/merchant_spec.rb +2 -2
  54. data/spec/integration/braintree/payment_method_spec.rb +254 -120
  55. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +8 -4
  56. data/spec/integration/braintree/paypal_account_spec.rb +1 -1
  57. data/spec/integration/braintree/subscription_spec.rb +11 -16
  58. data/spec/integration/braintree/transaction_search_spec.rb +3 -3
  59. data/spec/integration/braintree/transaction_spec.rb +300 -534
  60. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +12 -6
  61. data/spec/integration/spec_helper.rb +1 -4
  62. data/spec/spec_helper.rb +2 -11
  63. data/spec/unit/braintree/address_spec.rb +0 -8
  64. data/spec/unit/braintree/credit_card_spec.rb +3 -22
  65. data/spec/unit/braintree/customer_spec.rb +2 -13
  66. data/spec/unit/braintree/dispute_spec.rb +3 -12
  67. data/spec/unit/braintree/http_spec.rb +3 -3
  68. data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
  69. data/spec/unit/braintree/resource_collection_spec.rb +29 -0
  70. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  71. data/spec/unit/braintree/transaction/paypal_details_spec.rb +59 -0
  72. data/spec/unit/braintree/transaction_spec.rb +1 -35
  73. data/spec/unit/braintree/util_spec.rb +37 -3
  74. data/spec/unit/braintree/webhook_notification_spec.rb +1 -1
  75. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  76. metadata +30 -30
  77. data/lib/braintree/amex_express_checkout_card.rb +0 -38
  78. data/lib/braintree/coinbase_account.rb +0 -34
  79. data/lib/braintree/europe_bank_account.rb +0 -36
  80. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  81. data/lib/braintree/ideal_payment.rb +0 -61
  82. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  83. data/lib/braintree/masterpass_card.rb +0 -81
  84. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  85. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  86. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  87. data/lib/braintree/transaction/masterpass_card_details.rb +0 -47
  88. data/lib/braintree/transparent_redirect.rb +0 -40
  89. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  90. data/lib/braintree/xml/rexml.rb +0 -71
  91. data/spec/hacks/tcp_socket.rb +0 -18
  92. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  93. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  94. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  95. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  96. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -13,7 +13,8 @@ describe Braintree::PaymentMethod do
13
13
  context "plaid verified nonce" do
14
14
  let(:nonce) { generate_valid_plaid_us_bank_account_nonce }
15
15
 
16
- it "succeeds" do
16
+ # we are temporarily skipping this test until we have a more stable CI env
17
+ xit "succeeds" do
17
18
  customer = Braintree::Customer.create.customer
18
19
  result = Braintree::PaymentMethod.create(
19
20
  :payment_method_nonce => nonce,
@@ -49,7 +50,8 @@ describe Braintree::PaymentMethod do
49
50
  Braintree::UsBankAccountVerification::VerificationMethod::IndependentCheck,
50
51
  Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck,
51
52
  ].each do |method|
52
- it "succeeds and verifies via #{method}" do
53
+ # we are temporarily skipping this test until we have a more stable CI env
54
+ xit "succeeds and verifies via #{method}" do
53
55
  customer = Braintree::Customer.create.customer
54
56
  result = Braintree::PaymentMethod.create(
55
57
  :payment_method_nonce => nonce,
@@ -183,7 +185,8 @@ describe Braintree::PaymentMethod do
183
185
 
184
186
  let(:nonce) { generate_valid_plaid_us_bank_account_nonce }
185
187
 
186
- it "succeeds and verifies via independent check" do
188
+ # we are temporarily skipping this test until we have a more stable CI env
189
+ xit "succeeds and verifies via independent check" do
187
190
  customer = Braintree::Customer.create.customer
188
191
  result = Braintree::PaymentMethod.create(
189
192
  :payment_method_nonce => nonce,
@@ -219,7 +222,8 @@ describe Braintree::PaymentMethod do
219
222
  context "non plaid verified nonce" do
220
223
  let(:nonce) { generate_non_plaid_us_bank_account_nonce }
221
224
 
222
- it "succeeds and verifies via independent check" do
225
+ # we are temporarily skipping this test until we have a more stable CI env
226
+ xit "succeeds and verifies via independent check" do
223
227
  customer = Braintree::Customer.create.customer
224
228
  result = Braintree::PaymentMethod.create(
225
229
  :payment_method_nonce => nonce,
@@ -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
@@ -159,7 +159,6 @@ describe Braintree::Transaction do
159
159
  }
160
160
  )
161
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
162
  result.errors.for(:transaction).for(:risk_data).on(:customer_device_id).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerDeviceIdIsTooLong
164
163
  result.errors.for(:transaction).for(:risk_data).on(:customer_location_zip).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerLocationZipInvalidCharacters
165
164
  result.errors.for(:transaction).for(:risk_data).on(:customer_tenure).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerTenureIsTooLong
@@ -182,6 +181,42 @@ describe Braintree::Transaction do
182
181
  end
183
182
  end
184
183
 
184
+ describe "sca_exemption" do
185
+ context "with a valid request" do
186
+ it "succeeds" do
187
+ requested_exemption = "low_value"
188
+ result = Braintree::Transaction.create(
189
+ :type => "sale",
190
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
191
+ :credit_card => {
192
+ :number => Braintree::Test::CreditCardNumbers::VisaCountryOfIssuanceIE,
193
+ :expiration_date => "05/2009"
194
+ },
195
+ :sca_exemption => requested_exemption,
196
+ )
197
+ expect(result).to be_success
198
+ expect(result.transaction.sca_exemption_requested).to eq(requested_exemption)
199
+ end
200
+ end
201
+
202
+ context "with an invalid request" do
203
+ it "returns an error" do
204
+ result = Braintree::Transaction.create(
205
+ :type => "sale",
206
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
207
+ :credit_card => {
208
+ :number => Braintree::Test::CreditCardNumbers::Visa,
209
+ :expiration_date => "05/2009"
210
+ },
211
+ :sca_exemption => "invalid_sca_exemption_value",
212
+ )
213
+ sca_exemption_invalid = Braintree::ErrorCodes::Transaction::ScaExemptionInvalid
214
+ expect(result).not_to be_success
215
+ expect(result.errors.for(:transaction).map(&:code)).to eq([sca_exemption_invalid])
216
+ end
217
+ end
218
+ end
219
+
185
220
  describe "industry data" do
186
221
  context "for lodging" do
187
222
  it "accepts valid industry data" do
@@ -445,6 +480,7 @@ describe Braintree::Transaction do
445
480
  result.transaction.credit_card_details.expiration_date.should == "05/2009"
446
481
  result.transaction.credit_card_details.customer_location.should == "US"
447
482
  result.transaction.retrieval_reference_number.should_not be_nil
483
+ result.transaction.acquirer_reference_number.should be_nil
448
484
  end
449
485
 
450
486
  it "returns a successful network response code if successful" do
@@ -509,7 +545,7 @@ describe Braintree::Transaction do
509
545
  result.transaction.credit_card_details.customer_location.should == "US"
510
546
  end
511
547
 
512
- it "accepts additional security parameters: device_session_id and fraud_merchant_id" do
548
+ it "accepts additional security parameters: device_data" do
513
549
  result = Braintree::Transaction.create(
514
550
  :type => "sale",
515
551
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -517,8 +553,7 @@ describe Braintree::Transaction do
517
553
  :number => Braintree::Test::CreditCardNumbers::Visa,
518
554
  :expiration_date => "05/2009"
519
555
  },
520
- :device_session_id => "abc123",
521
- :fraud_merchant_id => "7"
556
+ :device_data => "device_data",
522
557
  )
523
558
 
524
559
  result.success?.should == true
@@ -1372,22 +1407,6 @@ describe Braintree::Transaction do
1372
1407
  end
1373
1408
  end
1374
1409
 
1375
- context "recurring" do
1376
- it "marks a transaction as recurring" do
1377
- result = Braintree::Transaction.create(
1378
- :type => "sale",
1379
- :amount => Braintree::Test::TransactionAmounts::Authorize,
1380
- :credit_card => {
1381
- :number => Braintree::Test::CreditCardNumbers::Visa,
1382
- :expiration_date => "12/12",
1383
- },
1384
- :recurring => true
1385
- )
1386
- result.success?.should == true
1387
- result.transaction.recurring.should == true
1388
- end
1389
- end
1390
-
1391
1410
  context "transaction_source" do
1392
1411
  it "marks a transactions as recurring_first" do
1393
1412
  result = Braintree::Transaction.create(
@@ -1804,106 +1823,83 @@ describe Braintree::Transaction do
1804
1823
  apple_pay_details.token.should_not be_nil
1805
1824
  end
1806
1825
 
1807
- it "can create a transaction with a fake android pay proxy card nonce" do
1826
+ it "can create a transaction with a fake google pay proxy card nonce" do
1808
1827
  customer = Braintree::Customer.create!
1809
1828
  result = Braintree::Transaction.create(
1810
1829
  :type => "sale",
1811
1830
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1812
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover
1831
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover
1813
1832
  )
1814
1833
  result.success?.should == true
1815
1834
  result.transaction.should_not be_nil
1816
- android_pay_details = result.transaction.android_pay_details
1817
- android_pay_details.should_not be_nil
1818
- android_pay_details.bin.should_not be_nil
1819
- android_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1820
- android_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1821
- android_pay_details.last_4.should == "1117"
1822
- android_pay_details.virtual_card_last_4.should == "1117"
1823
- android_pay_details.source_description.should == "Discover 1111"
1824
- android_pay_details.expiration_month.to_i.should > 0
1825
- android_pay_details.expiration_year.to_i.should > 0
1826
- android_pay_details.google_transaction_id.should == "google_transaction_id"
1827
- android_pay_details.image_url.should_not be_nil
1828
- android_pay_details.is_network_tokenized?.should == false
1829
- android_pay_details.token.should be_nil
1830
- android_pay_details.prepaid.should_not be_nil
1831
- android_pay_details.healthcare.should_not be_nil
1832
- android_pay_details.debit.should_not be_nil
1833
- android_pay_details.durbin_regulated.should_not be_nil
1834
- android_pay_details.commercial.should_not be_nil
1835
- android_pay_details.payroll.should_not be_nil
1836
- android_pay_details.product_id.should_not be_nil
1837
- end
1838
-
1839
- it "can create a vaulted transaction with a fake android pay proxy card nonce" do
1835
+ google_pay_details = result.transaction.google_pay_details
1836
+ google_pay_details.should_not be_nil
1837
+ google_pay_details.bin.should_not be_nil
1838
+ google_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1839
+ google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1840
+ google_pay_details.last_4.should == "1117"
1841
+ google_pay_details.virtual_card_last_4.should == "1117"
1842
+ google_pay_details.source_description.should == "Discover 1111"
1843
+ google_pay_details.expiration_month.to_i.should > 0
1844
+ google_pay_details.expiration_year.to_i.should > 0
1845
+ google_pay_details.google_transaction_id.should == "google_transaction_id"
1846
+ google_pay_details.image_url.should_not be_nil
1847
+ google_pay_details.is_network_tokenized?.should == false
1848
+ google_pay_details.token.should be_nil
1849
+ google_pay_details.prepaid.should_not be_nil
1850
+ google_pay_details.healthcare.should_not be_nil
1851
+ google_pay_details.debit.should_not be_nil
1852
+ google_pay_details.durbin_regulated.should_not be_nil
1853
+ google_pay_details.commercial.should_not be_nil
1854
+ google_pay_details.payroll.should_not be_nil
1855
+ google_pay_details.product_id.should_not be_nil
1856
+ end
1857
+
1858
+ it "can create a vaulted transaction with a fake google pay proxy card nonce" do
1840
1859
  customer = Braintree::Customer.create!
1841
1860
  result = Braintree::Transaction.create(
1842
1861
  :type => "sale",
1843
1862
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1844
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
1863
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1845
1864
  :options => { :store_in_vault_on_success => true }
1846
1865
  )
1847
1866
  result.success?.should == true
1848
1867
  result.transaction.should_not be_nil
1849
- android_pay_details = result.transaction.android_pay_details
1850
- android_pay_details.should_not be_nil
1851
- android_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1852
- android_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1853
- android_pay_details.last_4.should == "1117"
1854
- android_pay_details.virtual_card_last_4.should == "1117"
1855
- android_pay_details.source_description.should == "Discover 1111"
1856
- android_pay_details.expiration_month.to_i.should > 0
1857
- android_pay_details.expiration_year.to_i.should > 0
1858
- android_pay_details.google_transaction_id.should == "google_transaction_id"
1859
- android_pay_details.image_url.should_not be_nil
1860
- android_pay_details.is_network_tokenized?.should == false
1861
- android_pay_details.token.should_not be_nil
1862
- end
1863
-
1864
- it "can create a transaction with a fake android pay network token nonce" do
1868
+ google_pay_details = result.transaction.google_pay_details
1869
+ google_pay_details.should_not be_nil
1870
+ google_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1871
+ google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1872
+ google_pay_details.last_4.should == "1117"
1873
+ google_pay_details.virtual_card_last_4.should == "1117"
1874
+ google_pay_details.source_description.should == "Discover 1111"
1875
+ google_pay_details.expiration_month.to_i.should > 0
1876
+ google_pay_details.expiration_year.to_i.should > 0
1877
+ google_pay_details.google_transaction_id.should == "google_transaction_id"
1878
+ google_pay_details.image_url.should_not be_nil
1879
+ google_pay_details.is_network_tokenized?.should == false
1880
+ google_pay_details.token.should_not be_nil
1881
+ end
1882
+
1883
+ it "can create a transaction with a fake google pay network token nonce" do
1865
1884
  customer = Braintree::Customer.create!
1866
1885
  result = Braintree::Transaction.create(
1867
1886
  :type => "sale",
1868
1887
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1869
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard
1888
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard
1870
1889
  )
1871
1890
  result.success?.should == true
1872
1891
  result.transaction.should_not be_nil
1873
- android_pay_details = result.transaction.android_pay_details
1874
- android_pay_details.should_not be_nil
1875
- android_pay_details.card_type.should == Braintree::CreditCard::CardType::MasterCard
1876
- android_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1877
- android_pay_details.last_4.should == "4444"
1878
- android_pay_details.virtual_card_last_4.should == "4444"
1879
- android_pay_details.source_description.should == "MasterCard 4444"
1880
- android_pay_details.expiration_month.to_i.should > 0
1881
- android_pay_details.expiration_year.to_i.should > 0
1882
- android_pay_details.google_transaction_id.should == "google_transaction_id"
1883
- android_pay_details.is_network_tokenized?.should == true
1884
- end
1885
-
1886
- it "can create a transaction with a fake amex express checkout card nonce" do
1887
- result = Braintree::Transaction.create(
1888
- :type => "sale",
1889
- :merchant_account_id => SpecHelper::FakeAmexDirectMerchantAccountId,
1890
- :amount => Braintree::Test::TransactionAmounts::Authorize,
1891
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout,
1892
- :options => {:store_in_vault => true}
1893
- )
1894
- result.success?.should == true
1895
- result.transaction.should_not be_nil
1896
- checkout_details = result.transaction.amex_express_checkout_details
1897
- checkout_details.should_not be_nil
1898
- checkout_details.card_type.should == "American Express"
1899
- checkout_details.token.should respond_to(:to_str)
1900
- checkout_details.bin.should =~ /\A\d{6}\z/
1901
- checkout_details.expiration_month.should =~ /\A\d{2}\z/
1902
- checkout_details.expiration_year.should =~ /\A\d{4}\z/
1903
- checkout_details.card_member_number.should =~ /\A\d{4}\z/
1904
- checkout_details.card_member_expiry_date.should =~ /\A\d{2}\/\d{2}\z/
1905
- checkout_details.image_url.should include(".png")
1906
- checkout_details.source_description.should =~ /\AAmEx \d{4}\z/
1892
+ google_pay_details = result.transaction.google_pay_details
1893
+ google_pay_details.should_not be_nil
1894
+ google_pay_details.card_type.should == Braintree::CreditCard::CardType::MasterCard
1895
+ google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1896
+ google_pay_details.last_4.should == "4444"
1897
+ google_pay_details.virtual_card_last_4.should == "4444"
1898
+ google_pay_details.source_description.should == "MasterCard 4444"
1899
+ google_pay_details.expiration_month.to_i.should > 0
1900
+ google_pay_details.expiration_year.to_i.should > 0
1901
+ google_pay_details.google_transaction_id.should == "google_transaction_id"
1902
+ google_pay_details.is_network_tokenized?.should == true
1907
1903
  end
1908
1904
 
1909
1905
  it "can create a transaction with a fake venmo account nonce" do
@@ -2703,6 +2699,22 @@ describe Braintree::Transaction do
2703
2699
  end
2704
2700
  end
2705
2701
 
2702
+ context "billing agreement" do
2703
+ it "can create a paypal billing agreement" do
2704
+ result = Braintree::Transaction.create(
2705
+ :type => "sale",
2706
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
2707
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
2708
+ :options => {:store_in_vault => true}
2709
+ )
2710
+
2711
+ result.should be_success
2712
+ result.transaction.paypal_details.should_not be_nil
2713
+ result.transaction.paypal_details.debug_id.should_not be_nil
2714
+ result.transaction.paypal_details.billing_agreement_id.should_not be_nil
2715
+ end
2716
+ end
2717
+
2706
2718
  context "local payments" do
2707
2719
  it "can create a local payment transaction with a nonce" do
2708
2720
  result = Braintree::Transaction.create(
@@ -2865,14 +2877,6 @@ describe Braintree::Transaction do
2865
2877
  }.to raise_error(ArgumentError)
2866
2878
  end
2867
2879
 
2868
- it "assigns the refund_id on the original transaction" do
2869
- transaction = create_paypal_transaction_for_refund
2870
- refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
2871
- transaction = Braintree::Transaction.find(transaction.id)
2872
-
2873
- transaction.refund_id.should == refund_transaction.id
2874
- end
2875
-
2876
2880
  it "assigns the refunded_transaction_id to the original transaction" do
2877
2881
  transaction = create_paypal_transaction_for_refund
2878
2882
  refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
@@ -2902,7 +2906,13 @@ describe Braintree::Transaction do
2902
2906
  response = config.http.put("#{config.base_merchant_path}/transactions/#{transaction.id}/settle")
2903
2907
  result = Braintree::Transaction.refund(transaction.id, :amount => "2046.00")
2904
2908
  result.success?.should == false
2905
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::RefundAuthSoftDeclined
2909
+ result.transaction.id.should =~ /^\w{6,}$/
2910
+ result.transaction.type.should == "credit"
2911
+ result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
2912
+ result.transaction.processor_response_code.should == "2046"
2913
+ result.transaction.processor_response_text.should == "Declined"
2914
+ result.transaction.processor_response_type.should == Braintree::ProcessorResponseTypes::SoftDeclined
2915
+ result.transaction.additional_processor_response.should == "2046 : Declined"
2906
2916
  end
2907
2917
 
2908
2918
  it "handles hard declined refund authorizations" do
@@ -2917,7 +2927,13 @@ describe Braintree::Transaction do
2917
2927
  response = config.http.put("#{config.base_merchant_path}/transactions/#{transaction.id}/settle")
2918
2928
  result = Braintree::Transaction.refund(transaction.id, :amount => "2009.00")
2919
2929
  result.success?.should == false
2920
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::RefundAuthHardDeclined
2930
+ result.transaction.id.should =~ /^\w{6,}$/
2931
+ result.transaction.type.should == "credit"
2932
+ result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
2933
+ result.transaction.processor_response_code.should == "2009"
2934
+ result.transaction.processor_response_text.should == "No Such Issuer"
2935
+ result.transaction.processor_response_type.should == Braintree::ProcessorResponseTypes::HardDeclined
2936
+ result.transaction.additional_processor_response.should == "2009 : No Such Issuer"
2921
2937
  end
2922
2938
  end
2923
2939
 
@@ -4289,7 +4305,7 @@ describe Braintree::Transaction do
4289
4305
  result.errors.for(:transaction).for(:external_vault).on(:status)[0].code.should == Braintree::ErrorCodes::Transaction::ExternalVault::StatusIsInvalid
4290
4306
  end
4291
4307
 
4292
- context "Visa/Mastercard/Discover" do
4308
+ context "Visa/Mastercard/Discover/AmEx" do
4293
4309
  it "accepts status" do
4294
4310
  result = Braintree::Transaction.create(
4295
4311
  :type => "sale",
@@ -4341,12 +4357,12 @@ describe Braintree::Transaction do
4341
4357
  end
4342
4358
  end
4343
4359
 
4344
- context "Non-(Visa/Mastercard/Discover) card types" do
4360
+ context "Non-(Visa/Mastercard/Discover/AmEx) card types" do
4345
4361
  it "accepts status" do
4346
4362
  result = Braintree::Transaction.create(
4347
4363
  :type => "sale",
4348
4364
  :credit_card => {
4349
- :number => Braintree::Test::CreditCardNumbers::AmExes[0],
4365
+ :number => Braintree::Test::CreditCardNumbers::JCBs[0],
4350
4366
  :expiration_date => "05/2009"
4351
4367
  },
4352
4368
  :external_vault => {
@@ -4362,7 +4378,7 @@ describe Braintree::Transaction do
4362
4378
  result = Braintree::Transaction.create(
4363
4379
  :type => "sale",
4364
4380
  :credit_card => {
4365
- :number => Braintree::Test::CreditCardNumbers::AmExes[0],
4381
+ :number => Braintree::Test::CreditCardNumbers::JCBs[0],
4366
4382
  :expiration_date => "05/2009"
4367
4383
  },
4368
4384
  :external_vault => {
@@ -4374,25 +4390,7 @@ describe Braintree::Transaction do
4374
4390
  result.success?.should == true
4375
4391
  result.transaction.network_transaction_id.should be_nil
4376
4392
  end
4377
-
4378
- it "rejects previous_network_transaction_id" do
4379
- result = Braintree::Transaction.create(
4380
- :type => "sale",
4381
- :credit_card => {
4382
- :number => Braintree::Test::CreditCardNumbers::AmExes[0],
4383
- :expiration_date => "05/2009"
4384
- },
4385
- :external_vault => {
4386
- :status => Braintree::Transaction::ExternalVault::Status::Vaulted,
4387
- :previous_network_transaction_id => "123456789012345",
4388
- },
4389
- :amount => "10.00",
4390
- )
4391
- result.success?.should == false
4392
- result.errors.for(:transaction).for(:external_vault).on(:previous_network_transaction_id)[0].code.should == Braintree::ErrorCodes::Transaction::ExternalVault::CardTypeIsInvalid
4393
- end
4394
4393
  end
4395
-
4396
4394
  end
4397
4395
 
4398
4396
  context "account_type" do
@@ -4571,14 +4569,6 @@ describe Braintree::Transaction do
4571
4569
  result.transaction.type.should == "credit"
4572
4570
  end
4573
4571
 
4574
- it "assigns the refund_id on the original transaction" do
4575
- transaction = create_transaction_to_refund
4576
- refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
4577
- transaction = Braintree::Transaction.find(transaction.id)
4578
-
4579
- transaction.refund_id.should == refund_transaction.id
4580
- end
4581
-
4582
4572
  it "assigns the refunded_transaction_id to the original transaction" do
4583
4573
  transaction = create_transaction_to_refund
4584
4574
  refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
@@ -4986,6 +4976,73 @@ describe Braintree::Transaction do
4986
4976
  result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
4987
4977
  end
4988
4978
 
4979
+ it "validates currency_iso_code and creates transaction" do
4980
+ params = {
4981
+ :transaction => {
4982
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
4983
+ :currency_iso_code => "USD",
4984
+ :credit_card => {
4985
+ :number => Braintree::Test::CreditCardNumbers::Visa,
4986
+ :expiration_date => "05/2009"
4987
+ }
4988
+ }
4989
+ }
4990
+ result = Braintree::Transaction.sale(params[:transaction])
4991
+ result.success?.should == true
4992
+ result.transaction.currency_iso_code == "USD"
4993
+ end
4994
+
4995
+ it "validates currency_iso_code and returns error" do
4996
+ params = {
4997
+ :transaction => {
4998
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
4999
+ :currency_iso_code => "CAD",
5000
+ :credit_card => {
5001
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5002
+ :expiration_date => "05/2009"
5003
+ }
5004
+ }
5005
+ }
5006
+ result = Braintree::Transaction.sale(params[:transaction])
5007
+ result.success?.should == false
5008
+ result.errors.for(:transaction).on(:currency_iso_code)[0].code.should == Braintree::ErrorCodes::Transaction::CurrencyCodeNotSupportedByMerchantAccount
5009
+ end
5010
+
5011
+ it "validates currency_iso_code and creates transaction with specified merchant account" do
5012
+ params = {
5013
+ :transaction => {
5014
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
5015
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
5016
+ :currency_iso_code => "USD",
5017
+ :credit_card => {
5018
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5019
+ :expiration_date => "05/2009"
5020
+ }
5021
+ }
5022
+ }
5023
+ result = Braintree::Transaction.sale(params[:transaction])
5024
+ result.success?.should == true
5025
+ result.transaction.currency_iso_code == "USD"
5026
+ result.transaction.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
5027
+ end
5028
+
5029
+ it "validates currency_iso_code and returns error with specified merchant account" do
5030
+ params = {
5031
+ :transaction => {
5032
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
5033
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
5034
+ :currency_iso_code => "CAD",
5035
+ :credit_card => {
5036
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5037
+ :expiration_date => "05/2009"
5038
+ }
5039
+ }
5040
+ }
5041
+ result = Braintree::Transaction.sale(params[:transaction])
5042
+ result.success?.should == false
5043
+ result.errors.for(:transaction).on(:currency_iso_code)[0].code.should == Braintree::ErrorCodes::Transaction::CurrencyCodeNotSupportedByMerchantAccount
5044
+ end
5045
+
4989
5046
  it "skips advanced fraud checking if transaction[options][skip_advanced_fraud_checking] is set to true" do
4990
5047
  with_advanced_fraud_integration_merchant do
4991
5048
  result = Braintree::Transaction.sale(
@@ -5020,11 +5077,11 @@ describe Braintree::Transaction do
5020
5077
  result.transaction.status.should == Braintree::Transaction::Status::Authorized
5021
5078
  end
5022
5079
 
5023
- context "Android Pay params" do
5080
+ context "Google Pay params" do
5024
5081
  it "works with full params" do
5025
5082
  params = {
5026
5083
  :amount => "3.12",
5027
- :android_pay_card => {
5084
+ :google_pay_card => {
5028
5085
  :number => "4012888888881881",
5029
5086
  :cryptogram => "AAAAAAAA/COBt84dnIEcwAA3gAAGhgEDoLABAAhAgAABAAAALnNCLw==",
5030
5087
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
@@ -5043,7 +5100,7 @@ describe Braintree::Transaction do
5043
5100
  it "works with only number, cryptogram, expiration and transaction ID (network tokenized card)" do
5044
5101
  params = {
5045
5102
  :amount => "3.12",
5046
- :android_pay_card => {
5103
+ :google_pay_card => {
5047
5104
  :number => "4012888888881881",
5048
5105
  :cryptogram => "AAAAAAAA/COBt84dnIEcwAA3gAAGhgEDoLABAAhAgAABAAAALnNCLw==",
5049
5106
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
@@ -5059,7 +5116,7 @@ describe Braintree::Transaction do
5059
5116
  it "works with only number, expiration and transaction ID (non-tokenized card)" do
5060
5117
  params = {
5061
5118
  :amount => "3.12",
5062
- :android_pay_card => {
5119
+ :google_pay_card => {
5063
5120
  :number => "4012888888881881",
5064
5121
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
5065
5122
  :expiration_month => "10",
@@ -6048,184 +6105,6 @@ describe Braintree::Transaction do
6048
6105
  end
6049
6106
  end
6050
6107
 
6051
- describe "self.create_from_transparent_redirect" do
6052
- it "returns a successful result if successful" do
6053
- params = {
6054
- :transaction => {
6055
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6056
- :credit_card => {
6057
- :number => Braintree::Test::CreditCardNumbers::Visa,
6058
- :expiration_date => "05/2009"
6059
- }
6060
- }
6061
- }
6062
- tr_data_params = {
6063
- :transaction => {
6064
- :type => "sale"
6065
- }
6066
- }
6067
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
6068
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
6069
- result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
6070
-
6071
- result.success?.should == true
6072
- transaction = result.transaction
6073
- transaction.type.should == "sale"
6074
- transaction.amount.should == BigDecimal("1000.00")
6075
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
6076
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
6077
- transaction.credit_card_details.expiration_date.should == "05/2009"
6078
- end
6079
-
6080
- it "raises an error with a message if given invalid params" do
6081
- params = {
6082
- :transaction => {
6083
- :bad => "value",
6084
- :amount => Braintree::Test::TransactionAmounts::Authorize,
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
-
6099
- expect do
6100
- Braintree::Transaction.create_from_transparent_redirect(query_string_response)
6101
- end.to raise_error(Braintree::AuthorizationError, "Invalid params: transaction[bad]")
6102
- end
6103
-
6104
- it "can put any param in tr_data" do
6105
- params = {
6106
-
6107
- }
6108
- tr_data_params = {
6109
- :transaction => {
6110
- :amount => "100.00",
6111
- :order_id => "123",
6112
- :channel => "MyShoppingCartProvider",
6113
- :type => "sale",
6114
- :credit_card => {
6115
- :cardholder_name => "The Cardholder",
6116
- :number => "5105105105105100",
6117
- :expiration_date => "05/2011",
6118
- :cvv => "123"
6119
- },
6120
- :customer => {
6121
- :first_name => "Dan",
6122
- :last_name => "Smith",
6123
- :company => "Braintree",
6124
- :email => "dan@example.com",
6125
- :phone => "419-555-1234",
6126
- :fax => "419-555-1235",
6127
- :website => "http://braintreepayments.com"
6128
- },
6129
- :billing => {
6130
- :first_name => "Carl",
6131
- :last_name => "Jones",
6132
- :company => "Braintree",
6133
- :street_address => "123 E Main St",
6134
- :extended_address => "Suite 403",
6135
- :locality => "Chicago",
6136
- :region => "IL",
6137
- :postal_code => "60622",
6138
- :country_name => "United States of America"
6139
- },
6140
- :shipping => {
6141
- :first_name => "Andrew",
6142
- :last_name => "Mason",
6143
- :company => "Braintree",
6144
- :street_address => "456 W Main St",
6145
- :extended_address => "Apt 2F",
6146
- :locality => "Bartlett",
6147
- :region => "IL",
6148
- :postal_code => "60103",
6149
- :country_name => "United States of America"
6150
- }
6151
- }
6152
- }
6153
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
6154
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
6155
- result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
6156
-
6157
- transaction = result.transaction
6158
- transaction.id.should =~ /\A\w{6,}\z/
6159
- transaction.type.should == "sale"
6160
- transaction.status.should == Braintree::Transaction::Status::Authorized
6161
- transaction.amount.should == BigDecimal("100.00")
6162
- transaction.order_id.should == "123"
6163
- transaction.channel.should == "MyShoppingCartProvider"
6164
- transaction.processor_response_code.should == "1000"
6165
- transaction.authorization_expires_at.between?(Time.now, Time.now + (60 * 60 * 24 * 60)).should == true
6166
- transaction.created_at.between?(Time.now - 60, Time.now).should == true
6167
- transaction.updated_at.between?(Time.now - 60, Time.now).should == true
6168
- transaction.credit_card_details.bin.should == "510510"
6169
- transaction.credit_card_details.last_4.should == "5100"
6170
- transaction.credit_card_details.cardholder_name.should == "The Cardholder"
6171
- transaction.credit_card_details.masked_number.should == "510510******5100"
6172
- transaction.credit_card_details.card_type.should == "MasterCard"
6173
- transaction.avs_error_response_code.should == nil
6174
- transaction.avs_postal_code_response_code.should == "M"
6175
- transaction.avs_street_address_response_code.should == "M"
6176
- transaction.cvv_response_code.should == "M"
6177
- transaction.customer_details.first_name.should == "Dan"
6178
- transaction.customer_details.last_name.should == "Smith"
6179
- transaction.customer_details.company.should == "Braintree"
6180
- transaction.customer_details.email.should == "dan@example.com"
6181
- transaction.customer_details.phone.should == "419-555-1234"
6182
- transaction.customer_details.fax.should == "419-555-1235"
6183
- transaction.customer_details.website.should == "http://braintreepayments.com"
6184
- transaction.billing_details.first_name.should == "Carl"
6185
- transaction.billing_details.last_name.should == "Jones"
6186
- transaction.billing_details.company.should == "Braintree"
6187
- transaction.billing_details.street_address.should == "123 E Main St"
6188
- transaction.billing_details.extended_address.should == "Suite 403"
6189
- transaction.billing_details.locality.should == "Chicago"
6190
- transaction.billing_details.region.should == "IL"
6191
- transaction.billing_details.postal_code.should == "60622"
6192
- transaction.billing_details.country_name.should == "United States of America"
6193
- transaction.shipping_details.first_name.should == "Andrew"
6194
- transaction.shipping_details.last_name.should == "Mason"
6195
- transaction.shipping_details.company.should == "Braintree"
6196
- transaction.shipping_details.street_address.should == "456 W Main St"
6197
- transaction.shipping_details.extended_address.should == "Apt 2F"
6198
- transaction.shipping_details.locality.should == "Bartlett"
6199
- transaction.shipping_details.region.should == "IL"
6200
- transaction.shipping_details.postal_code.should == "60103"
6201
- transaction.shipping_details.country_name.should == "United States of America"
6202
- end
6203
-
6204
- it "returns an error result if validations fail" do
6205
- params = {
6206
- :transaction => {
6207
- :amount => "",
6208
- :credit_card => {
6209
- :number => Braintree::Test::CreditCardNumbers::Visa,
6210
- :expiration_date => "05/2009"
6211
- }
6212
- }
6213
- }
6214
- tr_data_params = {
6215
- :transaction => {
6216
- :type => "sale"
6217
- }
6218
- }
6219
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
6220
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
6221
- result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
6222
-
6223
- result.success?.should == false
6224
- result.params[:transaction].should == {:amount => "", :type => "sale", :credit_card => {:expiration_date => "05/2009"}}
6225
- result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
6226
- end
6227
- end
6228
-
6229
6108
  describe "self.find" do
6230
6109
  it "finds the transaction with the given id" do
6231
6110
  result = Braintree::Transaction.create(
@@ -6267,6 +6146,12 @@ describe Braintree::Transaction do
6267
6146
  end.to raise_error(Braintree::NotFoundError, 'transaction with id "invalid-id" not found')
6268
6147
  end
6269
6148
 
6149
+ it "finds a transaction and returns an acquirer_reference_number if the transaction has one" do
6150
+ transaction = Braintree::Transaction.find("transactionwithacquirerreferencenumber")
6151
+
6152
+ transaction.acquirer_reference_number.should == "123456789 091019"
6153
+ end
6154
+
6270
6155
  context "disbursement_details" do
6271
6156
  it "includes disbursement_details on found transactions" do
6272
6157
  found_transaction = Braintree::Transaction.find("deposittransaction")
@@ -6274,7 +6159,8 @@ describe Braintree::Transaction do
6274
6159
  found_transaction.disbursed?.should == true
6275
6160
  disbursement = found_transaction.disbursement_details
6276
6161
 
6277
- disbursement.disbursement_date.should == "2013-04-10"
6162
+ expect(disbursement.disbursement_date).to be_a Date
6163
+ expect(disbursement.disbursement_date).to eq Date.parse("2013-04-10")
6278
6164
  disbursement.settlement_amount.should == "100.00"
6279
6165
  disbursement.settlement_currency_iso_code.should == "USD"
6280
6166
  disbursement.settlement_currency_exchange_rate.should == "1"
@@ -6519,151 +6405,6 @@ describe Braintree::Transaction do
6519
6405
  end
6520
6406
  end
6521
6407
 
6522
- describe "refund" do
6523
- context "partial refunds" do
6524
- it "allows partial refunds" do
6525
- transaction = create_transaction_to_refund
6526
- result = transaction.refund(transaction.amount / 2)
6527
- result.success?.should == true
6528
- result.new_transaction.type.should == "credit"
6529
- end
6530
- end
6531
-
6532
- it "returns a successful result if successful" do
6533
- transaction = create_transaction_to_refund
6534
- transaction.status.should == Braintree::Transaction::Status::Settled
6535
- result = transaction.refund
6536
- result.success?.should == true
6537
- result.new_transaction.type.should == "credit"
6538
- end
6539
-
6540
- it "assigns the refund_id on the original transaction" do
6541
- transaction = create_transaction_to_refund
6542
- refund_transaction = transaction.refund.new_transaction
6543
- transaction = Braintree::Transaction.find(transaction.id)
6544
-
6545
- transaction.refund_id.should == refund_transaction.id
6546
- end
6547
-
6548
- it "assigns the refunded_transaction_id to the original transaction" do
6549
- transaction = create_transaction_to_refund
6550
- refund_transaction = transaction.refund.new_transaction
6551
-
6552
- refund_transaction.refunded_transaction_id.should == transaction.id
6553
- end
6554
-
6555
- it "returns an error if already refunded" do
6556
- transaction = create_transaction_to_refund
6557
- result = transaction.refund
6558
- result.success?.should == true
6559
- result = transaction.refund
6560
- result.success?.should == false
6561
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::HasAlreadyBeenRefunded
6562
- end
6563
-
6564
- it "returns an error result if unsettled" do
6565
- transaction = Braintree::Transaction.create!(
6566
- :type => "sale",
6567
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6568
- :credit_card => {
6569
- :number => Braintree::Test::CreditCardNumbers::Visa,
6570
- :expiration_date => "05/2009"
6571
- }
6572
- )
6573
- result = transaction.refund
6574
- result.success?.should == false
6575
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CannotRefundUnlessSettled
6576
- end
6577
- end
6578
-
6579
- describe "submit_for_settlement" do
6580
- it "returns a successful result if successful" do
6581
- transaction = Braintree::Transaction.sale!(
6582
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6583
- :credit_card => {
6584
- :number => Braintree::Test::CreditCardNumbers::Visa,
6585
- :expiration_date => "06/2009"
6586
- }
6587
- )
6588
- result = transaction.submit_for_settlement
6589
- result.success?.should == true
6590
- end
6591
-
6592
- it "can submit a specific amount for settlement" do
6593
- transaction = Braintree::Transaction.sale!(
6594
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6595
- :credit_card => {
6596
- :number => Braintree::Test::CreditCardNumbers::Visa,
6597
- :expiration_date => "06/2009"
6598
- }
6599
- )
6600
- transaction.amount.should == BigDecimal("1000.00")
6601
- result = transaction.submit_for_settlement("999.99")
6602
- result.success?.should == true
6603
- transaction.amount.should == BigDecimal("999.99")
6604
- end
6605
-
6606
- it "updates the transaction attributes" do
6607
- transaction = Braintree::Transaction.sale!(
6608
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6609
- :credit_card => {
6610
- :number => Braintree::Test::CreditCardNumbers::Visa,
6611
- :expiration_date => "06/2009"
6612
- }
6613
- )
6614
- transaction.amount.should == BigDecimal("1000.00")
6615
- result = transaction.submit_for_settlement("999.99")
6616
- result.success?.should == true
6617
- transaction.amount.should == BigDecimal("999.99")
6618
- transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
6619
- transaction.updated_at.between?(Time.now - 60, Time.now).should == true
6620
- end
6621
-
6622
- it "returns an error result if unsuccessful" do
6623
- transaction = Braintree::Transaction.sale!(
6624
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6625
- :credit_card => {
6626
- :number => Braintree::Test::CreditCardNumbers::Visa,
6627
- :expiration_date => "06/2009"
6628
- }
6629
- )
6630
- transaction.amount.should == BigDecimal("1000.00")
6631
- result = transaction.submit_for_settlement("1000.01")
6632
- result.success?.should == false
6633
- result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::SettlementAmountIsTooLarge
6634
- result.params[:transaction][:amount].should == "1000.01"
6635
- end
6636
- end
6637
-
6638
- describe "submit_for_settlement!" do
6639
- it "returns the transaction if successful" do
6640
- original_transaction = Braintree::Transaction.sale!(
6641
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6642
- :credit_card => {
6643
- :number => Braintree::Test::CreditCardNumbers::Visa,
6644
- :expiration_date => "06/2009"
6645
- }
6646
- )
6647
- transaction = original_transaction.submit_for_settlement!
6648
- transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
6649
- transaction.id.should == original_transaction.id
6650
- end
6651
-
6652
- it "raises a ValidationsFailed if unsuccessful" do
6653
- transaction = Braintree::Transaction.sale!(
6654
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6655
- :credit_card => {
6656
- :number => Braintree::Test::CreditCardNumbers::Visa,
6657
- :expiration_date => "06/2009"
6658
- }
6659
- )
6660
- transaction.amount.should == BigDecimal("1000.00")
6661
- expect do
6662
- transaction.submit_for_settlement!("1000.01")
6663
- end.to raise_error(Braintree::ValidationsFailed)
6664
- end
6665
- end
6666
-
6667
6408
  describe "status_history" do
6668
6409
  it "returns an array of StatusDetail" do
6669
6410
  transaction = Braintree::Transaction.sale!(
@@ -6673,10 +6414,10 @@ describe Braintree::Transaction do
6673
6414
  :expiration_date => "05/2009"
6674
6415
  }
6675
6416
  )
6676
- transaction.submit_for_settlement!
6677
- transaction.status_history.size.should == 2
6678
- transaction.status_history[0].status.should == Braintree::Transaction::Status::Authorized
6679
- transaction.status_history[1].status.should == Braintree::Transaction::Status::SubmittedForSettlement
6417
+ result = Braintree::Transaction.submit_for_settlement!(transaction.id)
6418
+ result.status_history.size.should == 2
6419
+ result.status_history[0].status.should == Braintree::Transaction::Status::Authorized
6420
+ result.status_history[1].status.should == Braintree::Transaction::Status::SubmittedForSettlement
6680
6421
  end
6681
6422
  end
6682
6423
 
@@ -6731,7 +6472,7 @@ describe Braintree::Transaction do
6731
6472
  :expiration_date => "05/2010"
6732
6473
  }
6733
6474
  )
6734
- transaction = customer.credit_cards[0].sale(:amount => "100.00").transaction
6475
+ transaction = Braintree::CreditCard.sale(customer.credit_cards[0].token, {:amount => "100.00"}).transaction
6735
6476
  transaction.vault_credit_card.should == customer.credit_cards[0]
6736
6477
  end
6737
6478
 
@@ -6756,7 +6497,7 @@ describe Braintree::Transaction do
6756
6497
  :expiration_date => "05/2010"
6757
6498
  }
6758
6499
  )
6759
- transaction = customer.credit_cards[0].sale(:amount => "100.00").transaction
6500
+ transaction = Braintree::CreditCard.sale(customer.credit_cards[0].token, :amount => "100.00").transaction
6760
6501
  transaction.vault_customer.should == customer
6761
6502
  end
6762
6503
 
@@ -6773,68 +6514,6 @@ describe Braintree::Transaction do
6773
6514
  end
6774
6515
  end
6775
6516
 
6776
- describe "void" do
6777
- it "returns a successful result if successful" do
6778
- result = Braintree::Transaction.create(
6779
- :type => "sale",
6780
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6781
- :credit_card => {
6782
- :number => Braintree::Test::CreditCardNumbers::Visa,
6783
- :expiration_date => "05/2009"
6784
- }
6785
- )
6786
- result.success?.should == true
6787
- transaction = result.transaction
6788
- transaction.status.should == Braintree::Transaction::Status::Authorized
6789
- void_result = transaction.void
6790
- void_result.success?.should == true
6791
- void_result.transaction.should == transaction
6792
- transaction.status.should == void_result.transaction.status
6793
- end
6794
-
6795
- it "returns an error result if unsuccessful" do
6796
- transaction = Braintree::Transaction.sale(
6797
- :amount => Braintree::Test::TransactionAmounts::Decline,
6798
- :credit_card => {
6799
- :number => Braintree::Test::CreditCardNumbers::Visa,
6800
- :expiration_date => "05/2009"
6801
- }
6802
- ).transaction
6803
- transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
6804
- result = transaction.void
6805
- result.success?.should == false
6806
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CannotBeVoided
6807
- end
6808
- end
6809
-
6810
- describe "void!" do
6811
- it "returns the transaction if successful" do
6812
- transaction = Braintree::Transaction.sale!(
6813
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6814
- :credit_card => {
6815
- :number => Braintree::Test::CreditCardNumbers::Visa,
6816
- :expiration_date => "05/2009"
6817
- }
6818
- )
6819
- transaction.void!.should == transaction
6820
- transaction.status.should == Braintree::Transaction::Status::Voided
6821
- end
6822
-
6823
- it "raises a ValidationsFailed if unsuccessful" do
6824
- transaction = Braintree::Transaction.sale(
6825
- :amount => Braintree::Test::TransactionAmounts::Decline,
6826
- :credit_card => {
6827
- :number => Braintree::Test::CreditCardNumbers::Visa,
6828
- :expiration_date => "05/2009"
6829
- }
6830
- ).transaction
6831
- transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
6832
- expect do
6833
- transaction.void!
6834
- end.to raise_error(Braintree::ValidationsFailed)
6835
- end
6836
- end
6837
-
6838
6517
  def create_transaction_to_refund
6839
6518
  transaction = Braintree::Transaction.sale!(
6840
6519
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -7194,4 +6873,91 @@ describe Braintree::Transaction do
7194
6873
  transaction.processed_with_network_token?.should == false
7195
6874
  end
7196
6875
  end
6876
+
6877
+ describe "installments" do
6878
+ it "creates a transaction with an installment count" do
6879
+ result = Braintree::Transaction.create(
6880
+ :type => "sale",
6881
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
6882
+ :credit_card => {
6883
+ :number => Braintree::Test::CreditCardNumbers::Visa,
6884
+ :expiration_date => "05/2009"
6885
+ },
6886
+ :amount => "100.01",
6887
+ :installments => {
6888
+ :count => 12,
6889
+ },
6890
+ )
6891
+
6892
+ expect(result.success?).to eq(true)
6893
+ expect(result.transaction.installment_count).to eq(12)
6894
+ end
6895
+
6896
+ it "creates a transaction with a installments during capture" do
6897
+ result = Braintree::Transaction.create(
6898
+ :type => "sale",
6899
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
6900
+ :credit_card => {
6901
+ :number => Braintree::Test::CreditCardNumbers::Visa,
6902
+ :expiration_date => "05/2009"
6903
+ },
6904
+ :amount => "100.01",
6905
+ :installments => {
6906
+ :count => 12,
6907
+ },
6908
+ :options => {
6909
+ :submit_for_settlement => true,
6910
+ },
6911
+ )
6912
+
6913
+ expect(result.success?).to eq(true)
6914
+ transaction = result.transaction
6915
+ expect(transaction.installment_count).to eq(12)
6916
+
6917
+ installments = transaction.installments
6918
+ expect(installments.map(&:id)).to match_array((1..12).map { |i| "#{transaction.id}_INST_#{i}" })
6919
+ expect(installments.map(&:amount)).to match_array([BigDecimal("8.33")] * 11 + [BigDecimal("8.38")])
6920
+ end
6921
+
6922
+ it "can refund a transaction with installments" do
6923
+ sale_result = Braintree::Transaction.create(
6924
+ :type => "sale",
6925
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
6926
+ :credit_card => {
6927
+ :number => Braintree::Test::CreditCardNumbers::Visa,
6928
+ :expiration_date => "05/2009"
6929
+ },
6930
+ :amount => "100.01",
6931
+ :installments => {
6932
+ :count => 12,
6933
+ },
6934
+ :options => {
6935
+ :submit_for_settlement => true,
6936
+ },
6937
+ )
6938
+
6939
+ expect(sale_result.success?).to eq(true)
6940
+ sale_transaction = sale_result.transaction
6941
+
6942
+ refund_result = Braintree::Transaction.refund(sale_transaction.id, "49.99")
6943
+
6944
+ expect(refund_result.success?).to eq(true)
6945
+ refund_transaction = refund_result.transaction
6946
+ installments = refund_transaction.refunded_installments
6947
+
6948
+ (1..11).each do |i|
6949
+ installment = installments.find { |installment| installment.id == "#{sale_transaction.id}_INST_#{i}" }
6950
+
6951
+ expect(installment.amount).to eq(BigDecimal("8.33"))
6952
+ expect(installment.adjustments.map(&:amount)).to match_array([BigDecimal("-4.16")])
6953
+ expect(installment.adjustments.map(&:kind)).to match_array([Braintree::Transaction::Installment::Adjustment::Kind::Refund])
6954
+ end
6955
+
6956
+ installment = installments.find { |installment| installment.id == "#{sale_transaction.id}_INST_12" }
6957
+
6958
+ expect(installment.amount).to eq(BigDecimal("8.38"))
6959
+ expect(installment.adjustments.map(&:amount)).to match_array([BigDecimal("-4.23")])
6960
+ expect(installment.adjustments.map(&:kind)).to match_array([Braintree::Transaction::Installment::Adjustment::Kind::Refund])
6961
+ end
6962
+ end
7197
6963
  end