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
@@ -82,7 +82,7 @@ describe Braintree::Dispute, "search" do
82
82
  effective_date = transaction.disputes.first.status_history.first.effective_date
83
83
 
84
84
  collection = Braintree::Dispute.search do |search|
85
- search.effective_date.between(effective_date, Date.parse(effective_date).next_day.to_s)
85
+ search.effective_date.between(effective_date, effective_date.next_day)
86
86
  end
87
87
 
88
88
  expect(collection.disputes.count).to be >= 1
@@ -95,7 +95,7 @@ describe Braintree::Dispute, "search" do
95
95
  disbursement_date = transaction.disputes.first.status_history.first.disbursement_date
96
96
 
97
97
  collection = Braintree::Dispute.search do |search|
98
- search.disbursement_date.between(disbursement_date, Date.parse(disbursement_date).next_day.to_s)
98
+ search.disbursement_date.between(disbursement_date, disbursement_date.next_day)
99
99
  end
100
100
 
101
101
  expect(collection.disputes.count).to be >= 1
@@ -109,7 +109,7 @@ describe Braintree::Dispute, "search" do
109
109
  search.received_date.between("03/03/2014", "03/05/2014")
110
110
  end
111
111
 
112
- expect(collection.disputes.count).to eq(1)
112
+ expect(collection.disputes.count).to be >= 1
113
113
  dispute = collection.disputes.first
114
114
 
115
115
  expect(dispute.received_date).to eq(Date.new(2014, 3, 4))
@@ -141,7 +141,7 @@ describe Braintree::Dispute do
141
141
  end
142
142
 
143
143
  it "creates text evidence for the dispute with optional parameters" do
144
- result = Braintree::Dispute.add_text_evidence(dispute.id, { content: "123456789", tag: "REFUND_ID", sequence_number: 7 })
144
+ result = Braintree::Dispute.add_text_evidence(dispute.id, { content: "123456789", category: "REFUND_ID", sequence_number: 7 })
145
145
 
146
146
  result.success?.should == true
147
147
  result.evidence.category.should == "REFUND_ID"
@@ -149,7 +149,6 @@ describe Braintree::Dispute do
149
149
  result.evidence.created_at.between?(Time.now - 10, Time.now).should == true
150
150
  result.evidence.id.should =~ /^\w{16,}$/
151
151
  result.evidence.sent_to_processor_at.should == nil
152
- result.evidence.tag.should == "REFUND_ID"
153
152
  result.evidence.sequence_number.should == 7
154
153
  end
155
154
  end
@@ -305,7 +305,7 @@ describe Braintree::MerchantGateway do
305
305
  it "succeeds" do
306
306
  result = Braintree::Merchant.provision_raw_apple_pay
307
307
  result.should be_success
308
- result.supported_networks.should == ["visa", "mastercard", "amex", "discover"]
308
+ result.supported_networks.should == ["visa", "mastercard", "amex", "discover", "maestro"]
309
309
  end
310
310
 
311
311
  it "is repeatable" do
@@ -313,7 +313,7 @@ describe Braintree::MerchantGateway do
313
313
  result.should be_success
314
314
  result = Braintree::Merchant.provision_raw_apple_pay
315
315
  result.should be_success
316
- result.supported_networks.should == ["visa", "mastercard", "amex", "discover"]
316
+ result.supported_networks.should == ["visa", "mastercard", "amex", "discover", "maestro"]
317
317
  end
318
318
  end
319
319
 
@@ -101,87 +101,60 @@ describe Braintree::PaymentMethod do
101
101
  apple_pay_card.customer_id.should == customer.id
102
102
  end
103
103
 
104
- it "creates a payment method from a fake android pay proxy card nonce" do
104
+ it "creates a payment method from a fake google pay proxy card nonce" do
105
105
  customer = Braintree::Customer.create.customer
106
106
  token = SecureRandom.hex(16)
107
107
  result = Braintree::PaymentMethod.create(
108
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
108
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
109
109
  :customer_id => customer.id,
110
110
  :token => token
111
111
  )
112
112
 
113
113
  result.should be_success
114
- android_pay_card = result.payment_method
115
- android_pay_card.should be_a(Braintree::AndroidPayCard)
116
- android_pay_card.should_not be_nil
117
- android_pay_card.token.should == token
118
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
119
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
120
- android_pay_card.expiration_month.to_i.should > 0
121
- android_pay_card.expiration_year.to_i.should > 0
122
- android_pay_card.default.should == true
123
- android_pay_card.image_url.should =~ /android_pay/
124
- android_pay_card.is_network_tokenized?.should == false
125
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
126
- android_pay_card.source_card_last_4.should == "1111"
127
- android_pay_card.google_transaction_id.should == "google_transaction_id"
128
- android_pay_card.source_description.should == "Discover 1111"
129
- android_pay_card.customer_id.should == customer.id
114
+ google_pay_card = result.payment_method
115
+ google_pay_card.should be_a(Braintree::GooglePayCard)
116
+ google_pay_card.should_not be_nil
117
+ google_pay_card.token.should == token
118
+ google_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
119
+ google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
120
+ google_pay_card.expiration_month.to_i.should > 0
121
+ google_pay_card.expiration_year.to_i.should > 0
122
+ google_pay_card.default.should == true
123
+ google_pay_card.image_url.should =~ /android_pay/
124
+ google_pay_card.is_network_tokenized?.should == false
125
+ google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
126
+ google_pay_card.source_card_last_4.should == "1111"
127
+ google_pay_card.google_transaction_id.should == "google_transaction_id"
128
+ google_pay_card.source_description.should == "Discover 1111"
129
+ google_pay_card.customer_id.should == customer.id
130
130
  end
131
131
 
132
- it "creates a payment method from a android pay network token nonce" do
132
+ it "creates a payment method from a google pay network token nonce" do
133
133
  customer = Braintree::Customer.create.customer
134
134
  token = SecureRandom.hex(16)
135
135
  result = Braintree::PaymentMethod.create(
136
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard,
136
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
137
137
  :customer_id => customer.id,
138
138
  :token => token
139
139
  )
140
140
 
141
141
  result.should be_success
142
- android_pay_card = result.payment_method
143
- android_pay_card.should be_a(Braintree::AndroidPayCard)
144
- android_pay_card.should_not be_nil
145
- android_pay_card.token.should == token
146
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
147
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
148
- android_pay_card.expiration_month.to_i.should > 0
149
- android_pay_card.expiration_year.to_i.should > 0
150
- android_pay_card.default.should == true
151
- android_pay_card.image_url.should =~ /android_pay/
152
- android_pay_card.is_network_tokenized?.should == true
153
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
154
- android_pay_card.source_card_last_4.should == "4444"
155
- android_pay_card.google_transaction_id.should == "google_transaction_id"
156
- android_pay_card.source_description.should == "MasterCard 4444"
157
- android_pay_card.customer_id.should == customer.id
158
- end
159
-
160
- it "creates a payment method from an amex express checkout card nonce" do
161
- customer = Braintree::Customer.create.customer
162
- token = SecureRandom.hex(16)
163
- result = Braintree::PaymentMethod.create(
164
- :payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout,
165
- :customer_id => customer.id,
166
- :token => token
167
- )
168
-
169
- result.should be_success
170
- amex_express_checkout_card = result.payment_method
171
- amex_express_checkout_card.should be_a(Braintree::AmexExpressCheckoutCard)
172
- amex_express_checkout_card.should_not be_nil
173
-
174
- amex_express_checkout_card.default.should == true
175
- amex_express_checkout_card.card_type.should == "American Express"
176
- amex_express_checkout_card.token.should == token
177
- amex_express_checkout_card.bin.should =~ /\A\d{6}\z/
178
- amex_express_checkout_card.expiration_month.should =~ /\A\d{2}\z/
179
- amex_express_checkout_card.expiration_year.should =~ /\A\d{4}\z/
180
- amex_express_checkout_card.card_member_number.should =~ /\A\d{4}\z/
181
- amex_express_checkout_card.card_member_expiry_date.should =~ /\A\d{2}\/\d{2}\z/
182
- amex_express_checkout_card.image_url.should include(".png")
183
- amex_express_checkout_card.source_description.should =~ /\AAmEx \d{4}\z/
184
- amex_express_checkout_card.customer_id.should == customer.id
142
+ google_pay_card = result.payment_method
143
+ google_pay_card.should be_a(Braintree::GooglePayCard)
144
+ google_pay_card.should_not be_nil
145
+ google_pay_card.token.should == token
146
+ google_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
147
+ google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
148
+ google_pay_card.expiration_month.to_i.should > 0
149
+ google_pay_card.expiration_year.to_i.should > 0
150
+ google_pay_card.default.should == true
151
+ google_pay_card.image_url.should =~ /android_pay/
152
+ google_pay_card.is_network_tokenized?.should == true
153
+ google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
154
+ google_pay_card.source_card_last_4.should == "4444"
155
+ google_pay_card.google_transaction_id.should == "google_transaction_id"
156
+ google_pay_card.source_description.should == "MasterCard 4444"
157
+ google_pay_card.customer_id.should == customer.id
185
158
  end
186
159
 
187
160
  it "creates a payment method from venmo account nonce" do
@@ -876,6 +849,99 @@ describe Braintree::PaymentMethod do
876
849
  payment_method.should be_a Braintree::UnknownPaymentMethod
877
850
  end
878
851
  end
852
+
853
+ context "verification_currency_iso_code" do
854
+ it "validates verification_currency_iso_code against currency configured in default merchant account" do
855
+ nonce = nonce_for_new_payment_method(
856
+ :credit_card => {
857
+ :number => Braintree::Test::CreditCardNumbers::Visa,
858
+ :expiration_month => "11",
859
+ :expiration_year => "2099",
860
+ }
861
+ )
862
+ customer = Braintree::Customer.create!
863
+ result = Braintree::PaymentMethod.create(
864
+ :payment_method_nonce => nonce,
865
+ :customer_id => customer.id,
866
+ :options => {
867
+ :verify_card => true,
868
+ :verification_currency_iso_code => "USD"
869
+ }
870
+ )
871
+
872
+ result.should be_success
873
+ result.payment_method.verification.currency_iso_code == "USD"
874
+ end
875
+
876
+ it "validates verification_currency_iso_code against currency configured in verification_merchant_account_id" do
877
+ nonce = nonce_for_new_payment_method(
878
+ :credit_card => {
879
+ :number => Braintree::Test::CreditCardNumbers::Visa,
880
+ :expiration_month => "11",
881
+ :expiration_year => "2099",
882
+ }
883
+ )
884
+ customer = Braintree::Customer.create!
885
+ result = Braintree::PaymentMethod.create(
886
+ :payment_method_nonce => nonce,
887
+ :customer_id => customer.id,
888
+ :options => {
889
+ :verify_card => true,
890
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
891
+ :verification_currency_iso_code => "USD"
892
+ }
893
+ )
894
+
895
+ result.should be_success
896
+ result.payment_method.verification.currency_iso_code == "USD"
897
+ result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
898
+ end
899
+
900
+
901
+ it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in default merchant account" do
902
+ nonce = nonce_for_new_payment_method(
903
+ :credit_card => {
904
+ :number => Braintree::Test::CreditCardNumbers::Visa,
905
+ :expiration_month => "11",
906
+ :expiration_year => "2099",
907
+ }
908
+ )
909
+ customer = Braintree::Customer.create!
910
+ result = Braintree::PaymentMethod.create(
911
+ :payment_method_nonce => nonce,
912
+ :customer_id => customer.id,
913
+ :options => {
914
+ :verify_card => true,
915
+ :verification_currency_iso_code => "GBP"
916
+ }
917
+ )
918
+ result.should_not be_success
919
+ result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
920
+ end
921
+
922
+ it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in verification_merchant_account_id" do
923
+ nonce = nonce_for_new_payment_method(
924
+ :credit_card => {
925
+ :number => Braintree::Test::CreditCardNumbers::Visa,
926
+ :expiration_month => "11",
927
+ :expiration_year => "2099",
928
+ }
929
+ )
930
+ customer = Braintree::Customer.create!
931
+ result = Braintree::PaymentMethod.create(
932
+ :payment_method_nonce => nonce,
933
+ :customer_id => customer.id,
934
+ :options => {
935
+ :verify_card => true,
936
+ :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
937
+ :verification_currency_iso_code => "GBP"
938
+ }
939
+ )
940
+
941
+ result.should_not be_success
942
+ result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
943
+ end
944
+ end
879
945
  end
880
946
 
881
947
  describe "self.create!" do
@@ -1024,61 +1090,61 @@ describe Braintree::PaymentMethod do
1024
1090
  end
1025
1091
  end
1026
1092
 
1027
- context "android pay cards" do
1093
+ context "google pay cards" do
1028
1094
  it "finds the proxy card payment method with the given token" do
1029
1095
  customer = Braintree::Customer.create!
1030
1096
  payment_method_token = make_token
1031
1097
  result = Braintree::PaymentMethod.create(
1032
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
1098
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1033
1099
  :customer_id => customer.id,
1034
1100
  :token => payment_method_token
1035
1101
  )
1036
1102
  result.should be_success
1037
1103
 
1038
- android_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1039
- android_pay_card.should be_a(Braintree::AndroidPayCard)
1040
- android_pay_card.should_not be_nil
1041
- android_pay_card.token.should == payment_method_token
1042
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
1043
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1044
- android_pay_card.expiration_month.to_i.should > 0
1045
- android_pay_card.expiration_year.to_i.should > 0
1046
- android_pay_card.default.should == true
1047
- android_pay_card.image_url.should =~ /android_pay/
1048
- android_pay_card.is_network_tokenized?.should == false
1049
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
1050
- android_pay_card.source_card_last_4.should == "1111"
1051
- android_pay_card.google_transaction_id.should == "google_transaction_id"
1052
- android_pay_card.source_description.should == "Discover 1111"
1053
- android_pay_card.customer_id.should == customer.id
1104
+ google_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1105
+ google_pay_card.should be_a(Braintree::GooglePayCard)
1106
+ google_pay_card.should_not be_nil
1107
+ google_pay_card.token.should == payment_method_token
1108
+ google_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
1109
+ google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1110
+ google_pay_card.expiration_month.to_i.should > 0
1111
+ google_pay_card.expiration_year.to_i.should > 0
1112
+ google_pay_card.default.should == true
1113
+ google_pay_card.image_url.should =~ /android_pay/
1114
+ google_pay_card.is_network_tokenized?.should == false
1115
+ google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
1116
+ google_pay_card.source_card_last_4.should == "1111"
1117
+ google_pay_card.google_transaction_id.should == "google_transaction_id"
1118
+ google_pay_card.source_description.should == "Discover 1111"
1119
+ google_pay_card.customer_id.should == customer.id
1054
1120
  end
1055
1121
 
1056
1122
  it "finds the network token payment method with the given token" do
1057
1123
  customer = Braintree::Customer.create!
1058
1124
  payment_method_token = make_token
1059
1125
  result = Braintree::PaymentMethod.create(
1060
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayMasterCard,
1126
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
1061
1127
  :customer_id => customer.id,
1062
1128
  :token => payment_method_token
1063
1129
  )
1064
1130
  result.should be_success
1065
1131
 
1066
- android_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1067
- android_pay_card.should be_a(Braintree::AndroidPayCard)
1068
- android_pay_card.should_not be_nil
1069
- android_pay_card.token.should == payment_method_token
1070
- android_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
1071
- android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1072
- android_pay_card.expiration_month.to_i.should > 0
1073
- android_pay_card.expiration_year.to_i.should > 0
1074
- android_pay_card.default.should == true
1075
- android_pay_card.image_url.should =~ /android_pay/
1076
- android_pay_card.is_network_tokenized?.should == true
1077
- android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
1078
- android_pay_card.source_card_last_4.should == "4444"
1079
- android_pay_card.google_transaction_id.should == "google_transaction_id"
1080
- android_pay_card.source_description.should == "MasterCard 4444"
1081
- android_pay_card.customer_id.should == customer.id
1132
+ google_pay_card = Braintree::PaymentMethod.find(payment_method_token)
1133
+ google_pay_card.should be_a(Braintree::GooglePayCard)
1134
+ google_pay_card.should_not be_nil
1135
+ google_pay_card.token.should == payment_method_token
1136
+ google_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
1137
+ google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1138
+ google_pay_card.expiration_month.to_i.should > 0
1139
+ google_pay_card.expiration_year.to_i.should > 0
1140
+ google_pay_card.default.should == true
1141
+ google_pay_card.image_url.should =~ /android_pay/
1142
+ google_pay_card.is_network_tokenized?.should == true
1143
+ google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
1144
+ google_pay_card.source_card_last_4.should == "4444"
1145
+ google_pay_card.google_transaction_id.should == "google_transaction_id"
1146
+ google_pay_card.source_description.should == "MasterCard 4444"
1147
+ google_pay_card.customer_id.should == customer.id
1082
1148
  end
1083
1149
  end
1084
1150
 
@@ -1110,18 +1176,18 @@ describe Braintree::PaymentMethod do
1110
1176
  end
1111
1177
 
1112
1178
  describe "self.delete" do
1113
- it "deletes an android pay card" do
1179
+ it "deletes an google pay card" do
1114
1180
  customer = Braintree::Customer.create!
1115
1181
 
1116
1182
  create_result = Braintree::PaymentMethod.create(
1117
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
1183
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1118
1184
  :customer_id => customer.id
1119
1185
  )
1120
1186
 
1121
1187
  token = create_result.payment_method.token
1122
1188
 
1123
- android_card = Braintree::PaymentMethod.find(token)
1124
- android_card.should be_a(Braintree::AndroidPayCard)
1189
+ google_card = Braintree::PaymentMethod.find(token)
1190
+ google_card.should be_a(Braintree::GooglePayCard)
1125
1191
 
1126
1192
  delete_result = Braintree::PaymentMethod.delete(token)
1127
1193
  delete_result.success?.should == true
@@ -1302,6 +1368,90 @@ describe Braintree::PaymentMethod do
1302
1368
  updated_credit_card.expiration_date.should == "06/2013"
1303
1369
  end
1304
1370
 
1371
+ context "verification_currency_iso_code" do
1372
+ it "validates verification_currency_iso_code and updates the credit card " do
1373
+ customer = Braintree::Customer.create!
1374
+ credit_card = Braintree::CreditCard.create!(
1375
+ :cardholder_name => "Original Holder",
1376
+ :customer_id => customer.id,
1377
+ :cvv => "123",
1378
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1379
+ :expiration_date => "05/2012"
1380
+ )
1381
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1382
+ :cardholder_name => "New Holder",
1383
+ :cvv => "456",
1384
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1385
+ :expiration_date => "06/2013",
1386
+ :options => {:verify_card => true, :verification_currency_iso_code => "USD"}
1387
+ )
1388
+ update_result.success?.should == true
1389
+ update_result.payment_method.verification.currency_iso_code == "USD"
1390
+ end
1391
+
1392
+ it "validates verification_currency_iso_code against the given verification_merchant_account_id and updates the credit card " do
1393
+ customer = Braintree::Customer.create!
1394
+ credit_card = Braintree::CreditCard.create!(
1395
+ :cardholder_name => "Original Holder",
1396
+ :customer_id => customer.id,
1397
+ :cvv => "123",
1398
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1399
+ :expiration_date => "05/2012"
1400
+ )
1401
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1402
+ :cardholder_name => "New Holder",
1403
+ :cvv => "456",
1404
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1405
+ :expiration_date => "06/2013",
1406
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"}
1407
+ )
1408
+ update_result.success?.should == true
1409
+ update_result.payment_method.verification.currency_iso_code == "USD"
1410
+ update_result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
1411
+ end
1412
+
1413
+ it "throws validation error when passing invalid verification_currency_iso_code" do
1414
+ customer = Braintree::Customer.create!
1415
+ credit_card = Braintree::CreditCard.create!(
1416
+ :cardholder_name => "Original Holder",
1417
+ :customer_id => customer.id,
1418
+ :cvv => "123",
1419
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1420
+ :expiration_date => "05/2012"
1421
+ )
1422
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1423
+ :cardholder_name => "New Holder",
1424
+ :cvv => "456",
1425
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1426
+ :expiration_date => "06/2013",
1427
+ :options => {:verify_card => true, :verification_currency_iso_code => "GBP"}
1428
+ )
1429
+ expect(update_result).to_not be_success
1430
+ update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1431
+ end
1432
+
1433
+ it "throws validation error when passing invalid verification_currency_iso_code of the given verification merchant account id" do
1434
+ customer = Braintree::Customer.create!
1435
+ credit_card = Braintree::CreditCard.create!(
1436
+ :cardholder_name => "Original Holder",
1437
+ :customer_id => customer.id,
1438
+ :cvv => "123",
1439
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1440
+ :expiration_date => "05/2012"
1441
+ )
1442
+ update_result = Braintree::PaymentMethod.update(credit_card.token,
1443
+ :cardholder_name => "New Holder",
1444
+ :cvv => "456",
1445
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
1446
+ :expiration_date => "06/2013",
1447
+ :options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"}
1448
+ )
1449
+ expect(update_result).to_not be_success
1450
+ update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
1451
+ end
1452
+ end
1453
+
1454
+
1305
1455
  context "billing address" do
1306
1456
  it "creates a new billing address by default" do
1307
1457
  customer = Braintree::Customer.create!
@@ -1522,22 +1672,6 @@ describe Braintree::PaymentMethod do
1522
1672
  end
1523
1673
  end
1524
1674
 
1525
- context "coinbase accounts" do
1526
- it "cannot create a payment method token with Coinbase" do
1527
- customer = Braintree::Customer.create!
1528
-
1529
- nonce = Braintree::Test::Nonce::Coinbase
1530
- result = Braintree::PaymentMethod.create(
1531
- :payment_method_nonce => nonce,
1532
- :customer_id => customer.id
1533
- )
1534
-
1535
- result.should_not be_success
1536
-
1537
- result.errors.for(:coinbase_account).first.code.should == Braintree::ErrorCodes::PaymentMethod::PaymentMethodNoLongerSupported
1538
- end
1539
- end
1540
-
1541
1675
  context "paypal accounts" do
1542
1676
  it "updates a paypal account's token" do
1543
1677
  customer = Braintree::Customer.create!
@@ -1739,7 +1873,7 @@ describe Braintree::PaymentMethod do
1739
1873
  it "raises an error if the token isn't found" do
1740
1874
  expect do
1741
1875
  @granting_gateway.payment_method.grant("not_a_real_token", false)
1742
- end.to raise_error
1876
+ end.to raise_error(Braintree::NotFoundError)
1743
1877
  end
1744
1878
 
1745
1879
  it "returns a valid nonce with no options set" do
@@ -1754,7 +1888,7 @@ describe Braintree::PaymentMethod do
1754
1888
  it "raises an error if the token isn't found" do
1755
1889
  expect do
1756
1890
  @granting_gateway.payment_method.revoke("not_a_real_token")
1757
- end.to raise_error
1891
+ end.to raise_error(Braintree::NotFoundError)
1758
1892
  end
1759
1893
 
1760
1894
  it "renders a granted nonce useless" do