braintree 2.104.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) 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/base_module.rb +6 -0
  7. data/lib/braintree/configuration.rb +1 -1
  8. data/lib/braintree/credit_card.rb +0 -75
  9. data/lib/braintree/credit_card_gateway.rb +3 -32
  10. data/lib/braintree/credit_card_verification.rb +13 -0
  11. data/lib/braintree/customer.rb +3 -74
  12. data/lib/braintree/customer_gateway.rb +0 -23
  13. data/lib/braintree/dispute.rb +1 -7
  14. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  15. data/lib/braintree/dispute_gateway.rb +2 -7
  16. data/lib/braintree/error_codes.rb +139 -170
  17. data/lib/braintree/exceptions.rb +5 -3
  18. data/lib/braintree/gateway.rb +0 -14
  19. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -2
  20. data/lib/braintree/merchant_account_gateway.rb +2 -0
  21. data/lib/braintree/payment_instrument_type.rb +1 -5
  22. data/lib/braintree/payment_method_gateway.rb +4 -9
  23. data/lib/braintree/payment_method_parser.rb +1 -8
  24. data/lib/braintree/subscription.rb +5 -5
  25. data/lib/braintree/successful_result.rb +0 -1
  26. data/lib/braintree/test/nonce.rb +4 -23
  27. data/lib/braintree/transaction.rb +2 -79
  28. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  29. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  30. data/lib/braintree/transaction/subscription_details.rb +2 -0
  31. data/lib/braintree/transaction_gateway.rb +12 -21
  32. data/lib/braintree/transaction_search.rb +0 -1
  33. data/lib/braintree/util.rb +17 -2
  34. data/lib/braintree/version.rb +2 -2
  35. data/lib/braintree/webhook_notification.rb +0 -10
  36. data/lib/braintree/webhook_testing_gateway.rb +0 -43
  37. data/lib/braintree/xml/libxml.rb +1 -0
  38. data/lib/braintree/xml/parser.rb +11 -34
  39. data/spec/integration/braintree/address_spec.rb +2 -89
  40. data/spec/integration/braintree/client_api/spec_helper.rb +0 -26
  41. data/spec/integration/braintree/credit_card_spec.rb +6 -471
  42. data/spec/integration/braintree/customer_spec.rb +22 -362
  43. data/spec/integration/braintree/dispute_search_spec.rb +2 -2
  44. data/spec/integration/braintree/dispute_spec.rb +1 -2
  45. data/spec/integration/braintree/payment_method_spec.rb +77 -120
  46. data/spec/integration/braintree/subscription_spec.rb +11 -16
  47. data/spec/integration/braintree/transaction_search_spec.rb +3 -3
  48. data/spec/integration/braintree/transaction_spec.rb +83 -511
  49. data/spec/integration/spec_helper.rb +1 -4
  50. data/spec/spec_helper.rb +1 -11
  51. data/spec/unit/braintree/address_spec.rb +0 -8
  52. data/spec/unit/braintree/credit_card_spec.rb +1 -20
  53. data/spec/unit/braintree/customer_spec.rb +0 -12
  54. data/spec/unit/braintree/dispute_spec.rb +1 -12
  55. data/spec/unit/braintree/http_spec.rb +3 -3
  56. data/spec/unit/braintree/transaction_spec.rb +1 -35
  57. data/spec/unit/braintree/util_spec.rb +37 -3
  58. data/spec/unit/braintree/webhook_notification_spec.rb +1 -1
  59. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  60. metadata +26 -30
  61. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  62. data/lib/braintree/coinbase_account.rb +0 -34
  63. data/lib/braintree/europe_bank_account.rb +0 -36
  64. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  65. data/lib/braintree/ideal_payment.rb +0 -61
  66. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  67. data/lib/braintree/masterpass_card.rb +0 -83
  68. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  69. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  70. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  71. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  72. data/lib/braintree/transparent_redirect.rb +0 -40
  73. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  74. data/lib/braintree/xml/rexml.rb +0 -71
  75. data/spec/hacks/tcp_socket.rb +0 -18
  76. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  77. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  78. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  79. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  80. 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
 
@@ -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
@@ -1545,214 +1412,7 @@ describe Braintree::Customer do
1545
1412
  end
1546
1413
  end
1547
1414
 
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
1415
+ describe "default_payment_method" do
1756
1416
  it "should return the default credit card for a given customer" do
1757
1417
  customer = Braintree::Customer.create!(
1758
1418
  :credit_card => {
@@ -1764,7 +1424,7 @@ describe Braintree::Customer do
1764
1424
  }
1765
1425
  )
1766
1426
 
1767
- default_credit_card = Braintree::CreditCard.create!(
1427
+ default_payment_method = Braintree::CreditCard.create!(
1768
1428
  :customer_id => customer.id,
1769
1429
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
1770
1430
  :expiration_date => "11/2015",
@@ -1775,7 +1435,7 @@ describe Braintree::Customer do
1775
1435
 
1776
1436
  customer = Braintree::Customer.find(customer.id)
1777
1437
 
1778
- customer.default_credit_card.should == default_credit_card
1438
+ customer.default_payment_method.should == default_payment_method
1779
1439
  end
1780
1440
  end
1781
1441