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
data/lib/braintree/util.rb
CHANGED
@@ -14,13 +14,13 @@ module Braintree
|
|
14
14
|
else
|
15
15
|
url_encode(full_key) + "=" + url_encode(value)
|
16
16
|
end
|
17
|
-
end.sort *
|
17
|
+
end.sort * "&"
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.parse_query_string(qs)
|
21
|
-
qs.split(
|
22
|
-
pair = couplet.split(
|
23
|
-
result[CGI.unescape(pair[0]).to_sym] = CGI.unescape(pair[1] ||
|
21
|
+
qs.split("&").inject({}) do |result, couplet|
|
22
|
+
pair = couplet.split("=")
|
23
|
+
result[CGI.unescape(pair[0]).to_sym] = CGI.unescape(pair[1] || "")
|
24
24
|
result
|
25
25
|
end
|
26
26
|
end
|
@@ -53,6 +53,8 @@ module Braintree
|
|
53
53
|
raise AuthorizationError, message
|
54
54
|
when 404
|
55
55
|
raise NotFoundError
|
56
|
+
when 408
|
57
|
+
raise RequestTimeoutError
|
56
58
|
when 426
|
57
59
|
raise UpgradeRequiredError, "Please upgrade your client library."
|
58
60
|
when 429
|
@@ -60,18 +62,51 @@ module Braintree
|
|
60
62
|
when 500
|
61
63
|
raise ServerError
|
62
64
|
when 503
|
63
|
-
raise
|
65
|
+
raise ServiceUnavailableError
|
66
|
+
when 504
|
67
|
+
raise GatewayTimeoutError
|
64
68
|
else
|
65
69
|
raise UnexpectedError, "Unexpected HTTP_RESPONSE #{status_code.to_i}"
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
73
|
+
def self.raise_exception_for_graphql_error(response)
|
74
|
+
return if !response[:errors]
|
75
|
+
|
76
|
+
for error in response[:errors]
|
77
|
+
if error[:extensions] && error[:extensions][:errorClass]
|
78
|
+
case error[:extensions][:errorClass]
|
79
|
+
when "VALIDATION"
|
80
|
+
next # skip raising an error if it is a validation error
|
81
|
+
when "AUTHENTICATION"
|
82
|
+
raise AuthenticationError
|
83
|
+
when "AUTHORIZATION"
|
84
|
+
raise AuthorizationError, error[:message]
|
85
|
+
when "NOT_FOUND"
|
86
|
+
raise NotFoundError
|
87
|
+
when "UNSUPPORTED_CLIENT"
|
88
|
+
raise UpgradeRequiredError, "Please upgrade your client library."
|
89
|
+
when "RESOURCE_LIMIT"
|
90
|
+
raise TooManyRequestsError
|
91
|
+
when "INTERNAL"
|
92
|
+
raise ServerError
|
93
|
+
when "SERVICE_AVAILABILITY"
|
94
|
+
raise ServiceUnavailableError
|
95
|
+
else
|
96
|
+
raise UnexpectedError, "Unexpected Response: #{error[:message]}"
|
97
|
+
end
|
98
|
+
else
|
99
|
+
raise UnexpectedError, "Unexpected Response: #{error[:message]}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
69
104
|
def self.to_big_decimal(decimal)
|
70
105
|
case decimal
|
71
106
|
when BigDecimal, NilClass
|
72
107
|
decimal
|
73
108
|
when String
|
74
|
-
BigDecimal
|
109
|
+
BigDecimal(decimal)
|
75
110
|
else
|
76
111
|
raise ArgumentError, "Argument must be a String or BigDecimal"
|
77
112
|
end
|
@@ -82,15 +117,30 @@ module Braintree
|
|
82
117
|
end
|
83
118
|
|
84
119
|
def self.verify_keys(valid_keys, hash)
|
85
|
-
|
86
|
-
invalid_keys = _flatten_hash_keys(hash) - flattened_valid_keys
|
87
|
-
invalid_keys = _remove_wildcard_keys(flattened_valid_keys, invalid_keys)
|
120
|
+
invalid_keys = _get_invalid_keys(valid_keys, hash)
|
88
121
|
if invalid_keys.any?
|
89
122
|
sorted = invalid_keys.sort_by { |k| k.to_s }.join(", ")
|
90
123
|
raise ArgumentError, "invalid keys: #{sorted}"
|
91
124
|
end
|
92
125
|
end
|
93
126
|
|
127
|
+
def self.keys_valid?(valid_keys, hash)
|
128
|
+
invalid_keys = _get_invalid_keys(valid_keys, hash)
|
129
|
+
|
130
|
+
!invalid_keys.any?
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.replace_key(hash, target_key, replacement_key)
|
134
|
+
hash.inject({}) do |new_hash, (key, value)|
|
135
|
+
if value.is_a?(Hash)
|
136
|
+
value = replace_key(value, target_key, replacement_key)
|
137
|
+
end
|
138
|
+
|
139
|
+
key = replacement_key if key == target_key
|
140
|
+
new_hash.merge(key => value)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
94
144
|
def self._flatten_valid_keys(valid_keys, namespace = nil)
|
95
145
|
valid_keys.inject([]) do |result, key|
|
96
146
|
if key.is_a?(Hash)
|
@@ -137,5 +187,25 @@ module Braintree
|
|
137
187
|
end
|
138
188
|
end
|
139
189
|
end
|
190
|
+
|
191
|
+
def self._get_invalid_keys(valid_keys, hash)
|
192
|
+
flattened_valid_keys = _flatten_valid_keys(valid_keys)
|
193
|
+
keys = _flatten_hash_keys(hash) - flattened_valid_keys
|
194
|
+
keys = _remove_wildcard_keys(flattened_valid_keys, keys)
|
195
|
+
end
|
196
|
+
|
197
|
+
module IdEquality
|
198
|
+
def ==(other) # :nodoc:
|
199
|
+
return false unless other.is_a?(self.class)
|
200
|
+
id == other.id
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
module TokenEquality
|
205
|
+
def ==(other) # :nodoc:
|
206
|
+
return false unless other.is_a?(self.class)
|
207
|
+
token == other.token
|
208
|
+
end
|
209
|
+
end
|
140
210
|
end
|
141
211
|
end
|
@@ -2,10 +2,20 @@ module Braintree
|
|
2
2
|
class ValidationError
|
3
3
|
include BaseModule
|
4
4
|
|
5
|
-
attr_reader :attribute
|
5
|
+
attr_reader :attribute
|
6
|
+
attr_reader :code
|
7
|
+
attr_reader :message
|
6
8
|
|
7
|
-
def initialize(
|
8
|
-
|
9
|
+
def initialize(error_hash)
|
10
|
+
# parse GraphQL response objects
|
11
|
+
if (error_hash[:extensions] &&
|
12
|
+
error_hash[:extensions][:errorClass] &&
|
13
|
+
error_hash[:extensions][:errorClass] == "VALIDATION")
|
14
|
+
error_hash[:code] = error_hash[:extensions][:legacyCode].to_i
|
15
|
+
error_hash[:attribute] = error_hash[:path].last
|
16
|
+
end
|
17
|
+
|
18
|
+
set_instance_variables_from_hash error_hash
|
9
19
|
end
|
10
20
|
|
11
21
|
def inspect # :nodoc:
|
@@ -3,7 +3,8 @@ module Braintree
|
|
3
3
|
include Enumerable
|
4
4
|
|
5
5
|
def initialize(data) # :nodoc:
|
6
|
-
|
6
|
+
return if !data.is_a? Hash
|
7
|
+
@errors = (data[:errors] || {}).map { |hash| Braintree::ValidationError.new(hash) }
|
7
8
|
@nested = {}
|
8
9
|
data.keys.each do |key|
|
9
10
|
next if key == :errors
|
@@ -2,8 +2,16 @@ module Braintree
|
|
2
2
|
class VenmoAccount
|
3
3
|
include BaseModule # :nodoc:
|
4
4
|
|
5
|
-
attr_reader :
|
6
|
-
|
5
|
+
attr_reader :created_at
|
6
|
+
attr_reader :customer_id
|
7
|
+
attr_reader :default
|
8
|
+
attr_reader :image_url
|
9
|
+
attr_reader :source_description
|
10
|
+
attr_reader :subscriptions
|
11
|
+
attr_reader :token
|
12
|
+
attr_reader :updated_at
|
13
|
+
attr_reader :username
|
14
|
+
attr_reader :venmo_user_id
|
7
15
|
|
8
16
|
def initialize(gateway, attributes) # :nodoc:
|
9
17
|
@gateway = gateway
|
@@ -20,8 +28,7 @@ module Braintree
|
|
20
28
|
end
|
21
29
|
|
22
30
|
def self._new(*args) # :nodoc:
|
23
|
-
self.new
|
31
|
+
self.new(*args)
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
27
|
-
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Braintree
|
2
|
+
class VenmoProfileData
|
3
|
+
include BaseModule
|
4
|
+
|
5
|
+
attr_reader :username
|
6
|
+
attr_reader :first_name
|
7
|
+
attr_reader :last_name
|
8
|
+
attr_reader :phone_number
|
9
|
+
attr_reader :email
|
10
|
+
|
11
|
+
def initialize(attributes) # :nodoc:
|
12
|
+
set_instance_variables_from_hash(attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
protected :new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self._new(*args) # :nodoc:
|
20
|
+
self.new(*args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/braintree/version.rb
CHANGED
@@ -1,13 +1,34 @@
|
|
1
1
|
module Braintree
|
2
2
|
class VisaCheckoutCard
|
3
3
|
include BaseModule # :nodoc:
|
4
|
+
include Braintree::Util::TokenEquality
|
4
5
|
|
5
|
-
attr_reader :billing_address
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
attr_reader :billing_address
|
7
|
+
attr_reader :bin
|
8
|
+
attr_reader :call_id
|
9
|
+
attr_reader :card_type
|
10
|
+
attr_reader :cardholder_name
|
11
|
+
attr_reader :commercial
|
12
|
+
attr_reader :country_of_issuance
|
13
|
+
attr_reader :created_at
|
14
|
+
attr_reader :customer_id
|
15
|
+
attr_reader :customer_location
|
16
|
+
attr_reader :debit
|
17
|
+
attr_reader :durbin_regulated
|
18
|
+
attr_reader :expiration_month
|
19
|
+
attr_reader :expiration_year
|
20
|
+
attr_reader :healthcare
|
21
|
+
attr_reader :image_url
|
22
|
+
attr_reader :issuing_bank
|
23
|
+
attr_reader :last_4
|
24
|
+
attr_reader :payroll
|
25
|
+
attr_reader :prepaid
|
26
|
+
attr_reader :product_id
|
27
|
+
attr_reader :subscriptions
|
28
|
+
attr_reader :token
|
29
|
+
attr_reader :unique_number_identifier
|
30
|
+
attr_reader :updated_at
|
31
|
+
attr_reader :verification
|
11
32
|
|
12
33
|
def initialize(gateway, attributes) # :nodoc:
|
13
34
|
@gateway = gateway
|
@@ -18,7 +39,7 @@ module Braintree
|
|
18
39
|
end
|
19
40
|
|
20
41
|
def _most_recent_verification(attributes)
|
21
|
-
verification = (attributes[:verifications] || []).sort_by{ |verification| verification[:created_at] }.reverse.first
|
42
|
+
verification = (attributes[:verifications] || []).sort_by { |verification| verification[:created_at] }.reverse.first
|
22
43
|
CreditCardVerification._new(verification) if verification
|
23
44
|
end
|
24
45
|
|
@@ -48,11 +69,6 @@ module Braintree
|
|
48
69
|
"#{bin}******#{last_4}"
|
49
70
|
end
|
50
71
|
|
51
|
-
def ==(other)
|
52
|
-
return false unless other.is_a?(VisaCheckoutCard)
|
53
|
-
token == other.token
|
54
|
-
end
|
55
|
-
|
56
72
|
class << self
|
57
73
|
protected :new
|
58
74
|
end
|
@@ -68,7 +84,7 @@ module Braintree
|
|
68
84
|
end
|
69
85
|
|
70
86
|
def self._new(*args) # :nodoc:
|
71
|
-
self.new
|
87
|
+
self.new(*args)
|
72
88
|
end
|
73
89
|
end
|
74
90
|
end
|
@@ -1,18 +1,49 @@
|
|
1
|
-
require
|
1
|
+
require "ostruct"
|
2
2
|
|
3
3
|
module Braintree
|
4
4
|
class WebhookNotification
|
5
5
|
include BaseModule
|
6
6
|
|
7
7
|
module Kind
|
8
|
+
|
9
|
+
AccountUpdaterDailyReport = "account_updater_daily_report"
|
10
|
+
|
8
11
|
Check = "check"
|
9
12
|
|
13
|
+
ConnectedMerchantPayPalStatusChanged = "connected_merchant_paypal_status_changed"
|
14
|
+
ConnectedMerchantStatusTransitioned = "connected_merchant_status_transitioned"
|
10
15
|
Disbursement = "disbursement"
|
11
16
|
DisbursementException = "disbursement_exception"
|
12
17
|
|
13
18
|
DisputeOpened = "dispute_opened"
|
14
19
|
DisputeLost = "dispute_lost"
|
15
20
|
DisputeWon = "dispute_won"
|
21
|
+
DisputeAccepted = "dispute_accepted"
|
22
|
+
DisputeAutoAccepted = "dispute_auto_accepted"
|
23
|
+
DisputeDisputed = "dispute_disputed"
|
24
|
+
DisputeExpired = "dispute_expired"
|
25
|
+
|
26
|
+
GrantedPaymentInstrumentRevoked = "granted_payment_instrument_revoked"
|
27
|
+
|
28
|
+
GrantorUpdatedGrantedPaymentMethod = "grantor_updated_granted_payment_method"
|
29
|
+
GrantedPaymentMethodRevoked = "granted_payment_method_revoked"
|
30
|
+
|
31
|
+
LocalPaymentCompleted = "local_payment_completed"
|
32
|
+
LocalPaymentExpired = "local_payment_expired"
|
33
|
+
LocalPaymentFunded = "local_payment_funded"
|
34
|
+
LocalPaymentReversed = "local_payment_reversed"
|
35
|
+
|
36
|
+
OAuthAccessRevoked = "oauth_access_revoked"
|
37
|
+
|
38
|
+
PartnerMerchantConnected = "partner_merchant_connected"
|
39
|
+
PartnerMerchantDisconnected = "partner_merchant_disconnected"
|
40
|
+
PartnerMerchantDeclined = "partner_merchant_declined"
|
41
|
+
|
42
|
+
PaymentMethodCustomerDataUpdated = "payment_method_customer_data_updated"
|
43
|
+
|
44
|
+
PaymentMethodRevokedByCustomer = "payment_method_revoked_by_customer"
|
45
|
+
|
46
|
+
RecipientUpdatedGrantedPaymentMethod = "recipient_updated_granted_payment_method"
|
16
47
|
|
17
48
|
SubscriptionCanceled = "subscription_canceled"
|
18
49
|
SubscriptionChargedSuccessfully = "subscription_charged_successfully"
|
@@ -24,40 +55,40 @@ module Braintree
|
|
24
55
|
|
25
56
|
SubMerchantAccountApproved = "sub_merchant_account_approved"
|
26
57
|
SubMerchantAccountDeclined = "sub_merchant_account_declined"
|
58
|
+
|
27
59
|
TransactionDisbursed = "transaction_disbursed"
|
60
|
+
TransactionReviewed = "transaction_reviewed"
|
28
61
|
TransactionSettlementDeclined = "transaction_settlement_declined"
|
29
62
|
TransactionSettled = "transaction_settled"
|
30
|
-
PartnerMerchantConnected = "partner_merchant_connected"
|
31
|
-
PartnerMerchantDisconnected = "partner_merchant_disconnected"
|
32
|
-
PartnerMerchantDeclined = "partner_merchant_declined"
|
33
|
-
|
34
|
-
AccountUpdaterDailyReport = "account_updater_daily_report"
|
35
|
-
|
36
|
-
IdealPaymentComplete = "ideal_payment_complete"
|
37
|
-
IdealPaymentFailed = "ideal_payment_failed"
|
38
|
-
|
39
|
-
ConnectedMerchantStatusTransitioned = "connected_merchant_status_transitioned"
|
40
|
-
ConnectedMerchantPayPalStatusChanged = "connected_merchant_paypal_status_changed"
|
41
63
|
end
|
42
64
|
|
43
|
-
attr_reader :
|
65
|
+
attr_reader :account_updater_daily_report
|
66
|
+
attr_reader :connected_merchant_paypal_status_changed
|
67
|
+
attr_reader :connected_merchant_status_transitioned
|
68
|
+
attr_reader :disbursement
|
69
|
+
attr_reader :dispute
|
70
|
+
attr_reader :granted_payment_instrument_update
|
71
|
+
attr_reader :revoked_payment_method_metadata
|
44
72
|
attr_reader :kind
|
73
|
+
attr_reader :local_payment_completed
|
74
|
+
attr_reader :local_payment_expired
|
75
|
+
attr_reader :local_payment_funded
|
76
|
+
attr_reader :local_payment_reversed
|
77
|
+
attr_reader :oauth_access_revocation
|
78
|
+
attr_reader :partner_merchant
|
79
|
+
attr_reader :payment_method_customer_data_updated_metadata
|
80
|
+
attr_reader :source_merchant_id
|
81
|
+
attr_reader :subscription
|
45
82
|
attr_reader :timestamp
|
46
83
|
attr_reader :transaction
|
47
|
-
attr_reader :
|
48
|
-
attr_reader :disbursement
|
49
|
-
attr_reader :dispute
|
50
|
-
attr_reader :account_updater_daily_report
|
51
|
-
attr_reader :ideal_payment
|
52
|
-
attr_reader :connected_merchant_status_transitioned
|
53
|
-
attr_reader :connected_merchant_paypal_status_changed
|
84
|
+
attr_reader :transaction_review
|
54
85
|
|
55
|
-
def self.parse(
|
56
|
-
Configuration.gateway.webhook_notification.parse(
|
86
|
+
def self.parse(*args)
|
87
|
+
Configuration.gateway.webhook_notification.parse(*args)
|
57
88
|
end
|
58
89
|
|
59
|
-
def self.verify(
|
60
|
-
Configuration.gateway.webhook_notification.verify(
|
90
|
+
def self.verify(*args)
|
91
|
+
Configuration.gateway.webhook_notification.verify(*args)
|
61
92
|
end
|
62
93
|
|
63
94
|
def initialize(gateway, attributes) # :nodoc:
|
@@ -66,14 +97,23 @@ module Braintree
|
|
66
97
|
@error_result = ErrorResult.new(gateway, @subject[:api_error_response]) if @subject.has_key?(:api_error_response)
|
67
98
|
@merchant_account = MerchantAccount._new(gateway, @subject[:merchant_account]) if @subject.has_key?(:merchant_account)
|
68
99
|
@partner_merchant = OpenStruct.new(@subject[:partner_merchant]) if @subject.has_key?(:partner_merchant)
|
100
|
+
@oauth_access_revocation = OpenStruct.new(@subject[:oauth_application_revocation]) if @subject.has_key?(:oauth_application_revocation)
|
69
101
|
@subscription = Subscription._new(gateway, @subject[:subscription]) if @subject.has_key?(:subscription)
|
70
102
|
@transaction = Transaction._new(gateway, @subject[:transaction]) if @subject.has_key?(:transaction)
|
103
|
+
@transaction_review = OpenStruct.new(@subject[:transaction_review]) if @subject.has_key?(:transaction_review)
|
71
104
|
@disbursement = Disbursement._new(gateway, @subject[:disbursement]) if @subject.has_key?(:disbursement)
|
72
105
|
@dispute = Dispute._new(@subject[:dispute]) if @subject.has_key?(:dispute)
|
73
106
|
@account_updater_daily_report = AccountUpdaterDailyReport._new(@subject[:account_updater_daily_report]) if @subject.has_key?(:account_updater_daily_report)
|
74
|
-
@ideal_payment = Braintree::IdealPayment._new(gateway, @subject[:ideal_payment]) if @subject.has_key?(:ideal_payment)
|
75
107
|
@connected_merchant_status_transitioned = ConnectedMerchantStatusTransitioned._new(@subject[:connected_merchant_status_transitioned]) if @subject.has_key?(:connected_merchant_status_transitioned)
|
76
108
|
@connected_merchant_paypal_status_changed = ConnectedMerchantPayPalStatusChanged._new(@subject[:connected_merchant_paypal_status_changed]) if @subject.has_key?(:connected_merchant_paypal_status_changed)
|
109
|
+
@granted_payment_instrument_update = GrantedPaymentInstrumentUpdate._new(@subject[:granted_payment_instrument_update]) if @subject.has_key?(:granted_payment_instrument_update)
|
110
|
+
@revoked_payment_method_metadata = RevokedPaymentMethodMetadata._new(gateway, @subject) if [Kind::GrantedPaymentInstrumentRevoked, Kind::PaymentMethodRevokedByCustomer, Kind::GrantedPaymentMethodRevoked].include?(@kind)
|
111
|
+
@local_payment_completed = LocalPaymentCompleted._new(@subject[:local_payment]) if @subject.has_key?(:local_payment) && Kind::LocalPaymentCompleted == @kind
|
112
|
+
@local_payment_expired = LocalPaymentExpired._new(@subject[:local_payment_expired]) if @subject.has_key?(:local_payment_expired) && Kind::LocalPaymentExpired == @kind
|
113
|
+
@local_payment_funded = LocalPaymentFunded._new(@subject[:local_payment_funded]) if @subject.has_key?(:local_payment_funded) && Kind::LocalPaymentFunded == @kind
|
114
|
+
@local_payment_reversed = LocalPaymentReversed._new(@subject[:local_payment_reversed]) if @subject.has_key?(:local_payment_reversed) && Kind::LocalPaymentReversed == @kind
|
115
|
+
@payment_method_customer_data_updated_metadata = PaymentMethodCustomerDataUpdatedMetadata._new(gateway, @subject[:payment_method_customer_data_updated_metadata]) if @subject.has_key?(:payment_method_customer_data_updated_metadata) && Kind::PaymentMethodCustomerDataUpdated == @kind
|
116
|
+
|
77
117
|
end
|
78
118
|
|
79
119
|
def merchant_account
|
@@ -95,7 +135,7 @@ module Braintree
|
|
95
135
|
class << self
|
96
136
|
protected :new
|
97
137
|
def _new(*args) # :nodoc:
|
98
|
-
self.new
|
138
|
+
self.new(*args)
|
99
139
|
end
|
100
140
|
end
|
101
141
|
end
|
@@ -7,6 +7,8 @@ module Braintree
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def parse(signature_string, payload)
|
10
|
+
raise InvalidSignature, "signature cannot be nil" if signature_string.nil?
|
11
|
+
raise InvalidSignature, "payload cannot be nil" if payload.nil?
|
10
12
|
if payload =~ /[^A-Za-z0-9+=\/\n]/
|
11
13
|
raise InvalidSignature, "payload contains illegal characters"
|
12
14
|
end
|
@@ -16,7 +18,7 @@ module Braintree
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def verify(challenge)
|
19
|
-
raise InvalidChallenge,
|
21
|
+
raise InvalidChallenge, "challenge contains non-hex characters" unless challenge =~ /\A[a-f0-9]{20,32}\z/
|
20
22
|
digest = Braintree::Digest.hexdigest(@config.private_key, challenge)
|
21
23
|
"#{@config.public_key}|#{digest}"
|
22
24
|
end
|
@@ -32,13 +34,13 @@ module Braintree
|
|
32
34
|
|
33
35
|
def _verify_signature(signature_string, payload)
|
34
36
|
public_key, signature = _matching_signature_pair(signature_string)
|
35
|
-
raise InvalidSignature,
|
37
|
+
raise InvalidSignature, "no matching public key" if public_key.nil?
|
36
38
|
|
37
39
|
signature_matches = [payload, payload + "\n"].any? do |payload|
|
38
40
|
payload_signature = Braintree::Digest.hexdigest(@config.private_key, payload)
|
39
41
|
Braintree::Digest.secure_compare(signature, payload_signature)
|
40
42
|
end
|
41
|
-
raise InvalidSignature,
|
43
|
+
raise InvalidSignature, "signature does not match payload - one has been modified" unless signature_matches
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Braintree
|
2
2
|
class WebhookTesting # :nodoc:
|
3
|
-
def self.sample_notification(
|
4
|
-
Configuration.gateway.webhook_testing.sample_notification(
|
3
|
+
def self.sample_notification(*args)
|
4
|
+
Configuration.gateway.webhook_testing.sample_notification(*args)
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|