Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix mypy errors
IKarbowiakabb558535fac
diff --git a/saleor/order/events.py b/saleor/order/events.pyindex fc0b6e3dc1..de666b81f5 100644--- a/saleor/order/events.py+++ b/saleor/order/events.py@@ -261,7 +261,7 @@ def payment_failed_event(def external_notification_event(- *, order: Order, user: UserType, message: str, payment: Payment+ *, order: Order, user: UserType, message: Optional[str], payment: Payment) -> OrderEvent:if not _user_is_valid(user):user = Nonediff --git a/saleor/payment/gateways/adyen/utils.py b/saleor/payment/gateways/adyen/utils.pyindex 838a9d280e..4a54f45b37 100644--- a/saleor/payment/gateways/adyen/utils.py+++ b/saleor/payment/gateways/adyen/utils.py@@ -1,6 +1,6 @@import loggingfrom decimal import Decimal-from typing import Any, Callable, Dict+from typing import Any, Callable, Dict, Optionalimport Adyenfrom babel.numbers import get_currency_precision@@ -35,9 +35,9 @@ def get_price_amount(value: Decimal, currency: str):return str(value_without_comma.quantize(Decimal("1")))-def api_call(requst_data: Dict[str, Any], method: Callable) -> Adyen.Adyen:+def api_call(request_data: Optional[Dict[str, Any]], method: Callable) -> Adyen.Adyen:try:- return method(requst_data)+ return method(request_data)except (Adyen.AdyenError, ValueError, TypeError) as e:logger.error(f"Unable to process the payment: {e}")raise PaymentError("Unable to process the payment request.")@@ -113,11 +113,8 @@ def request_data_for_payment(extra_request_params["origin"] = origin_urlmethod = payment_data["paymentMethod"].get("type", [])- if "klarna" in method:- # TODO- append_klarna_data()- request = {+ request_data = {"amount": {"value": get_price_amount(payment_information.amount, payment_information.currency@@ -130,7 +127,12 @@ def request_data_for_payment("merchantAccount": merchant_account,**extra_request_params,}- return request++ if "klarna" in method:+ # TODO+ append_klarna_data(payment_information, request_data)++ return request_datadef request_data_for_gateway_config(diff --git a/saleor/payment/gateways/adyen/webhooks.py b/saleor/payment/gateways/adyen/webhooks.pyindex 36e150938b..db7d81f39b 100644--- a/saleor/payment/gateways/adyen/webhooks.py+++ b/saleor/payment/gateways/adyen/webhooks.py@@ -25,15 +25,17 @@ from ...utils import create_transaction, gateway_postprocessfrom .utils import convert_adyen_price_format-def get_payment(payment_id: str) -> Payment:+def get_payment(payment_id: Optional[str]) -> Optional[Payment]:+ if not payment_id:+ return None_type, payment_id = from_global_id(payment_id)payment = Payment.objects.prefetch_related("order").filter(id=payment_id).first()return paymentdef get_transaction(- payment: "Payment", transaction_id: str, kind: TransactionKind,-) -> Transaction:+ payment: "Payment", transaction_id: Optional[str], kind: str,+) -> Optional[Transaction]:transaction = payment.transactions.filter(kind=kind, token=transaction_id).first()return transaction@@ -141,6 +143,8 @@ def handle_cancel_or_refund():# https://docs.adyen.com/checkout/cancel-or-refund#cancel-or-refund-notificationadditional_data = notification.get("additionalData")+ if not additional_data:+ returnaction = additional_data.get("modification.action")if action == "refund":handle_refund(notification, gateway_config)@@ -252,7 +256,7 @@ def handle_refund(notification: Dict[str, Any], _gateway_config: GatewayConfig):order_refunded(payment.order, None, new_transaction.amount, payment)-def _get_kind(transaction: Optional[Transaction]) -> TransactionKind:+def _get_kind(transaction: Optional[Transaction]) -> str:if transaction:return transaction.kind# To proceed the refund we already need to have the capture status so we will use it@@ -398,8 +402,10 @@ EVENT_MAP = {def validate_hmac_signature(notification: Dict[str, Any], gateway_config: "GatewayConfig") -> bool:- hmac_signature = notification.get("additionalData", {}).get("hmacSignature")- hmac_key = gateway_config.connection_params.get("webhook_hmac")+ hmac_signature: Optional[str] = notification.get("additionalData", {}).get(+ "hmacSignature"+ )+ hmac_key: Optional[str] = gateway_config.connection_params.get("webhook_hmac")if not hmac_key and not hmac_signature:return True@@ -409,7 +415,7 @@ def validate_hmac_signature(if not hmac_signature and hmac_key:return False- hmac_key = hmac_key.encode()+ hmac_key = hmac_key.encode() # type: ignoresuccess = "true" if notification.get("success", "") == "true" else "false"if notification.get("success", None) is None:@@ -436,7 +442,7 @@ def validate_hmac_signature(def validate_auth_user(headers: HttpHeaders, gateway_config: "GatewayConfig") -> bool:username = gateway_config.connection_params["webhook_user"]password = gateway_config.connection_params["webhook_user_password"]- auth_header = headers.get("Authorization")+ auth_header: Optional[str] = headers.get("Authorization")if not auth_header and not username:return Trueif auth_header and not username:@@ -444,7 +450,7 @@ def validate_auth_user(headers: HttpHeaders, gateway_config: "GatewayConfig") ->if not auth_header and username:return False- split_auth = auth_header.split(maxsplit=1)+ split_auth = auth_header.split(maxsplit=1) # type: ignoreprefix = "BASIC"if len(split_auth) != 2 or split_auth[0].upper() != prefix:@@ -452,8 +458,7 @@ def validate_auth_user(headers: HttpHeaders, gateway_config: "GatewayConfig") ->auth = split_auth[1]try:- decoded_auth = base64.b64decode(auth)- decoded_auth = decoded_auth.decode()+ decoded_auth = base64.b64decode(auth).decode()request_username, request_password = decoded_auth.split(":")user_is_correct = request_username == usernameif user_is_correct and check_password(request_password, password):diff --git a/saleor/payment/interface.py b/saleor/payment/interface.pyindex 3f074dd9b6..76d3925446 100644--- a/saleor/payment/interface.py+++ b/saleor/payment/interface.py@@ -72,7 +72,7 @@ class PaymentData:token: Optional[str] = Nonecustomer_id: Optional[str] = Nonereuse_source: bool = False- data: Optional[JSONType] = None+ data: Optional[dict] = None@dataclassdiff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 32da1008b2..c563a7c580 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -132,7 +132,7 @@ def create_payment(def create_transaction(payment: Payment,kind: str,- payment_information: Optional[PaymentData],+ payment_information: PaymentData,action_required: bool = False,gateway_response: GatewayResponse = None,error_msg=None,