braintree 2.74.0 → 4.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/braintree.gemspec +13 -7
- data/lib/braintree/account_updater_daily_report.rb +2 -2
- data/lib/braintree/ach_mandate.rb +2 -1
- data/lib/braintree/address/country_names.rb +4 -1
- data/lib/braintree/address.rb +30 -38
- data/lib/braintree/address_gateway.rb +12 -2
- data/lib/braintree/advanced_search.rb +8 -0
- data/lib/braintree/apple_pay.rb +29 -0
- data/lib/braintree/apple_pay_card.rb +28 -4
- data/lib/braintree/apple_pay_gateway.rb +37 -0
- data/lib/braintree/apple_pay_options.rb +19 -0
- data/lib/braintree/authorization_adjustment.rb +23 -0
- data/lib/braintree/base_module.rb +10 -0
- data/lib/braintree/bin_data.rb +33 -0
- data/lib/braintree/client_token.rb +3 -3
- data/lib/braintree/client_token_gateway.rb +3 -1
- data/lib/braintree/configuration.rb +57 -10
- data/lib/braintree/connected_merchant_paypal_status_changed.rb +6 -2
- data/lib/braintree/connected_merchant_status_transitioned.rb +6 -2
- data/lib/braintree/credentials_parser.rb +5 -1
- data/lib/braintree/credit_card.rb +53 -107
- data/lib/braintree/credit_card_gateway.rb +43 -30
- data/lib/braintree/credit_card_verification.rb +61 -21
- data/lib/braintree/credit_card_verification_gateway.rb +19 -6
- data/lib/braintree/credit_card_verification_search.rb +1 -1
- data/lib/braintree/customer.rb +51 -98
- data/lib/braintree/customer_gateway.rb +30 -23
- data/lib/braintree/customer_search.rb +1 -1
- data/lib/braintree/descriptor.rb +3 -1
- data/lib/braintree/disbursement.rb +24 -2
- data/lib/braintree/dispute/evidence.rb +24 -0
- data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -3
- data/lib/braintree/dispute/status_history.rb +18 -0
- data/lib/braintree/dispute/transaction.rb +20 -0
- data/lib/braintree/dispute/transaction_details.rb +2 -1
- data/lib/braintree/dispute.rb +114 -10
- data/lib/braintree/dispute_gateway.rb +142 -0
- data/lib/braintree/dispute_search.rb +31 -0
- data/lib/braintree/document_upload.rb +37 -0
- data/lib/braintree/document_upload_gateway.rb +38 -0
- data/lib/braintree/enriched_customer_data.rb +21 -0
- data/lib/braintree/error_codes.rb +328 -109
- data/lib/braintree/error_result.rb +8 -1
- data/lib/braintree/exceptions.rb +5 -3
- data/lib/braintree/exchange_rate.rb +13 -0
- data/lib/braintree/exchange_rate_quote.rb +24 -0
- data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
- data/lib/braintree/exchange_rate_quote_input.rb +21 -0
- data/lib/braintree/exchange_rate_quote_request.rb +18 -0
- data/lib/braintree/exchange_rate_quote_response.rb +18 -0
- data/lib/braintree/facilitated_details.rb +21 -0
- data/lib/braintree/facilitator_details.rb +2 -1
- data/lib/braintree/gateway.rb +29 -11
- data/lib/braintree/google_pay_card.rb +61 -0
- data/lib/braintree/granted_payment_instrument_update.rb +23 -0
- data/lib/braintree/graphql_client.rb +34 -0
- data/lib/braintree/http.rb +81 -20
- data/lib/braintree/local_payment_completed.rb +23 -0
- data/lib/braintree/local_payment_expired.rb +21 -0
- data/lib/braintree/local_payment_funded.rb +22 -0
- data/lib/braintree/local_payment_reversed.rb +19 -0
- data/lib/braintree/merchant.rb +11 -4
- data/lib/braintree/merchant_account/address_details.rb +4 -1
- data/lib/braintree/merchant_account/business_details.rb +4 -1
- data/lib/braintree/merchant_account/funding_details.rb +6 -1
- data/lib/braintree/merchant_account/individual_details.rb +7 -2
- data/lib/braintree/merchant_account.rb +23 -10
- data/lib/braintree/merchant_account_gateway.rb +13 -1
- data/lib/braintree/merchant_gateway.rb +2 -2
- data/lib/braintree/modification.rb +1 -1
- data/lib/braintree/oauth_credentials.rb +5 -2
- data/lib/braintree/oauth_gateway.rb +8 -14
- data/lib/braintree/paginated_result.rb +3 -1
- data/lib/braintree/payment_instrument_type.rb +11 -11
- data/lib/braintree/payment_method.rb +20 -12
- data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
- data/lib/braintree/payment_method_gateway.rb +82 -54
- data/lib/braintree/payment_method_nonce.rb +22 -8
- data/lib/braintree/payment_method_nonce_details.rb +40 -0
- data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
- data/lib/braintree/payment_method_nonce_gateway.rb +19 -2
- data/lib/braintree/payment_method_parser.rb +28 -0
- data/lib/braintree/paypal_account.rb +10 -1
- data/lib/braintree/plan.rb +25 -5
- data/lib/braintree/plan_gateway.rb +100 -0
- data/lib/braintree/processor_response_types.rb +7 -0
- data/lib/braintree/resource_collection.rb +8 -3
- data/lib/braintree/revoked_payment_method_metadata.rb +22 -0
- data/lib/braintree/risk_data/liability_shift.rb +22 -0
- data/lib/braintree/risk_data.rb +12 -2
- data/lib/braintree/samsung_pay_card.rb +83 -0
- data/lib/braintree/sepa_direct_debit_account.rb +60 -0
- data/lib/braintree/sepa_direct_debit_account_gateway.rb +25 -0
- data/lib/braintree/sepa_direct_debit_account_nonce_details.rb +28 -0
- data/lib/braintree/settlement_batch_summary.rb +2 -1
- data/lib/braintree/settlement_batch_summary_gateway.rb +2 -0
- data/lib/braintree/subscription/status_details.rb +8 -1
- data/lib/braintree/subscription.rb +56 -41
- data/lib/braintree/subscription_gateway.rb +25 -2
- data/lib/braintree/successful_result.rb +23 -1
- data/lib/braintree/test/authentication_id.rb +21 -0
- data/lib/braintree/test/credit_card.rb +13 -0
- data/lib/braintree/test/nonce.rb +28 -20
- data/lib/braintree/test/transaction_amounts.rb +1 -0
- data/lib/braintree/three_d_secure_info.rb +34 -2
- data/lib/braintree/transaction/address_details.rb +24 -4
- data/lib/braintree/transaction/apple_pay_details.rb +20 -2
- data/lib/braintree/transaction/credit_card_details.rb +45 -6
- data/lib/braintree/transaction/customer_details.rb +8 -1
- data/lib/braintree/transaction/disbursement_details.rb +6 -1
- data/lib/braintree/transaction/google_pay_details.rb +41 -0
- data/lib/braintree/transaction/installment/adjustment.rb +33 -0
- data/lib/braintree/transaction/installment.rb +28 -0
- data/lib/braintree/transaction/local_payment_details.rb +24 -0
- data/lib/braintree/transaction/paypal_details.rb +26 -4
- data/lib/braintree/transaction/paypal_here_details.rb +23 -0
- data/lib/braintree/transaction/{masterpass_card_details.rb → samsung_pay_card_details.rb} +21 -6
- data/lib/braintree/transaction/sepa_direct_debit_account_details.rb +27 -0
- data/lib/braintree/transaction/status_details.rb +5 -1
- data/lib/braintree/transaction/subscription_details.rb +4 -1
- data/lib/braintree/transaction/us_bank_account_details.rb +8 -1
- data/lib/braintree/transaction/venmo_account_details.rb +5 -1
- data/lib/braintree/transaction/visa_checkout_card_details.rb +19 -4
- data/lib/braintree/transaction.rb +201 -188
- data/lib/braintree/transaction_gateway.rb +124 -30
- data/lib/braintree/transaction_line_item.rb +40 -0
- data/lib/braintree/transaction_line_item_gateway.rb +19 -0
- data/lib/braintree/transaction_review.rb +18 -0
- data/lib/braintree/transaction_search.rb +6 -3
- data/lib/braintree/unknown_payment_method.rb +3 -2
- data/lib/braintree/us_bank_account.rb +24 -8
- data/lib/braintree/us_bank_account_gateway.rb +0 -1
- data/lib/braintree/us_bank_account_verification.rb +81 -0
- data/lib/braintree/us_bank_account_verification_gateway.rb +51 -0
- data/lib/braintree/us_bank_account_verification_search.rb +19 -0
- data/lib/braintree/util.rb +79 -9
- data/lib/braintree/validation_error.rb +13 -3
- data/lib/braintree/validation_error_collection.rb +2 -1
- data/lib/braintree/venmo_account.rb +11 -4
- data/lib/braintree/venmo_profile_data.rb +23 -0
- data/lib/braintree/version.rb +2 -2
- data/lib/braintree/visa_checkout_card.rb +29 -13
- data/lib/braintree/webhook_notification.rb +66 -26
- data/lib/braintree/webhook_notification_gateway.rb +5 -3
- data/lib/braintree/webhook_testing.rb +2 -2
- data/lib/braintree/webhook_testing_gateway.rb +721 -55
- data/lib/braintree/xml/generator.rb +6 -4
- data/lib/braintree/xml/parser.rb +22 -35
- data/lib/braintree/xml/rexml.rb +4 -5
- data/lib/braintree.rb +60 -22
- data/lib/ssl/api_braintreegateway_com.ca.crt +50 -0
- data/spec/fixtures/files/bt_logo.png +0 -0
- data/spec/fixtures/files/gif_extension_bt_logo.gif +0 -0
- data/spec/fixtures/files/malformed_pdf.pdf +1 -0
- data/spec/fixtures/files/too_long.pdf +0 -0
- data/spec/integration/braintree/add_on_spec.rb +3 -3
- data/spec/integration/braintree/address_spec.rb +30 -113
- data/spec/integration/braintree/advanced_search_spec.rb +45 -45
- data/spec/integration/braintree/apple_pay_spec.rb +63 -0
- data/spec/integration/braintree/braintree_gateway_spec.rb +72 -0
- data/spec/integration/braintree/client_api/client_token_spec.rb +14 -32
- data/spec/integration/braintree/client_api/spec_helper.rb +104 -65
- data/spec/integration/braintree/credit_card_spec.rb +460 -615
- data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
- data/spec/integration/braintree/credit_card_verification_spec.rb +222 -6
- data/spec/integration/braintree/customer_search_spec.rb +8 -8
- data/spec/integration/braintree/customer_spec.rb +810 -498
- data/spec/integration/braintree/discount_spec.rb +1 -1
- data/spec/integration/braintree/dispute_search_spec.rb +167 -0
- data/spec/integration/braintree/dispute_spec.rb +333 -0
- data/spec/integration/braintree/document_upload_spec.rb +87 -0
- data/spec/integration/braintree/error_codes_spec.rb +1 -1
- data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
- data/spec/integration/braintree/graphql_client_spec.rb +72 -0
- data/spec/integration/braintree/http_spec.rb +12 -4
- data/spec/integration/braintree/merchant_account_spec.rb +74 -26
- data/spec/integration/braintree/merchant_spec.rb +39 -13
- data/spec/integration/braintree/oauth_spec.rb +18 -25
- data/spec/integration/braintree/payment_method_nonce_spec.rb +239 -5
- data/spec/integration/braintree/payment_method_spec.rb +882 -300
- data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +416 -0
- data/spec/integration/braintree/paypal_account_spec.rb +32 -31
- data/spec/integration/braintree/plan_spec.rb +82 -0
- data/spec/integration/braintree/samsung_pay_card_spec.rb +144 -0
- data/spec/integration/braintree/sepa_direct_debit_account_spec.rb +196 -0
- data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
- data/spec/integration/braintree/subscription_spec.rb +274 -180
- data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
- data/spec/integration/braintree/test_transaction_spec.rb +18 -18
- data/spec/integration/braintree/transaction_line_item_spec.rb +38 -0
- data/spec/integration/braintree/transaction_search_spec.rb +280 -152
- data/spec/integration/braintree/transaction_spec.rb +3709 -1175
- data/spec/integration/braintree/transaction_us_bank_account_spec.rb +438 -0
- data/spec/integration/braintree/us_bank_account_spec.rb +38 -17
- data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +178 -0
- data/spec/integration/braintree/us_bank_account_verification_spec.rb +240 -0
- data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
- data/spec/integration/spec_helper.rb +27 -6
- data/spec/oauth_test_helper.rb +1 -1
- data/spec/script/httpsd.rb +6 -6
- data/spec/spec_helper.rb +26 -23
- data/spec/unit/braintree/address_spec.rb +1 -9
- data/spec/unit/braintree/apple_pay_card_spec.rb +104 -4
- data/spec/unit/braintree/client_token_spec.rb +2 -2
- data/spec/unit/braintree/configuration_spec.rb +108 -33
- data/spec/unit/braintree/credit_card_spec.rb +62 -33
- data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +51 -0
- data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
- data/spec/unit/braintree/credit_card_verification_spec.rb +39 -6
- data/spec/unit/braintree/customer_spec.rb +107 -27
- data/spec/unit/braintree/disbursement_spec.rb +59 -7
- data/spec/unit/braintree/dispute_search_spec.rb +66 -0
- data/spec/unit/braintree/dispute_spec.rb +472 -8
- data/spec/unit/braintree/document_upload_spec.rb +35 -0
- data/spec/unit/braintree/enriched_customer_data_spec.rb +32 -0
- data/spec/unit/braintree/error_result_spec.rb +5 -5
- data/spec/unit/braintree/errors_spec.rb +8 -8
- data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
- data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
- data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
- data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
- data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
- data/spec/unit/braintree/http_spec.rb +93 -5
- data/spec/unit/braintree/local_payment_completed_spec.rb +50 -0
- data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
- data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
- data/spec/unit/braintree/merchant_account_spec.rb +1 -1
- data/spec/unit/braintree/modification_spec.rb +1 -1
- data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
- data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
- data/spec/unit/braintree/payment_method_nonce_details_spec.rb +51 -0
- data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
- data/spec/unit/braintree/payment_method_spec.rb +1 -1
- data/spec/unit/braintree/paypal_account_spec.rb +2 -2
- data/spec/unit/braintree/resource_collection_spec.rb +30 -1
- data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
- data/spec/unit/braintree/risk_data_spec.rb +40 -6
- data/spec/unit/braintree/sepa_debit_account_nonce_details_spec.rb +29 -0
- data/spec/unit/braintree/sepa_debit_account_spec.rb +86 -0
- data/spec/unit/braintree/subscription_search_spec.rb +1 -1
- data/spec/unit/braintree/subscription_spec.rb +2 -2
- data/spec/unit/braintree/successful_result_spec.rb +1 -1
- data/spec/unit/braintree/three_d_secure_info_spec.rb +34 -6
- data/spec/unit/braintree/transaction/credit_card_details_spec.rb +19 -3
- data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
- data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
- data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
- data/spec/unit/braintree/transaction/paypal_details_spec.rb +63 -0
- data/spec/unit/braintree/transaction/sepa_direct_debit_account_details_spec.rb +33 -0
- data/spec/unit/braintree/transaction_gateway_spec.rb +111 -0
- data/spec/unit/braintree/transaction_search_spec.rb +12 -12
- data/spec/unit/braintree/transaction_spec.rb +171 -55
- data/spec/unit/braintree/us_bank_account_verification_search_spec.rb +60 -0
- data/spec/unit/braintree/us_bank_account_verification_spec.rb +93 -0
- data/spec/unit/braintree/util_spec.rb +162 -19
- data/spec/unit/braintree/validation_error_collection_spec.rb +336 -133
- data/spec/unit/braintree/venmo_profile_data_spec.rb +32 -0
- data/spec/unit/braintree/webhook_notification_spec.rb +546 -114
- data/spec/unit/braintree/xml/parser_spec.rb +21 -16
- data/spec/unit/braintree/xml_spec.rb +31 -24
- data/spec/unit/braintree_spec.rb +1 -0
- metadata +290 -198
- data/README.rdoc +0 -93
- data/lib/braintree/amex_express_checkout_card.rb +0 -26
- data/lib/braintree/android_pay_card.rb +0 -35
- data/lib/braintree/coinbase_account.rb +0 -25
- data/lib/braintree/europe_bank_account.rb +0 -34
- data/lib/braintree/europe_bank_account_gateway.rb +0 -17
- data/lib/braintree/ideal_payment.rb +0 -46
- data/lib/braintree/ideal_payment_gateway.rb +0 -18
- data/lib/braintree/masterpass_card.rb +0 -66
- data/lib/braintree/settlement_batch.rb +0 -0
- data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -14
- data/lib/braintree/transaction/android_pay_details.rb +0 -17
- data/lib/braintree/transaction/ideal_payment_details.rb +0 -13
- data/lib/braintree/transparent_redirect.rb +0 -40
- data/lib/braintree/transparent_redirect_gateway.rb +0 -105
- data/spec/hacks/tcp_socket.rb +0 -18
- data/spec/httpsd.pid +0 -1
- data/spec/integration/braintree/coinbase_spec.rb +0 -31
- data/spec/integration/braintree/ideal_payment_spec.rb +0 -87
- 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
@@ -1,6 +1,10 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
|
3
3
|
|
4
|
+
def make_token
|
5
|
+
SecureRandom.uuid
|
6
|
+
end
|
7
|
+
|
4
8
|
describe Braintree::PaymentMethod do
|
5
9
|
describe "self.create" do
|
6
10
|
it "creates a payment method from a vaulted credit card nonce" do
|
@@ -13,20 +17,20 @@ describe Braintree::PaymentMethod do
|
|
13
17
|
config,
|
14
18
|
:authorization_fingerprint => authorization_fingerprint,
|
15
19
|
:shared_customer_identifier => "fake_identifier",
|
16
|
-
:shared_customer_identifier_type => "testing"
|
20
|
+
:shared_customer_identifier_type => "testing",
|
17
21
|
)
|
18
22
|
|
19
23
|
response = http.create_credit_card(
|
20
24
|
:number => 4111111111111111,
|
21
25
|
:expirationMonth => 12,
|
22
|
-
:expirationYear => 2020
|
26
|
+
:expirationYear => 2020,
|
23
27
|
)
|
24
28
|
response.code.should == "201"
|
25
29
|
|
26
30
|
nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
|
27
31
|
result = Braintree::PaymentMethod.create(
|
28
32
|
:payment_method_nonce => nonce,
|
29
|
-
:customer_id => customer.id
|
33
|
+
:customer_id => customer.id,
|
30
34
|
)
|
31
35
|
|
32
36
|
result.should be_success
|
@@ -47,21 +51,21 @@ describe Braintree::PaymentMethod do
|
|
47
51
|
config,
|
48
52
|
:authorization_fingerprint => authorization_fingerprint,
|
49
53
|
:shared_customer_identifier => "fake_identifier",
|
50
|
-
:shared_customer_identifier_type => "testing"
|
54
|
+
:shared_customer_identifier_type => "testing",
|
51
55
|
)
|
52
56
|
|
53
57
|
response = http.create_credit_card(
|
54
58
|
:number => "4111111111111111",
|
55
59
|
:expirationMonth => "12",
|
56
60
|
:expirationYear => "2020",
|
57
|
-
:options => {:validate => false}
|
61
|
+
:options => {:validate => false},
|
58
62
|
)
|
59
63
|
response.code.should == "202"
|
60
64
|
|
61
65
|
nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
|
62
66
|
result = Braintree::PaymentMethod.create(
|
63
67
|
:payment_method_nonce => nonce,
|
64
|
-
:customer_id => customer.id
|
68
|
+
:customer_id => customer.id,
|
65
69
|
)
|
66
70
|
|
67
71
|
result.should be_success
|
@@ -78,13 +82,14 @@ describe Braintree::PaymentMethod do
|
|
78
82
|
result = Braintree::PaymentMethod.create(
|
79
83
|
:payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
|
80
84
|
:customer_id => customer.id,
|
81
|
-
:token => token
|
85
|
+
:token => token,
|
82
86
|
)
|
83
87
|
|
84
88
|
result.should be_success
|
85
89
|
apple_pay_card = result.payment_method
|
86
90
|
apple_pay_card.should be_a(Braintree::ApplePayCard)
|
87
91
|
apple_pay_card.should_not be_nil
|
92
|
+
apple_pay_card.bin.should_not be_nil
|
88
93
|
apple_pay_card.token.should == token
|
89
94
|
apple_pay_card.card_type.should == Braintree::ApplePayCard::CardType::AmEx
|
90
95
|
apple_pay_card.payment_instrument_name.should == "AmEx 41002"
|
@@ -94,87 +99,89 @@ describe Braintree::PaymentMethod do
|
|
94
99
|
apple_pay_card.expiration_month.to_i.should > 0
|
95
100
|
apple_pay_card.expiration_year.to_i.should > 0
|
96
101
|
apple_pay_card.customer_id.should == customer.id
|
102
|
+
apple_pay_card.commercial.should_not be_nil
|
103
|
+
apple_pay_card.country_of_issuance.should_not be_nil
|
104
|
+
apple_pay_card.debit.should_not be_nil
|
105
|
+
apple_pay_card.durbin_regulated.should_not be_nil
|
106
|
+
apple_pay_card.healthcare.should_not be_nil
|
107
|
+
apple_pay_card.issuing_bank.should_not be_nil
|
108
|
+
apple_pay_card.payroll.should_not be_nil
|
109
|
+
apple_pay_card.prepaid.should_not be_nil
|
110
|
+
apple_pay_card.product_id.should_not be_nil
|
97
111
|
end
|
98
112
|
|
99
|
-
it "creates a payment method from a fake
|
100
|
-
customer = Braintree::Customer.create.customer
|
101
|
-
token = SecureRandom.hex(16)
|
102
|
-
result = Braintree::PaymentMethod.create(
|
103
|
-
:payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
|
104
|
-
:customer_id => customer.id,
|
105
|
-
:token => token
|
106
|
-
)
|
107
|
-
|
108
|
-
result.should be_success
|
109
|
-
android_pay_card = result.payment_method
|
110
|
-
android_pay_card.should be_a(Braintree::AndroidPayCard)
|
111
|
-
android_pay_card.should_not be_nil
|
112
|
-
android_pay_card.token.should == token
|
113
|
-
android_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
|
114
|
-
android_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
|
115
|
-
android_pay_card.expiration_month.to_i.should > 0
|
116
|
-
android_pay_card.expiration_year.to_i.should > 0
|
117
|
-
android_pay_card.default.should == true
|
118
|
-
android_pay_card.image_url.should =~ /android_pay/
|
119
|
-
android_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Visa
|
120
|
-
android_pay_card.source_card_last_4.should == "1111"
|
121
|
-
android_pay_card.google_transaction_id.should == "google_transaction_id"
|
122
|
-
android_pay_card.source_description.should == "Visa 1111"
|
123
|
-
android_pay_card.customer_id.should == customer.id
|
124
|
-
end
|
125
|
-
|
126
|
-
it "creates a payment method from a android pay network token nonce" do
|
113
|
+
it "creates a payment method from a fake google pay proxy card nonce" do
|
127
114
|
customer = Braintree::Customer.create.customer
|
128
115
|
token = SecureRandom.hex(16)
|
129
116
|
result = Braintree::PaymentMethod.create(
|
130
|
-
:payment_method_nonce => Braintree::Test::Nonce::
|
117
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
|
131
118
|
:customer_id => customer.id,
|
132
|
-
:token => token
|
119
|
+
:token => token,
|
133
120
|
)
|
134
121
|
|
135
122
|
result.should be_success
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
123
|
+
google_pay_card = result.payment_method
|
124
|
+
google_pay_card.should be_a(Braintree::GooglePayCard)
|
125
|
+
google_pay_card.should_not be_nil
|
126
|
+
google_pay_card.token.should == token
|
127
|
+
google_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
|
128
|
+
google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
|
129
|
+
google_pay_card.expiration_month.to_i.should > 0
|
130
|
+
google_pay_card.expiration_year.to_i.should > 0
|
131
|
+
google_pay_card.default.should == true
|
132
|
+
google_pay_card.image_url.should =~ /android_pay/
|
133
|
+
google_pay_card.is_network_tokenized?.should == false
|
134
|
+
google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
|
135
|
+
google_pay_card.source_card_last_4.should == "1111"
|
136
|
+
google_pay_card.google_transaction_id.should == "google_transaction_id"
|
137
|
+
google_pay_card.source_description.should == "Discover 1111"
|
138
|
+
google_pay_card.customer_id.should == customer.id
|
139
|
+
google_pay_card.commercial.should_not be_nil
|
140
|
+
google_pay_card.country_of_issuance.should_not be_nil
|
141
|
+
google_pay_card.debit.should_not be_nil
|
142
|
+
google_pay_card.durbin_regulated.should_not be_nil
|
143
|
+
google_pay_card.healthcare.should_not be_nil
|
144
|
+
google_pay_card.issuing_bank.should_not be_nil
|
145
|
+
google_pay_card.payroll.should_not be_nil
|
146
|
+
google_pay_card.prepaid.should_not be_nil
|
147
|
+
google_pay_card.product_id.should_not be_nil
|
151
148
|
end
|
152
149
|
|
153
|
-
it "creates a payment method from
|
150
|
+
it "creates a payment method from a google pay network token nonce" do
|
154
151
|
customer = Braintree::Customer.create.customer
|
155
152
|
token = SecureRandom.hex(16)
|
156
153
|
result = Braintree::PaymentMethod.create(
|
157
|
-
:payment_method_nonce => Braintree::Test::Nonce::
|
154
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
|
158
155
|
:customer_id => customer.id,
|
159
|
-
:token => token
|
156
|
+
:token => token,
|
160
157
|
)
|
161
158
|
|
162
159
|
result.should be_success
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
160
|
+
google_pay_card = result.payment_method
|
161
|
+
google_pay_card.should be_a(Braintree::GooglePayCard)
|
162
|
+
google_pay_card.should_not be_nil
|
163
|
+
google_pay_card.token.should == token
|
164
|
+
google_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
|
165
|
+
google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
|
166
|
+
google_pay_card.expiration_month.to_i.should > 0
|
167
|
+
google_pay_card.expiration_year.to_i.should > 0
|
168
|
+
google_pay_card.default.should == true
|
169
|
+
google_pay_card.image_url.should =~ /android_pay/
|
170
|
+
google_pay_card.is_network_tokenized?.should == true
|
171
|
+
google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
|
172
|
+
google_pay_card.source_card_last_4.should == "4444"
|
173
|
+
google_pay_card.google_transaction_id.should == "google_transaction_id"
|
174
|
+
google_pay_card.source_description.should == "MasterCard 4444"
|
175
|
+
google_pay_card.customer_id.should == customer.id
|
176
|
+
google_pay_card.commercial.should_not be_nil
|
177
|
+
google_pay_card.country_of_issuance.should_not be_nil
|
178
|
+
google_pay_card.debit.should_not be_nil
|
179
|
+
google_pay_card.durbin_regulated.should_not be_nil
|
180
|
+
google_pay_card.healthcare.should_not be_nil
|
181
|
+
google_pay_card.issuing_bank.should_not be_nil
|
182
|
+
google_pay_card.payroll.should_not be_nil
|
183
|
+
google_pay_card.prepaid.should_not be_nil
|
184
|
+
google_pay_card.product_id.should_not be_nil
|
178
185
|
end
|
179
186
|
|
180
187
|
it "creates a payment method from venmo account nonce" do
|
@@ -183,7 +190,7 @@ describe Braintree::PaymentMethod do
|
|
183
190
|
result = Braintree::PaymentMethod.create(
|
184
191
|
:payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
|
185
192
|
:customer_id => customer.id,
|
186
|
-
:token => token
|
193
|
+
:token => token,
|
187
194
|
)
|
188
195
|
|
189
196
|
result.should be_success
|
@@ -193,7 +200,7 @@ describe Braintree::PaymentMethod do
|
|
193
200
|
venmo_account.default.should == true
|
194
201
|
venmo_account.token.should == token
|
195
202
|
venmo_account.username.should == "venmojoe"
|
196
|
-
venmo_account.venmo_user_id.should == "
|
203
|
+
venmo_account.venmo_user_id.should == "1234567891234567891"
|
197
204
|
venmo_account.image_url.should include(".png")
|
198
205
|
venmo_account.source_description.should == "Venmo Account: venmojoe"
|
199
206
|
venmo_account.customer_id.should == customer.id
|
@@ -205,7 +212,7 @@ describe Braintree::PaymentMethod do
|
|
205
212
|
:customer_id => customer.id,
|
206
213
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
207
214
|
:expiration_date => "05/2009",
|
208
|
-
:cvv => "100"
|
215
|
+
:cvv => "100",
|
209
216
|
)
|
210
217
|
result.success?.should == true
|
211
218
|
original_payment_method = result.credit_card
|
@@ -215,7 +222,7 @@ describe Braintree::PaymentMethod do
|
|
215
222
|
result = Braintree::PaymentMethod.create(
|
216
223
|
:payment_method_nonce => nonce,
|
217
224
|
:customer_id => customer.id,
|
218
|
-
:options => {:make_default => true}
|
225
|
+
:options => {:make_default => true},
|
219
226
|
)
|
220
227
|
|
221
228
|
result.should be_success
|
@@ -226,16 +233,16 @@ describe Braintree::PaymentMethod do
|
|
226
233
|
it "overrides the token in the nonce" do
|
227
234
|
customer = Braintree::Customer.create!
|
228
235
|
|
229
|
-
first_token =
|
230
|
-
second_token =
|
236
|
+
first_token = make_token
|
237
|
+
second_token = make_token
|
231
238
|
nonce = nonce_for_paypal_account(
|
232
239
|
:consent_code => "PAYPAL_CONSENT_CODE",
|
233
|
-
:token => first_token
|
240
|
+
:token => first_token,
|
234
241
|
)
|
235
242
|
result = Braintree::PaymentMethod.create(
|
236
243
|
:payment_method_nonce => nonce,
|
237
244
|
:customer_id => customer.id,
|
238
|
-
:token => second_token
|
245
|
+
:token => second_token,
|
239
246
|
)
|
240
247
|
|
241
248
|
result.should be_success
|
@@ -249,7 +256,7 @@ describe Braintree::PaymentMethod do
|
|
249
256
|
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
|
250
257
|
:expiration_month => "11",
|
251
258
|
:expiration_year => "2099",
|
252
|
-
}
|
259
|
+
},
|
253
260
|
)
|
254
261
|
customer = Braintree::Customer.create!
|
255
262
|
result = Braintree::PaymentMethod.create(
|
@@ -258,7 +265,7 @@ describe Braintree::PaymentMethod do
|
|
258
265
|
:options => {
|
259
266
|
:verify_card => true,
|
260
267
|
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId
|
261
|
-
}
|
268
|
+
},
|
262
269
|
)
|
263
270
|
|
264
271
|
result.should_not be_success
|
@@ -274,7 +281,7 @@ describe Braintree::PaymentMethod do
|
|
274
281
|
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
|
275
282
|
:expiration_month => "11",
|
276
283
|
:expiration_year => "2099",
|
277
|
-
}
|
284
|
+
},
|
278
285
|
)
|
279
286
|
customer = Braintree::Customer.create!
|
280
287
|
result = Braintree::PaymentMethod.create(
|
@@ -283,14 +290,79 @@ describe Braintree::PaymentMethod do
|
|
283
290
|
:options => {
|
284
291
|
:verify_card => true,
|
285
292
|
:verification_amount => "100.00"
|
286
|
-
}
|
293
|
+
},
|
287
294
|
)
|
288
295
|
|
289
296
|
result.should_not be_success
|
290
297
|
result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
291
298
|
result.credit_card_verification.processor_response_code.should == "2000"
|
292
299
|
result.credit_card_verification.processor_response_text.should == "Do Not Honor"
|
293
|
-
result.credit_card_verification.amount.should == BigDecimal
|
300
|
+
result.credit_card_verification.amount.should == BigDecimal("100.00")
|
301
|
+
end
|
302
|
+
|
303
|
+
it "validates presence of three_d_secure_version in 3ds pass thru params" do
|
304
|
+
customer = Braintree::Customer.create!
|
305
|
+
result = Braintree::PaymentMethod.create(
|
306
|
+
:customer_id => customer.id,
|
307
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
308
|
+
:three_d_secure_pass_thru => {
|
309
|
+
:eci_flag => "02",
|
310
|
+
:cavv => "some_cavv",
|
311
|
+
:xid => "some_xid",
|
312
|
+
:three_d_secure_version => "xx",
|
313
|
+
:authentication_response => "Y",
|
314
|
+
:directory_response => "Y",
|
315
|
+
:cavv_algorithm => "2",
|
316
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
317
|
+
},
|
318
|
+
:options => {:verify_card => true},
|
319
|
+
)
|
320
|
+
expect(result).not_to be_success
|
321
|
+
error = result.errors.for(:verification).first
|
322
|
+
expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsInvalid)
|
323
|
+
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`).")
|
324
|
+
end
|
325
|
+
|
326
|
+
it "accepts three_d_secure pass thru params in the request" do
|
327
|
+
customer = Braintree::Customer.create!
|
328
|
+
result = Braintree::PaymentMethod.create(
|
329
|
+
:customer_id => customer.id,
|
330
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
331
|
+
:three_d_secure_pass_thru => {
|
332
|
+
:eci_flag => "02",
|
333
|
+
:cavv => "some_cavv",
|
334
|
+
:xid => "some_xid",
|
335
|
+
:three_d_secure_version => "1.0.2",
|
336
|
+
:authentication_response => "Y",
|
337
|
+
:directory_response => "Y",
|
338
|
+
:cavv_algorithm => "2",
|
339
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
340
|
+
},
|
341
|
+
:options => {:verify_card => true},
|
342
|
+
)
|
343
|
+
|
344
|
+
expect(result).to be_success
|
345
|
+
end
|
346
|
+
|
347
|
+
it "returns 3DS info on cc verification" do
|
348
|
+
customer = Braintree::Customer.create.customer
|
349
|
+
result = Braintree::PaymentMethod.create(
|
350
|
+
:payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
|
351
|
+
:options => {:verify_card => true},
|
352
|
+
:customer_id => customer.id,
|
353
|
+
)
|
354
|
+
result.success?.should == true
|
355
|
+
|
356
|
+
three_d_secure_info = result.payment_method.verification.three_d_secure_info
|
357
|
+
three_d_secure_info.enrolled.should == "Y"
|
358
|
+
three_d_secure_info.should be_liability_shifted
|
359
|
+
three_d_secure_info.should be_liability_shift_possible
|
360
|
+
three_d_secure_info.status.should == "authenticate_successful"
|
361
|
+
three_d_secure_info.cavv.should == "cavv_value"
|
362
|
+
three_d_secure_info.xid.should == "xid_value"
|
363
|
+
three_d_secure_info.eci_flag.should == "05"
|
364
|
+
three_d_secure_info.three_d_secure_version.should == "1.0.2"
|
365
|
+
three_d_secure_info.ds_transaction_id.should == nil
|
294
366
|
end
|
295
367
|
|
296
368
|
it "respects fail_on_duplicate_payment_method when included outside of the nonce" do
|
@@ -298,7 +370,7 @@ describe Braintree::PaymentMethod do
|
|
298
370
|
result = Braintree::CreditCard.create(
|
299
371
|
:customer_id => customer.id,
|
300
372
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
301
|
-
:expiration_date => "05/2012"
|
373
|
+
:expiration_date => "05/2012",
|
302
374
|
)
|
303
375
|
result.should be_success
|
304
376
|
|
@@ -306,14 +378,14 @@ describe Braintree::PaymentMethod do
|
|
306
378
|
:credit_card => {
|
307
379
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
308
380
|
:expiration_date => "05/2012"
|
309
|
-
}
|
381
|
+
},
|
310
382
|
)
|
311
383
|
result = Braintree::PaymentMethod.create(
|
312
384
|
:payment_method_nonce => nonce,
|
313
385
|
:customer_id => customer.id,
|
314
386
|
:options => {
|
315
387
|
:fail_on_duplicate_payment_method => true
|
316
|
-
}
|
388
|
+
},
|
317
389
|
)
|
318
390
|
|
319
391
|
result.should_not be_success
|
@@ -330,14 +402,14 @@ describe Braintree::PaymentMethod do
|
|
330
402
|
config,
|
331
403
|
:authorization_fingerprint => authorization_fingerprint,
|
332
404
|
:shared_customer_identifier => "fake_identifier",
|
333
|
-
:shared_customer_identifier_type => "testing"
|
405
|
+
:shared_customer_identifier_type => "testing",
|
334
406
|
)
|
335
407
|
|
336
408
|
response = http.create_credit_card(
|
337
409
|
:number => "4111111111111111",
|
338
410
|
:expirationMonth => "12",
|
339
411
|
:expirationYear => "2020",
|
340
|
-
:options => {:validate => false}
|
412
|
+
:options => {:validate => false},
|
341
413
|
)
|
342
414
|
response.code.should == "202"
|
343
415
|
|
@@ -347,7 +419,7 @@ describe Braintree::PaymentMethod do
|
|
347
419
|
:customer_id => customer.id,
|
348
420
|
:billing_address => {
|
349
421
|
:street_address => "123 Abc Way"
|
350
|
-
}
|
422
|
+
},
|
351
423
|
)
|
352
424
|
|
353
425
|
result.should be_success
|
@@ -369,14 +441,14 @@ describe Braintree::PaymentMethod do
|
|
369
441
|
config,
|
370
442
|
:authorization_fingerprint => authorization_fingerprint,
|
371
443
|
:shared_customer_identifier => "fake_identifier",
|
372
|
-
:shared_customer_identifier_type => "testing"
|
444
|
+
:shared_customer_identifier_type => "testing",
|
373
445
|
)
|
374
446
|
|
375
447
|
response = http.create_credit_card(
|
376
448
|
:number => "4111111111111111",
|
377
449
|
:expirationMonth => "12",
|
378
450
|
:expirationYear => "2020",
|
379
|
-
:options => {:validate => false}
|
451
|
+
:options => {:validate => false},
|
380
452
|
)
|
381
453
|
response.code.should == "202"
|
382
454
|
|
@@ -386,7 +458,7 @@ describe Braintree::PaymentMethod do
|
|
386
458
|
result = Braintree::PaymentMethod.create(
|
387
459
|
:payment_method_nonce => nonce,
|
388
460
|
:customer_id => customer.id,
|
389
|
-
:billing_address_id => address.id
|
461
|
+
:billing_address_id => address.id,
|
390
462
|
)
|
391
463
|
|
392
464
|
result.should be_success
|
@@ -409,7 +481,7 @@ describe Braintree::PaymentMethod do
|
|
409
481
|
config,
|
410
482
|
:authorization_fingerprint => authorization_fingerprint,
|
411
483
|
:shared_customer_identifier => "fake_identifier",
|
412
|
-
:shared_customer_identifier_type => "testing"
|
484
|
+
:shared_customer_identifier_type => "testing",
|
413
485
|
)
|
414
486
|
|
415
487
|
response = http.create_credit_card(
|
@@ -419,7 +491,7 @@ describe Braintree::PaymentMethod do
|
|
419
491
|
:options => {:validate => false},
|
420
492
|
:billing_address => {
|
421
493
|
:street_address => "456 Xyz Way"
|
422
|
-
}
|
494
|
+
},
|
423
495
|
)
|
424
496
|
response.code.should == "202"
|
425
497
|
|
@@ -429,7 +501,7 @@ describe Braintree::PaymentMethod do
|
|
429
501
|
:customer_id => customer.id,
|
430
502
|
:billing_address => {
|
431
503
|
:street_address => "123 Abc Way"
|
432
|
-
}
|
504
|
+
},
|
433
505
|
)
|
434
506
|
|
435
507
|
result.should be_success
|
@@ -451,7 +523,7 @@ describe Braintree::PaymentMethod do
|
|
451
523
|
config,
|
452
524
|
:authorization_fingerprint => authorization_fingerprint,
|
453
525
|
:shared_customer_identifier => "fake_identifier",
|
454
|
-
:shared_customer_identifier_type => "testing"
|
526
|
+
:shared_customer_identifier_type => "testing",
|
455
527
|
)
|
456
528
|
|
457
529
|
response = http.create_credit_card(
|
@@ -460,7 +532,7 @@ describe Braintree::PaymentMethod do
|
|
460
532
|
:expirationYear => 2020,
|
461
533
|
:billing_address => {
|
462
534
|
:street_address => "456 Xyz Way"
|
463
|
-
}
|
535
|
+
},
|
464
536
|
)
|
465
537
|
response.code.should == "201"
|
466
538
|
|
@@ -470,7 +542,7 @@ describe Braintree::PaymentMethod do
|
|
470
542
|
:customer_id => customer.id,
|
471
543
|
:billing_address => {
|
472
544
|
:street_address => "123 Abc Way"
|
473
|
-
}
|
545
|
+
},
|
474
546
|
)
|
475
547
|
|
476
548
|
result.should be_success
|
@@ -482,38 +554,196 @@ describe Braintree::PaymentMethod do
|
|
482
554
|
found_credit_card.billing_address.street_address.should == "456 Xyz Way"
|
483
555
|
end
|
484
556
|
|
485
|
-
|
486
|
-
|
487
|
-
customer = Braintree::Customer.create
|
557
|
+
it "includes risk data when skip_advanced_fraud_checking is false" do
|
558
|
+
with_fraud_protection_enterprise_merchant do
|
559
|
+
customer = Braintree::Customer.create!
|
560
|
+
|
561
|
+
nonce = nonce_for_new_payment_method(
|
562
|
+
:credit_card => {
|
563
|
+
:cvv => "123",
|
564
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
565
|
+
:expiration_date => "05/2009",
|
566
|
+
},
|
567
|
+
)
|
568
|
+
result = Braintree::PaymentMethod.create(
|
569
|
+
:payment_method_nonce => nonce,
|
570
|
+
:customer_id => customer.id,
|
571
|
+
:options => {
|
572
|
+
:verify_card => true,
|
573
|
+
:skip_advanced_fraud_checking => false,
|
574
|
+
},
|
575
|
+
)
|
576
|
+
|
577
|
+
expect(result).to be_success
|
578
|
+
verification = result.payment_method.verification
|
579
|
+
expect(verification.risk_data).not_to be_nil
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
it "does not include risk data when skip_advanced_fraud_checking is true" do
|
584
|
+
with_fraud_protection_enterprise_merchant do
|
585
|
+
customer = Braintree::Customer.create!
|
586
|
+
|
587
|
+
nonce = nonce_for_new_payment_method(
|
588
|
+
:credit_card => {
|
589
|
+
:cvv => "123",
|
590
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
591
|
+
:expiration_date => "05/2009",
|
592
|
+
},
|
593
|
+
)
|
594
|
+
result = Braintree::PaymentMethod.create(
|
595
|
+
:payment_method_nonce => nonce,
|
596
|
+
:customer_id => customer.id,
|
597
|
+
:options => {
|
598
|
+
:verify_card => true,
|
599
|
+
:skip_advanced_fraud_checking => true,
|
600
|
+
},
|
601
|
+
)
|
602
|
+
|
603
|
+
expect(result).to be_success
|
604
|
+
verification = result.payment_method.verification
|
605
|
+
expect(verification.risk_data).to be_nil
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
context "account_type" do
|
610
|
+
it "verifies card with account_type debit" do
|
611
|
+
nonce = nonce_for_new_payment_method(
|
612
|
+
:credit_card => {
|
613
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
614
|
+
:expiration_month => "11",
|
615
|
+
:expiration_year => "2099",
|
616
|
+
},
|
617
|
+
)
|
618
|
+
customer = Braintree::Customer.create!
|
488
619
|
result = Braintree::PaymentMethod.create(
|
489
|
-
:payment_method_nonce =>
|
490
|
-
:customer_id => customer.id
|
620
|
+
:payment_method_nonce => nonce,
|
621
|
+
:customer_id => customer.id,
|
622
|
+
:options => {
|
623
|
+
:verify_card => true,
|
624
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
625
|
+
:verification_account_type => "debit",
|
626
|
+
},
|
491
627
|
)
|
492
628
|
|
493
629
|
result.should be_success
|
494
|
-
|
495
|
-
us_bank_account.should be_a(Braintree::UsBankAccount)
|
496
|
-
us_bank_account.routing_number.should == "021000021"
|
497
|
-
us_bank_account.last_4.should == "1234"
|
498
|
-
us_bank_account.account_type.should == "checking"
|
499
|
-
us_bank_account.account_holder_name.should == "Dan Schulman"
|
500
|
-
us_bank_account.bank_name.should =~ /CHASE/
|
501
|
-
us_bank_account.default.should == true
|
502
|
-
us_bank_account.ach_mandate.text.should == "cl mandate text"
|
503
|
-
us_bank_account.ach_mandate.accepted_at.should be_a Time
|
504
|
-
|
505
|
-
Braintree::PaymentMethod.find(us_bank_account.token).should be_a(Braintree::UsBankAccount)
|
630
|
+
result.payment_method.verification.credit_card[:account_type].should == "debit"
|
506
631
|
end
|
507
632
|
|
508
|
-
it "
|
509
|
-
|
633
|
+
it "verifies card with account_type credit" do
|
634
|
+
nonce = nonce_for_new_payment_method(
|
635
|
+
:credit_card => {
|
636
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
637
|
+
:expiration_month => "11",
|
638
|
+
:expiration_year => "2099",
|
639
|
+
},
|
640
|
+
)
|
641
|
+
customer = Braintree::Customer.create!
|
510
642
|
result = Braintree::PaymentMethod.create(
|
511
|
-
:payment_method_nonce =>
|
512
|
-
:customer_id => customer.id
|
643
|
+
:payment_method_nonce => nonce,
|
644
|
+
:customer_id => customer.id,
|
645
|
+
:options => {
|
646
|
+
:verify_card => true,
|
647
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
648
|
+
:verification_account_type => "credit",
|
649
|
+
},
|
650
|
+
)
|
651
|
+
|
652
|
+
result.should be_success
|
653
|
+
result.payment_method.verification.credit_card[:account_type].should == "credit"
|
654
|
+
end
|
655
|
+
|
656
|
+
it "errors with invalid account_type" do
|
657
|
+
nonce = nonce_for_new_payment_method(
|
658
|
+
:credit_card => {
|
659
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
660
|
+
:expiration_month => "11",
|
661
|
+
:expiration_year => "2099",
|
662
|
+
},
|
663
|
+
)
|
664
|
+
customer = Braintree::Customer.create!
|
665
|
+
result = Braintree::PaymentMethod.create(
|
666
|
+
:payment_method_nonce => nonce,
|
667
|
+
:customer_id => customer.id,
|
668
|
+
:options => {
|
669
|
+
:verify_card => true,
|
670
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
671
|
+
:verification_account_type => "ach",
|
672
|
+
},
|
513
673
|
)
|
514
674
|
|
515
675
|
result.should_not be_success
|
516
|
-
result.errors.for(:
|
676
|
+
result.errors.for(:credit_card).for(:options).on(:verification_account_type)[0].code.should == Braintree::ErrorCodes::CreditCard::VerificationAccountTypeIsInvalid
|
677
|
+
end
|
678
|
+
|
679
|
+
it "errors when account_type not supported by merchant" do
|
680
|
+
nonce = nonce_for_new_payment_method(
|
681
|
+
:credit_card => {
|
682
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
683
|
+
:expiration_month => "11",
|
684
|
+
:expiration_year => "2099",
|
685
|
+
},
|
686
|
+
)
|
687
|
+
customer = Braintree::Customer.create!
|
688
|
+
result = Braintree::PaymentMethod.create(
|
689
|
+
:payment_method_nonce => nonce,
|
690
|
+
:customer_id => customer.id,
|
691
|
+
:options => {
|
692
|
+
:verify_card => true,
|
693
|
+
:verification_account_type => "credit",
|
694
|
+
},
|
695
|
+
)
|
696
|
+
|
697
|
+
result.should_not be_success
|
698
|
+
result.errors.for(:credit_card).for(:options).on(:verification_account_type)[0].code.should == Braintree::ErrorCodes::CreditCard::VerificationAccountTypeNotSupported
|
699
|
+
end
|
700
|
+
|
701
|
+
it "updates the credit card with account_type credit" do
|
702
|
+
customer = Braintree::Customer.create!
|
703
|
+
credit_card = Braintree::CreditCard.create!(
|
704
|
+
:cardholder_name => "Original Holder",
|
705
|
+
:customer_id => customer.id,
|
706
|
+
:cvv => "123",
|
707
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
708
|
+
:expiration_date => "05/2012",
|
709
|
+
)
|
710
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
711
|
+
:cardholder_name => "New Holder",
|
712
|
+
:cvv => "456",
|
713
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
714
|
+
:expiration_date => "06/2013",
|
715
|
+
:options => {
|
716
|
+
:verify_card => true,
|
717
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
718
|
+
:verification_account_type => "credit",
|
719
|
+
},
|
720
|
+
)
|
721
|
+
update_result.success?.should == true
|
722
|
+
update_result.payment_method.verification.credit_card[:account_type].should == "credit"
|
723
|
+
end
|
724
|
+
|
725
|
+
it "updates the credit card with account_type debit" do
|
726
|
+
customer = Braintree::Customer.create!
|
727
|
+
credit_card = Braintree::CreditCard.create!(
|
728
|
+
:cardholder_name => "Original Holder",
|
729
|
+
:customer_id => customer.id,
|
730
|
+
:cvv => "123",
|
731
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
732
|
+
:expiration_date => "05/2012",
|
733
|
+
)
|
734
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
735
|
+
:cardholder_name => "New Holder",
|
736
|
+
:cvv => "456",
|
737
|
+
:number => Braintree::Test::CreditCardNumbers::Hiper,
|
738
|
+
:expiration_date => "06/2013",
|
739
|
+
:options => {
|
740
|
+
:verify_card => true,
|
741
|
+
:verification_merchant_account_id => SpecHelper::HiperBRLMerchantAccountId,
|
742
|
+
:verification_account_type => "debit",
|
743
|
+
},
|
744
|
+
)
|
745
|
+
update_result.success?.should == true
|
746
|
+
update_result.payment_method.verification.credit_card[:account_type].should == "debit"
|
517
747
|
end
|
518
748
|
end
|
519
749
|
|
@@ -523,7 +753,7 @@ describe Braintree::PaymentMethod do
|
|
523
753
|
customer = Braintree::Customer.create.customer
|
524
754
|
result = Braintree::PaymentMethod.create(
|
525
755
|
:payment_method_nonce => nonce,
|
526
|
-
:customer_id => customer.id
|
756
|
+
:customer_id => customer.id,
|
527
757
|
)
|
528
758
|
|
529
759
|
result.should be_success
|
@@ -548,6 +778,19 @@ describe Braintree::PaymentMethod do
|
|
548
778
|
:options => {
|
549
779
|
:paypal => {
|
550
780
|
:payee_email => "payee@example.com",
|
781
|
+
:order_id => "merchant-order-id",
|
782
|
+
:custom_field => "custom merchant field",
|
783
|
+
:description => "merchant description",
|
784
|
+
:amount => "1.23",
|
785
|
+
:shipping => {
|
786
|
+
:first_name => "first",
|
787
|
+
:last_name => "last",
|
788
|
+
:locality => "Austin",
|
789
|
+
:postal_code => "78729",
|
790
|
+
:street_address => "7700 W Parmer Ln",
|
791
|
+
:country_name => "US",
|
792
|
+
:region => "TX",
|
793
|
+
},
|
551
794
|
},
|
552
795
|
},
|
553
796
|
)
|
@@ -555,10 +798,31 @@ describe Braintree::PaymentMethod do
|
|
555
798
|
result.should be_success
|
556
799
|
result.payment_method.should be_a(Braintree::PayPalAccount)
|
557
800
|
result.payment_method.image_url.should_not be_nil
|
801
|
+
result.payment_method.payer_id.should_not be_nil
|
558
802
|
token = result.payment_method.token
|
559
803
|
|
560
804
|
found_paypal_account = Braintree::PayPalAccount.find(token)
|
561
805
|
found_paypal_account.should_not be_nil
|
806
|
+
found_paypal_account.payer_id.should_not be_nil
|
807
|
+
end
|
808
|
+
|
809
|
+
it "creates a billing agreement payment method from a refresh token" do
|
810
|
+
customer = Braintree::Customer.create.customer
|
811
|
+
result = Braintree::PaymentMethod.create(
|
812
|
+
:customer_id => customer.id,
|
813
|
+
:paypal_refresh_token => "some_future_payment_token",
|
814
|
+
)
|
815
|
+
|
816
|
+
result.should be_success
|
817
|
+
result.payment_method.should be_a(Braintree::PayPalAccount)
|
818
|
+
result.payment_method.billing_agreement_id.should eq("B_FAKE_ID")
|
819
|
+
result.payment_method.payer_id.should_not be_nil
|
820
|
+
token = result.payment_method.token
|
821
|
+
|
822
|
+
found_paypal_account = Braintree::PayPalAccount.find(token)
|
823
|
+
found_paypal_account.should_not be_nil
|
824
|
+
found_paypal_account.billing_agreement_id.should eq("B_FAKE_ID")
|
825
|
+
found_paypal_account.payer_id.should_not be_nil
|
562
826
|
end
|
563
827
|
|
564
828
|
it "does not create a payment method from an unvalidated onetime paypal account nonce" do
|
@@ -566,7 +830,7 @@ describe Braintree::PaymentMethod do
|
|
566
830
|
nonce = nonce_for_paypal_account(:access_token => "PAYPAL_ACCESS_TOKEN")
|
567
831
|
result = Braintree::PaymentMethod.create(
|
568
832
|
:payment_method_nonce => nonce,
|
569
|
-
:customer_id => customer.id
|
833
|
+
:customer_id => customer.id,
|
570
834
|
)
|
571
835
|
|
572
836
|
result.should_not be_success
|
@@ -581,7 +845,7 @@ describe Braintree::PaymentMethod do
|
|
581
845
|
:customer_id => customer.id,
|
582
846
|
:billing_address => {
|
583
847
|
:street_address => "123 Abc Way"
|
584
|
-
}
|
848
|
+
},
|
585
849
|
)
|
586
850
|
|
587
851
|
result.should be_success
|
@@ -599,7 +863,7 @@ describe Braintree::PaymentMethod do
|
|
599
863
|
result = Braintree::PaymentMethod.create(
|
600
864
|
:payment_method_nonce => nonce,
|
601
865
|
:customer_id => customer.id,
|
602
|
-
:billing_address_id => "address_id"
|
866
|
+
:billing_address_id => "address_id",
|
603
867
|
)
|
604
868
|
|
605
869
|
result.should be_success
|
@@ -616,7 +880,7 @@ describe Braintree::PaymentMethod do
|
|
616
880
|
nonce = nonce_for_paypal_account(:token => "PAYPAL_TOKEN")
|
617
881
|
result = Braintree::PaymentMethod.create(
|
618
882
|
:payment_method_nonce => nonce,
|
619
|
-
:customer_id => customer.id
|
883
|
+
:customer_id => customer.id,
|
620
884
|
)
|
621
885
|
|
622
886
|
result.should_not be_success
|
@@ -630,7 +894,7 @@ describe Braintree::PaymentMethod do
|
|
630
894
|
original_token = random_payment_method_token
|
631
895
|
nonce = nonce_for_paypal_account(
|
632
896
|
:consent_code => "consent-code",
|
633
|
-
:token => original_token
|
897
|
+
:token => original_token,
|
634
898
|
)
|
635
899
|
|
636
900
|
result = Braintree::PaymentMethod.create(
|
@@ -640,45 +904,10 @@ describe Braintree::PaymentMethod do
|
|
640
904
|
:verify_card => true,
|
641
905
|
:fail_on_duplicate_payment_method => true,
|
642
906
|
:verification_merchant_account_id => "not_a_real_merchant_account_id"
|
643
|
-
}
|
644
|
-
)
|
645
|
-
|
646
|
-
result.should be_success
|
647
|
-
end
|
648
|
-
end
|
649
|
-
|
650
|
-
context "SEPA" do
|
651
|
-
it "returns the SEPA bank account behind the nonce" do
|
652
|
-
config = Braintree::Configuration.instantiate
|
653
|
-
customer = Braintree::Customer.create.customer
|
654
|
-
raw_client_token = Braintree::ClientToken.generate(:customer_id => customer.id, :sepa_mandate_type => Braintree::EuropeBankAccount::MandateType::Business)
|
655
|
-
client_token = decode_client_token(raw_client_token)
|
656
|
-
authorization_fingerprint = client_token["authorizationFingerprint"]
|
657
|
-
http = ClientApiHttp.new(
|
658
|
-
config,
|
659
|
-
:authorization_fingerprint => authorization_fingerprint
|
660
|
-
)
|
661
|
-
|
662
|
-
nonce = http.create_europe_bank_account_nonce(
|
663
|
-
:accountHolderName => "Bob Holder",
|
664
|
-
:iban => "DE89370400440532013000",
|
665
|
-
:bic => "DEUTDEFF",
|
666
|
-
:locale => "en-US",
|
667
|
-
:billingAddress => {
|
668
|
-
:region => "Hesse",
|
669
|
-
:country_name => "Germany"
|
670
|
-
}
|
671
|
-
)
|
672
|
-
nonce.should_not == nil
|
673
|
-
result = Braintree::PaymentMethod.create(
|
674
|
-
:payment_method_nonce => nonce,
|
675
|
-
:customer_id => customer.id
|
907
|
+
},
|
676
908
|
)
|
677
909
|
|
678
910
|
result.should be_success
|
679
|
-
result.payment_method.token.should_not == nil
|
680
|
-
result.payment_method.image_url.should_not be_nil
|
681
|
-
result.payment_method.customer_id.should == customer.id
|
682
911
|
end
|
683
912
|
end
|
684
913
|
|
@@ -689,7 +918,7 @@ describe Braintree::PaymentMethod do
|
|
689
918
|
result = Braintree::PaymentMethod.create(
|
690
919
|
:payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
|
691
920
|
:customer_id => customer.id,
|
692
|
-
:token => token
|
921
|
+
:token => token,
|
693
922
|
)
|
694
923
|
|
695
924
|
result.should be_success
|
@@ -699,6 +928,134 @@ describe Braintree::PaymentMethod do
|
|
699
928
|
payment_method.should be_a Braintree::UnknownPaymentMethod
|
700
929
|
end
|
701
930
|
end
|
931
|
+
|
932
|
+
context "verification_currency_iso_code" do
|
933
|
+
it "validates verification_currency_iso_code against currency configured in default merchant account" do
|
934
|
+
nonce = nonce_for_new_payment_method(
|
935
|
+
:credit_card => {
|
936
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
937
|
+
:expiration_month => "11",
|
938
|
+
:expiration_year => "2099",
|
939
|
+
},
|
940
|
+
)
|
941
|
+
customer = Braintree::Customer.create!
|
942
|
+
result = Braintree::PaymentMethod.create(
|
943
|
+
:payment_method_nonce => nonce,
|
944
|
+
:customer_id => customer.id,
|
945
|
+
:options => {
|
946
|
+
:verify_card => true,
|
947
|
+
:verification_currency_iso_code => "USD"
|
948
|
+
},
|
949
|
+
)
|
950
|
+
|
951
|
+
result.should be_success
|
952
|
+
result.payment_method.verification.currency_iso_code == "USD"
|
953
|
+
end
|
954
|
+
|
955
|
+
it "validates verification_currency_iso_code against currency configured in verification_merchant_account_id" do
|
956
|
+
nonce = nonce_for_new_payment_method(
|
957
|
+
:credit_card => {
|
958
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
959
|
+
:expiration_month => "11",
|
960
|
+
:expiration_year => "2099",
|
961
|
+
},
|
962
|
+
)
|
963
|
+
customer = Braintree::Customer.create!
|
964
|
+
result = Braintree::PaymentMethod.create(
|
965
|
+
:payment_method_nonce => nonce,
|
966
|
+
:customer_id => customer.id,
|
967
|
+
:options => {
|
968
|
+
:verify_card => true,
|
969
|
+
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
970
|
+
:verification_currency_iso_code => "USD"
|
971
|
+
},
|
972
|
+
)
|
973
|
+
|
974
|
+
result.should be_success
|
975
|
+
result.payment_method.verification.currency_iso_code == "USD"
|
976
|
+
result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
|
977
|
+
end
|
978
|
+
|
979
|
+
|
980
|
+
it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in default merchant account" do
|
981
|
+
nonce = nonce_for_new_payment_method(
|
982
|
+
:credit_card => {
|
983
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
984
|
+
:expiration_month => "11",
|
985
|
+
:expiration_year => "2099",
|
986
|
+
},
|
987
|
+
)
|
988
|
+
customer = Braintree::Customer.create!
|
989
|
+
result = Braintree::PaymentMethod.create(
|
990
|
+
:payment_method_nonce => nonce,
|
991
|
+
:customer_id => customer.id,
|
992
|
+
:options => {
|
993
|
+
:verify_card => true,
|
994
|
+
:verification_currency_iso_code => "GBP"
|
995
|
+
},
|
996
|
+
)
|
997
|
+
result.should_not be_success
|
998
|
+
result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
|
999
|
+
end
|
1000
|
+
|
1001
|
+
it "errors with invalid presentment currency due to verification_currency_iso_code not matching with currency configured in verification_merchant_account_id" do
|
1002
|
+
nonce = nonce_for_new_payment_method(
|
1003
|
+
:credit_card => {
|
1004
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1005
|
+
:expiration_month => "11",
|
1006
|
+
:expiration_year => "2099",
|
1007
|
+
},
|
1008
|
+
)
|
1009
|
+
customer = Braintree::Customer.create!
|
1010
|
+
result = Braintree::PaymentMethod.create(
|
1011
|
+
:payment_method_nonce => nonce,
|
1012
|
+
:customer_id => customer.id,
|
1013
|
+
:options => {
|
1014
|
+
:verify_card => true,
|
1015
|
+
:verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
1016
|
+
:verification_currency_iso_code => "GBP"
|
1017
|
+
},
|
1018
|
+
)
|
1019
|
+
|
1020
|
+
result.should_not be_success
|
1021
|
+
result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
|
1022
|
+
end
|
1023
|
+
end
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
describe "self.create!" do
|
1027
|
+
it "creates a payment method from a vaulted credit card nonce" do
|
1028
|
+
config = Braintree::Configuration.instantiate
|
1029
|
+
customer = Braintree::Customer.create.customer
|
1030
|
+
raw_client_token = Braintree::ClientToken.generate(:customer_id => customer.id)
|
1031
|
+
client_token = decode_client_token(raw_client_token)
|
1032
|
+
authorization_fingerprint = client_token["authorizationFingerprint"]
|
1033
|
+
http = ClientApiHttp.new(
|
1034
|
+
config,
|
1035
|
+
:authorization_fingerprint => authorization_fingerprint,
|
1036
|
+
:shared_customer_identifier => "fake_identifier",
|
1037
|
+
:shared_customer_identifier_type => "testing",
|
1038
|
+
)
|
1039
|
+
|
1040
|
+
response = http.create_credit_card(
|
1041
|
+
:number => 4111111111111111,
|
1042
|
+
:expirationMonth => 12,
|
1043
|
+
:expirationYear => 2020,
|
1044
|
+
)
|
1045
|
+
response.code.should == "201"
|
1046
|
+
|
1047
|
+
nonce = JSON.parse(response.body)["creditCards"].first["nonce"]
|
1048
|
+
payment_method = Braintree::PaymentMethod.create!(
|
1049
|
+
:payment_method_nonce => nonce,
|
1050
|
+
:customer_id => customer.id,
|
1051
|
+
)
|
1052
|
+
|
1053
|
+
payment_method.should be_a(Braintree::CreditCard)
|
1054
|
+
token = payment_method.token
|
1055
|
+
|
1056
|
+
found_credit_card = Braintree::CreditCard.find(token)
|
1057
|
+
found_credit_card.should_not be_nil
|
1058
|
+
end
|
702
1059
|
end
|
703
1060
|
|
704
1061
|
describe "self.find" do
|
@@ -708,7 +1065,7 @@ describe Braintree::PaymentMethod do
|
|
708
1065
|
result = Braintree::CreditCard.create(
|
709
1066
|
:customer_id => customer.id,
|
710
1067
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
711
|
-
:expiration_date => "05/2012"
|
1068
|
+
:expiration_date => "05/2012",
|
712
1069
|
)
|
713
1070
|
result.success?.should == true
|
714
1071
|
|
@@ -724,34 +1081,34 @@ describe Braintree::PaymentMethod do
|
|
724
1081
|
credit_card = Braintree::CreditCard.create(
|
725
1082
|
:customer_id => customer.id,
|
726
1083
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
727
|
-
:expiration_date => "05/2012"
|
1084
|
+
:expiration_date => "05/2012",
|
728
1085
|
).credit_card
|
729
1086
|
|
730
1087
|
subscription = Braintree::Subscription.create(
|
731
1088
|
:payment_method_token => credit_card.token,
|
732
1089
|
:plan_id => "integration_trialless_plan",
|
733
|
-
:price => "1.00"
|
1090
|
+
:price => "1.00",
|
734
1091
|
).subscription
|
735
1092
|
|
736
1093
|
found_card = Braintree::PaymentMethod.find(credit_card.token)
|
737
1094
|
found_card.subscriptions.first.id.should == subscription.id
|
738
1095
|
found_card.subscriptions.first.plan_id.should == "integration_trialless_plan"
|
739
1096
|
found_card.subscriptions.first.payment_method_token.should == credit_card.token
|
740
|
-
found_card.subscriptions.first.price.should == BigDecimal
|
1097
|
+
found_card.subscriptions.first.price.should == BigDecimal("1.00")
|
741
1098
|
end
|
742
1099
|
end
|
743
1100
|
|
744
1101
|
context "paypal accounts" do
|
745
1102
|
it "finds the payment method with the given token" do
|
746
1103
|
customer = Braintree::Customer.create!
|
747
|
-
payment_method_token =
|
1104
|
+
payment_method_token = make_token
|
748
1105
|
nonce = nonce_for_paypal_account(
|
749
1106
|
:consent_code => "consent-code",
|
750
|
-
:token => payment_method_token
|
1107
|
+
:token => payment_method_token,
|
751
1108
|
)
|
752
1109
|
result = Braintree::PaymentMethod.create(
|
753
1110
|
:payment_method_nonce => nonce,
|
754
|
-
:customer_id => customer.id
|
1111
|
+
:customer_id => customer.id,
|
755
1112
|
)
|
756
1113
|
result.should be_success
|
757
1114
|
|
@@ -766,11 +1123,11 @@ describe Braintree::PaymentMethod do
|
|
766
1123
|
context "apple pay cards" do
|
767
1124
|
it "finds the payment method with the given token" do
|
768
1125
|
customer = Braintree::Customer.create!
|
769
|
-
payment_method_token =
|
1126
|
+
payment_method_token = make_token
|
770
1127
|
result = Braintree::PaymentMethod.create(
|
771
1128
|
:payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
|
772
1129
|
:customer_id => customer.id,
|
773
|
-
:token => payment_method_token
|
1130
|
+
:token => payment_method_token,
|
774
1131
|
)
|
775
1132
|
result.should be_success
|
776
1133
|
|
@@ -788,70 +1145,96 @@ describe Braintree::PaymentMethod do
|
|
788
1145
|
end
|
789
1146
|
end
|
790
1147
|
|
791
|
-
context "
|
1148
|
+
context "venmo accounts" do
|
1149
|
+
it "finds the payment method with the given token" do
|
1150
|
+
customer = Braintree::Customer.create!
|
1151
|
+
payment_method_token = make_token
|
1152
|
+
result = Braintree::PaymentMethod.create(
|
1153
|
+
:payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
|
1154
|
+
:customer_id => customer.id,
|
1155
|
+
:token => payment_method_token,
|
1156
|
+
)
|
1157
|
+
result.should be_success
|
1158
|
+
|
1159
|
+
venmo_account = Braintree::PaymentMethod.find(payment_method_token)
|
1160
|
+
venmo_account.should be_a(Braintree::VenmoAccount)
|
1161
|
+
venmo_account.should_not be_nil
|
1162
|
+
venmo_account.token.should == payment_method_token
|
1163
|
+
venmo_account.default.should == true
|
1164
|
+
venmo_account.image_url.should =~ /venmo/
|
1165
|
+
venmo_account.username.should == "venmojoe"
|
1166
|
+
venmo_account.venmo_user_id.should == "1234567891234567891"
|
1167
|
+
venmo_account.source_description.should == "Venmo Account: venmojoe"
|
1168
|
+
venmo_account.customer_id.should == customer.id
|
1169
|
+
end
|
1170
|
+
end
|
1171
|
+
|
1172
|
+
context "google pay cards" do
|
792
1173
|
it "finds the proxy card payment method with the given token" do
|
793
1174
|
customer = Braintree::Customer.create!
|
794
|
-
payment_method_token =
|
1175
|
+
payment_method_token = make_token
|
795
1176
|
result = Braintree::PaymentMethod.create(
|
796
|
-
:payment_method_nonce => Braintree::Test::Nonce::
|
1177
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
|
797
1178
|
:customer_id => customer.id,
|
798
|
-
:token => payment_method_token
|
1179
|
+
:token => payment_method_token,
|
799
1180
|
)
|
800
1181
|
result.should be_success
|
801
1182
|
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
1183
|
+
google_pay_card = Braintree::PaymentMethod.find(payment_method_token)
|
1184
|
+
google_pay_card.should be_a(Braintree::GooglePayCard)
|
1185
|
+
google_pay_card.should_not be_nil
|
1186
|
+
google_pay_card.token.should == payment_method_token
|
1187
|
+
google_pay_card.card_type.should == Braintree::CreditCard::CardType::Discover
|
1188
|
+
google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
|
1189
|
+
google_pay_card.expiration_month.to_i.should > 0
|
1190
|
+
google_pay_card.expiration_year.to_i.should > 0
|
1191
|
+
google_pay_card.default.should == true
|
1192
|
+
google_pay_card.image_url.should =~ /android_pay/
|
1193
|
+
google_pay_card.is_network_tokenized?.should == false
|
1194
|
+
google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::Discover
|
1195
|
+
google_pay_card.source_card_last_4.should == "1111"
|
1196
|
+
google_pay_card.google_transaction_id.should == "google_transaction_id"
|
1197
|
+
google_pay_card.source_description.should == "Discover 1111"
|
1198
|
+
google_pay_card.customer_id.should == customer.id
|
817
1199
|
end
|
818
1200
|
|
819
1201
|
it "finds the network token payment method with the given token" do
|
820
1202
|
customer = Braintree::Customer.create!
|
821
|
-
payment_method_token =
|
1203
|
+
payment_method_token = make_token
|
822
1204
|
result = Braintree::PaymentMethod.create(
|
823
|
-
:payment_method_nonce => Braintree::Test::Nonce::
|
1205
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
|
824
1206
|
:customer_id => customer.id,
|
825
|
-
:token => payment_method_token
|
1207
|
+
:token => payment_method_token,
|
826
1208
|
)
|
827
1209
|
result.should be_success
|
828
1210
|
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
1211
|
+
google_pay_card = Braintree::PaymentMethod.find(payment_method_token)
|
1212
|
+
google_pay_card.should be_a(Braintree::GooglePayCard)
|
1213
|
+
google_pay_card.should_not be_nil
|
1214
|
+
google_pay_card.token.should == payment_method_token
|
1215
|
+
google_pay_card.card_type.should == Braintree::CreditCard::CardType::MasterCard
|
1216
|
+
google_pay_card.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
|
1217
|
+
google_pay_card.expiration_month.to_i.should > 0
|
1218
|
+
google_pay_card.expiration_year.to_i.should > 0
|
1219
|
+
google_pay_card.default.should == true
|
1220
|
+
google_pay_card.image_url.should =~ /android_pay/
|
1221
|
+
google_pay_card.is_network_tokenized?.should == true
|
1222
|
+
google_pay_card.source_card_type.should == Braintree::CreditCard::CardType::MasterCard
|
1223
|
+
google_pay_card.source_card_last_4.should == "4444"
|
1224
|
+
google_pay_card.google_transaction_id.should == "google_transaction_id"
|
1225
|
+
google_pay_card.source_description.should == "MasterCard 4444"
|
1226
|
+
google_pay_card.customer_id.should == customer.id
|
844
1227
|
end
|
845
1228
|
end
|
846
1229
|
|
847
1230
|
context "unknown payment methods" do
|
848
1231
|
it "finds the payment method with the given token" do
|
849
1232
|
customer = Braintree::Customer.create!
|
850
|
-
payment_method_token =
|
1233
|
+
payment_method_token = make_token
|
851
1234
|
result = Braintree::PaymentMethod.create(
|
852
1235
|
:payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
|
853
1236
|
:customer_id => customer.id,
|
854
|
-
:token => payment_method_token
|
1237
|
+
:token => payment_method_token,
|
855
1238
|
)
|
856
1239
|
result.should be_success
|
857
1240
|
|
@@ -872,18 +1255,18 @@ describe Braintree::PaymentMethod do
|
|
872
1255
|
end
|
873
1256
|
|
874
1257
|
describe "self.delete" do
|
875
|
-
it "deletes an
|
1258
|
+
it "deletes an google pay card" do
|
876
1259
|
customer = Braintree::Customer.create!
|
877
1260
|
|
878
1261
|
create_result = Braintree::PaymentMethod.create(
|
879
|
-
:payment_method_nonce => Braintree::Test::Nonce::
|
880
|
-
:customer_id => customer.id
|
1262
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
|
1263
|
+
:customer_id => customer.id,
|
881
1264
|
)
|
882
1265
|
|
883
1266
|
token = create_result.payment_method.token
|
884
1267
|
|
885
|
-
|
886
|
-
|
1268
|
+
google_card = Braintree::PaymentMethod.find(token)
|
1269
|
+
google_card.should be_a(Braintree::GooglePayCard)
|
887
1270
|
|
888
1271
|
delete_result = Braintree::PaymentMethod.delete(token)
|
889
1272
|
delete_result.success?.should == true
|
@@ -898,7 +1281,7 @@ describe Braintree::PaymentMethod do
|
|
898
1281
|
|
899
1282
|
create_result = Braintree::PaymentMethod.create(
|
900
1283
|
:payment_method_nonce => Braintree::Test::Nonce::ApplePayAmEx,
|
901
|
-
:customer_id => customer.id
|
1284
|
+
:customer_id => customer.id,
|
902
1285
|
)
|
903
1286
|
token = create_result.payment_method.token
|
904
1287
|
|
@@ -915,14 +1298,15 @@ describe Braintree::PaymentMethod do
|
|
915
1298
|
|
916
1299
|
it "deletes a paypal account" do
|
917
1300
|
customer = Braintree::Customer.create!
|
918
|
-
paypal_account_token =
|
1301
|
+
paypal_account_token = make_token
|
1302
|
+
|
919
1303
|
nonce = nonce_for_paypal_account(
|
920
1304
|
:consent_code => "PAYPAL_CONSENT_CODE",
|
921
|
-
:token => paypal_account_token
|
1305
|
+
:token => paypal_account_token,
|
922
1306
|
)
|
923
1307
|
Braintree::PaymentMethod.create(
|
924
1308
|
:payment_method_nonce => nonce,
|
925
|
-
:customer_id => customer.id
|
1309
|
+
:customer_id => customer.id,
|
926
1310
|
)
|
927
1311
|
|
928
1312
|
paypal_account = Braintree::PaymentMethod.find(paypal_account_token)
|
@@ -937,7 +1321,7 @@ describe Braintree::PaymentMethod do
|
|
937
1321
|
end
|
938
1322
|
|
939
1323
|
it "deletes a credit card" do
|
940
|
-
token =
|
1324
|
+
token = make_token
|
941
1325
|
customer = Braintree::Customer.create!
|
942
1326
|
nonce = nonce_for_new_payment_method({
|
943
1327
|
:credit_card => {
|
@@ -951,7 +1335,7 @@ describe Braintree::PaymentMethod do
|
|
951
1335
|
|
952
1336
|
Braintree::PaymentMethod.create(
|
953
1337
|
:payment_method_nonce => nonce,
|
954
|
-
:customer_id => customer.id
|
1338
|
+
:customer_id => customer.id,
|
955
1339
|
)
|
956
1340
|
|
957
1341
|
result = Braintree::PaymentMethod.delete(token)
|
@@ -963,7 +1347,7 @@ describe Braintree::PaymentMethod do
|
|
963
1347
|
end
|
964
1348
|
|
965
1349
|
it "raises a NotFoundError exception if payment method cannot be found" do
|
966
|
-
token =
|
1350
|
+
token = make_token
|
967
1351
|
customer = Braintree::Customer.create!
|
968
1352
|
|
969
1353
|
expect do
|
@@ -974,6 +1358,71 @@ describe Braintree::PaymentMethod do
|
|
974
1358
|
|
975
1359
|
describe "self.update" do
|
976
1360
|
context "credit cards" do
|
1361
|
+
it "throws validation error when passing invalid pass thru params" do
|
1362
|
+
customer = Braintree::Customer.create!
|
1363
|
+
credit_card = Braintree::CreditCard.create!(
|
1364
|
+
:customer_id => customer.id,
|
1365
|
+
:payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
|
1366
|
+
:options => {:verify_card => true},
|
1367
|
+
)
|
1368
|
+
|
1369
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1370
|
+
:cardholder_name => "New Holder",
|
1371
|
+
:cvv => "456",
|
1372
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1373
|
+
:expiration_date => "06/2013",
|
1374
|
+
:three_d_secure_pass_thru => {
|
1375
|
+
:eci_flag => "02",
|
1376
|
+
:cavv => "some_cavv",
|
1377
|
+
:xid => "some_xid",
|
1378
|
+
:three_d_secure_version => "xx",
|
1379
|
+
:authentication_response => "Y",
|
1380
|
+
:directory_response => "Y",
|
1381
|
+
:cavv_algorithm => "2",
|
1382
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
1383
|
+
},
|
1384
|
+
:options => {:verify_card => true},
|
1385
|
+
)
|
1386
|
+
expect(update_result).to_not be_success
|
1387
|
+
error = update_result.errors.for(:verification).first
|
1388
|
+
expect(error.code).to eq(Braintree::ErrorCodes::Verification::ThreeDSecurePassThru::ThreeDSecureVersionIsInvalid)
|
1389
|
+
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`).")
|
1390
|
+
end
|
1391
|
+
|
1392
|
+
it "updates the credit card with three_d_secure pass thru params" do
|
1393
|
+
customer = Braintree::Customer.create!
|
1394
|
+
credit_card = Braintree::CreditCard.create!(
|
1395
|
+
:customer_id => customer.id,
|
1396
|
+
:payment_method_nonce => Braintree::Test::Nonce::ThreeDSecureVisaFullAuthentication,
|
1397
|
+
:options => {:verify_card => true},
|
1398
|
+
)
|
1399
|
+
|
1400
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1401
|
+
:cardholder_name => "New Holder",
|
1402
|
+
:cvv => "456",
|
1403
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1404
|
+
:expiration_date => "06/2013",
|
1405
|
+
:three_d_secure_pass_thru => {
|
1406
|
+
:eci_flag => "02",
|
1407
|
+
:cavv => "some_cavv",
|
1408
|
+
:xid => "some_xid",
|
1409
|
+
:three_d_secure_version => "1.0.2",
|
1410
|
+
:authentication_response => "Y",
|
1411
|
+
:directory_response => "Y",
|
1412
|
+
:cavv_algorithm => "2",
|
1413
|
+
:ds_transaction_id => "some_ds_transaction_id",
|
1414
|
+
},
|
1415
|
+
:options => {:verify_card => true},
|
1416
|
+
)
|
1417
|
+
update_result.success?.should == true
|
1418
|
+
update_result.payment_method.should == credit_card
|
1419
|
+
updated_credit_card = update_result.payment_method
|
1420
|
+
updated_credit_card.cardholder_name.should == "New Holder"
|
1421
|
+
updated_credit_card.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
|
1422
|
+
updated_credit_card.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
|
1423
|
+
updated_credit_card.expiration_date.should == "06/2013"
|
1424
|
+
end
|
1425
|
+
|
977
1426
|
it "updates the credit card" do
|
978
1427
|
customer = Braintree::Customer.create!
|
979
1428
|
credit_card = Braintree::CreditCard.create!(
|
@@ -981,13 +1430,13 @@ describe Braintree::PaymentMethod do
|
|
981
1430
|
:customer_id => customer.id,
|
982
1431
|
:cvv => "123",
|
983
1432
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
984
|
-
:expiration_date => "05/2012"
|
1433
|
+
:expiration_date => "05/2012",
|
985
1434
|
)
|
986
1435
|
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
987
1436
|
:cardholder_name => "New Holder",
|
988
1437
|
:cvv => "456",
|
989
1438
|
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
990
|
-
:expiration_date => "06/2013"
|
1439
|
+
:expiration_date => "06/2013",
|
991
1440
|
)
|
992
1441
|
update_result.success?.should == true
|
993
1442
|
update_result.payment_method.should == credit_card
|
@@ -998,6 +1447,142 @@ describe Braintree::PaymentMethod do
|
|
998
1447
|
updated_credit_card.expiration_date.should == "06/2013"
|
999
1448
|
end
|
1000
1449
|
|
1450
|
+
it "includes risk data when skip_advanced_fraud_checking is false" do
|
1451
|
+
with_fraud_protection_enterprise_merchant do
|
1452
|
+
customer = Braintree::Customer.create!
|
1453
|
+
credit_card = Braintree::CreditCard.create!(
|
1454
|
+
:customer_id => customer.id,
|
1455
|
+
:cvv => "123",
|
1456
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1457
|
+
:expiration_date => "05/2012",
|
1458
|
+
)
|
1459
|
+
update_result = Braintree::PaymentMethod.update(
|
1460
|
+
credit_card.token,
|
1461
|
+
:cvv => "456",
|
1462
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1463
|
+
:expiration_date => "06/2013",
|
1464
|
+
:options => {
|
1465
|
+
:verify_card => true,
|
1466
|
+
:skip_advanced_fraud_checking => false
|
1467
|
+
},
|
1468
|
+
)
|
1469
|
+
|
1470
|
+
expect(update_result).to be_success
|
1471
|
+
verification = update_result.payment_method.verification
|
1472
|
+
expect(verification.risk_data).not_to be_nil
|
1473
|
+
end
|
1474
|
+
end
|
1475
|
+
|
1476
|
+
it "does not include risk data when skip_advanced_fraud_checking is true" do
|
1477
|
+
with_fraud_protection_enterprise_merchant do
|
1478
|
+
customer = Braintree::Customer.create!
|
1479
|
+
credit_card = Braintree::CreditCard.create!(
|
1480
|
+
:customer_id => customer.id,
|
1481
|
+
:cvv => "123",
|
1482
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1483
|
+
:expiration_date => "05/2012",
|
1484
|
+
)
|
1485
|
+
update_result = Braintree::PaymentMethod.update(
|
1486
|
+
credit_card.token,
|
1487
|
+
:cvv => "456",
|
1488
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1489
|
+
:expiration_date => "06/2013",
|
1490
|
+
:options => {
|
1491
|
+
:verify_card => true,
|
1492
|
+
:skip_advanced_fraud_checking => true
|
1493
|
+
},
|
1494
|
+
)
|
1495
|
+
|
1496
|
+
expect(update_result).to be_success
|
1497
|
+
verification = update_result.payment_method.verification
|
1498
|
+
expect(verification.risk_data).to be_nil
|
1499
|
+
end
|
1500
|
+
end
|
1501
|
+
|
1502
|
+
context "verification_currency_iso_code" do
|
1503
|
+
it "validates verification_currency_iso_code and updates the credit card " do
|
1504
|
+
customer = Braintree::Customer.create!
|
1505
|
+
credit_card = Braintree::CreditCard.create!(
|
1506
|
+
:cardholder_name => "Original Holder",
|
1507
|
+
:customer_id => customer.id,
|
1508
|
+
:cvv => "123",
|
1509
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1510
|
+
:expiration_date => "05/2012",
|
1511
|
+
)
|
1512
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1513
|
+
:cardholder_name => "New Holder",
|
1514
|
+
:cvv => "456",
|
1515
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1516
|
+
:expiration_date => "06/2013",
|
1517
|
+
:options => {:verify_card => true, :verification_currency_iso_code => "USD"},
|
1518
|
+
)
|
1519
|
+
update_result.success?.should == true
|
1520
|
+
update_result.payment_method.verification.currency_iso_code == "USD"
|
1521
|
+
end
|
1522
|
+
|
1523
|
+
it "validates verification_currency_iso_code against the given verification_merchant_account_id and updates the credit card " do
|
1524
|
+
customer = Braintree::Customer.create!
|
1525
|
+
credit_card = Braintree::CreditCard.create!(
|
1526
|
+
:cardholder_name => "Original Holder",
|
1527
|
+
:customer_id => customer.id,
|
1528
|
+
:cvv => "123",
|
1529
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1530
|
+
:expiration_date => "05/2012",
|
1531
|
+
)
|
1532
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1533
|
+
:cardholder_name => "New Holder",
|
1534
|
+
:cvv => "456",
|
1535
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1536
|
+
:expiration_date => "06/2013",
|
1537
|
+
:options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "USD"},
|
1538
|
+
)
|
1539
|
+
update_result.success?.should == true
|
1540
|
+
update_result.payment_method.verification.currency_iso_code == "USD"
|
1541
|
+
update_result.payment_method.verification.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
|
1542
|
+
end
|
1543
|
+
|
1544
|
+
it "throws validation error when passing invalid verification_currency_iso_code" do
|
1545
|
+
customer = Braintree::Customer.create!
|
1546
|
+
credit_card = Braintree::CreditCard.create!(
|
1547
|
+
:cardholder_name => "Original Holder",
|
1548
|
+
:customer_id => customer.id,
|
1549
|
+
:cvv => "123",
|
1550
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1551
|
+
:expiration_date => "05/2012",
|
1552
|
+
)
|
1553
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1554
|
+
:cardholder_name => "New Holder",
|
1555
|
+
:cvv => "456",
|
1556
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1557
|
+
:expiration_date => "06/2013",
|
1558
|
+
:options => {:verify_card => true, :verification_currency_iso_code => "GBP"},
|
1559
|
+
)
|
1560
|
+
expect(update_result).to_not be_success
|
1561
|
+
update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
|
1562
|
+
end
|
1563
|
+
|
1564
|
+
it "throws validation error when passing invalid verification_currency_iso_code of the given verification merchant account id" do
|
1565
|
+
customer = Braintree::Customer.create!
|
1566
|
+
credit_card = Braintree::CreditCard.create!(
|
1567
|
+
:cardholder_name => "Original Holder",
|
1568
|
+
:customer_id => customer.id,
|
1569
|
+
:cvv => "123",
|
1570
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1571
|
+
:expiration_date => "05/2012",
|
1572
|
+
)
|
1573
|
+
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1574
|
+
:cardholder_name => "New Holder",
|
1575
|
+
:cvv => "456",
|
1576
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1577
|
+
:expiration_date => "06/2013",
|
1578
|
+
:options => {:verify_card => true, :verification_merchant_account_id => SpecHelper::NonDefaultMerchantAccountId, :verification_currency_iso_code => "GBP"},
|
1579
|
+
)
|
1580
|
+
expect(update_result).to_not be_success
|
1581
|
+
update_result.errors.for(:credit_card).for(:options).on(:verification_currency_iso_code)[0].code.should == Braintree::ErrorCodes::CreditCard::CurrencyCodeNotSupportedByMerchantAccount
|
1582
|
+
end
|
1583
|
+
end
|
1584
|
+
|
1585
|
+
|
1001
1586
|
context "billing address" do
|
1002
1587
|
it "creates a new billing address by default" do
|
1003
1588
|
customer = Braintree::Customer.create!
|
@@ -1007,12 +1592,12 @@ describe Braintree::PaymentMethod do
|
|
1007
1592
|
:expiration_date => "05/2012",
|
1008
1593
|
:billing_address => {
|
1009
1594
|
:street_address => "123 Nigeria Ave"
|
1010
|
-
}
|
1595
|
+
},
|
1011
1596
|
)
|
1012
1597
|
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1013
1598
|
:billing_address => {
|
1014
1599
|
:region => "IL"
|
1015
|
-
}
|
1600
|
+
},
|
1016
1601
|
)
|
1017
1602
|
update_result.success?.should == true
|
1018
1603
|
updated_credit_card = update_result.payment_method
|
@@ -1029,13 +1614,13 @@ describe Braintree::PaymentMethod do
|
|
1029
1614
|
:expiration_date => "05/2012",
|
1030
1615
|
:billing_address => {
|
1031
1616
|
:street_address => "123 Nigeria Ave"
|
1032
|
-
}
|
1617
|
+
},
|
1033
1618
|
)
|
1034
1619
|
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1035
1620
|
:billing_address => {
|
1036
1621
|
:region => "IL",
|
1037
1622
|
:options => {:update_existing => true}
|
1038
|
-
}
|
1623
|
+
},
|
1039
1624
|
)
|
1040
1625
|
update_result.success?.should == true
|
1041
1626
|
updated_credit_card = update_result.payment_method
|
@@ -1052,7 +1637,7 @@ describe Braintree::PaymentMethod do
|
|
1052
1637
|
:expiration_date => "05/2012",
|
1053
1638
|
:billing_address => {
|
1054
1639
|
:street_address => "123 Nigeria Ave"
|
1055
|
-
}
|
1640
|
+
},
|
1056
1641
|
)
|
1057
1642
|
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1058
1643
|
:billing_address => {
|
@@ -1061,7 +1646,7 @@ describe Braintree::PaymentMethod do
|
|
1061
1646
|
:country_code_alpha3 => "ASM",
|
1062
1647
|
:country_code_numeric => "016",
|
1063
1648
|
:options => {:update_existing => true}
|
1064
|
-
}
|
1649
|
+
},
|
1065
1650
|
)
|
1066
1651
|
update_result.success?.should == true
|
1067
1652
|
updated_credit_card = update_result.payment_method
|
@@ -1077,12 +1662,12 @@ describe Braintree::PaymentMethod do
|
|
1077
1662
|
credit_card = Braintree::CreditCard.create!(
|
1078
1663
|
:customer_id => customer.id,
|
1079
1664
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1080
|
-
:expiration_date => "05/2012"
|
1665
|
+
:expiration_date => "05/2012",
|
1081
1666
|
)
|
1082
1667
|
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1083
1668
|
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1084
1669
|
:expiration_month => "07",
|
1085
|
-
:expiration_year => "2011"
|
1670
|
+
:expiration_year => "2011",
|
1086
1671
|
)
|
1087
1672
|
update_result.success?.should == true
|
1088
1673
|
update_result.payment_method.should == credit_card
|
@@ -1098,14 +1683,14 @@ describe Braintree::PaymentMethod do
|
|
1098
1683
|
:customer_id => customer.id,
|
1099
1684
|
:cvv => "123",
|
1100
1685
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1101
|
-
:expiration_date => "05/2012"
|
1686
|
+
:expiration_date => "05/2012",
|
1102
1687
|
)
|
1103
1688
|
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1104
1689
|
:cardholder_name => "New Holder",
|
1105
1690
|
:cvv => "456",
|
1106
1691
|
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::MasterCard,
|
1107
1692
|
:expiration_date => "06/2013",
|
1108
|
-
:options => {:verify_card => true}
|
1693
|
+
:options => {:verify_card => true},
|
1109
1694
|
)
|
1110
1695
|
update_result.success?.should == false
|
1111
1696
|
update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
@@ -1119,11 +1704,11 @@ describe Braintree::PaymentMethod do
|
|
1119
1704
|
:customer_id => customer.id,
|
1120
1705
|
:cvv => "123",
|
1121
1706
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1122
|
-
:expiration_date => "05/2020"
|
1707
|
+
:expiration_date => "05/2020",
|
1123
1708
|
)
|
1124
1709
|
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1125
1710
|
:payment_method_nonce => Braintree::Test::Nonce::ProcessorDeclinedMasterCard,
|
1126
|
-
:options => {:verify_card => true, :verification_amount => "2.34"}
|
1711
|
+
:options => {:verify_card => true, :verification_amount => "2.34"},
|
1127
1712
|
)
|
1128
1713
|
update_result.success?.should == false
|
1129
1714
|
update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
@@ -1149,7 +1734,7 @@ describe Braintree::PaymentMethod do
|
|
1149
1734
|
:region => "Old State",
|
1150
1735
|
:postal_code => "12345",
|
1151
1736
|
:country_name => "Canada"
|
1152
|
-
}
|
1737
|
+
},
|
1153
1738
|
)
|
1154
1739
|
result = Braintree::PaymentMethod.update(credit_card.token,
|
1155
1740
|
:options => {:verify_card => false},
|
@@ -1163,7 +1748,7 @@ describe Braintree::PaymentMethod do
|
|
1163
1748
|
:region => "New State",
|
1164
1749
|
:postal_code => "56789",
|
1165
1750
|
:country_name => "United States of America"
|
1166
|
-
}
|
1751
|
+
},
|
1167
1752
|
)
|
1168
1753
|
result.success?.should == true
|
1169
1754
|
address = result.payment_method.billing_address
|
@@ -1184,12 +1769,12 @@ describe Braintree::PaymentMethod do
|
|
1184
1769
|
:cardholder_name => "Original Holder",
|
1185
1770
|
:customer_id => customer.id,
|
1186
1771
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1187
|
-
:expiration_date => "05/2012"
|
1772
|
+
:expiration_date => "05/2012",
|
1188
1773
|
)
|
1189
1774
|
update_result = Braintree::PaymentMethod.update(credit_card.token,
|
1190
1775
|
:cardholder_name => "New Holder",
|
1191
1776
|
:number => "invalid",
|
1192
|
-
:expiration_date => "05/2014"
|
1777
|
+
:expiration_date => "05/2014",
|
1193
1778
|
)
|
1194
1779
|
update_result.success?.should == false
|
1195
1780
|
update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
|
@@ -1200,12 +1785,12 @@ describe Braintree::PaymentMethod do
|
|
1200
1785
|
card1 = Braintree::CreditCard.create(
|
1201
1786
|
:customer_id => customer.id,
|
1202
1787
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1203
|
-
:expiration_date => "05/2009"
|
1788
|
+
:expiration_date => "05/2009",
|
1204
1789
|
).credit_card
|
1205
1790
|
card2 = Braintree::CreditCard.create(
|
1206
1791
|
:customer_id => customer.id,
|
1207
1792
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1208
|
-
:expiration_date => "05/2009"
|
1793
|
+
:expiration_date => "05/2009",
|
1209
1794
|
).credit_card
|
1210
1795
|
|
1211
1796
|
card1.should be_default
|
@@ -1218,50 +1803,23 @@ describe Braintree::PaymentMethod do
|
|
1218
1803
|
end
|
1219
1804
|
end
|
1220
1805
|
|
1221
|
-
context "coinbase accounts" do
|
1222
|
-
it "can make a coinbase account the default payment method" do
|
1223
|
-
customer = Braintree::Customer.create!
|
1224
|
-
result = Braintree::CreditCard.create(
|
1225
|
-
:customer_id => customer.id,
|
1226
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1227
|
-
:expiration_date => "05/2009",
|
1228
|
-
:options => {:make_default => true}
|
1229
|
-
)
|
1230
|
-
result.should be_success
|
1231
|
-
|
1232
|
-
nonce = Braintree::Test::Nonce::Coinbase
|
1233
|
-
original_token = Braintree::PaymentMethod.create(
|
1234
|
-
:payment_method_nonce => nonce,
|
1235
|
-
:customer_id => customer.id
|
1236
|
-
).payment_method.token
|
1237
|
-
|
1238
|
-
updated_result = Braintree::PaymentMethod.update(
|
1239
|
-
original_token,
|
1240
|
-
:options => {:make_default => true}
|
1241
|
-
)
|
1242
|
-
|
1243
|
-
updated_customer = Braintree::Customer.find(customer.id)
|
1244
|
-
updated_customer.default_payment_method.token.should == original_token
|
1245
|
-
end
|
1246
|
-
end
|
1247
|
-
|
1248
1806
|
context "paypal accounts" do
|
1249
1807
|
it "updates a paypal account's token" do
|
1250
1808
|
customer = Braintree::Customer.create!
|
1251
1809
|
original_token = random_payment_method_token
|
1252
1810
|
nonce = nonce_for_paypal_account(
|
1253
1811
|
:consent_code => "consent-code",
|
1254
|
-
:token => original_token
|
1812
|
+
:token => original_token,
|
1255
1813
|
)
|
1256
1814
|
original_result = Braintree::PaymentMethod.create(
|
1257
1815
|
:payment_method_nonce => nonce,
|
1258
|
-
:customer_id => customer.id
|
1816
|
+
:customer_id => customer.id,
|
1259
1817
|
)
|
1260
1818
|
|
1261
|
-
updated_token =
|
1819
|
+
updated_token = make_token
|
1262
1820
|
updated_result = Braintree::PaymentMethod.update(
|
1263
1821
|
original_token,
|
1264
|
-
:token => updated_token
|
1822
|
+
:token => updated_token,
|
1265
1823
|
)
|
1266
1824
|
|
1267
1825
|
updated_paypal_account = Braintree::PayPalAccount.find(updated_token)
|
@@ -1278,19 +1836,19 @@ describe Braintree::PaymentMethod do
|
|
1278
1836
|
:customer_id => customer.id,
|
1279
1837
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1280
1838
|
:expiration_date => "05/2009",
|
1281
|
-
:options => {:make_default => true}
|
1839
|
+
:options => {:make_default => true},
|
1282
1840
|
)
|
1283
1841
|
result.should be_success
|
1284
1842
|
|
1285
1843
|
nonce = nonce_for_paypal_account(:consent_code => "consent-code")
|
1286
1844
|
original_token = Braintree::PaymentMethod.create(
|
1287
1845
|
:payment_method_nonce => nonce,
|
1288
|
-
:customer_id => customer.id
|
1846
|
+
:customer_id => customer.id,
|
1289
1847
|
).payment_method.token
|
1290
1848
|
|
1291
1849
|
updated_result = Braintree::PaymentMethod.update(
|
1292
1850
|
original_token,
|
1293
|
-
:options => {:make_default => true}
|
1851
|
+
:options => {:make_default => true},
|
1294
1852
|
)
|
1295
1853
|
|
1296
1854
|
updated_paypal_account = Braintree::PayPalAccount.find(original_token)
|
@@ -1304,25 +1862,25 @@ describe Braintree::PaymentMethod do
|
|
1304
1862
|
|
1305
1863
|
first_nonce = nonce_for_paypal_account(
|
1306
1864
|
:consent_code => "consent-code",
|
1307
|
-
:token => first_token
|
1865
|
+
:token => first_token,
|
1308
1866
|
)
|
1309
1867
|
first_result = Braintree::PaymentMethod.create(
|
1310
1868
|
:payment_method_nonce => first_nonce,
|
1311
|
-
:customer_id => customer.id
|
1869
|
+
:customer_id => customer.id,
|
1312
1870
|
)
|
1313
1871
|
|
1314
1872
|
second_nonce = nonce_for_paypal_account(
|
1315
1873
|
:consent_code => "consent-code",
|
1316
|
-
:token => second_token
|
1874
|
+
:token => second_token,
|
1317
1875
|
)
|
1318
1876
|
second_result = Braintree::PaymentMethod.create(
|
1319
1877
|
:payment_method_nonce => second_nonce,
|
1320
|
-
:customer_id => customer.id
|
1878
|
+
:customer_id => customer.id,
|
1321
1879
|
)
|
1322
1880
|
|
1323
1881
|
updated_result = Braintree::PaymentMethod.update(
|
1324
1882
|
first_token,
|
1325
|
-
:token => second_token
|
1883
|
+
:token => second_token,
|
1326
1884
|
)
|
1327
1885
|
|
1328
1886
|
updated_result.should_not be_success
|
@@ -1331,44 +1889,68 @@ describe Braintree::PaymentMethod do
|
|
1331
1889
|
end
|
1332
1890
|
end
|
1333
1891
|
|
1892
|
+
describe "self.update!" do
|
1893
|
+
it "updates the credit card" do
|
1894
|
+
customer = Braintree::Customer.create!
|
1895
|
+
credit_card = Braintree::CreditCard.create!(
|
1896
|
+
:cardholder_name => "Original Holder",
|
1897
|
+
:customer_id => customer.id,
|
1898
|
+
:cvv => "123",
|
1899
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1900
|
+
:expiration_date => "05/2012",
|
1901
|
+
)
|
1902
|
+
payment_method = Braintree::PaymentMethod.update!(credit_card.token,
|
1903
|
+
:cardholder_name => "New Holder",
|
1904
|
+
:cvv => "456",
|
1905
|
+
:number => Braintree::Test::CreditCardNumbers::MasterCard,
|
1906
|
+
:expiration_date => "06/2013",
|
1907
|
+
)
|
1908
|
+
payment_method.should == credit_card
|
1909
|
+
payment_method.cardholder_name.should == "New Holder"
|
1910
|
+
payment_method.bin.should == Braintree::Test::CreditCardNumbers::MasterCard[0, 6]
|
1911
|
+
payment_method.last_4.should == Braintree::Test::CreditCardNumbers::MasterCard[-4..-1]
|
1912
|
+
payment_method.expiration_date.should == "06/2013"
|
1913
|
+
end
|
1914
|
+
end
|
1915
|
+
|
1334
1916
|
context "payment method grant and revoke" do
|
1335
1917
|
before(:each) do
|
1336
|
-
partner_merchant_gateway = Braintree::Gateway.new(
|
1918
|
+
@partner_merchant_gateway = Braintree::Gateway.new(
|
1337
1919
|
:merchant_id => "integration_merchant_public_id",
|
1338
1920
|
:public_key => "oauth_app_partner_user_public_key",
|
1339
1921
|
:private_key => "oauth_app_partner_user_private_key",
|
1340
1922
|
:environment => Braintree::Configuration.environment,
|
1341
|
-
:logger => Logger.new("/dev/null")
|
1923
|
+
:logger => Logger.new("/dev/null"),
|
1342
1924
|
)
|
1343
|
-
customer = partner_merchant_gateway.customer.create(
|
1925
|
+
customer = @partner_merchant_gateway.customer.create(
|
1344
1926
|
:first_name => "Joe",
|
1345
1927
|
:last_name => "Brown",
|
1346
1928
|
:company => "ExampleCo",
|
1347
1929
|
:email => "joe@example.com",
|
1348
1930
|
:phone => "312.555.1234",
|
1349
1931
|
:fax => "614.555.5678",
|
1350
|
-
:website => "www.example.com"
|
1932
|
+
:website => "www.example.com",
|
1351
1933
|
).customer
|
1352
|
-
@credit_card = partner_merchant_gateway.credit_card.create(
|
1934
|
+
@credit_card = @partner_merchant_gateway.credit_card.create(
|
1353
1935
|
:customer_id => customer.id,
|
1354
1936
|
:cardholder_name => "Adam Davis",
|
1355
1937
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1356
|
-
:expiration_date => "05/2009"
|
1938
|
+
:expiration_date => "05/2009",
|
1357
1939
|
).credit_card
|
1358
1940
|
|
1359
|
-
oauth_gateway = Braintree::Gateway.new(
|
1941
|
+
@oauth_gateway = Braintree::Gateway.new(
|
1360
1942
|
:client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
|
1361
1943
|
:client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
|
1362
|
-
:logger => Logger.new("/dev/null")
|
1944
|
+
:logger => Logger.new("/dev/null"),
|
1363
1945
|
)
|
1364
|
-
access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
|
1946
|
+
access_token = Braintree::OAuthTestHelper.create_token(@oauth_gateway, {
|
1365
1947
|
:merchant_public_id => "integration_merchant_id",
|
1366
1948
|
:scope => "grant_payment_method"
|
1367
1949
|
}).credentials.access_token
|
1368
1950
|
|
1369
1951
|
@granting_gateway = Braintree::Gateway.new(
|
1370
1952
|
:access_token => access_token,
|
1371
|
-
:logger => Logger.new("/dev/null")
|
1953
|
+
:logger => Logger.new("/dev/null"),
|
1372
1954
|
)
|
1373
1955
|
end
|
1374
1956
|
|
@@ -1384,13 +1966,13 @@ describe Braintree::PaymentMethod do
|
|
1384
1966
|
|
1385
1967
|
result = Braintree::Transaction.sale(
|
1386
1968
|
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
1387
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize
|
1969
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
1388
1970
|
)
|
1389
1971
|
result.should be_success
|
1390
1972
|
|
1391
1973
|
result2 = Braintree::Transaction.sale(
|
1392
1974
|
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
1393
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize
|
1975
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
1394
1976
|
)
|
1395
1977
|
result2.should_not be_success
|
1396
1978
|
end
|
@@ -1402,7 +1984,7 @@ describe Braintree::PaymentMethod do
|
|
1402
1984
|
|
1403
1985
|
result = Braintree::PaymentMethod.create(
|
1404
1986
|
:customer_id => customer_result.customer.id,
|
1405
|
-
:payment_method_nonce => grant_result.payment_method_nonce.nonce
|
1987
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
1406
1988
|
)
|
1407
1989
|
result.should_not be_success
|
1408
1990
|
end
|
@@ -1414,7 +1996,7 @@ describe Braintree::PaymentMethod do
|
|
1414
1996
|
|
1415
1997
|
result = Braintree::PaymentMethod.create(
|
1416
1998
|
:customer_id => customer_result.customer.id,
|
1417
|
-
:payment_method_nonce => grant_result.payment_method_nonce.nonce
|
1999
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
1418
2000
|
)
|
1419
2001
|
result.should be_success
|
1420
2002
|
end
|
@@ -1422,7 +2004,7 @@ describe Braintree::PaymentMethod do
|
|
1422
2004
|
it "raises an error if the token isn't found" do
|
1423
2005
|
expect do
|
1424
2006
|
@granting_gateway.payment_method.grant("not_a_real_token", false)
|
1425
|
-
end.to raise_error
|
2007
|
+
end.to raise_error(Braintree::NotFoundError)
|
1426
2008
|
end
|
1427
2009
|
|
1428
2010
|
it "returns a valid nonce with no options set" do
|
@@ -1437,7 +2019,7 @@ describe Braintree::PaymentMethod do
|
|
1437
2019
|
it "raises an error if the token isn't found" do
|
1438
2020
|
expect do
|
1439
2021
|
@granting_gateway.payment_method.revoke("not_a_real_token")
|
1440
|
-
end.to raise_error
|
2022
|
+
end.to raise_error(Braintree::NotFoundError)
|
1441
2023
|
end
|
1442
2024
|
|
1443
2025
|
it "renders a granted nonce useless" do
|
@@ -1449,7 +2031,7 @@ describe Braintree::PaymentMethod do
|
|
1449
2031
|
|
1450
2032
|
result = Braintree::PaymentMethod.create(
|
1451
2033
|
:customer_id => customer_result.customer.id,
|
1452
|
-
:payment_method_nonce => grant_result.payment_method_nonce.nonce
|
2034
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
1453
2035
|
)
|
1454
2036
|
result.should_not be_success
|
1455
2037
|
end
|
@@ -1463,7 +2045,7 @@ describe Braintree::PaymentMethod do
|
|
1463
2045
|
|
1464
2046
|
result = Braintree::PaymentMethod.create(
|
1465
2047
|
:customer_id => customer_result.customer.id,
|
1466
|
-
:payment_method_nonce => grant_result.payment_method_nonce.nonce
|
2048
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
1467
2049
|
)
|
1468
2050
|
result.should_not be_success
|
1469
2051
|
end
|