Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extend checkout complete mutation with flag to store source
Jakub Draganekdd72482de0a2
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex 9ce2322b15..7f870d8244 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -469,6 +469,7 @@ class CheckoutComplete(BaseMutation):class Arguments:checkout_id = graphene.ID(description="Checkout ID", required=True)+ store_source = graphene.Boolean(default_value=False)class Meta:description = (@@ -478,7 +479,7 @@ class CheckoutComplete(BaseMutation):)@classmethod- def perform_mutation(cls, _root, info, checkout_id):+ def perform_mutation(cls, _root, info, checkout_id, store_source):checkout = cls.get_node_or_error(info, checkout_id, only_type=Checkout, field="checkout_id")@@ -511,6 +512,7 @@ class CheckoutComplete(BaseMutation):payment_token=payment.token,billing_address=AddressData(**billing_address.as_data()),shipping_address=AddressData(**shipping_address.as_data()),+ store_source=store_source,)except PaymentError as e:abort_order_data(order_data)diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 6fe1db6ee2..4fe320724a 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -63,6 +63,7 @@ def create_payment_information(billing_address: AddressData = None,shipping_address: AddressData = None,customer_id: str = None,+ store_source: bool = False,) -> PaymentData:"""Extracts order information along with payment details.@@ -89,6 +90,7 @@ def create_payment_information(customer_ip_address=payment.customer_ip_address,customer_id=customer_id,customer_email=payment.billing_email,+ reuse_source=store_source,)@@ -280,9 +282,11 @@ def call_gateway(operation_type, payment, payment_token, **extra_params):gateway, gateway_config = get_payment_gateway(payment.gateway)gateway_response = Noneerror_msg = None-+ store_source = (+ extra_params.pop("store_source", False) and gateway_config.store_customer+ )payment_information = create_payment_information(- payment, payment_token, **extra_params+ payment, payment_token, store_source=store_source, **extra_params)try:diff --git a/tests/gateway/test_braintree.py b/tests/gateway/test_braintree.pyindex 61dd1d7038..bf88053a1b 100644--- a/tests/gateway/test_braintree.py+++ b/tests/gateway/test_braintree.py@@ -30,9 +30,6 @@ from saleor.payment.gateways.braintree.forms import BraintreePaymentFormfrom saleor.payment.interface import GatewayConfig, TokenConfigfrom saleor.payment.utils import create_payment_information-INCORRECT_TOKEN_ERROR = (- "Unable to process the transaction. Transaction's token is incorrect " "or expired."-)DEFAULT_ERROR = "Unable to process transaction. Please try again in a moment"@@ -81,11 +78,6 @@ def braintree_error_response(braintree_error):)-def braintree_not_found_error():- return Mock(side_effect=NotFoundError)--@pytest.fixturedef gateway_config():return GatewayConfig(@@ -101,13 +93,6 @@ def gateway_config():)-def success_gateway_response(gateway_response):- data = extract_gateway_response(gateway_response)- data.pop("currency")- data.pop("amount")- return data--def test_get_customer_data(payment_dummy):payment = payment_dummypayment_info = create_payment_information(payment)