Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix passing incorrect email to payment gateway (#7486)
Maciej Korycinskib2622810adf1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex da03d0af8f..0c201e6bd5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -261,6 +261,7 @@ All notable, unreleased changes to this project will be documented in this file.- Return empty results when filtering by non-existing attribute - #7025 by @maarcingebala- Add new authorization header `Authorization-Bearer` - #6998 by @korycins- Add field `paymentMethodType` to `Payment` object - #7073 by @korycins+- Fix passing incorrect customer email to payment gateways - #7486 by @korycins# 2.11.1diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex c60933da05..6b4a2727ac 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -560,7 +560,8 @@ class CheckoutCustomerAttach(BaseMutation):)checkout.user = info.context.user- checkout.save(update_fields=["user", "last_change"])+ checkout.email = info.context.user.email+ checkout.save(update_fields=["email", "user", "last_change"])info.context.plugins.checkout_updated(checkout)return CheckoutCustomerAttach(checkout=checkout)diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex 48d445a5b4..8726e90d73 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -2076,6 +2076,8 @@ def test_checkout_customer_attach(api_client, user_api_client, checkout_with_item, customer_user):checkout = checkout_with_item+ checkout.email = "[email protected]"+ checkout.save()assert checkout.user is Nonequery = """@@ -2106,6 +2108,7 @@ def test_checkout_customer_attach(assert not data["errors"]checkout.refresh_from_db()assert checkout.user == customer_user+ assert checkout.email == customer_user.emailMUTATION_CHECKOUT_CUSTOMER_DETACH = """diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex c5cf8634b2..e40452512e 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -169,7 +169,7 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):payment_token=data.get("token", ""),total=amount,currency=checkout.currency,- email=checkout.email,+ email=checkout.get_customer_email(),extra_data=extra_data,# FIXME this is not a customer IP address. It is a client storefront ipcustomer_ip_address=get_client_ip(info.context),diff --git a/saleor/graphql/payment/tests/test_payment.py b/saleor/graphql/payment/tests/test_payment.pyindex 849aea5d59..d3219ac935 100644--- a/saleor/graphql/payment/tests/test_payment.py+++ b/saleor/graphql/payment/tests/test_payment.py@@ -220,10 +220,12 @@ def test_checkout_add_payment_with_shipping_method_and_shipping_required(def test_checkout_add_payment(- user_api_client, checkout_without_shipping_required, address+ user_api_client, checkout_without_shipping_required, address, customer_user):checkout = checkout_without_shipping_requiredcheckout.billing_address = address+ checkout.email = "old@example"+ checkout.user = customer_usercheckout.save()checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)@@ -261,6 +263,7 @@ def test_checkout_add_payment(assert payment.billing_first_name == checkout.billing_address.first_nameassert payment.billing_last_name == checkout.billing_address.last_nameassert payment.return_url == return_url+ assert payment.billing_email == customer_user.emaildef test_checkout_add_payment_default_amount(diff --git a/saleor/payment/gateways/stripe/tests/test_utils.py b/saleor/payment/gateways/stripe/tests/test_utils.pyindex 56e3106e67..981eb54e93 100644--- a/saleor/payment/gateways/stripe/tests/test_utils.py+++ b/saleor/payment/gateways/stripe/tests/test_utils.py@@ -69,6 +69,18 @@ def test_get_payment_billing_fullname_no_billing(payment_dummy):assert get_payment_billing_fullname(payment_info) == ""+def test_get_payment_customer_email(payment_dummy, checkout, customer_user):+ checkout.user = customer_user+ checkout.email = "[email protected]"+ checkout.save()+ payment_dummy.order = None+ payment_dummy.checkout = checkout+ payment_dummy.save()++ payment_info = create_payment_information(payment_dummy)+ assert payment_info.customer_email == checkout.user.email++def test_shipping_address_to_stripe_dict(address):address_data = AddressData(**address.as_data())expected_address_dict = {diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 4026c40d01..61d9760df7 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -37,14 +37,17 @@ def create_payment_information(Returns information required to process payment and additionalbilling/shipping addresses for optional fraud-prevention mechanisms."""- if payment.checkout:- billing = payment.checkout.billing_address- shipping = payment.checkout.shipping_address+ checkout = payment.checkout+ if checkout:+ billing = checkout.billing_address+ shipping = checkout.shipping_address+ email = checkout.get_customer_email()elif payment.order:billing = payment.order.billing_addressshipping = payment.order.shipping_address+ email = payment.order.user_emailelse:- billing, shipping = None, None+ billing, shipping, email = None, None, payment.billing_emailbilling_address = AddressData(**billing.as_data()) if billing else Noneshipping_address = AddressData(**shipping.as_data()) if shipping else None@@ -64,7 +67,7 @@ def create_payment_information(graphql_payment_id=graphql_payment_id,customer_ip_address=payment.customer_ip_address,customer_id=customer_id,- customer_email=payment.billing_email,+ customer_email=email,reuse_source=store_source,data=additional_data or {},)