Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Update all store payment method names to be more explicit
Mateusz Grzybeaf1577585a2
diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 25a66f49bf..5817379f24 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -12,7 +12,7 @@ from ...core.error_codes import MetadataErrorCodefrom ...core.permissions import OrderPermissionsfrom ...core.utils import get_client_ipfrom ...core.utils.url import validate_storefront_url-from ...payment import PaymentError, Store, gateway+from ...payment import PaymentError, StorePaymentMethod, gatewayfrom ...payment.error_codes import PaymentErrorCodefrom ...payment.utils import create_payment, is_currency_supportedfrom ..account.i18n import I18nMixin@@ -49,7 +49,7 @@ def description(enum):StorePaymentMethodEnum = to_enum(- Store, type_name="StorePaymentMethodEnum", description=description+ StorePaymentMethod, type_name="StorePaymentMethodEnum", description=description)@@ -85,7 +85,7 @@ class PaymentInput(graphene.InputObjectType):store_payment_method = StorePaymentMethodEnum(description=f"{ADDED_IN_31} Payment store type.",required=False,- default_value=Store.NONE,+ default_value=StorePaymentMethod.NONE,)metadata = graphene.List(graphene.NonNull(MetadataInput),@@ -256,7 +256,8 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):customer_ip_address=get_client_ip(info.context),checkout=checkout,return_url=data.get("return_url"),- store_payment_method=data.get("store") or Store.NONE,+ store_payment_method=data.get("store_payment_method")+ or StorePaymentMethod.NONE,metadata=metadata,)return CheckoutPaymentCreate(payment=payment, checkout=checkout)diff --git a/saleor/graphql/payment/tests/test_payment.py b/saleor/graphql/payment/tests/test_payment.pyindex 3c4261e1ea..ea5e3138f3 100644--- a/saleor/graphql/payment/tests/test_payment.py+++ b/saleor/graphql/payment/tests/test_payment.py@@ -17,7 +17,7 @@ from ....payment.interface import (CustomerSource,InitializedPaymentResponse,PaymentMethodInfo,- StoreEnum,+ StorePaymentMethodEnum,TokenConfig,)from ....payment.models import ChargeStatus, Payment, TransactionKind@@ -443,7 +443,13 @@ def test_create_payment_for_checkout_with_active_payments(@pytest.mark.parametrize(- "store", [None, StoreEnum.NONE, StoreEnum.ON_SESSION, StoreEnum.OFF_SESSION]+ "store",+ [+ None,+ StorePaymentMethodEnum.NONE,+ StorePaymentMethodEnum.ON_SESSION,+ StorePaymentMethodEnum.OFF_SESSION,+ ],)def test_create_payment_with_store(user_api_client, checkout_without_shipping_required, address, store@@ -466,7 +472,7 @@ def test_create_payment_with_store("gateway": DUMMY_GATEWAY,"token": "sample-token","amount": total.gross.amount,- "store": store,+ "storePaymentMethod": store,},}@@ -476,7 +482,7 @@ def test_create_payment_with_store(# thencheckout.refresh_from_db()payment = checkout.payments.first()- assert payment.store == (store or StoreEnum.NONE).lower()+ assert payment.store == (store or StorePaymentMethodEnum.NONE).lower()@pytest.mark.parametrize(diff --git a/saleor/payment/__init__.py b/saleor/payment/__init__.pyindex 713f2d1663..9b54756874 100644--- a/saleor/payment/__init__.py+++ b/saleor/payment/__init__.py@@ -121,7 +121,7 @@ class ChargeStatus:]-class Store:+class StorePaymentMethod:"""Represents if and how a payment should be stored in a payment gateway.The following store types are possible:diff --git a/saleor/payment/interface.py b/saleor/payment/interface.pyindex a95198ec20..9d15dfdcc5 100644--- a/saleor/payment/interface.py+++ b/saleor/payment/interface.py@@ -60,7 +60,7 @@ class AddressData:phone: str-class StoreEnum(str, Enum):+class StorePaymentMethodEnum(str, Enum):NONE = "NONE"ON_SESSION = "ON_SESSION"OFF_SESSION = "OFF_SESSION"@@ -89,7 +89,7 @@ class PaymentData:reuse_source: bool = False # Note: this field will be removed in 4.0.data: Optional[dict] = Nonegraphql_customer_id: Optional[str] = None- store_payment_method: StoreEnum = StoreEnum.NONE+ store_payment_method: StorePaymentMethodEnum = StorePaymentMethodEnum.NONEpayment_metadata: Dict[str, str] = field(default_factory=dict)diff --git a/saleor/payment/models.py b/saleor/payment/models.pyindex 415047e91e..4689fd7ad7 100644--- a/saleor/payment/models.py+++ b/saleor/payment/models.py@@ -13,7 +13,7 @@ from ..checkout.models import Checkoutfrom ..core.models import ModelWithMetadatafrom ..core.permissions import PaymentPermissionsfrom ..core.taxes import zero_money-from . import ChargeStatus, CustomPaymentChoices, Store, TransactionKind+from . import ChargeStatus, CustomPaymentChoices, StorePaymentMethod, TransactionKindclass Payment(ModelWithMetadata):@@ -60,7 +60,11 @@ class Payment(ModelWithMetadata):order = models.ForeignKey("order.Order", null=True, related_name="payments", on_delete=models.PROTECT)- store = models.CharField(max_length=11, choices=Store.CHOICES, default=Store.NONE)+ store = models.CharField(+ max_length=11,+ choices=StorePaymentMethod.CHOICES,+ default=StorePaymentMethod.NONE,+ )billing_email = models.EmailField(blank=True)billing_first_name = models.CharField(max_length=256, blank=True)diff --git a/saleor/payment/tests/test_payment.py b/saleor/payment/tests/test_payment.pyindex 90d3d8bc99..a3dec267a5 100644--- a/saleor/payment/tests/test_payment.py+++ b/saleor/payment/tests/test_payment.py@@ -7,7 +7,14 @@ from django.contrib.auth.models import AnonymousUserfrom ...checkout.calculations import checkout_totalfrom ...checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ...plugins.manager import PluginsManager, get_plugins_manager-from .. import ChargeStatus, GatewayError, PaymentError, Store, TransactionKind, gateway+from .. import (+ ChargeStatus,+ GatewayError,+ PaymentError,+ StorePaymentMethod,+ TransactionKind,+ gateway,+)from ..error_codes import PaymentErrorCodefrom ..interface import GatewayResponse, PaymentMethodInfofrom ..models import Payment@@ -113,7 +120,7 @@ def test_create_payment(checkout_with_item, address):}payment = create_payment(**data)assert payment.gateway == "Dummy"- assert payment.store == Store.NONE+ assert payment.store == StorePaymentMethod.NONEsame_payment = create_payment(**data)assert payment == same_payment@@ -254,7 +261,7 @@ def test_create_payment_information_store(checkout_with_item, address, store):"email": "[email protected]","customer_ip_address": "127.0.0.1","checkout": checkout_with_item,- "store": store,+ "store_payment_method": store,}# when@@ -262,7 +269,7 @@ def test_create_payment_information_store(checkout_with_item, address, store):payment_data = create_payment_information(payment, "token", payment.total)# then- assert payment_data.store == store+ assert payment_data.store_payment_method == store@pytest.mark.parametrize(diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex aa63225ad4..2fddabfb98 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -13,14 +13,20 @@ from ..checkout.models import Checkoutfrom ..core.prices import quantize_pricefrom ..core.tracing import traced_atomic_transactionfrom ..order.models import Order-from . import ChargeStatus, GatewayError, PaymentError, Store, TransactionKind+from . import (+ ChargeStatus,+ GatewayError,+ PaymentError,+ StorePaymentMethod,+ TransactionKind,+)from .error_codes import PaymentErrorCodefrom .interface import (AddressData,GatewayResponse,PaymentData,PaymentMethodInfo,- StoreEnum,+ StorePaymentMethodEnum,)from .models import Payment, Transaction@@ -86,7 +92,7 @@ def create_payment_information(reuse_source=store_source,data=additional_data or {},graphql_customer_id=graphql_customer_id,- store_payment_method=StoreEnum[payment.store.upper()],+ store_payment_method=StorePaymentMethodEnum[payment.store.upper()],payment_metadata=payment.metadata,)@@ -103,7 +109,7 @@ def create_payment(order: Order = None,return_url: str = None,external_reference: Optional[str] = None,- store_payment_method: str = Store.NONE,+ store_payment_method: str = StorePaymentMethod.NONE,metadata: Optional[Dict[str, str]] = None,) -> Payment:"""Create a payment instance.