Skip to content

Fix 400 Bad Request on guest virtual checkout when setting payment - #41110

Open
dmytrokaplin wants to merge 1 commit into
magento:2.4-developfrom
dmytrokaplin:2.4-develop
Open

Fix 400 Bad Request on guest virtual checkout when setting payment#41110
dmytrokaplin wants to merge 1 commit into
magento:2.4-developfrom
dmytrokaplin:2.4-develop

Conversation

@dmytrokaplin

@dmytrokaplin dmytrokaplin commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description (*)

Fixes an intermittent HTTP 400 Bad Request error on guest checkout for virtual products (or checkouts without a shipping step) when only a single payment method is available.

Root Cause

On a guest virtual checkout (where the shipping step is absent), the payment step renders immediately upon page load. If there is only one payment method available, Magento_Checkout/js/model/payment-service::setPaymentMethods() automatically selects it via selectPaymentMethod(filteredMethods[0]):
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/view/frontend/web/js/model/payment-service.js#L54

This triggers a call to save payment information before the guest user has typed an email address into the checkout form. At this point, quote.guestEmail is still undefined or null.

When sending the REST API request to /V1/guest-carts/:cartId/set-payment-information, JSON.stringify() drops keys with undefined values (or omits non-string types).

Since \Magento\Quote\Api\GuestPaymentInformationManagementInterface::savePaymentInformation() defines $email as a required scalar parameter without a default value, Magento's Webapi ServiceInputProcessor fails validation and throws an InputException: "email" is required. Enter and try again.

Passing quote.guestEmail || '' ensures that "email": "" is present in the payload, satisfying Webapi requirements when quote.guestEmail is still undefined or null, until the user actually inputs their email address.

Related Issue (#)

N/A

Fixed Issues (if relevant)

  1. Fixes HTTP 400 error on guest virtual checkout when a single payment method is auto-selected upon initial page load.

Manual testing scenarios (*)

  1. Ensure the store configuration has only one active payment method available for guest checkout.
  2. Add a virtual product to the shopping cart as a guest user.
  3. Open a clean/incognito session and proceed to Checkout (/checkout/#payment).
  4. Open Browser DevTools -> Console and Network tabs.
  5. Observe the initial POST request to /rest/default/V1/guest-carts/{cart_id}/set-payment-information.

Actual Result (Before fix)

The request returns HTTP 400 Bad Request with response body:
{"message":"\"%fieldName\" is required. Enter and try again.","parameters":{"fieldName":"email"}}

Expected Result (After fix)

The request completes successfully without Webapi payload schema validation failure.

Questions or comments

N/A

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests pass locally

Resolved issues:

  1. resolves [Issue] Fix 400 Bad Request on guest virtual checkout when setting payment #41112: Fix 400 Bad Request on guest virtual checkout when setting payment

@m2-assistant

m2-assistant Bot commented Aug 11, 2026

Copy link
Copy Markdown

Hi @dmytrokaplin. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@dmytrokaplin
dmytrokaplin marked this pull request as ready for review August 11, 2026 20:34
@engcom-Bravo

Copy link
Copy Markdown
Contributor

@magento create issue

@engcom-Bravo engcom-Bravo added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Aug 12, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

[Issue] Fix 400 Bad Request on guest virtual checkout when setting payment

2 participants