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.53k stars 9.31k forks source link

Unable to place order with existing (Briantree) payment token. #32357

Closed daceej closed 3 years ago

daceej commented 3 years ago

Preconditions (*)

  1. Magento 2.3.3 - Looking at the relevant code, this is likely an issue in Magento 2.4.x as well
  2. Store set up to use Braintree for payments
  3. An api customization to allows orders to be placed with an existing payment token.
  4. Payment token has been updated in Braintree (ie, expiration date updated)

Steps to reproduce (*)

  1. Create a new customer and place an order for a product. Ensure payment token has been added in vault_payment_token
  2. Login in to Braintree management console and update expiration date of payment method token used.
  3. Place an order for the same customer using the updated payment token. Note, the payment token has not changed in Magento, only on the Braintree side of things.
  4. Related issue, for different payment gateway https://github.com/Adyen/adyen-magento2/issues/678

Expected result (*)

  1. Order is placed with updated payment token without issue.

Actual result (*)

  1. Unique constraint violation is thrown.
  2. Issue result of Magento querying existing payment tokens by the public_hash, without checking by customer, payment method, and token itself (ie PaymentTokenManagement::getByGatewayToken($token, $paymentMethodCode, $customerId).
  3. The vault_payment_token table has a unique index on the (customer_id, token, and payment method type) as well as a unique index on the public hash.
  4. The data from the incoming token is different as it has an updated expiration date, so the resulting public hash will be different.
  5. Magento queries by a hash that does not exist, and attempts to insert the new payment token, but fails because a token already exists for that customer, payment token, and payment method type.

I suspect adding the public hash to the multi key unique index on the vault_payment_token table would resolve this, but there may be other implications there that I'm not aware of.


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 3 years ago

Hi @daceej. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

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

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


: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, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

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

daceej commented 3 years ago

To clarify, this is likely outside of any scope as I found this issue due to a customization. However, it took far too long to figure out what was happening, so I'm flagging it as a potential enhancement in the future.

Maybe this will be useful to someone in the future. :)

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!