Skip to content

Commit

Permalink
4.26.0
Browse files Browse the repository at this point in the history
Co-authored-by: Iris Booker <iris.booker@getbraintree.com>
Co-authored-by: Sara Vasquez <saravasquez@paypal.com>
  • Loading branch information
3 people committed Jan 9, 2024
1 parent c379eba commit 282cb0d
Show file tree
Hide file tree
Showing 19 changed files with 450 additions and 52 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 4.26.0
* Remove usage of standard library deprecated `cgi` module. _Note: this will break integrations on versions of Python below 3.2. However, this is NOT a breaking change to this library, due to our current support of Python 3.5+._
* Add `PackageDetails` class.
* Add `packages` to `Transaction` attributes.
* Add `package_tracking` method to `TransactionGateway` to make request to add tracking information to transactions.
* Add `process_debit_as_credit` to `credit_card` field in `options` field during Transaction create.
* Deprecate `three_d_secure_token` in favor of `three_d_secure_authentication_id`
* Add `upc_code`, `upc_type`, and `image_url` to `line_items` in `transaction`
* Deprecate `venmo_sdk_session` and `venmo_sdk_payment_method_code`

## 4.25.0
* Add `PickupInStore` to `ShippingMethod` enum
* Add `external_vault` and `risk_data` to `CreditCardVerification.create` request
Expand Down
6 changes: 1 addition & 5 deletions braintree/apple_pay_gateway.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
try:
from html import escape
except ImportError:
from cgi import escape

from html import escape
from braintree.apple_pay_options import ApplePayOptions
from braintree.error_result import ErrorResult
from braintree.successful_result import SuccessfulResult
Expand Down
4 changes: 2 additions & 2 deletions braintree/credit_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def signature(type):
"fail_on_duplicate_payment_method",
"make_default",
"skip_advanced_fraud_checking",
"venmo_sdk_session",
"venmo_sdk_session", # NEXT_MJOR_VERSION remove venmo_sdk_session
"verification_account_type",
"verification_amount",
"verification_merchant_account_id",
Expand Down Expand Up @@ -268,7 +268,7 @@ def signature(type):
"expiration_year",
"number",
"token",
"venmo_sdk_payment_method_code",
"venmo_sdk_payment_method_code", # NEXT_MJOR_VERSION remove venmo_sdk_payment_method_code
"device_data",
"payment_method_nonce",
"device_session_id", "fraud_merchant_id", # NEXT_MAJOR_VERSION remove device_session_id and fraud_merchant_id
Expand Down
3 changes: 3 additions & 0 deletions braintree/credit_card_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ def _post(self, url, params=None):
elif "api_error_response" in response:
return ErrorResult(self.gateway, response["api_error_response"])

# NEXT_MAJOR_VERSION remove these checks when the attributes are removed
def __check_for_deprecated_attributes(self, params):
if "device_session_id" in params.keys():
warnings.warn("device_session_id is deprecated, use device_data parameter instead", DeprecationWarning)
if "fraud_merchant_id" in params.keys():
warnings.warn("fraud_merchant_id is deprecated, use device_data parameter instead", DeprecationWarning)
if "venmo_sdk_payment_method_code" in params.keys() or "venmo_sdk_session" in params.keys():
warnings.warn("The Venmo SDK integration is Unsupported. Please update your integration to use Pay with Venmo instead.", DeprecationWarning)
20 changes: 12 additions & 8 deletions braintree/error_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CreditCard(object):
ExpirationMonthIsInvalid = "81712"
ExpirationYearIsInvalid = "81713"
InvalidParamsForCreditCardUpdate = "91745"
InvalidVenmoSDKPaymentMethodCode = "91727"
InvalidVenmoSDKPaymentMethodCode = "91727" # NEXT_MJOR_VERSION remove this code
NumberHasInvalidLength = NumberLengthIsInvalid = "81716"
NumberIsInvalid = "81715"
NumberIsProhibited = "81750"
Expand All @@ -129,7 +129,7 @@ class CreditCard(object):
TokenIsNotAllowed = "91721"
TokenIsRequired = "91722"
TokenIsTooLong = "91720"
VenmoSDKPaymentMethodCodeCardTypeIsNotAccepted = "91726"
VenmoSDKPaymentMethodCodeCardTypeIsNotAccepted = "91726" # NEXT_MJOR_VERSION remove this code
VerificationNotSupportedOnThisMerchantAccount = "91730"
VerificationAccountTypeIsInvald = "91757"
VerificationAccountTypeNotSupported = "91758"
Expand Down Expand Up @@ -558,7 +558,7 @@ class Transaction(object):
PaymentInstrumentTypeIsNotAccepted = "915101"
PaymentInstrumentWithExternalVaultIsInvalid = "915176"
PaymentMethodConflict = "91515"
PaymentMethodConflictWithVenmoSDK = "91549"
PaymentMethodConflictWithVenmoSDK = "91549" # NEXT_MJOR_VERSION remove this code
PaymentMethodDoesNotBelongToCustomer = "91516"
PaymentMethodDoesNotBelongToSubscription = "91527"
PaymentMethodNonceCardTypeIsNotAccepted = "91567"
Expand Down Expand Up @@ -740,9 +740,9 @@ class AdditionalCharge(object):
class LineItem(object):
CommodityCodeIsTooLong = "95801"
DescriptionIsTooLong = "95803"
DiscountAmountCannotBeNegative = "95806"
DiscountAmountFormatIsInvalid = "95804"
DiscountAmountIsTooLarge = "95805"
DiscountAmountCannotBeNegative = "95806"
KindIsInvalid = "95807"
KindIsRequired = "95808"
NameIsRequired = "95822"
Expand All @@ -751,21 +751,25 @@ class LineItem(object):
QuantityFormatIsInvalid = "95810"
QuantityIsRequired = "95811"
QuantityIsTooLarge = "95812"
TaxAmountCannotBeNegative = "95829"
TaxAmountFormatIsInvalid = "95827"
TaxAmountIsTooLarge = "95828"
TotalAmountFormatIsInvalid = "95813"
TotalAmountIsRequired = "95814"
TotalAmountIsTooLarge = "95815"
TotalAmountMustBeGreaterThanZero = "95816"
UPCCodeIsMissing = "95830"
UPCCodeIsTooLong = "95831"
UPCTypeIsInvalid = "95833"
UPCTypeIsMissing = "95832"
UnitAmountFormatIsInvalid = "95817"
UnitAmountIsRequired = "95818"
UnitAmountIsTooLarge = "95819"
UnitAmountMustBeGreaterThanZero = "95820"
UnitOfMeasureIsTooLarge = "95821"
UnitTaxAmountCannotBeNegative = "95826"
UnitTaxAmountFormatIsInvalid = "95824"
UnitTaxAmountIsTooLarge = "95825"
UnitTaxAmountCannotBeNegative = "95826"
TaxAmountFormatIsInvalid = "95827"
TaxAmountIsTooLarge = "95828"
TaxAmountCannotBeNegative = "95829"

class UsBankAccountVerification(object):
NotConfirmable = "96101"
Expand Down
25 changes: 25 additions & 0 deletions braintree/package_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from braintree.attribute_getter import AttributeGetter

class PackageDetails(AttributeGetter):
"""
A class representing the package tracking information of a transaction.
An example of package details including all available fields::
result = braintree.PackageDetails.create({
"id": "my_id",
"carrier": "a_carrier",
"tracking_number": "my_tracking_number",
"paypal_tracking_id": "my_paypal_tracking_id",
})
"""
detail_list = [
"id",
"carrier",
"tracking_number",
"paypal_tracking_id",
]

def __init__(self, attributes):
AttributeGetter.__init__(self, attributes)
4 changes: 2 additions & 2 deletions braintree/payment_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ def update_signature():
"number",
"payment_method_nonce",
"token",
"venmo_sdk_payment_method_code",
"venmo_sdk_payment_method_code", # NEXT_MJOR_VERSION remove venmo_sdk_payment_method_code
"device_session_id", "fraud_merchant_id", # NEXT_MAJOR_VERSION remove device_session_id and fraud_merchant_id
{
"options": [
"make_default",
"skip_advanced_fraud_checking",
"us_bank_account_verification_method",
"venmo_sdk_session",
"venmo_sdk_session", # NEXT_MJOR_VERSION remove venmo_sdk_session
"verification_account_type",
"verification_add_ons",
"verification_amount",
Expand Down
3 changes: 3 additions & 0 deletions braintree/payment_method_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ def _parse_payment_method_nonce(self, response):
return PaymentMethodNonce(self.gateway, response["payment_method_nonce"])
raise ValueError("payment_method_nonce not present in response")

# NEXT_MAJOR_VERSION remove these checks when the attributes are removed
def __check_for_deprecated_attributes(self, params):
if "device_session_id" in params.keys():
warnings.warn("device_session_id is deprecated, use device_data parameter instead", DeprecationWarning)
if "fraud_merchant_id" in params.keys():
warnings.warn("fraud_merchant_id is deprecated, use device_data parameter instead", DeprecationWarning)
if "venmo_sdk_payment_method_code" in params.keys() or "venmo_sdk_session" in params.keys():
warnings.warn("The Venmo SDK integration is Unsupported. Please update your integration to use Pay with Venmo instead.", DeprecationWarning)
44 changes: 38 additions & 6 deletions braintree/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from braintree.risk_data import RiskData
from braintree.samsung_pay_card import SamsungPayCard
from braintree.sepa_direct_debit_account import SepaDirectDebitAccount
from braintree.package_details import PackageDetails
from braintree.status_event import StatusEvent
from braintree.subscription_details import SubscriptionDetails
from braintree.successful_result import SuccessfulResult
Expand Down Expand Up @@ -132,6 +133,7 @@ def __repr__(self):
"network_response_text",
"network_transaction_id",
"order_id",
"packages",
"payment_instrument_type",
"payment_method_token",
"plan_id",
Expand Down Expand Up @@ -529,8 +531,9 @@ def create_signature():
"device_data", "billing_address_id", "payment_method_nonce", "product_sku", "tax_amount",
"shared_payment_method_token", "shared_customer_id", "shared_billing_address_id", "shared_shipping_address_id", "shared_payment_method_nonce",
"discount_amount", "shipping_amount", "ships_from_postal_code",
"tax_exempt", "three_d_secure_authentication_id", "three_d_secure_token", "type", "venmo_sdk_payment_method_code", "service_fee_amount",
"sca_exemption","exchange_rate_quote_id",
"tax_exempt", "three_d_secure_authentication_id", "three_d_secure_token", # NEXT_MAJOR_VERSION Remove three_d_secure_token
"type", "venmo_sdk_payment_method_code", # NEXT_MJOR_VERSION remove venmo_sdk_payment_method_code
"service_fee_amount", "sca_exemption","exchange_rate_quote_id",
"device_session_id", "fraud_merchant_id", # NEXT_MAJOR_VERSION remove device_session_id and fraud_merchant_id
{
"risk_data": [
Expand Down Expand Up @@ -582,15 +585,16 @@ def create_signature():
"store_in_vault_on_success",
"store_shipping_address_in_vault",
"submit_for_settlement",
"venmo_sdk_session",
"venmo_sdk_session", # NEXT_MJOR_VERSION remove venmo_sdk_session
"payee_id",
"payee_email",
"skip_advanced_fraud_checking",
"skip_avs",
"skip_cvv",
{
"credit_card": [
"account_type"
"account_type",
"process_debit_as_credit"
],
"paypal": [
"payee_id",
Expand Down Expand Up @@ -663,7 +667,7 @@ def create_signature():
},
{"line_items":
[
"quantity", "name", "description", "kind", "unit_amount", "unit_tax_amount", "total_amount", "discount_amount", "tax_amount", "unit_of_measure", "product_code", "commodity_code", "url",
"commodity_code", "description", "discount_amount", "image_url", "kind", "name", "product_code", "quantity", "tax_amount", "total_amount", "unit_amount", "unit_of_measure", "unit_tax_amount", "upc_code", "upc_type", "url",
]
},
{"apple_pay_card": ["number", "cardholder_name", "cryptogram", "expiration_month", "expiration_year", "eci_indicator"]},
Expand Down Expand Up @@ -708,7 +712,7 @@ def submit_for_settlement_signature():
},
{"line_items":
[
"quantity", "name", "description", "kind", "unit_amount", "unit_tax_amount", "total_amount", "discount_amount", "tax_amount", "unit_of_measure", "product_code", "commodity_code", "url",
"commodity_code", "description", "discount_amount", "image_url", "kind", "name", "product_code", "quantity", "tax_amount", "total_amount", "unit_amount", "unit_of_measure", "unit_tax_amount", "upc_code", "upc_type", "url,"
]
},
{"shipping":
Expand Down Expand Up @@ -743,6 +747,32 @@ def submit_for_settlement_signature():
},
]

@staticmethod
def package_tracking_signature():
return [ "carrier", "notify_payer", "tracking_number",
{ "line_items": [
"commodity_code", "description", "discount_amount", "image_url", "kind", "name",
"product_code", "quantity", "tax_amount", "total_amount", "unit_amount", "unit_of_measure",
"unit_tax_amount", "upc_code", "upc_type", "url"
]
},
]

@staticmethod
def package_tracking(transaction_id, params=None):
"""
Creates a request to send package tracking information for a transaction which has already submitted for settlement.
Requires the transaction id of the transaction and the package tracking request details::
result = braintree.Transaction.package_tracking("my_transaction_id", params )
"""
if params is None:
params = {}
return Configuration.gateway().transaction.package_tracking(transaction_id, params)


@staticmethod
def update_details_signature():
return ["amount", "order_id", {"descriptor": ["name", "phone", "url"]}]
Expand Down Expand Up @@ -779,6 +809,8 @@ def __init__(self, gateway, attributes):
self.billing_details = Address(gateway, attributes.pop("billing"))
if "credit_card" in attributes:
self.credit_card_details = CreditCard(gateway, attributes.pop("credit_card"))
if "shipments" in attributes:
self.packages = [PackageDetails(detail) for detail in self.shipments]
if "paypal" in attributes:
self.paypal_details = PayPalAccount(gateway, attributes.pop("paypal"))
if "paypal_here" in attributes:
Expand Down
20 changes: 20 additions & 0 deletions braintree/transaction_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ def submit_for_partial_settlement(self, transaction_id, amount, params=None):
elif "api_error_response" in response:
return ErrorResult(self.gateway, response["api_error_response"])

def package_tracking(self, transaction_id, params=None):
try:
if params is None:
params = {}
if transaction_id is None or transaction_id.strip() == "":
raise NotFoundError()
Resource.verify_keys(params, Transaction.package_tracking_signature())
response = self.config.http().post(self.config.base_merchant_path() + "/transactions/" + transaction_id + "/shipments", {"shipment": params})
if "transaction" in response:
return SuccessfulResult({"transaction": Transaction(self.gateway, response["transaction"])})
elif "api_error_response" in response:
return ErrorResult(self.gateway, response["api_error_response"])
except NotFoundError:
raise NotFoundError("transaction with id " + repr(transaction_id) + " not found")

def void(self, transaction_id):
response = self.config.http().put(self.config.base_merchant_path() + "/transactions/" + transaction_id + "/void")
if "transaction" in response:
Expand Down Expand Up @@ -179,8 +194,13 @@ def _post(self, url, params=None):
elif "api_error_response" in response:
return ErrorResult(self.gateway, response["api_error_response"])

# NEXT_MAJOR_VERSION remove these checks when the attributes are removed
def __check_for_deprecated_attributes(self, params):
if "device_session_id" in params.keys():
warnings.warn("device_session_id is deprecated, use device_data parameter instead", DeprecationWarning)
if "fraud_merchant_id" in params.keys():
warnings.warn("fraud_merchant_id is deprecated, use device_data parameter instead", DeprecationWarning)
if "three_d_secure_token" in params.keys():
warnings.warn("three_d_secure_token is deprecated, use three_d_secure_authentication_id parameter instead", DeprecationWarning)
if "venmo_sdk_payment_method_code" in params.keys() or "venmo_sdk_session" in params.keys():
warnings.warn("The Venmo SDK integration is Unsupported. Please update your integration to use Pay with Venmo instead.", DeprecationWarning)
2 changes: 1 addition & 1 deletion braintree/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Version = "4.25.0"
Version = "4.26.0"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="braintree",
version="4.25.0",
version="4.26.0",
description="Braintree Python Library",
long_description=long_description,
author="Braintree",
Expand Down
Loading

0 comments on commit 282cb0d

Please sign in to comment.