Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add returnUrl to CheckoutPaymentCreate mutation
IKarbowiakbff48054a0c1
diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 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_paymentsfrom ...core.permissions import OrderPermissionsfrom ...core.taxes import zero_taxed_moneyfrom ...core.utils import get_client_ip+from ...core.utils.url import validate_storefront_urlfrom ...graphql.checkout.utils import clean_billing_address, clean_checkout_shippingfrom ...payment import PaymentError, gateway, modelsfrom ...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+ )+@classmethoddef 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.graphqlindex 3d199c1efd..0bb77c3556 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3441,6 +3441,7 @@ input PaymentInput {token: Stringamount: DecimalbillingAddress: AddressInput+ returnUrl: String}type PaymentRefund {