Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Addd to PaymentData the graphql_payment_id
Maciej Korycinskicb49da196b70
diff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.pyindex 76f93aba92..701c2bf9bf 100644--- a/saleor/payment/gateways/adyen/plugin.py+++ b/saleor/payment/gateways/adyen/plugin.py@@ -7,7 +7,6 @@ from django.contrib.auth.hashers import make_passwordfrom django.core.exceptions import ObjectDoesNotExistfrom django.core.handlers.wsgi import WSGIRequestfrom django.http import HttpResponse, HttpResponseNotFound-from graphql_relay import from_global_idfrom ....checkout.models import Checkoutfrom ....core.utils import build_absolute_uri@@ -243,9 +242,8 @@ class AdyenGatewayPlugin(BasePlugin):def process_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":- _type, payment_pk = from_global_id(payment_information.payment_id)try:- payment = Payment.objects.get(pk=payment_pk)+ payment = Payment.objects.get(pk=payment_information.payment_id)except ObjectDoesNotExist:raise PaymentError("Payment cannot be performed. Payment does not exists.")@@ -256,7 +254,7 @@ class AdyenGatewayPlugin(BasePlugin):)params = urlencode(- {"payment": payment_information.payment_id, "checkout": checkout.pk}+ {"payment": payment_information.graphql_payment_id, "checkout": checkout.pk})return_url = prepare_url(params,@@ -332,17 +330,15 @@ class AdyenGatewayPlugin(BasePlugin):self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":- _type, payment_id = from_global_id(payment_information.payment_id)-# The additional checks are proceed asynchronously so we try to confirm that# the payment is already processed- payment = Payment.objects.filter(id=payment_id).first()+ payment = Payment.objects.filter(id=payment_information.payment_id).first()if not payment:raise PaymentError("Unable to find the payment.")transaction = (payment.transactions.filter(- payment__id=payment_id,+ payment__id=payment_information.payment_id,kind__in=[TransactionKind.AUTH, TransactionKind.CAPTURE],is_success=True,)@@ -370,11 +366,12 @@ class AdyenGatewayPlugin(BasePlugin):self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":- _type, payment_id = from_global_id(payment_information.payment_id)# we take Auth kind because it contains the transaction id that we needtransaction = (Transaction.objects.filter(- payment__id=payment_id, kind=TransactionKind.AUTH, is_success=True+ payment__id=payment_information.payment_id,+ kind=TransactionKind.AUTH,+ is_success=True,).exclude(token__isnull=True, token__exact="").last()@@ -405,10 +402,11 @@ class AdyenGatewayPlugin(BasePlugin):def capture_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":- _type, payment_id = from_global_id(payment_information.payment_id)transaction = (Transaction.objects.filter(- payment__id=payment_id, kind=TransactionKind.AUTH, is_success=True+ payment__id=payment_information.payment_id,+ kind=TransactionKind.AUTH,+ is_success=True,).exclude(token__isnull=True, token__exact="").last()diff --git a/saleor/payment/gateways/adyen/tests/test_utils.py b/saleor/payment/gateways/adyen/tests/test_utils.pyindex 7c3d4f9cfd..8827af78ec 100644--- a/saleor/payment/gateways/adyen/tests/test_utils.py+++ b/saleor/payment/gateways/adyen/tests/test_utils.py@@ -152,7 +152,7 @@ def test_request_data_for_payment(dummy_payment_data):),"currency": dummy_payment_data.currency,},- "reference": dummy_payment_data.payment_id,+ "reference": dummy_payment_data.graphql_payment_id,"paymentMethod": {"type": "scheme"},"returnUrl": return_url,"merchantAccount": merchant_account,@@ -186,7 +186,7 @@ def test_request_data_for_payment_append_klarna_data(),"currency": dummy_payment_data.currency,},- "reference": dummy_payment_data.payment_id,+ "reference": dummy_payment_data.graphql_payment_id,"paymentMethod": {"type": "scheme"},"returnUrl": return_url,"merchantAccount": merchant_account,diff --git a/saleor/payment/gateways/adyen/utils.py b/saleor/payment/gateways/adyen/utils.pyindex b9e00975eb..10db50dfa5 100644--- a/saleor/payment/gateways/adyen/utils.py+++ b/saleor/payment/gateways/adyen/utils.py@@ -4,7 +4,6 @@ from decimal import Decimalfrom typing import Any, Callable, Dict, Optionalimport Adyen-import graphenefrom babel.numbers import get_currency_precisionfrom django.conf import settingsfrom django_countries.fields import Country@@ -84,7 +83,7 @@ def request_data_for_payment(),"currency": payment_information.currency,},- "reference": payment_information.payment_id,+ "reference": payment_information.graphql_payment_id,"paymentMethod": payment_method,"returnUrl": return_url,"merchantAccount": merchant_account,@@ -98,8 +97,9 @@ def request_data_for_payment(def append_klarna_data(payment_information: "PaymentData", payment_data: dict):- _type, payment_pk = graphene.Node.from_global_id(payment_information.payment_id)- checkout = Checkout.objects.filter(payments__id=payment_pk).first()+ checkout = Checkout.objects.filter(+ payments__id=payment_information.payment_id+ ).first()if not checkout:raise PaymentError("Unable to calculate products for klarna")@@ -188,7 +188,7 @@ def request_for_payment_refund("currency": payment_information.currency,},"originalReference": token,- "reference": payment_information.payment_id,+ "reference": payment_information.graphql_payment_id,}@@ -204,7 +204,7 @@ def request_for_payment_capture("currency": payment_information.currency,},"originalReference": token,- "reference": payment_information.payment_id,+ "reference": payment_information.graphql_payment_id,}diff --git a/saleor/payment/interface.py b/saleor/payment/interface.pyindex 76d3925446..3c0030f90b 100644--- a/saleor/payment/interface.py+++ b/saleor/payment/interface.py@@ -65,7 +65,8 @@ class PaymentData:currency: strbilling: Optional[AddressData]shipping: Optional[AddressData]- payment_id: str # GraphQL id+ payment_id: int+ graphql_payment_id: strorder_id: Optional[int]customer_ip_address: Optional[str]customer_email: strdiff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 715278719a..16ab204813 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -49,7 +49,7 @@ def create_payment_information(shipping_address = AddressData(**shipping.as_data()) if shipping else Noneorder_id = payment.order.pk if payment.order else None- payment_id = graphene.Node.to_global_id("Payment", payment.pk)+ graphql_payment_id = graphene.Node.to_global_id("Payment", payment.pk)return PaymentData(token=payment_token,@@ -58,7 +58,8 @@ def create_payment_information(billing=billing_address,shipping=shipping_address,order_id=order_id,- payment_id=payment_id,+ payment_id=payment.pk,+ graphql_payment_id=graphql_payment_id,customer_ip_address=payment.customer_ip_address,customer_id=customer_id,customer_email=payment.billing_email,diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex 5478a2f593..99a0442038 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -1574,7 +1574,8 @@ def dummy_payment_data(payment_dummy):return PaymentData(amount=Decimal(10),currency="USD",- payment_id=graphene.Node.to_global_id("Payment", payment_dummy.pk),+ graphql_payment_id=graphene.Node.to_global_id("Payment", payment_dummy.pk),+ payment_id=payment_dummy.pk,billing=None,shipping=None,order_id=None,