-
Notifications
You must be signed in to change notification settings - Fork 219
Add an endpoint for processing pay for order orders #10287
Add an endpoint for processing pay for order orders #10287
Conversation
The release ZIP for this PR is accessible via:
Script Dependencies ReportThe
This comment was automatically generated by the TypeScript Errors Report
🎉 🎉 This PR does not introduce new TS errors. |
Size Change: +1.2 kB (0%) Total Size: 1.36 MB
ℹ️ View Unchanged
|
@@ -271,8 +271,8 @@ public function get_item_response( $order ) { | |||
'coupons' => $this->get_item_responses_from_schema( $this->coupon_schema, $order->get_items( 'coupon' ) ), | |||
'fees' => $this->get_item_responses_from_schema( $this->fee_schema, $order->get_items( 'fee' ) ), | |||
'totals' => (object) $this->prepare_currency_response( $this->get_totals( $order ) ), | |||
'shipping_address' => (object) $this->shipping_address_schema->get_item_response( new \WC_Customer( $order->get_customer_id() ) ), | |||
'billing_address' => (object) $this->billing_address_schema->get_item_response( new \WC_Customer( $order->get_customer_id() ) ), | |||
'shipping_address' => (object) $this->shipping_address_schema->get_item_response( $order ), |
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.
This is because an order does not necessarily have a customer. This will also get guest details.
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.
Works as expected, just a comment for the requires_nonce
method that maybe is not needed, also Checkout.php
and CheckoutOrder.php
share many methods with the exact same code, why not move it to a trait or something like a CheckoutRouteUtils
class?
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.
Thanks for working on this. I made some suggestions inline, and I think we could avoid quite a bit of duplication by extending the current route/schema, since there is quite a bit of overlap.
$order_id = absint( $request['id'] ); | ||
$this->order = wc_get_order( $order_id ); | ||
|
||
if ( $this->order->get_status() !== 'pending' ) { |
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.
Can failed
orders be paid for? What about the checkout-draft status?
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.
Can failed orders be paid for?
Thank you! Updated here 461be20.
What about the checkout-draft status?
The checkout-draft status, do you mean the draft
status in WC->orders?
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.
Yeah, the status checkout block creates. But maybe its not needed.
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.
Ok, I just tested and we can pay for draft
. Checkout order should not have draft
but do we want to make them consistent?
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.
Changes look good. I also tested by editing an order to pending.
I am pre-approving, but I found the following things which may need resolving here or as a follow up:
- When you don't have auth (e.g. no billing email) you see the following API error:
This order belongs to a different customer. Please log in to the correct account.
We should drop the log in part because that doesn't apply to the API calls.
-
If you provide a different billing email to that in the query string, the next request will fail. Not sure if this is a problem or not, but should the request fail for payment reasons, it breaks retries unless you change the provided email.
-
Do we need to support logged out user providing valid ID, key, and billing email? My requests failed because I was not authed and logged in.
Thanks
Updated here b88fe53.
I don't quite understand what you mean here. The request will fail and it breaks retries, do you mean you'll see
For security purposes, I think we should ask the logged-out user to log in for non-guest orders. |
Thats it. It may be expected. |
Let me know if I'm following. Screen.Recording.2023-07-25.at.8.54.36.AM.mov |
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.
LGTM
@mikejolley Since we need to make it to the |
Add an endpoint for processing pay-for-order orders so we can pay for the orders.
Fixes #9312
Other Checks
Testing instructions
Guest
Customer payment page
to go to the pay-for-order pagekey
from the URLhttp://merchant.local/wp-json/wc/store/checkout/YOUR_ORDER_NUMBER?key=YOUR_KEY&billing_email=YOUR_BILLING_EMAIL
No Auth
Pending payment
and Customer:Existing customer
key
andbilling_email
params and send the requestAutomated Tests
Changes in this PR are covered by Automated Tests.
Do not include in the Testing Notes
Changelog