diff --git a/CHANGELOG.md b/CHANGELOG.md index 61aefc9..2283d17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Unreleased +* Fix missing deprecation warnings import causing payment method creation and updates with legacy fields to raise `NameError` + ## 4.47.0 * Fix path traversal vulnerability in `CreditCard`, `CreditCardVerification`, `Customer`, `MerchantAccount`, `PayPalAccount`, `PaymentMethod`, `PaymentMethodNonce`, `Plan`, `SepaDirectDebitAccount`, `Subscription`, `Testing`, `Transaction`, `TransactionLineItem`, `UsBankAccount`, and `UsBankAccountVerification` gateways by validating that IDs used in request paths do not contain path separators or relative-path segments * Add `ach_type` to transaction search diff --git a/braintree/payment_method_gateway.py b/braintree/payment_method_gateway.py index 66094e1..8d09811 100644 --- a/braintree/payment_method_gateway.py +++ b/braintree/payment_method_gateway.py @@ -27,6 +27,7 @@ from braintree.util.validation import is_invalid_path_segment import sys +import warnings from urllib.parse import urlencode diff --git a/tests/unit/test_payment_method_gateway.py b/tests/unit/test_payment_method_gateway.py index 445a70b..205848c 100644 --- a/tests/unit/test_payment_method_gateway.py +++ b/tests/unit/test_payment_method_gateway.py @@ -214,3 +214,35 @@ def setup_payment_method_gateway_and_mock_http(self): http_mock = MagicMock(name='config.http.delete') braintree_gateway.config.http = http_mock return payment_method_gateway, http_mock + + +class TestPaymentMethodGatewayDeprecation(unittest.TestCase): + def test_create_with_deprecated_device_session_id(self): + gateway = PaymentMethodGateway(BraintreeGateway(Configuration.instantiate())) + gateway._post = MagicMock() + params = {"device_session_id": "legacy-session"} + + with self.assertWarnsRegex(DeprecationWarning, "device_session_id is deprecated"): + result = gateway.create(params) + + gateway._post.assert_called_once_with("/payment_methods", {"payment_method": params}) + self.assertIs(result, gateway._post.return_value) + + def test_update_with_deprecated_attributes(self): + cases = [ + ("device_session_id", "device_session_id is deprecated"), + ("fraud_merchant_id", "fraud_merchant_id is deprecated"), + ("venmo_sdk_payment_method_code", "The Venmo SDK integration is Unsupported"), + ] + for attribute, message in cases: + with self.subTest(attribute=attribute): + gateway = PaymentMethodGateway(BraintreeGateway(Configuration.instantiate())) + gateway._put = MagicMock() + params = {attribute: "legacy-value"} + + with self.assertWarnsRegex(DeprecationWarning, message): + result = gateway.update("some_token", params) + + gateway._put.assert_called_once_with( + "/payment_methods/any/some_token", {"payment_method": params}) + self.assertIs(result, gateway._put.return_value)