Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix braintree tests
Jakub Draganek6a687c7e9de4
diff --git a/saleor/payment/gateways/braintree/__init__.py b/saleor/payment/gateways/braintree/__init__.pyindex 29fc43a8c5..a435625a18 100644--- a/saleor/payment/gateways/braintree/__init__.py+++ b/saleor/payment/gateways/braintree/__init__.py@@ -75,8 +75,12 @@ def extract_gateway_response(braintree_result) -> Dict:{"code": error.code, "message": error.message}for error in braintree_result.errors.deep_errors]+ customer_id = Nonebt_transaction = braintree_result.transaction+ if hasattr(bt_transaction, "customer"):+ customer_id = bt_transaction.id+if not bt_transaction:return {"errors": errors}return {@@ -84,7 +88,7 @@ def extract_gateway_response(braintree_result) -> Dict:"currency": bt_transaction.currency_iso_code,"amount": bt_transaction.amount, # Decimal type"credit_card": bt_transaction.credit_card,- "customer_id": bt_transaction.customer.id, # TODO: check if exists always+ "customer_id": customer_id,"errors": errors,}@@ -110,11 +114,12 @@ def get_braintree_gateway(sandbox_mode, merchant_id, public_key, private_key):return gateway-def get_client_token(config: GatewayConfig, token_config: TokenConfig) -> str:+def get_client_token(config: GatewayConfig, token_config: TokenConfig = None) -> str:gateway = get_braintree_gateway(**config.connection_params)+ if not token_config:+ return gateway.client_token.generate()parameters = create_token_params(token_config)- client_token = gateway.client_token.generate(parameters)- return client_token+ return gateway.client_token.generate(parameters)def create_token_params(token_config: TokenConfig) -> dict:diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 00bd59c23f..2a94ee5904 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -235,10 +235,12 @@ def create_transaction(return txn-def gateway_get_client_token(gateway_name: str, token_config: TokenConfig):+def gateway_get_client_token(gateway_name: str, token_config: TokenConfig = None):"""Gets client token, that will be used as a customer's identificator forclient-side tokenization of the chosen payment method."""+ if not token_config:+ token_config = TokenConfig()gateway, gateway_config = get_payment_gateway(gateway_name)return gateway.get_client_token(config=gateway_config, token_config=token_config)@@ -280,7 +282,7 @@ def call_gateway(operation_type, payment, payment_token, **extra_params):error_msg = Nonepayment_information = create_payment_information(- payment, payment_token, customer_id, **extra_params+ payment, payment_token, **extra_params)try:diff --git a/tests/gateway/test_braintree.py b/tests/gateway/test_braintree.pyindex 9363f14539..ea5285e5f5 100644--- a/tests/gateway/test_braintree.py+++ b/tests/gateway/test_braintree.py@@ -163,6 +163,7 @@ def test_extract_gateway_response(braintree_success_response):"credit_card": t.credit_card,"errors": [],"transaction_id": t.id,+ "customer_id": None,}assert result == expected_result@@ -303,6 +304,7 @@ def test_authorize("amount": str(payment.total),"payment_method_nonce": "auth-token","options": {+ "store_in_vault_on_success": False,"submit_for_settlement": CONFIRM_MANUALLY,"three_d_secure": {"required": THREE_D_SECURE_REQUIRED},},