Skip to content

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

Store customer id in user private meta

Jakub Draganek94f799cb04a1
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 7f870d8244..c662af98da 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -28,7 +28,7 @@ from ...core.taxes.interface import calculate_checkout_subtotal
from ...discount import models as voucher_model
from ...payment import PaymentError
from ...payment.interface import AddressData
-from ...payment.utils import gateway_process_payment
+from ...payment.utils import gateway_process_payment, store_id_for_payment_gateway
from ...shipping.models import ShippingMethod as ShippingMethodModel
from ..account.i18n import I18nMixin
from ..account.types import AddressInput, User
@@ -507,13 +507,19 @@ class CheckoutComplete(BaseMutation):
try:
billing_address = order_data["billing_address"] # type: models.Address
shipping_address = order_data["shipping_address"] # type: models.Address
- gateway_process_payment(
+ trs = gateway_process_payment(
payment=payment,
payment_token=payment.token,
billing_address=AddressData(**billing_address.as_data()),
shipping_address=AddressData(**shipping_address.as_data()),
store_source=store_source,
)
+ if trs.is_success and trs.customer_id:
+ user = info.context.user
+ if user:
+ gateway = payment.gateway
+ store_id_for_payment_gateway(user, gateway, trs.customer_id)
+
except PaymentError as e:
abort_order_data(order_data)
raise ValidationError(str(e))
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.py
index 4fe320724a..f47ddf1160 100644
--- a/saleor/payment/utils.py
+++ b/saleor/payment/utils.py
@@ -232,6 +232,7 @@ def create_transaction(
amount=gateway_response.amount,
currency=gateway_response.currency,
error=gateway_response.error,
+ customer_id=gateway_response.customer_id,
gateway_response=gateway_response.raw_response or {},
)
return txn