Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix charging more amount than checkout total
Aleksander Spyra4ee0c7e6a976
diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 2fbd41f97a..aa5ee85ed7 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -92,7 +92,7 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):)checkout_total = max(checkout_total, zero_taxed_money(checkout_total.currency))amount = data.get("amount", checkout_total.gross.amount)- if amount < checkout_total.gross.amount:+ if amount != checkout_total.gross.amount:raise ValidationError({"amount": ValidationError(diff --git a/tests/api/test_payment.py b/tests/api/test_payment.pyindex f23004c353..552b33ce05 100644--- a/tests/api/test_payment.py+++ b/tests/api/test_payment.py@@ -120,6 +120,58 @@ def test_checkout_add_payment(assert payment.charge_status == ChargeStatus.NOT_CHARGED+def test_checkout_add_payment_default_amount(+ user_api_client, checkout_with_item, graphql_address_data+):+ checkout = checkout_with_item+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)+ total = checkout.get_total()+ total = TaxedMoney(net=total, gross=total)++ variables = {+ "checkoutId": checkout_id,+ "input": {+ "gateway": "DUMMY",+ "token": "sample-token",+ "billingAddress": graphql_address_data,+ },+ }+ response = user_api_client.post_graphql(CREATE_QUERY, variables)+ content = get_graphql_content(response)+ data = content["data"]["checkoutPaymentCreate"]+ assert not data["errors"]+ transactions = data["payment"]["transactions"]+ assert not transactions+ payment = Payment.objects.get()+ assert payment.checkout == checkout+ assert payment.is_active+ assert payment.token == "sample-token"+ assert payment.total == total.gross.amount+ assert payment.currency == total.gross.currency+ assert payment.charge_status == ChargeStatus.NOT_CHARGED+++def test_checkout_add_payment_bad_amount(+ user_api_client, checkout_with_item, graphql_address_data+):+ checkout = checkout_with_item+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)++ variables = {+ "checkoutId": checkout_id,+ "input": {+ "gateway": "DUMMY",+ "token": "sample-token",+ "amount": str(checkout.get_total().amount + Decimal(1)),+ "billingAddress": graphql_address_data,+ },+ }+ response = user_api_client.post_graphql(CREATE_QUERY, variables)+ content = get_graphql_content(response)+ data = content["data"]["checkoutPaymentCreate"]+ assert data["errors"]++def test_use_checkout_billing_address_as_payment_billing(user_api_client, checkout_with_item, address):