braintree 2.101.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +6 -3
  4. data/lib/braintree.rb +3 -17
  5. data/lib/braintree/address.rb +0 -22
  6. data/lib/braintree/address_gateway.rb +2 -2
  7. data/lib/braintree/base_module.rb +6 -0
  8. data/lib/braintree/configuration.rb +1 -1
  9. data/lib/braintree/credit_card.rb +5 -76
  10. data/lib/braintree/credit_card_gateway.rb +16 -32
  11. data/lib/braintree/credit_card_verification.rb +14 -0
  12. data/lib/braintree/customer.rb +3 -72
  13. data/lib/braintree/customer_gateway.rb +0 -23
  14. data/lib/braintree/dispute.rb +1 -7
  15. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  16. data/lib/braintree/dispute/transaction.rb +2 -0
  17. data/lib/braintree/dispute_gateway.rb +2 -7
  18. data/lib/braintree/error_codes.rb +162 -157
  19. data/lib/braintree/exceptions.rb +5 -3
  20. data/lib/braintree/gateway.rb +0 -14
  21. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -1
  22. data/lib/braintree/local_payment_completed.rb +1 -1
  23. data/lib/braintree/merchant_account_gateway.rb +2 -0
  24. data/lib/braintree/payment_instrument_type.rb +1 -4
  25. data/lib/braintree/payment_method_gateway.rb +16 -8
  26. data/lib/braintree/payment_method_nonce.rb +2 -0
  27. data/lib/braintree/payment_method_nonce_gateway.rb +13 -2
  28. data/lib/braintree/payment_method_parser.rb +1 -7
  29. data/lib/braintree/risk_data.rb +4 -1
  30. data/lib/braintree/subscription.rb +5 -5
  31. data/lib/braintree/successful_result.rb +0 -1
  32. data/lib/braintree/test/authentication_id.rb +21 -0
  33. data/lib/braintree/test/credit_card.rb +1 -0
  34. data/lib/braintree/test/nonce.rb +19 -20
  35. data/lib/braintree/transaction.rb +8 -72
  36. data/lib/braintree/transaction/address_details.rb +11 -0
  37. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  38. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  39. data/lib/braintree/transaction/paypal_details.rb +2 -0
  40. data/lib/braintree/transaction/subscription_details.rb +2 -0
  41. data/lib/braintree/transaction_gateway.rb +14 -21
  42. data/lib/braintree/transaction_search.rb +0 -1
  43. data/lib/braintree/util.rb +17 -2
  44. data/lib/braintree/version.rb +3 -3
  45. data/lib/braintree/webhook_notification.rb +3 -10
  46. data/lib/braintree/webhook_testing_gateway.rb +243 -43
  47. data/lib/braintree/xml/libxml.rb +1 -0
  48. data/lib/braintree/xml/parser.rb +11 -34
  49. data/spec/integration/braintree/address_spec.rb +2 -89
  50. data/spec/integration/braintree/client_api/spec_helper.rb +100 -67
  51. data/spec/integration/braintree/credit_card_spec.rb +119 -467
  52. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -0
  53. data/spec/integration/braintree/customer_spec.rb +135 -362
  54. data/spec/integration/braintree/dispute_search_spec.rb +2 -2
  55. data/spec/integration/braintree/dispute_spec.rb +1 -2
  56. data/spec/integration/braintree/document_upload_spec.rb +12 -0
  57. data/spec/integration/braintree/merchant_spec.rb +2 -2
  58. data/spec/integration/braintree/payment_method_nonce_spec.rb +77 -0
  59. data/spec/integration/braintree/payment_method_spec.rb +186 -120
  60. data/spec/integration/braintree/paypal_account_spec.rb +1 -1
  61. data/spec/integration/braintree/subscription_spec.rb +11 -16
  62. data/spec/integration/braintree/transaction_search_spec.rb +3 -3
  63. data/spec/integration/braintree/transaction_spec.rb +252 -524
  64. data/spec/integration/spec_helper.rb +1 -4
  65. data/spec/spec_helper.rb +1 -11
  66. data/spec/unit/braintree/address_spec.rb +0 -8
  67. data/spec/unit/braintree/credit_card_spec.rb +50 -23
  68. data/spec/unit/braintree/credit_card_verification_spec.rb +7 -0
  69. data/spec/unit/braintree/customer_spec.rb +26 -14
  70. data/spec/unit/braintree/dispute_spec.rb +4 -12
  71. data/spec/unit/braintree/http_spec.rb +3 -3
  72. data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
  73. data/spec/unit/braintree/transaction/paypal_details_spec.rb +57 -0
  74. data/spec/unit/braintree/transaction_spec.rb +17 -37
  75. data/spec/unit/braintree/util_spec.rb +37 -3
  76. data/spec/unit/braintree/webhook_notification_spec.rb +49 -1
  77. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  78. metadata +29 -31
  79. data/lib/braintree/amex_express_checkout_card.rb +0 -38
  80. data/lib/braintree/coinbase_account.rb +0 -34
  81. data/lib/braintree/europe_bank_account.rb +0 -36
  82. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  83. data/lib/braintree/ideal_payment.rb +0 -61
  84. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  85. data/lib/braintree/masterpass_card.rb +0 -81
  86. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  87. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  88. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  89. data/lib/braintree/transaction/masterpass_card_details.rb +0 -47
  90. data/lib/braintree/transparent_redirect.rb +0 -40
  91. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  92. data/lib/braintree/xml/rexml.rb +0 -71
  93. data/spec/hacks/tcp_socket.rb +0 -18
  94. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  95. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  96. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  97. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  98. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -22,6 +22,7 @@ describe Braintree::CreditCardVerification, "search" do
22
22
  result.credit_card_verification.processor_response_code.should == "1000"
23
23
  result.credit_card_verification.processor_response_text.should == "Approved"
24
24
  result.credit_card_verification.processor_response_type.should == Braintree::ProcessorResponseTypes::Approved
25
+ expect(result.credit_card_verification.network_transaction_id).not_to be_nil
25
26
  end
26
27
 
27
28
  it "creates a new verification with network response code/text" do
@@ -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
 
@@ -698,68 +697,12 @@ describe Braintree::Customer do
698
697
  :expiration_date => "05/2010"
699
698
  }
700
699
  )
701
- transaction = customer.sale!(:amount => "100.00")
700
+ transaction = Braintree::Customer.sale!(customer.id, :amount => "100.00")
702
701
  collection = Braintree::Customer.transactions(customer.id)
703
702
  collection.first.should == transaction
704
703
  end
705
704
  end
706
705
 
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
706
  describe "credit" do
764
707
  it "creates a credit transaction using the customer, returning a result object" do
765
708
  customer = Braintree::Customer.create!(
@@ -801,67 +744,6 @@ describe Braintree::Customer do
801
744
  end
802
745
  end
803
746
 
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
747
  describe "delete" do
866
748
  it "deletes the customer" do
867
749
  result = Braintree::Customer.create(
@@ -1003,51 +885,36 @@ describe Braintree::Customer do
1003
885
  apple_pay_card.payment_instrument_name.should == "AmEx 41002"
1004
886
  end
1005
887
 
1006
- it "returns associated android pay proxy cards" do
888
+ it "returns associated google pay proxy cards" do
1007
889
  result = Braintree::Customer.create(
1008
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover
890
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover
1009
891
  )
1010
892
  result.success?.should == true
1011
893
 
1012
894
  found_customer = Braintree::Customer.find(result.customer.id)
1013
- found_customer.android_pay_cards.size.should == 1
895
+ found_customer.google_pay_cards.size.should == 1
1014
896
  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
897
+ google_pay_card = found_customer.google_pay_cards.first
898
+ google_pay_card.should be_a Braintree::GooglePayCard
899
+ google_pay_card.token.should_not be_nil
900
+ google_pay_card.expiration_year.should_not be_nil
901
+ google_pay_card.is_network_tokenized?.should == false
1020
902
  end
1021
903
 
1022
- it "returns associated android pay network tokens" do
904
+ it "returns associated google pay network tokens" do
1023
905
  result = Braintree::Customer.create(
1024
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard
906
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard
1025
907
  )
1026
908
  result.success?.should == true
1027
909
 
1028
910
  found_customer = Braintree::Customer.find(result.customer.id)
1029
- found_customer.android_pay_cards.size.should == 1
911
+ found_customer.google_pay_cards.size.should == 1
1030
912
  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
1036
- end
1037
-
1038
- it "returns associated amex express checkout cards" do
1039
- result = Braintree::Customer.create(
1040
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout
1041
- )
1042
- result.success?.should == true
1043
-
1044
- found_customer = Braintree::Customer.find(result.customer.id)
1045
- found_customer.amex_express_checkout_cards.size.should == 1
1046
- 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
913
+ google_pay_card = found_customer.google_pay_cards.first
914
+ google_pay_card.should be_a Braintree::GooglePayCard
915
+ google_pay_card.token.should_not be_nil
916
+ google_pay_card.expiration_year.should_not be_nil
917
+ google_pay_card.is_network_tokenized?.should == true
1051
918
  end
1052
919
 
1053
920
  it "returns associated venmo accounts" do
@@ -1115,6 +982,74 @@ describe Braintree::Customer do
1115
982
  end
1116
983
 
1117
984
  describe "self.update" do
985
+ it "updates the credit card with three_d_secure pass thru params" do
986
+ customer = Braintree::Customer.create!(
987
+ :first_name => "Joe",
988
+ :last_name => "Cool"
989
+ )
990
+ result = Braintree::Customer.update(
991
+ customer.id,
992
+ :first_name => "Mr. Joe",
993
+ :last_name => "Super Cool",
994
+ :custom_fields => {
995
+ :store_me => "a value"
996
+ },
997
+ :credit_card => {
998
+ :number => 4111111111111111,
999
+ :expiration_date => "05/2060",
1000
+ :three_d_secure_pass_thru => {
1001
+ :eci_flag => '02',
1002
+ :cavv => 'some_cavv',
1003
+ :xid => 'some_xid',
1004
+ :three_d_secure_version => '1.0.2',
1005
+ :authentication_response => 'Y',
1006
+ :directory_response => 'Y',
1007
+ :cavv_algorithm => '2',
1008
+ :ds_transaction_id => 'some_ds_transaction_id',
1009
+ },
1010
+ :options => {:verify_card => true},
1011
+ }
1012
+ )
1013
+ result.success?.should == true
1014
+ result.customer.id.should == customer.id
1015
+ result.customer.first_name.should == "Mr. Joe"
1016
+ result.customer.last_name.should == "Super Cool"
1017
+ result.customer.custom_fields[:store_me].should == "a value"
1018
+ end
1019
+
1020
+ it "validates the presence of three_d_secure_version while passing three_d_secure_pass_thru in update" do
1021
+ customer = Braintree::Customer.create!(
1022
+ :first_name => "Joe",
1023
+ :last_name => "Cool"
1024
+ )
1025
+ result = Braintree::Customer.update(
1026
+ customer.id,
1027
+ :first_name => "Mr. Joe",
1028
+ :last_name => "Super Cool",
1029
+ :custom_fields => {
1030
+ :store_me => "a value"
1031
+ },
1032
+ :credit_card => {
1033
+ :number => 4111111111111111,
1034
+ :expiration_date => "05/2060",
1035
+ :three_d_secure_pass_thru => {
1036
+ :eci_flag => '02',
1037
+ :cavv => 'some_cavv',
1038
+ :xid => 'some_xid',
1039
+ :authentication_response => 'Y',
1040
+ :directory_response => 'Y',
1041
+ :cavv_algorithm => '2',
1042
+ :ds_transaction_id => 'some_ds_transaction_id',
1043
+ },
1044
+ options: {:verify_card => true}
1045
+ }
1046
+ )
1047
+ expect(result).to_not be_success
1048
+ error = result.errors.for(:verification).first
1049
+ expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsRequired)
1050
+ expect(error.message).to eq("ThreeDSecureVersion is required.")
1051
+ end
1052
+
1118
1053
  it "updates the customer with the given id if successful" do
1119
1054
  customer = Braintree::Customer.create!(
1120
1055
  :first_name => "Joe",
@@ -1312,6 +1247,51 @@ describe Braintree::Customer do
1312
1247
  result.success?.should == true
1313
1248
  end
1314
1249
 
1250
+ it "validates presence of three_d_secure_version in 3ds pass thru params" do
1251
+ result = Braintree::Customer.create(
1252
+ :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1253
+ :credit_card => {
1254
+ :three_d_secure_pass_thru => {
1255
+ :eci_flag => '02',
1256
+ :cavv => 'some_cavv',
1257
+ :xid => 'some_xid',
1258
+ :three_d_secure_version => 'xx',
1259
+ :authentication_response => 'Y',
1260
+ :directory_response => 'Y',
1261
+ :cavv_algorithm => '2',
1262
+ :ds_transaction_id => 'some_ds_transaction_id',
1263
+ },
1264
+ :options => {:verify_card => true}
1265
+ }
1266
+ )
1267
+
1268
+ expect(result).not_to be_success
1269
+ error = result.errors.for(:verification).first
1270
+ expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsInvalid)
1271
+ expect(error.message).to eq("The version of 3D Secure authentication must be composed only of digits and separated by periods (e.g. `1.0.2`).")
1272
+ end
1273
+
1274
+ it "accepts three_d_secure pass thru params in the request" do
1275
+ result = Braintree::Customer.create(
1276
+ :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
1277
+ :credit_card => {
1278
+ :three_d_secure_pass_thru => {
1279
+ :eci_flag => '02',
1280
+ :cavv => 'some_cavv',
1281
+ :xid => 'some_xid',
1282
+ :three_d_secure_version => '2.2.1',
1283
+ :authentication_response => 'Y',
1284
+ :directory_response => 'Y',
1285
+ :cavv_algorithm => '2',
1286
+ :ds_transaction_id => 'some_ds_transaction_id',
1287
+ },
1288
+ :options => {:verify_card => true}
1289
+ }
1290
+ )
1291
+
1292
+ expect(result).to be_success
1293
+ end
1294
+
1315
1295
  it "returns 3DS info on cc verification" do
1316
1296
  result = Braintree::Customer.create(
1317
1297
  :payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
@@ -1432,214 +1412,7 @@ describe Braintree::Customer do
1432
1412
  end
1433
1413
  end
1434
1414
 
1435
- describe "update" do
1436
- it "updates the customer" do
1437
- customer = Braintree::Customer.create!(
1438
- :first_name => "Joe",
1439
- :last_name => "Cool"
1440
- )
1441
- update_result = customer.update(
1442
- :first_name => "Mr. Joe",
1443
- :last_name => "Super Cool"
1444
- )
1445
- update_result.success?.should == true
1446
- update_result.customer.should == customer
1447
- updated_customer = update_result.customer
1448
- updated_customer.first_name.should == "Mr. Joe"
1449
- updated_customer.last_name.should == "Super Cool"
1450
- end
1451
-
1452
- it "returns an error response if invalid" do
1453
- customer = Braintree::Customer.create!(
1454
- :email => "valid@email.com"
1455
- )
1456
- result = customer.update(
1457
- :email => "@invalid.com"
1458
- )
1459
- result.success?.should == false
1460
- result.errors.for(:customer).on(:email)[0].message.should == "Email is an invalid format."
1461
- end
1462
- end
1463
-
1464
- describe "update!" do
1465
- it "returns the customer and updates the customer if successful" do
1466
- customer = Braintree::Customer.create!(
1467
- :first_name => "Joe",
1468
- :last_name => "Cool"
1469
- )
1470
- customer.update!(
1471
- :first_name => "Mr. Joe",
1472
- :last_name => "Super Cool"
1473
- ).should == customer
1474
- customer.first_name.should == "Mr. Joe"
1475
- customer.last_name.should == "Super Cool"
1476
- customer.updated_at.between?(Time.now - 60, Time.now).should == true
1477
- end
1478
-
1479
- it "raises an error if unsuccessful" do
1480
- customer = Braintree::Customer.create!(
1481
- :email => "valid@email.com"
1482
- )
1483
- expect do
1484
- customer.update!(:email => "@invalid.com")
1485
- end.to raise_error(Braintree::ValidationsFailed)
1486
- end
1487
- end
1488
-
1489
- describe "update_from_transparent_redirect" do
1490
- it "returns a successful result if successful" do
1491
- result = Braintree::Customer.create(
1492
- :first_name => "Old First",
1493
- :last_name => "Old Last",
1494
- :company => "Old Company",
1495
- :email => "old@email.com",
1496
- :phone => "000.111.2222",
1497
- :fax => "000.222.3333",
1498
- :website => "old.website.com"
1499
- )
1500
- result.success?.should == true
1501
- original_customer = result.customer
1502
- params = {
1503
- :customer => {
1504
- :first_name => "New First",
1505
- :last_name => "New Last",
1506
- :company => "New Company",
1507
- :email => "new@email.com",
1508
- :phone => "888.111.2222",
1509
- :fax => "999.222.3333",
1510
- :website => "new.website.com"
1511
- }
1512
- }
1513
- tr_data_params = {
1514
- :customer_id => original_customer.id
1515
- }
1516
-
1517
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1518
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Customer.update_customer_url)
1519
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1520
-
1521
- result.success?.should == true
1522
- customer = result.customer
1523
- customer.id.should == original_customer.id
1524
- customer.first_name.should == "New First"
1525
- customer.last_name.should == "New Last"
1526
- customer.company.should == "New Company"
1527
- customer.email.should == "new@email.com"
1528
- customer.phone.should == "888.111.2222"
1529
- customer.fax.should == "999.222.3333"
1530
- customer.website.should == "new.website.com"
1531
- end
1532
-
1533
- it "returns a successful result when updating an existing credit card" do
1534
- result = Braintree::Customer.create(
1535
- :first_name => "Old First",
1536
- :last_name => "Old Last",
1537
- :company => "Old Company",
1538
- :email => "old@email.com",
1539
- :phone => "000.111.2222",
1540
- :fax => "000.222.3333",
1541
- :website => "old.website.com",
1542
- :credit_card => {
1543
- :number => Braintree::Test::CreditCardNumbers::Visa,
1544
- :expiration_date => "12/2009",
1545
- :billing_address => {
1546
- :first_name => "Joe",
1547
- :postal_code => "60622"
1548
- }
1549
- }
1550
- )
1551
- result.success?.should == true
1552
- original_customer = result.customer
1553
-
1554
- tr_data_params = {
1555
- :customer_id => original_customer.id,
1556
- :customer => {
1557
- :first_name => "New First",
1558
- :last_name => "New Last",
1559
- :company => "New Company",
1560
- :email => "new@email.com",
1561
- :phone => "888.111.2222",
1562
- :fax => "999.222.3333",
1563
- :website => "new.website.com",
1564
- :credit_card => {
1565
- :cardholder_name => "New Joe Cardholder",
1566
- :options => { :update_existing_token => original_customer.credit_cards.first.token },
1567
- :billing_address => {
1568
- :last_name => "Cool",
1569
- :postal_code => "60666",
1570
- :options => { :update_existing => true }
1571
- }
1572
- }
1573
- }
1574
- }
1575
-
1576
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1577
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
1578
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1579
-
1580
- result.success?.should == true
1581
- customer = result.customer
1582
- customer.id.should == original_customer.id
1583
- customer.first_name.should == "New First"
1584
- customer.last_name.should == "New Last"
1585
- customer.company.should == "New Company"
1586
- customer.email.should == "new@email.com"
1587
- customer.phone.should == "888.111.2222"
1588
- customer.fax.should == "999.222.3333"
1589
- customer.website.should == "new.website.com"
1590
-
1591
- credit_card = customer.credit_cards.first
1592
- credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa.slice(0, 6)
1593
- credit_card.cardholder_name.should == "New Joe Cardholder"
1594
-
1595
- credit_card.billing_address.first_name.should == "Joe"
1596
- credit_card.billing_address.last_name.should == "Cool"
1597
- credit_card.billing_address.postal_code.should == "60666"
1598
- end
1599
-
1600
- it "can pass any attribute through tr_data" do
1601
- original_customer = Braintree::Customer.create!(
1602
- :first_name => "Old First",
1603
- :last_name => "Old Last",
1604
- :company => "Old Company",
1605
- :email => "old@email.com",
1606
- :phone => "000.111.2222",
1607
- :fax => "000.222.3333",
1608
- :website => "old.website.com"
1609
- )
1610
- new_customer_id = "customer_#{rand(1_000_000)}"
1611
- tr_data_params = {
1612
- :customer_id => original_customer.id,
1613
- :customer => {
1614
- :id => new_customer_id,
1615
- :first_name => "New First",
1616
- :last_name => "New Last",
1617
- :company => "New Company",
1618
- :email => "new@email.com",
1619
- :phone => "888.111.2222",
1620
- :fax => "999.222.3333",
1621
- :website => "new.website.com"
1622
- }
1623
- }
1624
-
1625
- tr_data = Braintree::TransparentRedirect.update_customer_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
1626
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, {}, Braintree::Customer.update_customer_url)
1627
- result = Braintree::Customer.update_from_transparent_redirect(query_string_response)
1628
-
1629
- result.success?.should == true
1630
- customer = result.customer
1631
- customer.id.should == new_customer_id
1632
- customer.first_name.should == "New First"
1633
- customer.last_name.should == "New Last"
1634
- customer.company.should == "New Company"
1635
- customer.email.should == "new@email.com"
1636
- customer.phone.should == "888.111.2222"
1637
- customer.fax.should == "999.222.3333"
1638
- customer.website.should == "new.website.com"
1639
- end
1640
- end
1641
-
1642
- describe "default_credit_card" do
1415
+ describe "default_payment_method" do
1643
1416
  it "should return the default credit card for a given customer" do
1644
1417
  customer = Braintree::Customer.create!(
1645
1418
  :credit_card => {
@@ -1651,7 +1424,7 @@ describe Braintree::Customer do
1651
1424
  }
1652
1425
  )
1653
1426
 
1654
- default_credit_card = Braintree::CreditCard.create!(
1427
+ default_payment_method = Braintree::CreditCard.create!(
1655
1428
  :customer_id => customer.id,
1656
1429
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1657
1430
  :expiration_date => "11/2015",
@@ -1662,7 +1435,7 @@ describe Braintree::Customer do
1662
1435
 
1663
1436
  customer = Braintree::Customer.find(customer.id)
1664
1437
 
1665
- customer.default_credit_card.should == default_credit_card
1438
+ customer.default_payment_method.should == default_payment_method
1666
1439
  end
1667
1440
  end
1668
1441