braintree 2.104.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/braintree.gemspec +6 -3
- data/lib/braintree.rb +5 -17
- data/lib/braintree/address.rb +0 -22
- data/lib/braintree/base_module.rb +6 -0
- data/lib/braintree/bin_data.rb +9 -2
- data/lib/braintree/configuration.rb +1 -1
- data/lib/braintree/credit_card.rb +0 -75
- data/lib/braintree/credit_card_gateway.rb +4 -33
- data/lib/braintree/credit_card_verification.rb +13 -0
- data/lib/braintree/customer.rb +3 -74
- data/lib/braintree/customer_gateway.rb +0 -23
- data/lib/braintree/dispute.rb +1 -7
- data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
- data/lib/braintree/dispute_gateway.rb +2 -7
- data/lib/braintree/error_codes.rb +144 -170
- data/lib/braintree/exceptions.rb +5 -3
- data/lib/braintree/gateway.rb +0 -14
- data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -2
- data/lib/braintree/local_payment_completed.rb +1 -1
- data/lib/braintree/merchant_account_gateway.rb +2 -0
- data/lib/braintree/payment_instrument_type.rb +1 -5
- data/lib/braintree/payment_method_gateway.rb +5 -10
- data/lib/braintree/payment_method_parser.rb +1 -8
- data/lib/braintree/resource_collection.rb +8 -3
- data/lib/braintree/risk_data.rb +3 -1
- data/lib/braintree/subscription.rb +5 -5
- data/lib/braintree/successful_result.rb +0 -1
- data/lib/braintree/test/credit_card.rb +1 -0
- data/lib/braintree/test/nonce.rb +4 -23
- data/lib/braintree/three_d_secure_info.rb +22 -12
- data/lib/braintree/transaction.rb +12 -80
- data/lib/braintree/transaction/disbursement_details.rb +1 -0
- data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
- data/lib/braintree/transaction/installment.rb +28 -0
- data/lib/braintree/transaction/installment/adjustment.rb +33 -0
- data/lib/braintree/transaction/paypal_details.rb +1 -0
- data/lib/braintree/transaction/subscription_details.rb +2 -0
- data/lib/braintree/transaction_gateway.rb +14 -21
- data/lib/braintree/transaction_search.rb +0 -1
- data/lib/braintree/util.rb +17 -2
- data/lib/braintree/version.rb +2 -2
- data/lib/braintree/webhook_notification.rb +0 -10
- data/lib/braintree/webhook_testing_gateway.rb +0 -43
- data/lib/braintree/xml/libxml.rb +1 -0
- data/lib/braintree/xml/parser.rb +11 -34
- data/spec/integration/braintree/address_spec.rb +2 -89
- data/spec/integration/braintree/client_api/spec_helper.rb +0 -26
- data/spec/integration/braintree/credit_card_spec.rb +13 -476
- data/spec/integration/braintree/customer_spec.rb +189 -362
- data/spec/integration/braintree/dispute_search_spec.rb +3 -3
- data/spec/integration/braintree/dispute_spec.rb +1 -2
- data/spec/integration/braintree/merchant_spec.rb +2 -2
- data/spec/integration/braintree/payment_method_spec.rb +254 -120
- data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +8 -4
- data/spec/integration/braintree/subscription_spec.rb +11 -16
- data/spec/integration/braintree/transaction_search_spec.rb +3 -3
- data/spec/integration/braintree/transaction_spec.rb +324 -550
- data/spec/integration/braintree/transaction_us_bank_account_spec.rb +12 -6
- data/spec/integration/spec_helper.rb +8 -5
- data/spec/spec_helper.rb +2 -11
- data/spec/unit/braintree/address_spec.rb +0 -8
- data/spec/unit/braintree/credit_card_spec.rb +3 -22
- data/spec/unit/braintree/credit_card_verification_spec.rb +6 -2
- data/spec/unit/braintree/customer_spec.rb +2 -13
- data/spec/unit/braintree/dispute_spec.rb +1 -12
- data/spec/unit/braintree/http_spec.rb +3 -3
- data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
- data/spec/unit/braintree/resource_collection_spec.rb +29 -0
- data/spec/unit/braintree/risk_data_spec.rb +9 -5
- data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
- data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
- data/spec/unit/braintree/transaction/paypal_details_spec.rb +2 -0
- data/spec/unit/braintree/transaction_spec.rb +1 -35
- data/spec/unit/braintree/util_spec.rb +37 -3
- data/spec/unit/braintree/webhook_notification_spec.rb +1 -1
- data/spec/unit/braintree/xml/parser_spec.rb +21 -16
- metadata +29 -30
- data/lib/braintree/amex_express_checkout_card.rb +0 -40
- data/lib/braintree/coinbase_account.rb +0 -34
- data/lib/braintree/europe_bank_account.rb +0 -36
- data/lib/braintree/europe_bank_account_gateway.rb +0 -17
- data/lib/braintree/ideal_payment.rb +0 -61
- data/lib/braintree/ideal_payment_gateway.rb +0 -19
- data/lib/braintree/masterpass_card.rb +0 -83
- data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
- data/lib/braintree/transaction/coinbase_details.rb +0 -16
- data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
- data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
- data/lib/braintree/transparent_redirect.rb +0 -40
- data/lib/braintree/transparent_redirect_gateway.rb +0 -105
- data/lib/braintree/xml/rexml.rb +0 -71
- data/spec/hacks/tcp_socket.rb +0 -18
- data/spec/integration/braintree/coinbase_spec.rb +0 -34
- data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
- data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
- data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
- data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -136,32 +136,6 @@ def generate_valid_plaid_us_bank_account_nonce
|
|
136
136
|
json["data"]["tokenizeUsBankLogin"]["paymentMethod"]["id"]
|
137
137
|
end
|
138
138
|
|
139
|
-
def generate_valid_ideal_payment_nonce(amount = Braintree::Test::TransactionAmounts::Authorize)
|
140
|
-
raw_client_token = Braintree::ClientToken.generate(:merchant_account_id => "ideal_merchant_account")
|
141
|
-
client_token = decode_client_token(raw_client_token)
|
142
|
-
client = ClientApiHttp.new(
|
143
|
-
Braintree::Configuration.instantiate,
|
144
|
-
:authorization_fingerprint => client_token["authorizationFingerprint"],
|
145
|
-
)
|
146
|
-
config = JSON.parse(client.get_configuration.body)
|
147
|
-
|
148
|
-
braintree_api = client_token["braintree_api"]
|
149
|
-
url = braintree_api["url"] + "/ideal-payments"
|
150
|
-
|
151
|
-
token = braintree_api["access_token"]
|
152
|
-
payload = {
|
153
|
-
:issuer => "RABONL2U",
|
154
|
-
:order_id => SpecHelper::DefaultOrderId,
|
155
|
-
:amount => amount,
|
156
|
-
:currency => "EUR",
|
157
|
-
:redirect_url => "https://braintree-api.com",
|
158
|
-
:route_id => config["ideal"]["routeId"]
|
159
|
-
}
|
160
|
-
|
161
|
-
json = _cosmos_post(token, url, payload)
|
162
|
-
json["data"]["id"]
|
163
|
-
end
|
164
|
-
|
165
139
|
def sample(arr)
|
166
140
|
6.times.map { arr[rand(arr.length)] }.join
|
167
141
|
end
|
@@ -35,8 +35,7 @@ describe Braintree::CreditCard do
|
|
35
35
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
36
36
|
:expiration_date => "05/2009",
|
37
37
|
:cvv => "100",
|
38
|
-
:
|
39
|
-
:fraud_merchant_id => "7"
|
38
|
+
:device_data => "device_data",
|
40
39
|
)
|
41
40
|
result.success?.should == true
|
42
41
|
end
|
@@ -110,7 +109,7 @@ describe Braintree::CreditCard do
|
|
110
109
|
:options => {:verify_card => true}
|
111
110
|
)
|
112
111
|
result.success?.should == false
|
113
|
-
result.credit_card_verification.status.should == Braintree::
|
112
|
+
result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
|
114
113
|
result.credit_card_verification.processor_response_code.should == "2000"
|
115
114
|
result.credit_card_verification.processor_response_text.should == "Do Not Honor"
|
116
115
|
result.credit_card_verification.cvv_response_code.should == "I"
|
@@ -128,7 +127,7 @@ describe Braintree::CreditCard do
|
|
128
127
|
:options => {:verify_card => true, :verification_amount => "100.00"}
|
129
128
|
)
|
130
129
|
result.success?.should == false
|
131
|
-
result.credit_card_verification.status.should == Braintree::
|
130
|
+
result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
|
132
131
|
result.credit_card_verification.processor_response_code.should == "2000"
|
133
132
|
result.credit_card_verification.processor_response_text.should == "Do Not Honor"
|
134
133
|
result.credit_card_verification.cvv_response_code.should == "I"
|
@@ -138,7 +137,7 @@ describe Braintree::CreditCard do
|
|
138
137
|
end
|
139
138
|
|
140
139
|
it "returns risk data on verification on credit_card create" do
|
141
|
-
|
140
|
+
with_fraud_protection_enterprise_merchant do
|
142
141
|
customer = Braintree::Customer.create!
|
143
142
|
credit_card = Braintree::CreditCard.create!(
|
144
143
|
:cardholder_name => "Original Holder",
|
@@ -149,10 +148,12 @@ describe Braintree::CreditCard do
|
|
149
148
|
:options => {:verify_card => true}
|
150
149
|
)
|
151
150
|
verification = credit_card.verification
|
152
|
-
verification.risk_data.
|
153
|
-
verification.risk_data.
|
154
|
-
verification.risk_data.
|
155
|
-
verification.risk_data.
|
151
|
+
verification.risk_data.id.should_not be_nil
|
152
|
+
verification.risk_data.decision.should_not be_nil
|
153
|
+
verification.risk_data.decision_reasons.should_not be_nil
|
154
|
+
verification.risk_data.device_data_captured.should_not be_nil
|
155
|
+
verification.risk_data.fraud_service_provider.should_not be_nil
|
156
|
+
expect(verification.risk_data).to respond_to(:transaction_risk_score)
|
156
157
|
end
|
157
158
|
end
|
158
159
|
|
@@ -175,7 +176,7 @@ describe Braintree::CreditCard do
|
|
175
176
|
:options => {:verify_card => true}
|
176
177
|
)
|
177
178
|
result.success?.should == false
|
178
|
-
result.credit_card_verification.gateway_rejection_reason.should == Braintree::
|
179
|
+
result.credit_card_verification.gateway_rejection_reason.should == Braintree::CreditCardVerification::GatewayRejectionReason::CVV
|
179
180
|
ensure
|
180
181
|
Braintree::Configuration.merchant_id = old_merchant
|
181
182
|
Braintree::Configuration.public_key = old_public_key
|
@@ -192,7 +193,7 @@ describe Braintree::CreditCard do
|
|
192
193
|
:options => {:verify_card => true, :verification_amount => "1.01"}
|
193
194
|
)
|
194
195
|
result.success?.should == false
|
195
|
-
result.credit_card_verification.status.should == Braintree::
|
196
|
+
result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
|
196
197
|
result.credit_card_verification.processor_response_code.should == "2000"
|
197
198
|
result.credit_card_verification.processor_response_text.should == "Do Not Honor"
|
198
199
|
result.credit_card_verification.cvv_response_code.should == "I"
|
@@ -773,95 +774,6 @@ describe Braintree::CreditCard do
|
|
773
774
|
end
|
774
775
|
end
|
775
776
|
|
776
|
-
describe "self.create_from_transparent_redirect" do
|
777
|
-
it "returns a successful result if successful" do
|
778
|
-
result = Braintree::Customer.create
|
779
|
-
result.success?.should == true
|
780
|
-
customer = result.customer
|
781
|
-
params = {
|
782
|
-
:credit_card => {
|
783
|
-
:cardholder_name => "Card Holder",
|
784
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
785
|
-
:expiration_date => "05/2012"
|
786
|
-
}
|
787
|
-
}
|
788
|
-
tr_data_params = {
|
789
|
-
:credit_card => {
|
790
|
-
:customer_id => customer.id
|
791
|
-
}
|
792
|
-
}
|
793
|
-
tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
794
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
|
795
|
-
result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
|
796
|
-
result.success?.should == true
|
797
|
-
credit_card = result.credit_card
|
798
|
-
credit_card.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
799
|
-
credit_card.cardholder_name.should == "Card Holder"
|
800
|
-
credit_card.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
801
|
-
credit_card.expiration_month.should == "05"
|
802
|
-
credit_card.expiration_year.should == "2012"
|
803
|
-
credit_card.expiration_date.should == "05/2012"
|
804
|
-
credit_card.customer_id.should == customer.id
|
805
|
-
end
|
806
|
-
|
807
|
-
it "create card as default" do
|
808
|
-
customer = Braintree::Customer.create!(
|
809
|
-
:credit_card => {
|
810
|
-
:cardholder_name => "Old Cardholder Name",
|
811
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
812
|
-
:expiration_date => "05/2012"
|
813
|
-
}
|
814
|
-
)
|
815
|
-
card1 = customer.credit_cards[0]
|
816
|
-
|
817
|
-
params = {
|
818
|
-
:credit_card => {
|
819
|
-
:cardholder_name => "Card Holder",
|
820
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
821
|
-
:expiration_date => "05/2012",
|
822
|
-
:options => {:make_default => true}
|
823
|
-
}
|
824
|
-
}
|
825
|
-
tr_data_params = {
|
826
|
-
:credit_card => {
|
827
|
-
:customer_id => customer.id
|
828
|
-
}
|
829
|
-
}
|
830
|
-
tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
831
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
|
832
|
-
result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
|
833
|
-
result.success?.should == true
|
834
|
-
card2 = result.credit_card
|
835
|
-
|
836
|
-
Braintree::CreditCard.find(card1.token).should_not be_default
|
837
|
-
card2.should be_default
|
838
|
-
end
|
839
|
-
|
840
|
-
it "returns xml with nested errors if validation errors" do
|
841
|
-
customer = Braintree::Customer.create.customer
|
842
|
-
params = {
|
843
|
-
:credit_card => {
|
844
|
-
:cardholder_name => "Card Holder",
|
845
|
-
:number => "eleventy",
|
846
|
-
:expiration_date => "y2k"
|
847
|
-
}
|
848
|
-
}
|
849
|
-
tr_data_params = {
|
850
|
-
:credit_card => {
|
851
|
-
:customer_id => customer.id
|
852
|
-
}
|
853
|
-
}
|
854
|
-
tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
855
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.create_credit_card_url)
|
856
|
-
result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
|
857
|
-
result.success?.should == false
|
858
|
-
result.params[:customer_id] == customer.id
|
859
|
-
result.params[:credit_card]["cardholder_name"] == customer.id
|
860
|
-
result.params[:credit_card]["number"] == "eleventy"
|
861
|
-
result.params[:credit_card]["exipiration_date"] == "y2k"
|
862
|
-
end
|
863
|
-
end
|
864
|
-
|
865
777
|
describe "self.update" do
|
866
778
|
it "updates the credit card" do
|
867
779
|
customer = Braintree::Customer.create!
|
@@ -1053,7 +965,7 @@ describe Braintree::CreditCard do
|
|
1053
965
|
:options => {:verify_card => true}
|
1054
966
|
)
|
1055
967
|
update_result.success?.should == false
|
1056
|
-
update_result.credit_card_verification.status.should == Braintree::
|
968
|
+
update_result.credit_card_verification.status.should == Braintree::CreditCardVerification::Status::ProcessorDeclined
|
1057
969
|
update_result.credit_card_verification.gateway_rejection_reason.should be_nil
|
1058
970
|
end
|
1059
971
|
|
@@ -1222,132 +1134,6 @@ describe Braintree::CreditCard do
|
|
1222
1134
|
end
|
1223
1135
|
end
|
1224
1136
|
|
1225
|
-
describe "self.update_from_transparent_redirect" do
|
1226
|
-
it "updates the credit card" do
|
1227
|
-
old_token = "token_#{rand(10**10)}"
|
1228
|
-
new_token = "token_#{rand(10**10)}"
|
1229
|
-
customer = Braintree::Customer.create!(
|
1230
|
-
:credit_card => {
|
1231
|
-
:cardholder_name => "Old Cardholder Name",
|
1232
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1233
|
-
:expiration_date => "05/2012",
|
1234
|
-
:token => old_token
|
1235
|
-
}
|
1236
|
-
)
|
1237
|
-
credit_card = customer.credit_cards[0]
|
1238
|
-
params = {
|
1239
|
-
:credit_card => {
|
1240
|
-
:cardholder_name => "New Cardholder Name",
|
1241
|
-
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1242
|
-
:expiration_date => "05/2014"
|
1243
|
-
}
|
1244
|
-
}
|
1245
|
-
tr_data_params = {
|
1246
|
-
:payment_method_token => old_token,
|
1247
|
-
:credit_card => {
|
1248
|
-
:token => new_token
|
1249
|
-
}
|
1250
|
-
}
|
1251
|
-
tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
1252
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.update_credit_card_url)
|
1253
|
-
result = Braintree::CreditCard.update_from_transparent_redirect(query_string_response)
|
1254
|
-
result.success?.should == true
|
1255
|
-
credit_card = result.credit_card
|
1256
|
-
credit_card.cardholder_name.should == "New Cardholder Name"
|
1257
|
-
credit_card.masked_number.should == "555555******4444"
|
1258
|
-
credit_card.expiration_date.should == "05/2014"
|
1259
|
-
credit_card.token.should == new_token
|
1260
|
-
end
|
1261
|
-
|
1262
|
-
it "updates the default credit card" do
|
1263
|
-
customer = Braintree::Customer.create!(
|
1264
|
-
:credit_card => {
|
1265
|
-
:cardholder_name => "Old Cardholder Name",
|
1266
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1267
|
-
:expiration_date => "05/2012"
|
1268
|
-
}
|
1269
|
-
)
|
1270
|
-
card1 = customer.credit_cards[0]
|
1271
|
-
|
1272
|
-
card2 = Braintree::CreditCard.create(
|
1273
|
-
:customer_id => customer.id,
|
1274
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1275
|
-
:expiration_date => "05/2009"
|
1276
|
-
).credit_card
|
1277
|
-
|
1278
|
-
card1.should be_default
|
1279
|
-
card2.should_not be_default
|
1280
|
-
|
1281
|
-
params = {
|
1282
|
-
:credit_card => {
|
1283
|
-
:options => {:make_default => true}
|
1284
|
-
}
|
1285
|
-
}
|
1286
|
-
tr_data_params = {
|
1287
|
-
:payment_method_token => card2.token
|
1288
|
-
}
|
1289
|
-
tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
1290
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::CreditCard.update_credit_card_url)
|
1291
|
-
result = Braintree::CreditCard.update_from_transparent_redirect(query_string_response)
|
1292
|
-
|
1293
|
-
Braintree::CreditCard.find(card1.token).should_not be_default
|
1294
|
-
Braintree::CreditCard.find(card2.token).should be_default
|
1295
|
-
end
|
1296
|
-
end
|
1297
|
-
|
1298
|
-
describe "credit" do
|
1299
|
-
it "creates a credit transaction using the customer, returning a result object" do
|
1300
|
-
customer = Braintree::Customer.create!(
|
1301
|
-
:credit_card => {
|
1302
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1303
|
-
:expiration_date => "05/2010"
|
1304
|
-
}
|
1305
|
-
)
|
1306
|
-
result = customer.credit_cards[0].credit(
|
1307
|
-
:amount => "100.00"
|
1308
|
-
)
|
1309
|
-
result.success?.should == true
|
1310
|
-
result.transaction.amount.should == BigDecimal("100.00")
|
1311
|
-
result.transaction.type.should == "credit"
|
1312
|
-
result.transaction.customer_details.id.should == customer.id
|
1313
|
-
result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
|
1314
|
-
result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
1315
|
-
result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
1316
|
-
result.transaction.credit_card_details.expiration_date.should == "05/2010"
|
1317
|
-
end
|
1318
|
-
end
|
1319
|
-
|
1320
|
-
describe "credit!" do
|
1321
|
-
it "returns the created credit tranaction if valid" do
|
1322
|
-
customer = Braintree::Customer.create!(
|
1323
|
-
:credit_card => {
|
1324
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1325
|
-
:expiration_date => "05/2010"
|
1326
|
-
}
|
1327
|
-
)
|
1328
|
-
transaction = customer.credit_cards[0].credit!(:amount => "100.00")
|
1329
|
-
transaction.amount.should == BigDecimal("100.00")
|
1330
|
-
transaction.type.should == "credit"
|
1331
|
-
transaction.customer_details.id.should == customer.id
|
1332
|
-
transaction.credit_card_details.token.should == customer.credit_cards[0].token
|
1333
|
-
transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
1334
|
-
transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
1335
|
-
transaction.credit_card_details.expiration_date.should == "05/2010"
|
1336
|
-
end
|
1337
|
-
|
1338
|
-
it "raises a ValidationsFailed if invalid" do
|
1339
|
-
customer = Braintree::Customer.create!(
|
1340
|
-
:credit_card => {
|
1341
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1342
|
-
:expiration_date => "05/2010"
|
1343
|
-
}
|
1344
|
-
)
|
1345
|
-
expect do
|
1346
|
-
customer.credit_cards[0].credit!(:amount => "invalid")
|
1347
|
-
end.to raise_error(Braintree::ValidationsFailed)
|
1348
|
-
end
|
1349
|
-
end
|
1350
|
-
|
1351
1137
|
describe "self.delete" do
|
1352
1138
|
it "deletes the credit card" do
|
1353
1139
|
customer = Braintree::Customer.create.customer
|
@@ -1589,255 +1375,6 @@ describe Braintree::CreditCard do
|
|
1589
1375
|
end
|
1590
1376
|
end
|
1591
1377
|
|
1592
|
-
describe "sale" do
|
1593
|
-
it "creates a sale transaction using the credit card, returning a result object" do
|
1594
|
-
customer = Braintree::Customer.create!(
|
1595
|
-
:credit_card => {
|
1596
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1597
|
-
:expiration_date => "05/2010"
|
1598
|
-
}
|
1599
|
-
)
|
1600
|
-
result = customer.credit_cards[0].sale(
|
1601
|
-
:amount => "100.00"
|
1602
|
-
)
|
1603
|
-
result.success?.should == true
|
1604
|
-
result.transaction.amount.should == BigDecimal("100.00")
|
1605
|
-
result.transaction.type.should == "sale"
|
1606
|
-
result.transaction.customer_details.id.should == customer.id
|
1607
|
-
result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
|
1608
|
-
result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
1609
|
-
result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
1610
|
-
result.transaction.credit_card_details.expiration_date.should == "05/2010"
|
1611
|
-
end
|
1612
|
-
end
|
1613
|
-
|
1614
|
-
describe "sale!" do
|
1615
|
-
it "returns the created sale tranaction if valid" do
|
1616
|
-
customer = Braintree::Customer.create!(
|
1617
|
-
:credit_card => {
|
1618
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1619
|
-
:expiration_date => "05/2010"
|
1620
|
-
}
|
1621
|
-
)
|
1622
|
-
transaction = customer.credit_cards[0].sale!(:amount => "100.00")
|
1623
|
-
transaction.amount.should == BigDecimal("100.00")
|
1624
|
-
transaction.type.should == "sale"
|
1625
|
-
transaction.customer_details.id.should == customer.id
|
1626
|
-
transaction.credit_card_details.token.should == customer.credit_cards[0].token
|
1627
|
-
transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
1628
|
-
transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
1629
|
-
transaction.credit_card_details.expiration_date.should == "05/2010"
|
1630
|
-
end
|
1631
|
-
|
1632
|
-
it "raises a ValidationsFailed if invalid" do
|
1633
|
-
customer = Braintree::Customer.create!(
|
1634
|
-
:credit_card => {
|
1635
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1636
|
-
:expiration_date => "05/2010"
|
1637
|
-
}
|
1638
|
-
)
|
1639
|
-
expect do
|
1640
|
-
customer.credit_cards[0].sale!(:amount => "invalid")
|
1641
|
-
end.to raise_error(Braintree::ValidationsFailed)
|
1642
|
-
end
|
1643
|
-
end
|
1644
|
-
|
1645
|
-
describe "update" do
|
1646
|
-
it "updates the credit card" do
|
1647
|
-
customer = Braintree::Customer.create!
|
1648
|
-
credit_card = Braintree::CreditCard.create!(
|
1649
|
-
:cardholder_name => "Original Holder",
|
1650
|
-
:customer_id => customer.id,
|
1651
|
-
:cvv => "123",
|
1652
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1653
|
-
:expiration_date => "05/2012"
|
1654
|
-
)
|
1655
|
-
update_result = credit_card.update(
|
1656
|
-
:cardholder_name => "New Holder",
|
1657
|
-
:cvv => "456",
|
1658
|
-
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1659
|
-
:expiration_date => "06/2013"
|
1660
|
-
)
|
1661
|
-
update_result.success?.should == true
|
1662
|
-
update_result.credit_card.should == credit_card
|
1663
|
-
updated_credit_card = update_result.credit_card
|
1664
|
-
updated_credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
|
1665
|
-
updated_credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
|
1666
|
-
updated_credit_card.expiration_date.should == "06/2013"
|
1667
|
-
updated_credit_card.cardholder_name.should == "New Holder"
|
1668
|
-
end
|
1669
|
-
|
1670
|
-
it "verifies the update if options[verify_card]=true" do
|
1671
|
-
customer = Braintree::Customer.create!
|
1672
|
-
credit_card = Braintree::CreditCard.create!(
|
1673
|
-
:cardholder_name => "Original Holder",
|
1674
|
-
:customer_id => customer.id,
|
1675
|
-
:cvv => "123",
|
1676
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1677
|
-
:expiration_date => "05/2012"
|
1678
|
-
)
|
1679
|
-
update_result = credit_card.update(
|
1680
|
-
:cardholder_name => "New Holder",
|
1681
|
-
:cvv => "456",
|
1682
|
-
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
|
1683
|
-
:expiration_date => "06/2013",
|
1684
|
-
:options => {:verify_card => true}
|
1685
|
-
)
|
1686
|
-
update_result.success?.should == false
|
1687
|
-
update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
1688
|
-
end
|
1689
|
-
|
1690
|
-
it "fails on create if credit_card[options][fail_on_duplicate_payment_method]=true and there is a duplicated payment method" do
|
1691
|
-
customer = Braintree::Customer.create!
|
1692
|
-
Braintree::CreditCard.create(
|
1693
|
-
:customer_id => customer.id,
|
1694
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1695
|
-
:expiration_date => "05/2015"
|
1696
|
-
)
|
1697
|
-
|
1698
|
-
result = Braintree::CreditCard.create(
|
1699
|
-
:customer_id => customer.id,
|
1700
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1701
|
-
:expiration_date => "05/2015",
|
1702
|
-
:options => {:fail_on_duplicate_payment_method => true}
|
1703
|
-
)
|
1704
|
-
|
1705
|
-
result.success?.should == false
|
1706
|
-
result.errors.for(:credit_card).on(:number)[0].message.should == "Duplicate card exists in the vault."
|
1707
|
-
end
|
1708
|
-
|
1709
|
-
it "allows user to specify merchant account for verification" do
|
1710
|
-
customer = Braintree::Customer.create!
|
1711
|
-
credit_card = Braintree::CreditCard.create!(
|
1712
|
-
:cardholder_name => "Original Holder",
|
1713
|
-
:customer_id => customer.id,
|
1714
|
-
:cvv => "123",
|
1715
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1716
|
-
:expiration_date => "05/2012"
|
1717
|
-
)
|
1718
|
-
update_result = credit_card.update(
|
1719
|
-
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
|
1720
|
-
:expiration_date => "05/2009",
|
1721
|
-
:options => {
|
1722
|
-
:verify_card => true,
|
1723
|
-
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
|
1724
|
-
}
|
1725
|
-
)
|
1726
|
-
update_result.success?.should == false
|
1727
|
-
update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
1728
|
-
update_result.credit_card_verification.processor_response_code.should == "2000"
|
1729
|
-
update_result.credit_card_verification.processor_response_text.should == "Do Not Honor"
|
1730
|
-
update_result.credit_card_verification.cvv_response_code.should == "I"
|
1731
|
-
update_result.credit_card_verification.avs_error_response_code.should == nil
|
1732
|
-
update_result.credit_card_verification.avs_postal_code_response_code.should == "I"
|
1733
|
-
update_result.credit_card_verification.avs_street_address_response_code.should == "I"
|
1734
|
-
end
|
1735
|
-
|
1736
|
-
it "can update the billing address" do
|
1737
|
-
customer = Braintree::Customer.create!
|
1738
|
-
credit_card = Braintree::CreditCard.create!(
|
1739
|
-
:cardholder_name => "Original Holder",
|
1740
|
-
:customer_id => customer.id,
|
1741
|
-
:cvv => "123",
|
1742
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1743
|
-
:expiration_date => "05/2012",
|
1744
|
-
:billing_address => {
|
1745
|
-
:first_name => "Old First Name",
|
1746
|
-
:last_name => "Old Last Name",
|
1747
|
-
:company => "Old Company",
|
1748
|
-
:street_address => "123 Old St",
|
1749
|
-
:extended_address => "Apt Old",
|
1750
|
-
:locality => "Old City",
|
1751
|
-
:region => "Old State",
|
1752
|
-
:postal_code => "12345",
|
1753
|
-
:country_name => "Canada"
|
1754
|
-
}
|
1755
|
-
)
|
1756
|
-
result = credit_card.update(
|
1757
|
-
:options => {:verify_card => false},
|
1758
|
-
:billing_address => {
|
1759
|
-
:first_name => "New First Name",
|
1760
|
-
:last_name => "New Last Name",
|
1761
|
-
:company => "New Company",
|
1762
|
-
:street_address => "123 New St",
|
1763
|
-
:extended_address => "Apt New",
|
1764
|
-
:locality => "New City",
|
1765
|
-
:region => "New State",
|
1766
|
-
:postal_code => "56789",
|
1767
|
-
:country_name => "United States of America"
|
1768
|
-
}
|
1769
|
-
)
|
1770
|
-
result.success?.should == true
|
1771
|
-
address = result.credit_card.billing_address
|
1772
|
-
address.should == credit_card.billing_address # making sure credit card instance was updated
|
1773
|
-
address.first_name.should == "New First Name"
|
1774
|
-
address.last_name.should == "New Last Name"
|
1775
|
-
address.company.should == "New Company"
|
1776
|
-
address.street_address.should == "123 New St"
|
1777
|
-
address.extended_address.should == "Apt New"
|
1778
|
-
address.locality.should == "New City"
|
1779
|
-
address.region.should == "New State"
|
1780
|
-
address.postal_code.should == "56789"
|
1781
|
-
address.country_name.should == "United States of America"
|
1782
|
-
end
|
1783
|
-
|
1784
|
-
it "returns an error response if invalid" do
|
1785
|
-
customer = Braintree::Customer.create!
|
1786
|
-
credit_card = Braintree::CreditCard.create!(
|
1787
|
-
:cardholder_name => "Original Holder",
|
1788
|
-
:customer_id => customer.id,
|
1789
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1790
|
-
:expiration_date => "05/2012"
|
1791
|
-
)
|
1792
|
-
update_result = credit_card.update(
|
1793
|
-
:cardholder_name => "New Holder",
|
1794
|
-
:number => "invalid",
|
1795
|
-
:expiration_date => "05/2014"
|
1796
|
-
)
|
1797
|
-
update_result.success?.should == false
|
1798
|
-
update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
|
1799
|
-
end
|
1800
|
-
end
|
1801
|
-
|
1802
|
-
describe "update!" do
|
1803
|
-
it "updates the credit card and returns true if valid" do
|
1804
|
-
customer = Braintree::Customer.create!
|
1805
|
-
credit_card = Braintree::CreditCard.create!(
|
1806
|
-
:cardholder_name => "Original Holder",
|
1807
|
-
:customer_id => customer.id,
|
1808
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1809
|
-
:expiration_date => "05/2012"
|
1810
|
-
)
|
1811
|
-
credit_card.update!(
|
1812
|
-
:cardholder_name => "New Holder",
|
1813
|
-
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1814
|
-
:expiration_date => "06/2013"
|
1815
|
-
).should == credit_card
|
1816
|
-
credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
|
1817
|
-
credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
|
1818
|
-
credit_card.expiration_date.should == "06/2013"
|
1819
|
-
credit_card.cardholder_name.should == "New Holder"
|
1820
|
-
credit_card.updated_at.between?(Time.now - 60, Time.now).should == true
|
1821
|
-
end
|
1822
|
-
|
1823
|
-
it "raises a ValidationsFailed if invalid" do
|
1824
|
-
customer = Braintree::Customer.create!
|
1825
|
-
credit_card = Braintree::CreditCard.create!(
|
1826
|
-
:cardholder_name => "Original Holder",
|
1827
|
-
:customer_id => customer.id,
|
1828
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1829
|
-
:expiration_date => "05/2012"
|
1830
|
-
)
|
1831
|
-
expect do
|
1832
|
-
credit_card.update!(
|
1833
|
-
:cardholder_name => "New Holder",
|
1834
|
-
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1835
|
-
:expiration_date => "invalid/date"
|
1836
|
-
)
|
1837
|
-
end.to raise_error(Braintree::ValidationsFailed)
|
1838
|
-
end
|
1839
|
-
end
|
1840
|
-
|
1841
1378
|
describe "nonce" do
|
1842
1379
|
it "returns the credit card nonce" do
|
1843
1380
|
customer = Braintree::Customer.create!
|