Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow to update checkout shipping method with mismatching currency #16026

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ def perform_on_external_shipping_method(
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
id
}
}
totalPrice {
gross {
amount
}
net {
amount
}
}
}
errors {
field
Expand Down Expand Up @@ -261,6 +269,50 @@ def test_checkout_delivery_method_update_external_shipping(
)


@mock.patch("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"
Expand Down
Loading