Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Conversation

@hsingyuc
Copy link
Contributor

@hsingyuc hsingyuc commented May 9, 2023

Create a PayForOrder service class to implement authentication checks for the pay-for-order checkout block.

Fixes #9400

Screenshots

Before After
Customer Screen Shot 2023-05-08 at 10 27 33 PM Screen Shot 2023-05-08 at 10 28 12 PM
Guest Screen Shot 2023-05-08 at 10 27 33 PM Screen Shot 2023-05-08 at 10 27 33 PM

Testing

  1. Comment out is_wc_endpoint_url( 'order-pay' ) ( Done in this PR )
  2. Create a pay-for-order order as a guest
  3. Go to WC -> Orders -> find the order you just created
  4. Click on the Customer payment page and copy the URL to incognito
  5. See Your cart is currently empty! ( Because we don't allow guest to pay for order )
  6. Go back to the order you just created
  7. Change Customer to an existing customer
  8. Go back to the Your cart is currently empty! page and refresh
  9. See the login form

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

Changelog

Create a PayForOrder service class to implement authentication checks

@hsingyuc hsingyuc requested a review from mikejolley May 9, 2023 05:41
@mikejolley
Copy link
Member

@hsingyuc What do I need to do on my store (in terms of blocks, pages etc) in order to test this?

Is there a reason why we're using content filters vs adding this login form as part of an existing block or (core) shortcode? Thanks for any background info on this.

@hsingyuc
Copy link
Contributor Author

Is there a reason why we're using content filters vs adding this login form as part of an existing block or (core) shortcode? Thanks for any background info on this.

Is this what you are thinking of?

@hsingyuc
Copy link
Contributor Author

What do I need to do on my store (in terms of blocks, pages etc) in order to test this?

I think that we need to continue supporting guest checkouts, which means that we will continue to show the checkout block for guests.

Noting that this PR is just one piece of the pay-for-order flow and won't show the checkout until the other PRs are merged. Specifically this one.

I updated the testing instruction. Let me know if it works for you. Thank you!

@mikejolley
Copy link
Member

I think that we need to continue supporting guest checkouts, which means that we will continue to show the checkout block for guests.

If the order being paid for does not belong to a customer, do we need to require login? I think we could account for that in the authentication check.

Comment out is_wc_endpoint_url( 'order-pay' )
Is this what you are thinking of?

Okay I think I understand what you're doing now. Using checkout Block instead of the legacy shortcode when handling payments. In this case, do you think we need to move the login to the block rather than replacing blocks via the_content hook? Or is this a temporary solution to help with testing?

Noting that this PR is just one piece of the pay-for-order flow and won't show the checkout until the other PRs are merged. Specifically #8960.

I think we should either merge to a feature branch to keep this work separate from trunk, or put it behind a feature flag.

$order = wc_get_order( $order_id );

// Logged out customer does not have permission to pay for this order.
if ( ! current_user_can( 'pay_for_order', $order_id ) && ! is_user_logged_in() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the current_user_can logic already handles user ID validation, and allows guests to pay for guest orders.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check could also move above the wc_get_order to prevent loading an order if its not needed.


$order_id = ! empty( $wp->query_vars['order-pay'] ) ? $wp->query_vars['order-pay'] : null;

if ( isset( $_GET['pay_for_order'], $_GET['key'] ) && $order_id ) { // phpcs:ignore WordPress.Security.NonceVerification
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking to see if pay_for_order is set, but its not validating it against the actual order key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already validate the order key in this PR so we don't need to validate it again, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer we have the same validation logic everywhere (including that check) just in case a future developer assumes this is safe and either reuses it or inserts something that identifies an order. Could turn it into a reusable utility to avoid repetition?

@hsingyuc hsingyuc changed the base branch from trunk to add/pay-for-order-flow May 11, 2023 23:34
@hsingyuc
Copy link
Contributor Author

If the order being paid for does not belong to a customer, do we need to require login? I think we could account for that in the authentication check.

Cool. I don't think we should require login but maybe I miss understood what you mean by With that in mind, I could see an /orders endpoint being useful (to list the logged in current user's orders only), with an /order/ID route for specific order details.

do you think we need to move the login to the block rather than replacing blocks via the_content hook? Or is this a temporary solution to help with testing?

A login block is a good solution long term. For the scope of this project, I prefer to temporarily use the existing login form. We will render the normal checkout block with the order items when login is not required.

I think we should either merge to a feature branch to keep this work separate from trunk, or put it behind a feature flag.

Good idea. Updated.

@mikejolley
Copy link
Member

Cool. I don't think we should require login but maybe I miss understood what you mean by #8922 (comment)

I was thinking ahead to when we'll support "my account" pages. We won't want to include order listing functionality for guests, but we can retrieve a specific order if the correct keys etc are provided.

I wouldn't be too concerned with order listing for this project.

A login block is a good solution long term. For the scope of this project, I prefer to temporarily use the existing login form. We will render the normal checkout block with the order items when login is not required.

👍🏻

@github-actions
Copy link
Contributor

This PR has been marked as stale because it has not seen any activity within the past 7 days. Our team uses this tool to help surface pull requests that have slipped through review.

If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label May 20, 2023
@hsingyuc hsingyuc removed the status: stale Stale issues and PRs have had no updates for 60 days. label Jun 8, 2023
@github-actions
Copy link
Contributor

This PR has been marked as stale because it has not seen any activity within the past 7 days. Our team uses this tool to help surface pull requests that have slipped through review.

If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Jun 16, 2023
@hsingyuc hsingyuc removed the status: stale Stale issues and PRs have had no updates for 60 days. label Jun 20, 2023
@github-actions
Copy link
Contributor

This PR has been marked as stale because it has not seen any activity within the past 7 days. Our team uses this tool to help surface pull requests that have slipped through review.

If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Jun 27, 2023
@hsingyuc hsingyuc removed the status: stale Stale issues and PRs have had no updates for 60 days. label Jun 28, 2023
@hsingyuc hsingyuc deleted the branch woocommerce:add/pay-for-order-flow July 19, 2023 13:49
@hsingyuc hsingyuc closed this Jul 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check authentication for logged out user on the checkout blocks pay for order page

2 participants