Fix 400 Bad Request on guest virtual checkout when setting payment - #41110
Open
dmytrokaplin wants to merge 1 commit into
Open
Fix 400 Bad Request on guest virtual checkout when setting payment#41110dmytrokaplin wants to merge 1 commit into
dmytrokaplin wants to merge 1 commit into
Conversation
|
Hi @dmytrokaplin. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
dmytrokaplin
marked this pull request as ready for review
August 11, 2026 20:34
Contributor
|
@magento create issue |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 viaselectPaymentMethod(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.guestEmailis stillundefinedornull.When sending the REST API request to
/V1/guest-carts/:cartId/set-payment-information,JSON.stringify()drops keys withundefinedvalues (or omits non-string types).Since
\Magento\Quote\Api\GuestPaymentInformationManagementInterface::savePaymentInformation()defines$emailas a required scalar parameter without a default value, Magento's WebapiServiceInputProcessorfails validation and throws anInputException:"email" is required. Enter and try again.Passing
quote.guestEmail || ''ensures that"email": ""is present in the payload, satisfying Webapi requirements whenquote.guestEmailis stillundefinedornull, until the user actually inputs their email address.Related Issue (#)
N/A
Fixed Issues (if relevant)
Manual testing scenarios (*)
/checkout/#payment)./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 (*)
Resolved issues: