braintree 2.103.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -85,14 +85,13 @@ describe Braintree::Customer do
85
85
  result.customer.last_name.should == "Brown"
86
86
  end
87
87
 
88
- it "supports creation with a device session ID and (optional) fraud_merchant_id" do
88
+ it "supports creation with device_data" do
89
89
  result = Braintree::Customer.create(
90
90
  :credit_card => {
91
91
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
92
92
  :expiration_date => "05/2010",
93
93
  :cvv => "100",
94
- :device_session_id => "abc123",
95
- :fraud_merchant_id => "7"
94
+ :device_data => "device_data",
96
95
  }
97
96
  )
98
97
 
@@ -258,6 +257,92 @@ describe Braintree::Customer do
258
257
  result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
259
258
  end
260
259
 
260
+ it "can create a customer and a payment method at the same time after validating verification_currency_iso_code" do
261
+ result = Braintree::Customer.create(
262
+ :first_name => "Mike",
263
+ :last_name => "Jones",
264
+ :credit_card => {
265
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
266
+ :expiration_date => "05/2010",
267
+ :cvv => "100",
268
+ :options => {
269
+ :verify_card => true,
270
+ :verification_currency_iso_code => "USD"
271
+ }
272
+ }
273
+ )
274
+
275
+ result.success?.should == true
276
+ result.customer.first_name.should == "Mike"
277
+ result.customer.last_name.should == "Jones"
278
+ result.customer.credit_cards[0].bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
279
+ result.customer.credit_cards[0].last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
280
+ result.customer.credit_cards[0].expiration_date.should == "05/2010"
281
+ result.customer.credit_cards[0].unique_number_identifier.should =~ /\A\w{32}\z/
282
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
283
+ end
284
+
285
+ it "errors when verification_currency_iso_code is not supported by merchant account" do
286
+ result = Braintree::Customer.create(
287
+ :first_name => "Mike",
288
+ :last_name => "Jones",
289
+ :credit_card => {
290
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
291
+ :expiration_date => "05/2010",
292
+ :cvv => "100",
293
+ :options => {
294
+ :verify_card => true,
295
+ :verification_currency_iso_code => "GBP"
296
+ }
297
+ }
298
+ )
299
+ expect(result).to_not be_success
300
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
301
+ end
302
+
303
+ it "validates verification_currency_iso_code of the given verification_merchant_account_id and creates customer" do
304
+ result = Braintree::Customer.create(
305
+ :first_name => "Mike",
306
+ :last_name => "Jones",
307
+ :credit_card => {
308
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
309
+ :expiration_date => "05/2010",
310
+ :options => {
311
+ :verify_card => true,
312
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
313
+ :verification_currency_iso_code => "USD"
314
+ }
315
+ }
316
+ )
317
+ result.success?.should == true
318
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
319
+ result.customer.first_name.should == "Mike"
320
+ result.customer.last_name.should == "Jones"
321
+ result.customer.credit_cards[0].bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
322
+ result.customer.credit_cards[0].last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
323
+ result.customer.credit_cards[0].expiration_date.should == "05/2010"
324
+ result.customer.credit_cards[0].unique_number_identifier.should =~ /\A\w{32}\z/
325
+ end
326
+
327
+ it "validates verification_currency_iso_code of the given verification_merchant_account_id and returns error" do
328
+ result = Braintree::Customer.create(
329
+ :first_name => "Mike",
330
+ :last_name => "Jones",
331
+ :credit_card => {
332
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
333
+ :expiration_date => "05/2010",
334
+ :options => {
335
+ :verify_card => true,
336
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
337
+ :verification_currency_iso_code => "GBP"
338
+ }
339
+ }
340
+ )
341
+ expect(result).to_not be_success
342
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
343
+ end
344
+
345
+
261
346
  it "can create a customer, payment method, and billing address at the same time" do
262
347
  result = Braintree::Customer.create(
263
348
  :first_name => "Mike",
@@ -698,68 +783,12 @@ describe Braintree::Customer do
698
783
  :expiration_date => "05/2010"
699
784
  }
700
785
  )
701
- transaction = customer.sale!(:amount => "100.00")
786
+ transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
702
787
  collection = Braintree::Customer.transactions(customer.id)
703
788
  collection.first.should == transaction
704
789
  end
705
790
  end
706
791
 
707
-
708
- describe "sale" do
709
- it "creates a sale transaction using the customer, returning a result object" do
710
- customer = Braintree::Customer.create!(
711
- :credit_card => {
712
- :number => Braintree::Test::CreditCardNumbers::Visa,
713
- :expiration_date => "05/2010"
714
- }
715
- )
716
- result = customer.sale(
717
- :amount => "100.00"
718
- )
719
- result.success?.should == true
720
- result.transaction.amount.should == BigDecimal("100.00")
721
- result.transaction.type.should == "sale"
722
- result.transaction.customer_details.id.should == customer.id
723
- result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
724
- result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
725
- result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
726
- result.transaction.credit_card_details.expiration_date.should == "05/2010"
727
- end
728
- end
729
-
730
- describe "sale!" do
731
- it "returns the created sale tranaction if valid" do
732
- customer = Braintree::Customer.create!(
733
- :credit_card => {
734
- :number => Braintree::Test::CreditCardNumbers::Visa,
735
- :expiration_date => "05/2010"
736
- }
737
- )
738
- transaction = customer.sale!(:amount => "100.00")
739
- transaction.amount.should == BigDecimal("100.00")
740
- transaction.type.should == "sale"
741
- transaction.customer_details.id.should == customer.id
742
- transaction.credit_card_details.token.should == customer.credit_cards[0].token
743
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
744
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
745
- transaction.credit_card_details.expiration_date.should == "05/2010"
746
- end
747
- end
748
-
749
- describe "transactions" do
750
- it "finds transactions for the customer" do
751
- customer = Braintree::Customer.create!(
752
- :credit_card => {
753
- :number => Braintree::Test::CreditCardNumbers::Visa,
754
- :expiration_date => "05/2010"
755
- }
756
- )
757
- transaction = customer.sale!(:amount => "100.00")
758
- collection = customer.transactions
759
- collection.first.should == transaction
760
- end
761
- end
762
-
763
792
  describe "credit" do
764
793
  it "creates a credit transaction using the customer, returning a result object" do
765
794
  customer = Braintree::Customer.create!(
@@ -801,67 +830,6 @@ describe Braintree::Customer do
801
830
  end
802
831
  end
803
832
 
804
- describe "create_from_transparent_redirect" do
805
- it "returns a successful result if successful" do
806
- params = {
807
- :customer => {
808
- :first_name => "John",
809
- :last_name => "Doe",
810
- :company => "Doe Co",
811
- :email => "john@doe.com",
812
- :phone => "312.555.2323",
813
- :fax => "614.555.5656",
814
- :website => "www.johndoe.com"
815
- }
816
- }
817
-
818
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge({}))
819
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Customer.create_customer_url)
820
- result = Braintree::Customer.create_from_transparent_redirect(query_string_response)
821
-
822
- result.success?.should == true
823
- customer = result.customer
824
- customer.first_name.should == "John"
825
- customer.last_name.should == "Doe"
826
- customer.company.should == "Doe Co"
827
- customer.email.should == "john@doe.com"
828
- customer.phone.should == "312.555.2323"
829
- customer.fax.should == "614.555.5656"
830
- customer.website.should == "www.johndoe.com"
831
- end
832
-
833
- it "can pass any attribute through tr_data" do
834
- customer_id = "customer_#{rand(1_000_000)}"
835
- tr_data_params = {
836
- :customer => {
837
- :id => customer_id,
838
- :first_name => "John",
839
- :last_name => "Doe",
840
- :company => "Doe Co",
841
- :email => "john@doe.com",
842
- :phone => "312.555.2323",
843
- :fax => "614.555.5656",
844
- :website => "www.johndoe.com"
845
- }
846
- }
847
-
848
- tr_data = Braintree::TransparentRedirect.create_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
849
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.create_customer_url)
850
- result = Braintree::Customer.create_from_transparent_redirect(query_string_response)
851
-
852
- result.success?.should == true
853
- customer = result.customer
854
- customer.id.should == customer_id
855
- customer.first_name.should == "John"
856
- customer.last_name.should == "Doe"
857
- customer.company.should == "Doe Co"
858
- customer.email.should == "john@doe.com"
859
- customer.phone.should == "312.555.2323"
860
- customer.fax.should == "614.555.5656"
861
- customer.website.should == "www.johndoe.com"
862
- end
863
- end
864
-
865
833
  describe "delete" do
866
834
  it "deletes the customer" do
867
835
  result = Braintree::Customer.create(
@@ -1003,51 +971,36 @@ describe Braintree::Customer do
1003
971
  apple_pay_card.payment_instrument_name.should == "AmEx 41002"
1004
972
  end
1005
973
 
1006
- it "returns associated android pay proxy cards" do
1007
- result = Braintree::Customer.create(
1008
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover
1009
- )
1010
- result.success?.should == true
1011
-
1012
- found_customer = Braintree::Customer.find(result.customer.id)
1013
- found_customer.android_pay_cards.size.should == 1
1014
- found_customer.payment_methods.size.should == 1
1015
- android_pay_card = found_customer.android_pay_cards.first
1016
- android_pay_card.should be_a Braintree::AndroidPayCard
1017
- android_pay_card.token.should_not be_nil
1018
- android_pay_card.expiration_year.should_not be_nil
1019
- android_pay_card.is_network_tokenized?.should == false
1020
- end
1021
-
1022
- it "returns associated android pay network tokens" do
974
+ it "returns associated google pay proxy cards" do
1023
975
  result = Braintree::Customer.create(
1024
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard
976
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover
1025
977
  )
1026
978
  result.success?.should == true
1027
979
 
1028
980
  found_customer = Braintree::Customer.find(result.customer.id)
1029
- found_customer.android_pay_cards.size.should == 1
981
+ found_customer.google_pay_cards.size.should == 1
1030
982
  found_customer.payment_methods.size.should == 1
1031
- android_pay_card = found_customer.android_pay_cards.first
1032
- android_pay_card.should be_a Braintree::AndroidPayCard
1033
- android_pay_card.token.should_not be_nil
1034
- android_pay_card.expiration_year.should_not be_nil
1035
- android_pay_card.is_network_tokenized?.should == true
983
+ google_pay_card = found_customer.google_pay_cards.first
984
+ google_pay_card.should be_a Braintree::GooglePayCard
985
+ google_pay_card.token.should_not be_nil
986
+ google_pay_card.expiration_year.should_not be_nil
987
+ google_pay_card.is_network_tokenized?.should == false
1036
988
  end
1037
989
 
1038
- it "returns associated amex express checkout cards" do
990
+ it "returns associated google pay network tokens" do
1039
991
  result = Braintree::Customer.create(
1040
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout
992
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard
1041
993
  )
1042
994
  result.success?.should == true
1043
995
 
1044
996
  found_customer = Braintree::Customer.find(result.customer.id)
1045
- found_customer.amex_express_checkout_cards.size.should == 1
997
+ found_customer.google_pay_cards.size.should == 1
1046
998
  found_customer.payment_methods.size.should == 1
1047
- amex_express_checkout_card = found_customer.amex_express_checkout_cards.first
1048
- amex_express_checkout_card.should be_a Braintree::AmexExpressCheckoutCard
1049
- amex_express_checkout_card.token.should_not be_nil
1050
- amex_express_checkout_card.expiration_year.should_not be_nil
999
+ google_pay_card = found_customer.google_pay_cards.first
1000
+ google_pay_card.should be_a Braintree::GooglePayCard
1001
+ google_pay_card.token.should_not be_nil
1002
+ google_pay_card.expiration_year.should_not be_nil
1003
+ google_pay_card.is_network_tokenized?.should == true
1051
1004
  end
1052
1005
 
1053
1006
  it "returns associated venmo accounts" do
@@ -1480,6 +1433,87 @@ describe Braintree::Customer do
1480
1433
  result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
1481
1434
  end
1482
1435
 
1436
+ context "verification_currency_iso_code" do
1437
+ it "can update the customer after validating verification_currency_iso_code" do
1438
+ customer = Braintree::Customer.create!(
1439
+ :first_name => "Joe"
1440
+ )
1441
+
1442
+ result = Braintree::Customer.update(
1443
+ customer.id,
1444
+ :first_name => "New Joe",
1445
+ :credit_card => {
1446
+ :cardholder_name => "New Joe Cardholder",
1447
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1448
+ :expiration_date => "12/2009",
1449
+ :options => { :verify_card => true, :verification_currency_iso_code => "USD" }
1450
+ }
1451
+ )
1452
+ result.success?.should == true
1453
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
1454
+ end
1455
+
1456
+ it "can update the customer after validating verification_currency_iso_code against the given verification_merchant_account_id" do
1457
+ customer = Braintree::Customer.create!(
1458
+ :first_name => "Joe"
1459
+ )
1460
+
1461
+ result = Braintree::Customer.update(
1462
+ customer.id,
1463
+ :first_name => "New Joe",
1464
+ :credit_card => {
1465
+ :cardholder_name => "New Joe Cardholder",
1466
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1467
+ :expiration_date => "12/2009",
1468
+ :options => { :verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD" }
1469
+ }
1470
+ )
1471
+ result.success?.should == true
1472
+ result.customer.credit_cards[0].verification.currency_iso_code == "USD"
1473
+ result.customer.credit_cards[0].verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
1474
+ end
1475
+
1476
+ it "throws error due to verification_currency_iso_code not matching against the currency configured in default merchant account" do
1477
+ customer = Braintree::Customer.create!(
1478
+ :first_name => "Joe"
1479
+ )
1480
+
1481
+ result = Braintree::Customer.update(
1482
+ customer.id,
1483
+ :first_name => "New Joe",
1484
+ :credit_card => {
1485
+ :cardholder_name => "New Joe Cardholder",
1486
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1487
+ :expiration_date => "12/2009",
1488
+ :options => { :verify_card => true, :verification_currency_iso_code => "GBP" }
1489
+ }
1490
+ )
1491
+ result.success?.should == false
1492
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1493
+
1494
+ end
1495
+
1496
+ it "throws error due to verification_currency_iso_code not matching against the currency configured in the given verification merchant account" do
1497
+ customer = Braintree::Customer.create!(
1498
+ :first_name => "Joe"
1499
+ )
1500
+
1501
+ result = Braintree::Customer.update(
1502
+ customer.id,
1503
+ :first_name => "New Joe",
1504
+ :credit_card => {
1505
+ :cardholder_name => "New Joe Cardholder",
1506
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1507
+ :expiration_date => "12/2009",
1508
+ :options => { :verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP" }
1509
+ }
1510
+ )
1511
+ result.success?.should == false
1512
+ expect(result.errors.for(:customer).for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code).to eq Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1513
+
1514
+ end
1515
+ end
1516
+
1483
1517
  context "verification_account_type" do
1484
1518
  it "updates the credit card with account_type credit" do
1485
1519
  customer = Braintree::Customer.create!
@@ -1545,214 +1579,7 @@ describe Braintree::Customer do
1545
1579
  end
1546
1580
  end
1547
1581
 
1548
- describe "update" do
1549
- it "updates the customer" do
1550
- customer = Braintree::Customer.create!(
1551
- :first_name => "Joe",
1552
- :last_name => "Cool"
1553
- )
1554
- update_result = customer.update(
1555
- :first_name => "Mr. Joe",
1556
- :last_name => "Super Cool"
1557
- )
1558
- update_result.success?.should == true
1559
- update_result.customer.should == customer
1560
- updated_customer = update_result.customer
1561
- updated_customer.first_name.should == "Mr. Joe"
1562
- updated_customer.last_name.should == "Super Cool"
1563
- end
1564
-
1565
- it "returns an error response if invalid" do
1566
- customer = Braintree::Customer.create!(
1567
- :email => "valid@email.com"
1568
- )
1569
- result = customer.update(
1570
- :email => "@invalid.com"
1571
- )
1572
- result.success?.should == false
1573
- result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
1574
- end
1575
- end
1576
-
1577
- describe "update!" do
1578
- it "returns the customer and updates the customer if successful" do
1579
- customer = Braintree::Customer.create!(
1580
- :first_name => "Joe",
1581
- :last_name => "Cool"
1582
- )
1583
- customer.update!(
1584
- :first_name => "Mr. Joe",
1585
- :last_name => "Super Cool"
1586
- ).should == customer
1587
- customer.first_name.should == "Mr. Joe"
1588
- customer.last_name.should == "Super Cool"
1589
- customer.updated_at.between?(Time.now - 60, Time.now).should == true
1590
- end
1591
-
1592
- it "raises an error if unsuccessful" do
1593
- customer = Braintree::Customer.create!(
1594
- :email => "valid@email.com"
1595
- )
1596
- expect do
1597
- customer.update!(:email => "@invalid.com")
1598
- end.to raise_error(Braintree::ValidationsFailed)
1599
- end
1600
- end
1601
-
1602
- describe "update_from_transparent_redirect" do
1603
- it "returns a successful result if successful" do
1604
- result = Braintree::Customer.create(
1605
- :first_name => "Old First",
1606
- :last_name => "Old Last",
1607
- :company => "Old Company",
1608
- :email => "old@email.com",
1609
- :phone => "000.111.2222",
1610
- :fax => "000.222.3333",
1611
- :website => "old.website.com"
1612
- )
1613
- result.success?.should == true
1614
- original_customer = result.customer
1615
- params = {
1616
- :customer => {
1617
- :first_name => "New First",
1618
- :last_name => "New Last",
1619
- :company => "New Company",
1620
- :email => "new@email.com",
1621
- :phone => "888.111.2222",
1622
- :fax => "999.222.3333",
1623
- :website => "new.website.com"
1624
- }
1625
- }
1626
- tr_data_params = {
1627
- :customer_id => original_customer.id
1628
- }
1629
-
1630
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1631
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Customer.update_customer_url)
1632
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1633
-
1634
- result.success?.should == true
1635
- customer = result.customer
1636
- customer.id.should == original_customer.id
1637
- customer.first_name.should == "New First"
1638
- customer.last_name.should == "New Last"
1639
- customer.company.should == "New Company"
1640
- customer.email.should == "new@email.com"
1641
- customer.phone.should == "888.111.2222"
1642
- customer.fax.should == "999.222.3333"
1643
- customer.website.should == "new.website.com"
1644
- end
1645
-
1646
- it "returns a successful result when updating an existing credit card" do
1647
- result = Braintree::Customer.create(
1648
- :first_name => "Old First",
1649
- :last_name => "Old Last",
1650
- :company => "Old Company",
1651
- :email => "old@email.com",
1652
- :phone => "000.111.2222",
1653
- :fax => "000.222.3333",
1654
- :website => "old.website.com",
1655
- :credit_card => {
1656
- :number => Braintree::Test::CreditCardNumbers::Visa,
1657
- :expiration_date => "12/2009",
1658
- :billing_address => {
1659
- :first_name => "Joe",
1660
- :postal_code => "60622"
1661
- }
1662
- }
1663
- )
1664
- result.success?.should == true
1665
- original_customer = result.customer
1666
-
1667
- tr_data_params = {
1668
- :customer_id => original_customer.id,
1669
- :customer => {
1670
- :first_name => "New First",
1671
- :last_name => "New Last",
1672
- :company => "New Company",
1673
- :email => "new@email.com",
1674
- :phone => "888.111.2222",
1675
- :fax => "999.222.3333",
1676
- :website => "new.website.com",
1677
- :credit_card => {
1678
- :cardholder_name => "New Joe Cardholder",
1679
- :options => { :update_existing_token => original_customer.credit_cards.first.token },
1680
- :billing_address => {
1681
- :last_name => "Cool",
1682
- :postal_code => "60666",
1683
- :options => { :update_existing => true }
1684
- }
1685
- }
1686
- }
1687
- }
1688
-
1689
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1690
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
1691
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1692
-
1693
- result.success?.should == true
1694
- customer = result.customer
1695
- customer.id.should == original_customer.id
1696
- customer.first_name.should == "New First"
1697
- customer.last_name.should == "New Last"
1698
- customer.company.should == "New Company"
1699
- customer.email.should == "new@email.com"
1700
- customer.phone.should == "888.111.2222"
1701
- customer.fax.should == "999.222.3333"
1702
- customer.website.should == "new.website.com"
1703
-
1704
- credit_card = customer.credit_cards.first
1705
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa.slice(0, 6)
1706
- credit_card.cardholder_name.should == "New Joe Cardholder"
1707
-
1708
- credit_card.billing_address.first_name.should == "Joe"
1709
- credit_card.billing_address.last_name.should == "Cool"
1710
- credit_card.billing_address.postal_code.should == "60666"
1711
- end
1712
-
1713
- it "can pass any attribute through tr_data" do
1714
- original_customer = Braintree::Customer.create!(
1715
- :first_name => "Old First",
1716
- :last_name => "Old Last",
1717
- :company => "Old Company",
1718
- :email => "old@email.com",
1719
- :phone => "000.111.2222",
1720
- :fax => "000.222.3333",
1721
- :website => "old.website.com"
1722
- )
1723
- new_customer_id = "customer_#{rand(1_000_000)}"
1724
- tr_data_params = {
1725
- :customer_id => original_customer.id,
1726
- :customer => {
1727
- :id => new_customer_id,
1728
- :first_name => "New First",
1729
- :last_name => "New Last",
1730
- :company => "New Company",
1731
- :email => "new@email.com",
1732
- :phone => "888.111.2222",
1733
- :fax => "999.222.3333",
1734
- :website => "new.website.com"
1735
- }
1736
- }
1737
-
1738
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1739
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
1740
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1741
-
1742
- result.success?.should == true
1743
- customer = result.customer
1744
- customer.id.should == new_customer_id
1745
- customer.first_name.should == "New First"
1746
- customer.last_name.should == "New Last"
1747
- customer.company.should == "New Company"
1748
- customer.email.should == "new@email.com"
1749
- customer.phone.should == "888.111.2222"
1750
- customer.fax.should == "999.222.3333"
1751
- customer.website.should == "new.website.com"
1752
- end
1753
- end
1754
-
1755
- describe "default_credit_card" do
1582
+ describe "default_payment_method" do
1756
1583
  it "should return the default credit card for a given customer" do
1757
1584
  customer = Braintree::Customer.create!(
1758
1585
  :credit_card => {
@@ -1764,7 +1591,7 @@ describe Braintree::Customer do
1764
1591
  }
1765
1592
  )
1766
1593
 
1767
- default_credit_card = Braintree::CreditCard.create!(
1594
+ default_payment_method = Braintree::CreditCard.create!(
1768
1595
  :customer_id => customer.id,
1769
1596
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1770
1597
  :expiration_date => "11/2015",
@@ -1775,7 +1602,7 @@ describe Braintree::Customer do
1775
1602
 
1776
1603
  customer = Braintree::Customer.find(customer.id)
1777
1604
 
1778
- customer.default_credit_card.should == default_credit_card
1605
+ customer.default_payment_method.should == default_payment_method
1779
1606
  end
1780
1607
  end
1781
1608