magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

Mutation deletePaymentToken just disables and hide instead of deleting? #36137

Open rafaelpatro opened 2 years ago

rafaelpatro commented 2 years ago

*Pre Conditions ()** Magento 2.4-develop with Credit card payment and vault enabled.

Description

I'm having some issues with disabled tokens. And I figured out the repository for tokens never deletes the registries. Actually they are just disabled by setting visibility and activation flags to zero.

https://github.com/magento/magento2/blob/7c6b6365a3c099509d6f6e6c306cb1821910aab0/app/code/Magento/Vault/Model/PaymentTokenRepository.php#L127-L140

So I was wondering why not removing these registries when requested by the customer. Is there a reason for this? Is it a good practice to keep in table old and disabled tokens?

*Manual steps to reproduce ()**

  1. Generate customer token using "generateCustomerToken" mutation
  2. Login to store-front and place order with Credit card vault enabled (with Save card for future option)
  3. Run "customerPaymentTokens" query and retrieve public_hash
  4. Run deletePaymentToken mutation
  5. Run deletePaymentToken mutation again using same public_hash

Issue: deletePaymentToken mutation always returining true. No error message displayed. No payment tokens are removed from vault_payment_token DB table.

  1. Run "customerPaymentTokens" query again No issue: Empty set retrieved in the response as the payment token is deleted.
  2. Run deletePaymentToken mutation with invalid public_hash No issue: Expected error is retrieved in the response

Expected result: Could not find a token .. Error message should be displayed. Just like if invalid public_hash is given.

Actual Result: deletePaymentToken mutation always returining true.

Additional Information https://github.com/magento/magento2/issues/36137#issuecomment-1318340325

m2-assistant[bot] commented 2 years ago

Hi @rafaelpatro. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] commented 1 year ago

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-November commented 1 year ago

Hi @rafaelpatro , Thank you for reporting and collaboration. Verified the behavior on Magento 2.4-develop instance and is reproducible. deletePaymentToken mutation is always returning true even if already deleted payment tokens public_hash is given in the graphql request. If any invalid public_hash is given in the request, there is no issue. Proper error message is displayed as expected. This issue exists when deleted payment token public_hash is used. All the payment tokens created before are not removed in the vault_payment_token DB table even after deleting. As per Magento devdocs, mutation should delete a payment token from the system. There is no issue with "customerPaymentTokens" query. Empty set is retrieved if all payment tokens are deleted and no payment tokens are retrieved in the response. Hence updating the description with manual steps to reproduce and confirming this issue.

When deleted public_hash is used: image

With invalid public_hash: image

customerPaymentTokens query after deleting all payment tokens: image

github-jira-sync-bot commented 1 year ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-7048 is successfully created for this GitHub issue.

m2-assistant[bot] commented 1 year ago

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

engcom-Bravo commented 1 year ago

Hi @rafaelpatro,

Thank you for reporting and collaboration. Verified the issue on Magento 2.4-develop instance and the issue is reproducible. Kindly refer the screenhshots.

Steps to Reproduce :

1.Generated customer token using "generateCustomerToken" mutation 2.Loggedin to store-front and placed order with Credit card vault enabled (with Save card for future option) 3.Ran "customerPaymentTokens" query and retrieved public_hash 4.Ran deletePaymentToken mutation 5.Ran deletePaymentToken mutation again using same public_hash

Screenshot 2023-01-16 at 2 41 13 PM Screenshot 2023-01-16 at 2 41 13 PM Screenshot 2023-01-16 at 2 41 55 PM Screenshot 2023-01-16 at 2 42 38 PM

There is no issue if we add invalid public_hash it is throwing errors but if we reran mutation with already used public_has then also result is getting true and no payment tokens are removed from vault_payment_token DB table. so issue is getting reproducible

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 1 year ago

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-7048

vinothjkgds commented 1 year ago

@magento I am working on this

m2-assistant[bot] commented 1 year ago

Hi @vinothjkgds! :wave: Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use @magento add to contributors team command to join Contributors team.

vinothjkgds commented 1 year ago

@magento add to contributors team

m2-assistant[bot] commented 1 year ago

Hi @vinothjkgds! :wave: Thank you for joining. Please accept team invitation :point_right: here :point_left: and add your comment one more time.

vinothjkgds commented 1 year ago

Hi,

Verified this issue and reproducible in Magento2.4 develop instance. I have added the below code to fix this issue. @magento team can you please confirm to create PR for this issue.

File Path: app/code/Magento/Vault/Model/PaymentTokenRepository.php#L128

/** @var PaymentToken $tokenModel */ $tokenModel = $this->getById($paymentToken->getEntityId()); if (empty($tokenModel->getPublicHash())) { return false; } try { **$tokenModel->delete();** return true; }catch(\Exception $e){ return false; }

image

Note: Rest API delete action also uses the same method.

vinothjkgds commented 1 year ago

@magento I am working on this

vinothjkgds commented 1 year ago

@magento i am working on this