Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Implement SALEOR-4233
Mateusz Grzyb8c527eee94e5
diff --git a/saleor/payment/interface.py b/saleor/payment/interface.pyindex 6b70145eb4..ff7462d91c 100644--- a/saleor/payment/interface.py+++ b/saleor/payment/interface.py@@ -1,7 +1,9 @@-from dataclasses import dataclass+from dataclasses import dataclass, fieldfrom decimal import Decimalfrom typing import Any, Dict, List, Optional, Union+from saleor.payment import Store+JSONValue = Union[str, int, float, bool, None, Dict[str, Any], List[Any]]JSONType = Union[Dict[str, JSONValue], List[JSONValue]]@@ -79,9 +81,11 @@ class PaymentData:customer_email: strtoken: Optional[str] = Nonecustomer_id: Optional[str] = None # stores payment gateway customer ID- reuse_source: bool = False+ reuse_source: bool = False # Note: this field will be removed in 4.0.data: Optional[dict] = Nonegraphql_customer_id: Optional[str] = None+ store: str = Store.NONE+ payment_metadata: Dict[str, str] = field(default_factory=dict)@dataclassdiff --git a/saleor/payment/tests/test_payment.py b/saleor/payment/tests/test_payment.pyindex 0f7545108b..80f309fc0f 100644--- a/saleor/payment/tests/test_payment.py+++ b/saleor/payment/tests/test_payment.py@@ -26,7 +26,6 @@ from ..utils import (pytest_plugins = ["saleor.plugins.webhook.tests.test_payment_webhook"]-NOT_ACTIVE_PAYMENT_ERROR = "This payment is no longer active."EXAMPLE_ERROR = "Example dummy error"@@ -235,6 +234,74 @@ def test_create_payment_information_for_draft_order(draft_order):assert shipping == billing[email protected]("store", ["NONE", "ON_SESSION", "OFF_SESSION"])+def test_create_payment_information_store(checkout_with_item, address, store):+ # given+ checkout_with_item.billing_address = address+ checkout_with_item.shipping_address = address+ checkout_with_item.save()++ manager = get_plugins_manager()+ lines = fetch_checkout_lines(checkout_with_item)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ total = checkout_total(+ manager=manager, checkout_info=checkout_info, lines=lines, address=address+ )++ data = {+ "gateway": "Dummy",+ "payment_token": "token",+ "total": total.gross.amount,+ "currency": checkout_with_item.currency,+ "email": "[email protected]",+ "customer_ip_address": "127.0.0.1",+ "checkout": checkout_with_item,+ "store": store,+ }++ # when+ payment = create_payment(**data)+ payment_data = create_payment_information(payment, "token", payment.total)++ # then+ assert payment_data.store == store+++ "metadata", [{f"key{i}": f"value{i}" for i in range(5)}, {}, None]+)+def test_create_payment_information_metadata(checkout_with_item, address, metadata):+ # given+ checkout_with_item.billing_address = address+ checkout_with_item.shipping_address = address+ checkout_with_item.save()++ manager = get_plugins_manager()+ lines = fetch_checkout_lines(checkout_with_item)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ total = checkout_total(+ manager=manager, checkout_info=checkout_info, lines=lines, address=address+ )++ data = {+ "gateway": "Dummy",+ "payment_token": "token",+ "total": total.gross.amount,+ "currency": checkout_with_item.currency,+ "email": "[email protected]",+ "customer_ip_address": "127.0.0.1",+ "checkout": checkout_with_item,+ "metadata": metadata,+ }++ # when+ payment = create_payment(**data)+ payment_data = create_payment_information(payment, "token", payment.total)++ # then+ assert payment_data.payment_metadata == (metadata or {})++def test_create_transaction(transaction_data):txn = create_transaction(**transaction_data)diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 3a26860c28..5fedea3e68 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -80,6 +80,8 @@ def create_payment_information(reuse_source=store_source,data=additional_data or {},graphql_customer_id=graphql_customer_id,+ store=payment.store,+ payment_metadata=payment.metadata,)