This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Validate available payment methods before attempting payment or updating order statuses #5440
Merged
Conversation
This file contains 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
rubikuserbot
requested review from
a team and
opr
and removed request for
a team
December 22, 2021 14:17
mikejolley
added
the
needs: dev note
PR that has some text that needs to be included in the release notes.
label
Dec 22, 2021
Size Change: 0 B Total Size: 819 kB ℹ️ View Unchanged
|
opr
approved these changes
Jan 4, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests well and the code changes look good to me, cheers Mike!
14 tasks
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
focus: rest api
Work impacting REST api routes.
needs: dev note
PR that has some text that needs to be included in the release notes.
type: enhancement
The issue is a request for an enhancement.
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.
Fixes an issue where orders would be set pending before first validating the given payment method was available.
In this PR we:
PUT
endpoint. This was not being used and it confused validation further because payment method was optional. There is no reason to call the checkout route early because data is updated via/cart/
routes. By removing this, we can force thepayment_method
to be required on all requests. I removed the PUT example from docs.payment_method
required. It was required anyway for POST requests, but I've made it required in the schema so validation happens early on.get_request_payment_method
andget_request_payment_method_id
soget_request_payment_method
is always used.get_request_payment_method
validates the given requestpayment_method
against those that are available.Fixes #5405
Testing
Prerequisites:
add_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' );
to the bottom of your wp-config.php file to disable nonce checkingAdd an item to the cart:
POST https://store.local/wp-json/wc/store/cart/add-item
Testing invalid Methods
For each of these tests, confirm there is an error message response (
400
) and the order remains in draft status.1. Invalid method:
POST https://store.local/wp-json/wc/store/checkout
2. Missing method:
POST https://store.local/wp-json/wc/store/checkout
3. Non-available method:
POST https://store.local/wp-json/wc/store/checkout
Testing valid Methods
Do the following request and confirm the order processes and goes to on-hold status.
POST https://store.local/wp-json/wc/store/checkout
Dev Note
In the StoreAPI we've removed the unused PUT method from
wc/store/checkout
to fix some validation issues in POST requests. Like the Block Checkout,wc/store/cart/
routes should be used to update address data instead.Changelog