Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use existing customer when provided for Braintree transaction

Jakub Draganekc315e4e2ce97
diff --git a/saleor/payment/gateways/braintree/__init__.py b/saleor/payment/gateways/braintree/__init__.py
index ac31dd77f5..11a691c11a 100644
--- a/saleor/payment/gateways/braintree/__init__.py
+++ b/saleor/payment/gateways/braintree/__init__.py
@@ -120,7 +120,10 @@ def authorize(
payment_information: PaymentData, config: GatewayConfig
) -> GatewayResponse:
try:
- result = transaction_for_new_customer(payment_information, config)
+ if not payment_information.customer_id:
+ result = transaction_for_new_customer(payment_information, config)
+ else:
+ result = transaction_for_existing_customer(payment_information, config)
except braintree_sdk.exceptions.NotFoundError:
raise BraintreeException(DEFAULT_ERROR_MESSAGE)
@@ -156,6 +159,16 @@ def transaction_for_new_customer(payment_information: PaymentData, config: Gatew
)
+def transaction_for_existing_customer(payment_information: PaymentData, config: GatewayConfig):
+ gateway = get_braintree_gateway(**config.connection_params)
+ return gateway.transaction.sale(
+ {
+ "amount": str(payment_information.amount),
+ "customer_id": payment_information.customer_id,
+ }
+ )
+
+
def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:
gateway = get_braintree_gateway(**config.connection_params)