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

Implemented order available payment methods and order update payment #422

Merged
merged 12 commits into from
Feb 7, 2020

Conversation

dlobato
Copy link
Contributor

@dlobato dlobato commented Apr 8, 2019

Hi,

We have implemented two new actions to handle payment state on placed orders:

  1. Get available payment methods: Same as /{channelCode}/checkout/{token}/payment but on order endpoint.
  2. Update payment method on unpaid placed orders to implement the same behavior as in ShopBundle to allow a customer to change the payment method while order is unpaid.

1 is just reusing the same action from checkout, not sure if I should reimplement this as a different action.
2 adds validation as I've seen on other controllers, is this the preferred approach?

Tests are failing, there's something weird I couldn't figure out on loading the fixtures. I bet I'm doing something wrong. Am I missing something obvious there?

I've also added a new field to placedorder view: paymentState.

David.

@dlobato dlobato requested a review from a team as a code owner April 8, 2019 16:01
src/Command/Order/UpdatePaymentMethod.php Outdated Show resolved Hide resolved
src/Command/Order/UpdatePaymentMethod.php Outdated Show resolved Hide resolved
src/Handler/Order/UpdatePaymentMethodHandler.php Outdated Show resolved Hide resolved
src/Resources/config/routing/order.yml Outdated Show resolved Hide resolved
src/Validator/Constraints/OrderExists.php Outdated Show resolved Hide resolved
tests/Controller/Order/OrderUpdatePaymentMethodApiTest.php Outdated Show resolved Hide resolved
tests/Controller/Order/OrderUpdatePaymentMethodApiTest.php Outdated Show resolved Hide resolved
@dlobato
Copy link
Contributor Author

dlobato commented Apr 16, 2019

@GSadee @mamazu I'm struggling here with the tests... Can't figure out what's wrong. If I run the tests alone on local they work fine, but when running them one after the other there's an unrelated error. Seems to me some sort of race condition while loading the fixtures for the second time. Is something obvious that I'm not seeing here?

@dlobato
Copy link
Contributor Author

dlobato commented Apr 29, 2019

I fixed the tests by changing the item used on the order. Sadly, I couldn't figure out what was the problem but it is related to mug item having product attributes. Since the items on the order are irrelevant for the test purposes I've just used another one and updated the expected responses accordingly.

@mamazu @GSadee is there anything else to code review?

@mamazu
Copy link
Member

mamazu commented Apr 29, 2019

Ill have a look at it this evening.

@mamazu
Copy link
Member

mamazu commented Apr 29, 2019

There are still some open conversations if you could resolve that, this would be great.

Copy link
Member

@lchrusciel lchrusciel left a comment

Choose a reason for hiding this comment

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

I know it was a while, but can you apply my changes as well?

Sorry, for late review

doc/swagger.yml Outdated
@@ -1009,6 +1009,53 @@ paths:
description: "Order with given tokenValue not found"
security:
- bearerAuth: []
/{channelCode}/orders/{token}/payment:
Copy link
Member

Choose a reason for hiding this comment

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

payment -> payments ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather keep it like this to be homogeneous with /{channelCode}/checkout/{token}/payment

spec/Command/Order/UpdatePaymentMethodSpec.php Outdated Show resolved Hide resolved
spec/Handler/Order/UpdatePaymentMethodHandlerSpec.php Outdated Show resolved Hide resolved
tests/DataFixtures/ORM/order.yml Outdated Show resolved Hide resolved
@lchrusciel
Copy link
Member

Hello David,

Sorry for such a long response time. I found some time to dig into ShopAPI and recently fix the way, how we handle placed orders in the test environment (0e445e4)

This made this PR conflicted. Would you like to fix it?

@dlobato
Copy link
Contributor Author

dlobato commented May 10, 2019

@lchrusciel I've updated the tests. But now I can't set the payment state to something different from awaiting_payment to test it_does_not_allow_to_update_payment_method_on_paid_order, any suggestion?
I'd say that I need to trigger pay, but not sure how...

@mamazu
Copy link
Member

mamazu commented May 15, 2019

You can not set the payment method once the payment is completed.

@mamazu
Copy link
Member

mamazu commented May 15, 2019

Ah, I see your problem. Currently there is no way for the API to mark an order as payed. What you can do is try to generate a fixture with a payed order. Other than that I don't know see #310

@jdeveloper
Copy link

What's the status of this issue?

Is there any hope to get merged? It would be great. So if I choose a payment method, paypal for example, complete the order but then I cancel in paypal, I could change the payment method.

@mamazu
Copy link
Member

mamazu commented Feb 4, 2020

I have rebased the issue but I can not push it. @dlobato Please allow edits from maintainers to your branch.

@dlobato
Copy link
Contributor Author

dlobato commented Feb 5, 2020

@mamazu I don't know how to enable that. I was trying this: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork But I don't see said checkbox anywhere...

Implemented validator and tests
Update to symfony messenger
Use tokenValue from fixture
Revert small changes on non related order fixtures
Check order state on UpdatePaymentMethodHandler
Assert payment is in new state
@mamazu
Copy link
Member

mamazu commented Feb 5, 2020

Hm, very strange. I can push to other merge request. Anyhow I have pushed my version of the branch to my repository mamazu/handle_order_payment. You can run the following commands to get this merge request up to speed:

# Add me as a remote
git remote add mamazu git@github.com:mamazu/ShopApiPlugin.git

# Fetch all the branches
git fetch mamazu

# If you are not on your local branch change to it. Otherwise just run
git reset --hard mamazu/handle_order_payment

# Push the new changes to git (you might need to explicitly add `origin handle_order_payment`)
git push --force-with-lease

If you have any questions, don't hesitate to ask.

@dlobato
Copy link
Contributor Author

dlobato commented Feb 5, 2020

Your changes are already on my branch...

@mamazu
Copy link
Member

mamazu commented Feb 6, 2020

This can't be I have fixed the tests (eg. removed the channelcode from the route).

@dlobato
Copy link
Contributor Author

dlobato commented Feb 6, 2020

Check it out now

@mamazu
Copy link
Member

mamazu commented Feb 6, 2020

Looks good. Can you run composer fix and then commit the changes. Then the merge request ready for merge.

Copy link
Member

@mamazu mamazu left a comment

Choose a reason for hiding this comment

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

If you apply those fixes this should be all.

src/Command/Order/UpdatePaymentMethod.php Show resolved Hide resolved
src/Command/Order/UpdatePaymentMethod.php Show resolved Hide resolved
src/Validator/Order/OrderExistsValidator.php Show resolved Hide resolved
dlobato and others added 3 commits February 6, 2020 14:11
Co-Authored-By: mamazu <14860264+mamazu@users.noreply.github.com>
Co-Authored-By: mamazu <14860264+mamazu@users.noreply.github.com>
Co-Authored-By: mamazu <14860264+mamazu@users.noreply.github.com>
Copy link
Member

@mamazu mamazu left a comment

Choose a reason for hiding this comment

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

Last one I promise. :D

src/Validator/Order/OrderExistsValidator.php Outdated Show resolved Hide resolved
src/Validator/Order/OrderExistsValidator.php Show resolved Hide resolved
Co-Authored-By: mamazu <14860264+mamazu@users.noreply.github.com>
@mamazu
Copy link
Member

mamazu commented Feb 6, 2020

Can you please checkout the code and put the right doc comment in there.

@mamazu mamazu merged commit 6f2133c into Sylius:master Feb 7, 2020
@mamazu
Copy link
Member

mamazu commented Feb 7, 2020

Thank you, David! 🥇

$order = $this->orderRepository->findOneBy(['tokenValue' => $choosePaymentMethod->orderToken()]);

Assert::notNull($order, 'Order has not been found.');
Assert::notSame(OrderInterface::STATE_CART, $order->getState(), 'Only orders can be updated.');
Copy link
Member

Choose a reason for hiding this comment

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

Not 100% true, I suppose. Order's in fulfilled state should be blocked as well.

Suggested change
Assert::notSame(OrderInterface::STATE_CART, $order->getState(), 'Only orders can be updated.');
Assert::same(OrderInterface::STATE_NEW, $order->getState(), 'Only new orders can be updated.');

Copy link
Member

Choose a reason for hiding this comment

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

The validator checks if the payment you are trying to edit was not payed yet. This would be a safer option as an assertion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants