Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Apply code review suggestions for adyen process_payment methos
IKarbowiakda1c5f56cf11
diff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.pyindex ff16572701..39f2cc7184 100644--- a/saleor/payment/gateways/adyen/plugin.py+++ b/saleor/payment/gateways/adyen/plugin.py@@ -11,7 +11,6 @@ from graphql_relay import from_global_idfrom ....checkout.models import Checkoutfrom ....core.emails import prepare_url-from ....payment.models import Paymentfrom ....plugins.base_plugin import BasePlugin, ConfigurationTypeFieldfrom ... import PaymentError, TransactionKindfrom ...interface import GatewayConfig, GatewayResponse, PaymentData, PaymentGateway@@ -23,6 +22,7 @@ from .utils import (request_data_for_payment,request_for_payment_capture,request_for_payment_refund,+ update_payment_with_action_required_data,)from .webhooks import handle_webhook@@ -251,19 +251,12 @@ class AdyenGatewayPlugin(BasePlugin):action = result.message.get("action")error_message = result.message.get("refusalReason")if action:- _type, payment_id = from_global_id(payment_information.payment_id)try:- payment = Payment.objects.get(pk=payment_id)- details = result.message.get("details")- payment.extra_data = json.dumps(- {- "payment_data": action["paymentData"],- "parameters": [detail["key"] for detail in details]- if details- else [],- }+ update_payment_with_action_required_data(+ payment_information.payment_id,+ action,+ result.message.get("details", []),)- payment.save(update_fields=["extra_data"])except ObjectDoesNotExist:is_success = Falseerror_message = "Payment cannot be performed. Payment does not exists."diff --git a/saleor/payment/gateways/adyen/utils.py b/saleor/payment/gateways/adyen/utils.pyindex 4a54f45b37..bbdb86971a 100644--- a/saleor/payment/gateways/adyen/utils.py+++ b/saleor/payment/gateways/adyen/utils.py@@ -1,3 +1,4 @@+import jsonimport loggingfrom decimal import Decimalfrom typing import Any, Callable, Dict, Optional@@ -6,9 +7,11 @@ import Adyenfrom babel.numbers import get_currency_precisionfrom django.conf import settingsfrom django_countries.fields import Country+from graphql_relay import from_global_idfrom ....checkout.models import Checkoutfrom ....core.prices import quantize_price+from ....payment.models import Paymentfrom ... import PaymentErrorfrom ...interface import PaymentData@@ -183,3 +186,17 @@ def request_for_payment_capture("originalReference": token,"reference": payment_information.payment_id,}+++def update_payment_with_action_required_data(+ payment_id: str, action: dict, details: list+):+ _type, payment_pk = from_global_id(payment_id)+ payment = Payment.objects.get(pk=payment_pk)+ payment.extra_data = json.dumps(+ {+ "payment_data": action["paymentData"],+ "parameters": [detail["key"] for detail in details],+ }+ )+ payment.save(update_fields=["extra_data"])