Skip to content

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

Disallow to update checkout shipping method with mismatching currency

Tomasz Szymanski26c5d362ba5b
diff --git a/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py b/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
index 57487eabe5..42a207487c 100644
--- a/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
@@ -158,6 +158,16 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):
checkout_info, lines, shipping_method=delivery_method, collection_point=None
)
+ if delivery_method and delivery_method.price.currency != checkout.currency:
+ raise ValidationError(
+ {
+ "delivery_method_id": ValidationError(
+ "Cannot choose shipping method with different currency than the checkout.",
+ code=CheckoutErrorCode.DELIVERY_METHOD_NOT_APPLICABLE.value,
+ )
+ }
+ )
+
cls._update_delivery_method(
manager,
checkout_info,
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py
index a13ff5ff57..26573695f4 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py
@@ -42,6 +42,14 @@ MUTATION_UPDATE_DELIVERY_METHOD = """
id
}
}
+ totalPrice {
+ gross {
+ amount
+ }
+ net {
+ amount
+ }
+ }
}
errors {
field
@@ -261,6 +269,50 @@ def test_checkout_delivery_method_update_external_shipping(
)
[email protected]("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
+def test_checkout_delivery_method_update_external_shipping_invalid_currency(
+ mock_send_request,
+ api_client,
+ checkout_with_item_for_cc,
+ settings,
+ shipping_app,
+):
+ # given
+ settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]
+ checkout = checkout_with_item_for_cc
+ response_method_id = "abcd"
+ mock_json_response = [
+ {
+ "id": response_method_id,
+ "name": "Provider - Economy",
+ "amount": "10",
+ "currency": "AUD", # checkout currency is USD
+ "maximum_delivery_days": "7",
+ }
+ ]
+ mock_send_request.return_value = mock_json_response
+ method_id = graphene.Node.to_global_id(
+ "app", f"{shipping_app.id}:{response_method_id}"
+ )
+ query = MUTATION_UPDATE_DELIVERY_METHOD
+
+ # when
+ response = api_client.post_graphql(
+ query, {"id": to_global_id_or_none(checkout), "deliveryMethodId": method_id}
+ )
+
+ # then
+ data = get_graphql_content(response)["data"]["checkoutDeliveryMethodUpdate"]
+ errors = data["errors"]
+ assert len(errors) == 1
+ assert errors[0]["field"] == "deliveryMethodId"
+ assert errors[0]["code"] == CheckoutErrorCode.DELIVERY_METHOD_NOT_APPLICABLE.name
+ assert (
+ errors[0]["message"]
+ == "Cannot choose shipping method with different currency than the checkout."
+ )
+
+
@patch(
"saleor.graphql.checkout.mutations.checkout_shipping_method_update."
"clean_delivery_method"