Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Create union of payment and checkout error code
Damian Wccfd6de025c5
diff --git a/saleor/graphql/checkout/utils.py b/saleor/graphql/checkout/utils.pyindex 9b26a92577..e0522644bc 100644--- a/saleor/graphql/checkout/utils.py+++ b/saleor/graphql/checkout/utils.py@@ -1,18 +1,19 @@-from enum import Enum-from typing import Iterable+from typing import Iterable, Unionfrom django.core.exceptions import ValidationError+from ...checkout.error_codes import CheckoutErrorCodefrom ...checkout.models import Checkout, CheckoutLinefrom ...checkout.utils import is_fully_paid, is_valid_shipping_methodfrom ...discount import DiscountInfo+from ...payment.error_codes import PaymentErrorCodedef clean_checkout_shipping(checkout: Checkout,lines: Iterable[CheckoutLine],discounts: Iterable[DiscountInfo],- error_code: Enum,+ error_code: Union[CheckoutErrorCode, PaymentErrorCode],):if checkout.is_shipping_required():if not checkout.shipping_method:@@ -20,7 +21,7 @@ def clean_checkout_shipping({"shipping_method": ValidationError("Shipping method is not set",- code=error_code.SHIPPING_METHOD_NOT_SET.value, # type: ignore+ code=error_code.SHIPPING_METHOD_NOT_SET)})@@ -29,7 +30,7 @@ def clean_checkout_shipping({"shipping_address": ValidationError("Shipping address is not set",- code=error_code.SHIPPING_ADDRESS_NOT_SET.value, # type: ignore+ code=error_code.SHIPPING_ADDRESS_NOT_SET)})@@ -38,19 +39,21 @@ def clean_checkout_shipping({"shipping_method": ValidationError("Shipping method is not valid for your shipping address",- code=error_code.INVALID_SHIPPING_METHOD.value, # type: ignore+ code=error_code.INVALID_SHIPPING_METHOD,)})-def clean_billing_address(checkout: Checkout, error_code: Enum):+def clean_billing_address(+ checkout: Checkout, error_code: Union[CheckoutErrorCode, PaymentErrorCode],+):if not checkout.billing_address:raise ValidationError({"billing_address": ValidationError("Billing address is not set",- code=error_code.BILLING_ADDRESS_NOT_SET.value, # type: ignore+ code=error_code.BILLING_ADDRESS_NOT_SET,)})@@ -60,11 +63,11 @@ def clean_checkout_payment(checkout: Checkout,lines: Iterable[CheckoutLine],discounts: Iterable[DiscountInfo],- error_code: Enum,+ error_code: CheckoutErrorCode,):clean_billing_address(checkout, error_code)if not is_fully_paid(checkout, lines, discounts):raise ValidationError("Provided payment methods can not cover the checkout's total amount",- code=error_code.CHECKOUT_NOT_FULLY_PAID.value, # type: ignore+ code=error_code.CHECKOUT_NOT_FULLY_PAID,)