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

[PaymentRequest] Automatically cancel all pending payment requests when the payment method gets changed #15950

Open
wants to merge 103 commits into
base: payment-request
Choose a base branch
from

Conversation

TheMilek
Copy link
Member

@TheMilek TheMilek commented Mar 5, 2024

Q A
Branch? payment-request
Bug fix? no
New feature? yes
BC breaks? no
License MIT

@TheMilek TheMilek force-pushed the SYL-3368 branch 3 times, most recently from 915f378 to 64305ce Compare March 13, 2024 08:35
Comment on lines 15 to 21
@no-ui @api
Scenario: Cancelling the payment request when payment method is changed
Given I added product "Iron Maiden T-Shirt" to the cart
And I have proceeded selecting "PayPal" payment method
When I confirm my order with paypal payment
And I change payment method to "Offline" after checkout
Then the payment request for payment method "PayPal" should be cancelled
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@no-ui @api
Scenario: Cancelling the payment request when payment method is changed
Given I added product "Iron Maiden T-Shirt" to the cart
And I have proceeded selecting "PayPal" payment method
When I confirm my order with paypal payment
And I change payment method to "Offline" after checkout
Then the payment request for payment method "PayPal" should be cancelled
@no-ui @api
Scenario: Cancelling the payment request when payment method is changed
Given I added product "Iron Maiden T-Shirt" to the cart
And I have proceeded selecting "PayPal" payment method
And I confirm my order with paypal payment # <- I'm wondering whether it's necessary as we have "I have proceeded"
When I change payment method to "Offline" after checkout
Then the payment request for payment method "PayPal" should be cancelled

IMO confirm is a part of preparation, and When starts for this scenario when I want to change the payment method. Also I'm wondering whether the I confirm can be skipped here.

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 renamed it a bit, as yeah it might be misleading

TheMilek and others added 5 commits March 13, 2024 13:30
This PR was merged into the payment-request branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | `payment-request`


Commits
-------
  Create an environment for payumless tests
  Add workflows using the test_cached_payumless env
  Rename the test_cached_payumless environment to test_cached_payum
  Change the 'sylius.payment_request.command_provider.payum.offline' priority when the test_cached_payum env is used
  Fix Payum-related tests
@TheMilek TheMilek force-pushed the SYL-3368 branch 2 times, most recently from 931cbb1 to 258ffda Compare March 13, 2024 13:14
Wojdylak and others added 2 commits March 13, 2024 14:58
…ngful exceptions or remove some of them (TheMilek)

This PR was merged into the payment-request branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | payment-request <!-- see the comment below -->                  |
| Bug fix?        | no                                                      |
| New feature?    | no                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | no <!-- don't forget to update the UPGRADE-*.md file --> |
| License         | MIT                                                          |

<!--
 - Bug fixes must be submitted against the 1.12 branch
 - Features and deprecations must be submitted against the 1.13 branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------
  Make some methods non nullable
  Add new exceptions
  Remove unecessary asserts or convert them to exceptions
  Rename PaymentRequestChecker to provider
  Use just find() repository method instead of creating a new one
And the store ships everywhere for Free
And the store allows paying Offline
And the store has a payment method "PayPal" with a code "PAYPAL" and Paypal Express Checkout gateway
And there is a customer "sylius@example.com" that placed an order "#00000022"
Copy link
Member

Choose a reason for hiding this comment

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

This step seems not to be needed in this scenario

Suggested change
And there is a customer "sylius@example.com" that placed an order "#00000022"

@paying_for_order
Feature: Cancelling payment request when payment method is changed
In order to pay with the correct payment method
As a Customer
Copy link
Member

Choose a reason for hiding this comment

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

The actor is a visitor, not a customer, as there is no login step in the scenario

Suggested change
As a Customer
As a Visitor

Copy link
Contributor

Choose a reason for hiding this comment

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

But only customer can change the payment method (once you bought anything, you became a customer), so IMO the actor is valid here.


foreach ($commands as $command) {
if ($this->isNotValid($command) || $method !== Request::METHOD_PATCH) {
return;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return;
continue;

Should we check other arguments?

$method = $event->getRequest()->getMethod();

foreach ($commands as $command) {
if ($this->isNotValid($command) || $method !== Request::METHOD_PATCH) {
Copy link
Member

Choose a reason for hiding this comment

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

The method could be checked before the foreach

*
* @return array<PaymentRequestInterface>
*/
public function findByStatesAndPaymentId(array $states, int|string $paymentId): array
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public function findByStatesAndPaymentId(array $states, int|string $paymentId): array
public function findByPaymentIdAndStates(int|string $paymentId, array $states): array

🤔

@Prometee
Copy link
Contributor

Prometee commented Apr 8, 2024

@TheMilek can you rebase this PR, your changes are lost in my commits :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API APIs related issues and PRs. Maintenance CI configurations, READMEs, releases, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants