Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix Duplicate Customer Creation in Gateway (#7357)
Farook Ibrahimf182bc3cd5d9
diff --git a/saleor/checkout/complete_checkout.py b/saleor/checkout/complete_checkout.pyindex 976b3df222..2c23ec599a 100644--- a/saleor/checkout/complete_checkout.py+++ b/saleor/checkout/complete_checkout.py@@ -33,7 +33,7 @@ from ..order.models import Order, OrderLinefrom ..order.notifications import send_order_confirmationfrom ..payment import PaymentError, gatewayfrom ..payment.models import Payment, Transaction-from ..payment.utils import store_customer_id+from ..payment.utils import fetch_customer_id, store_customer_idfrom ..product.models import ProductTranslation, ProductVariantTranslationfrom ..warehouse.availability import check_stock_quantity_bulkfrom ..warehouse.management import allocate_stocks@@ -513,6 +513,7 @@ def _get_order_data(def _process_payment(payment: Payment,+ customer_id: Optional[str],store_source: bool,payment_data: Optional[dict],order_data: dict,@@ -533,6 +534,7 @@ def _process_payment(payment=payment,token=payment.token,manager=manager,+ customer_id=customer_id,store_source=store_source,additional_data=payment_data,channel_slug=channel_slug,@@ -583,8 +585,13 @@ def complete_checkout(gateway.payment_refund_or_void(payment, manager, channel_slug=channel_slug)raise exc+ customer_id = None+ if store_source and payment:+ customer_id = fetch_customer_id(user=user, gateway=payment.gateway)+txn = _process_payment(payment=payment, # type: ignore+ customer_id=customer_id,store_source=store_source,payment_data=payment_data,order_data=order_data,diff --git a/saleor/payment/gateway.py b/saleor/payment/gateway.pyindex 169b50df4b..7f90a5e88a 100644--- a/saleor/payment/gateway.py+++ b/saleor/payment/gateway.py@@ -75,12 +75,14 @@ def process_payment(token: str,manager: "PluginsManager",channel_slug: str,+ customer_id: str = None,store_source: bool = False,additional_data: Optional[dict] = None,) -> Transaction:payment_data = create_payment_information(payment=payment,payment_token=token,+ customer_id=customer_id,store_source=store_source,additional_data=additional_data,)@@ -113,12 +115,14 @@ def authorize(token: str,manager: "PluginsManager",channel_slug: str,+ customer_id: str = None,store_source: bool = False,) -> Transaction:clean_authorize(payment)payment_data = create_payment_information(payment=payment,payment_token=token,+ customer_id=customer_id,store_source=store_source,)response, error = _fetch_gateway_response(@@ -148,6 +152,7 @@ def capture(manager: "PluginsManager",channel_slug: str,amount: Decimal = None,+ customer_id: str = None,store_source: bool = False,) -> Transaction:if amount is None:@@ -155,7 +160,11 @@ def capture(clean_capture(payment, Decimal(amount))token = _get_past_transaction_token(payment, TransactionKind.AUTH)payment_data = create_payment_information(- payment=payment, payment_token=token, amount=amount, store_source=store_source+ payment=payment,+ payment_token=token,+ amount=amount,+ customer_id=customer_id,+ store_source=store_source,)response, error = _fetch_gateway_response(manager.capture_payment,