Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout bug #351

Closed
wants to merge 13 commits into from
Closed

Checkout bug #351

wants to merge 13 commits into from

Conversation

mamazu
Copy link
Member

@mamazu mamazu commented Nov 23, 2018

Customer needs to be logged in in order to use the checkout.

@mamazu mamazu requested a review from a team as a code owner November 23, 2018 16:01
OrderInterface $order,
OrderRepositoryInterface $orderRepository,
StateMachineFactoryInterface $stateMachineFactory,
StateMachineInterface $stateMachine
): void {
$orderRepository->findOneBy(['tokenValue' => 'ORDERTOKEN'])->willReturn($order);
$customerProvider->provide('example@customer.com')->willReturn($customer);

$customerRepository->findOneBy(['email' => 'example@customer.com'])->willReturn($customer);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to fetch customer from the database? Won't checking just the customer's mail be enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need the customer object later on anyways to add it to the order.

$order->setCustomer($customer)->shouldNotBeCalled();
$stateMachine->apply('complete')->shouldNotBeCalled();

$this->shouldThrow(WrongUserException::class)
Copy link
Member

Choose a reason for hiding this comment

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

👍 but I'm not sure about naming. WDYT about CheckingOutOnBehalfOfAnotherUserException?

Copy link
Member Author

Choose a reason for hiding this comment

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

A little too descriptive but sure, I can change that. I would have a catchier name in mind something like IdentityTheftException

Copy link
Member Author

Choose a reason for hiding this comment

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

This makes it possible to use it also in other places.

return $user->getCustomer()->getEmail();
try {
return $this->loggedInUserProvider->provide()->getEmail();
} catch (TokenNotFoundException $tokenNotFoundException) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to base our login on exception? I would prefer to use if statement and add a new method in loggedInUserProvider/ allow a null return in provide

Copy link
Member Author

Choose a reason for hiding this comment

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

Well that is how the user provider is implemented. I am sure we could also add another method to the LoggedInUserProvider that checks if a user is logged in or not without throwing an exception.

Copy link
Member

Choose a reason for hiding this comment

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

Would be awesome. I don't like base business logic on exceptions

Copy link
Member Author

Choose a reason for hiding this comment

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

I will add that to the interface and then to the UPDATE.md file.

}

// If the customer does exist the user has to be logged in with this customer. Otherwise the user is not authorized to complete the checkout
$loggedInUser = $this->loggedInUserProvider->provide();
Copy link
Member

Choose a reason for hiding this comment

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

That's not exactly true. Customer may exist without ShopUser on only during first guest checkout. We need to cover:

  1. User is logged in - valid
  2. User is not logged in and customer exists, but doesn't have an account - valid
  3. User is not logged in and customer exists, but has an account - exception, he needs to log in
  4. User is logged in but mail is provided - exception

Copy link
Member Author

Choose a reason for hiding this comment

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

So the email is just thought for guest checkout and not needed when the user is already 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.

That would be the perfect solution

Copy link
Member Author

Choose a reason for hiding this comment

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

Then I guess we should introduce another route for checkout. Otherwise this might lead to confusion with the documentation.

@mamazu
Copy link
Member Author

mamazu commented Dec 17, 2018

@lchrusciel Can you have a look at it again?

@lchrusciel
Copy link
Member

Closing in favour of #365

@lchrusciel lchrusciel closed this Jan 3, 2019
Zales0123 added a commit that referenced this pull request Jan 4, 2019
This PR was merged into the 1.0-dev branch.

Discussion
----------

This PR contains the improved implementation of #351. Current implementation will support following scenarios:

1. User is logged in - valid
2. User is not logged in and customer exists, but doesn't have an account - valid
3. User is logged in and customer exists and they are related - valid
4. User is not logged in and customer exists, but has an account - exception, he needs to log in
5. User is logged in but different mail is provided - exception

Commits
-------

ae0575e Fixed the bug and added tests to prevent it
d4c81f6 Fixed phpspec
836982c Removed redundant comparision
069e714 Refactored to use the user provider
2d6deaa Renaming the exception
98f9981 Fixed tests
ef6dc51 Fixed routes in PHPUnit Test
2fcec7d Changed the code to match the requirements
d1e99a2 Fixed phpspec tests
ae7433f Fixed tests for logged in customers
52e4e05 Adding check if a token exists
0408b78 Codestyle
2e64316 Improve logged in shop user provider
a8e8762 Provide logged in safe customer provider implementation
@mamazu mamazu deleted the checkout_bug branch January 9, 2019 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants