Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Addd to PaymentData the graphql_payment_id

Maciej Korycinskicb49da196b70
diff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.py
index 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_password
from django.core.exceptions import ObjectDoesNotExist
from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponse, HttpResponseNotFound
-from graphql_relay import from_global_id
from ....checkout.models import Checkout
from ....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 need
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()
@@ -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.py
index 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.py
index b9e00975eb..10db50dfa5 100644
--- a/saleor/payment/gateways/adyen/utils.py
+++ b/saleor/payment/gateways/adyen/utils.py
@@ -4,7 +4,6 @@ from decimal import Decimal
from typing import Any, Callable, Dict, Optional
import Adyen
-import graphene
from babel.numbers import get_currency_precision
from django.conf import settings
from 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.py
index 76d3925446..3c0030f90b 100644
--- a/saleor/payment/interface.py
+++ b/saleor/payment/interface.py
@@ -65,7 +65,8 @@ class PaymentData:
currency: str
billing: Optional[AddressData]
shipping: Optional[AddressData]
- payment_id: str # GraphQL id
+ payment_id: int
+ graphql_payment_id: str
order_id: Optional[int]
customer_ip_address: Optional[str]
customer_email: str
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.py
index 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 None
order_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.py
index 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,