Skip to content

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

Add returnUrl to CheckoutPaymentCreate mutation

IKarbowiakbff48054a0c1
diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.py
index b85dbbb2b9..76407528f9 100644
--- a/saleor/graphql/payment/mutations.py
+++ b/saleor/graphql/payment/mutations.py
@@ -7,6 +7,7 @@ from ...checkout.utils import cancel_active_payments
from ...core.permissions import OrderPermissions
from ...core.taxes import zero_taxed_money
from ...core.utils import get_client_ip
+from ...core.utils.url import validate_storefront_url
from ...graphql.checkout.utils import clean_billing_address, clean_checkout_shipping
from ...payment import PaymentError, gateway, models
from ...payment.error_codes import PaymentErrorCode
@@ -51,6 +52,14 @@ class PaymentInput(graphene.InputObjectType):
"removed after 2020-07-31."
),
)
+ return_url = graphene.String(
+ required=False,
+ description=(
+ "URL of a storefront view where user should be redirected after "
+ "3D secure confirmation. 3D secure payments payment will not work "
+ "if this field is not provided."
+ ),
+ )
class CheckoutPaymentCreate(BaseMutation, I18nMixin):
@@ -132,6 +141,18 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):
}
)
+ @classmethod
+ def validate_return_url(cls, input_data):
+ return_url = input_data.get("return_url")
+ if not return_url:
+ return
+ try:
+ validate_storefront_url(return_url)
+ except ValidationError as error:
+ raise ValidationError(
+ {"redirect_url": error}, code=PaymentErrorCode.INVALID
+ )
+
@classmethod
def perform_mutation(cls, _root, info, checkout_id, **data):
checkout_id = from_global_id_strict_type(
@@ -146,6 +167,7 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):
cls.validate_gateway(gateway, checkout.currency)
cls.validate_token(info.context.plugins, gateway, data)
+ cls.validate_return_url(data)
checkout_total = cls.calculate_total(info, checkout)
amount = data.get("amount", checkout_total.gross.amount)
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 3d199c1efd..0bb77c3556 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -3441,6 +3441,7 @@ input PaymentInput {
token: String
amount: Decimal
billingAddress: AddressInput
+ returnUrl: String
}
type PaymentRefund {