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

Cannot place order at checkout with Braintree and 3DS enabled using billing addresses without region set #34204

Closed dphilipps closed 2 years ago

dphilipps commented 3 years ago

Preconditions (*)

  1. Magento 2.4.3
  2. Braintree enabled
  3. Card Payments enabled
  4. 3D Secure enabled
  5. Use billing address without state/region set

Steps to reproduce (*)

  1. Enable Braintree in Sandbox mode.
  2. Sandbox credentials: PUBLIC: hpbfzdqypph3njjq PRIVATE: 4de9983821adb24738636e502c557248 MERCHANTID: vq82jrtv65hsgjbk
  3. Enable Braintree Card Payments
  4. Enable Braintree 3D Secure
  5. Sign in to front end as demo user
  6. Under account edit default address and ensure set as default shipping and billing
  7. Country: United Kingdom
  8. Street address: 123 Somewhere
  9. City: London
  10. State/Province: [MUST BE LEFT EMPTY]
  11. Postcode: SE3 9SZ
  12. Make up any other address details
  13. Save address
  14. Add a product to basket and proceed to payment step
  15. Select credit card
  16. Enter card details: 4242 4242 4242 4242 12/23 123
  17. Click 'Place Order'

Expected result (*)

  1. Order confirmation is displayed

Actual result (*)

  1. Cannot proceed past payment screen and cannot place order. Button is non responsive and no errors are displayed on screen. Console messages below:

image

Note: If 3DS is disabled, then the same address (above) will complete OK. Likewise, if a state/region is set it will too.


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

3DS is vital for processing credit card payments as is a regulatory requirement in some jurisdictions and some processors do not approve payments without, therefore disabling it is not a work around. UK addresses which typically do not have state or region set will not be able to place orders with 3DS enabled.

m2-assistant[bot] commented 3 years ago

Hi @dphilipps. 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

dphilipps commented 3 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 3 years ago

Hi @dphilipps. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 3 years ago

Hi @dphilipps, here is your Magento Instance: https://2e0e748fe9adb6f5da4bafbe39d78c0c-2-4-develop.instances.magento-community.engineering Admin access: https://2e0e748fe9adb6f5da4bafbe39d78c0c-2-4-develop.instances.magento-community.engineering/admin_dbfb Login: 8f213e7d Password: c6d8bb5f8e82

dphilipps commented 3 years ago

Hi @engcom-November How do i get an instance deployed with Braintree included in the build? Even with country set in payment methods config, it does not appear.

Many thanks Dave

dphilipps commented 3 years ago

I have verified these steps on a fresh composer install of M2.4.3

dphilipps commented 3 years ago

What do I need to add to this ticket to get it to be triaged @magento/engcom-team-members? This is a serious checkout issue in the latest version of Magento using a mainstream payment gateway?

nicholasscottfish commented 3 years ago

Is there any update on this, we are also experiencing the same issue. This is a critical bug and needs addressing, happy to assist with a fix if required.

@dphilipps did you happen to find a workaround? Disabling 3DS is a no-go for legal reasons, yet making the state field required is a UX problem.

nicholasscottfish commented 3 years ago

@dphilipps For all those who come across this issue, I have created a patch file, attached.

ISSUE-34204__PayPal-Braintree-Validation.patch.zip

diff --git a/view/frontend/web/js/view/payment/3d-secure.js b/view/frontend/web/js/view/payment/3d-secure.js
index 864d5e53..ef832923 100644
--- a/view/frontend/web/js/view/payment/3d-secure.js
+++ b/view/frontend/web/js/view/payment/3d-secure.js
@@ -55,7 +55,7 @@ define([
                 totalAmount = parseFloat(quote.totals()['base_grand_total']).toFixed(2),
                 billingAddress = quote.billingAddress();

-            if (billingAddress.regionCode !== undefined && billingAddress.regionCode.length > 2) {
+            if (billingAddress.regionCode != null && billingAddress.regionCode.length > 2) {
                 billingAddress.regionCode = undefined;
             }

This patch file updates the validation to check for null, which naturally covers both 'undefined and null', thus bypassing the 'cannot read properties of null' error when reading the length in the case a region is not set.

I have created a PR on the Braintree repo, is this the correct place for it? If I need to raise a PR on a different repo please may somebody assign the issue to me and point me in the right direction.

https://github.com/genecommerce/module-braintree-magento2/pull/182

I would question the original code as it seems a bit of a hack having to set regionCode to undefined, a possible workaround for a bug in the system at Braintree's end?

dphilipps commented 3 years ago

Hi @nicholasscottfish Agree this is a nasty one - checkout just freezes. In the end I contacted Gene directly through their Braintree Magento support channel. They got back to me with a patch yesterday but I haven't had a chance to test it yet. I'll post it here. Thanks for your patch BTW.

dphilipps commented 3 years ago

Patch supplied by Gene support directly in response to this issue, however I have not tested it yet.

when region-code is not mandatory(for Magento 2.4.3).zip

nicholasscottfish commented 3 years ago

Hi @dphilipps, the patch I posted has been tested and fixes the issue, however, looking at the patch they supplied it is fixing the same lines of code but is slightly different in that they still set regionCode as undefined if it was null, possibly what needs to happen.

I will get in touch to find out why that is necessary.

Thanks for sharing!

IanFiretoys commented 2 years ago

worth noting that while this seems to only occur using saved addresses for logged in users with a blank region, freshly entered ones work fine. (it was mentioned to save the address in the reproduction steps, but not explicitly anywhere else in the body)

also someone should include the JS error in this issue as text somewhere so it's not so hard for anyone else with the same issue to find. screenshots aren't searchable

hosted-fields.min.js:1 Error in callback function
hosted-fields.min.js:1 TypeError: Cannot read properties of null (reading 'length')
    at Object.validate (3d-secure.js:1)
    at validator-handler.js:1
    at Function.map (jquery.js:2)
    at Object.validate (validator-handler.js:1)
    at UiClass.handleNonce (cc-form.js:1)
    at UiClass.onPaymentMethodReceived (cc-form.js:1)
    at Object.<anonymous> (adapter.js:1)
    at hosted-fields.min.js:1

you're welcome, frantic googlers

anyway, thanks to @dphilipps for logging this, and @nicholasscottfish for the fix, this has been a particularly nasty one to root out.

nicholasscottfish commented 2 years ago

Patch supplied by Gene support directly in response to this issue, however I have not tested it yet.

when region-code is not mandatory(for Magento 2.4.3).zip

I have updated my patch as it had a strict type check on null when it needed to be !=, to be safe I would use the official patch provided by @dphilipps as I have tested and this fixes the bug.

m2-assistant[bot] commented 2 years ago

Hi @engcom-Hotel. 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-Hotel commented 2 years ago

Hi @dphilipps,

Thank you for reporting the issue.

We followed your steps and were able to reproduce it on Magento 2.4-develop/2.4.3/2.4.3-p1. Hence confirming the issue.

Thank you

github-jira-sync-bot commented 2 years ago

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

m2-assistant[bot] commented 2 years ago

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

engcom-Hotel commented 2 years ago

Hello @dphilipps,

Fix for the issue is added to the 2.4.4-release of Braintree package.

With 'paypal/module-braintree' version 4.3.0 issue will be fixed.

Below is the patch which is added to 4.3.0 of 'paypal/module-braintree'

if (billingAddress.regionCode == null)

{ billingAddress.regionCode = undefined; }

We are closing this issue.

Thanks

dphilipps commented 2 years ago

Thank you @engcom-Hotel

engcom-Hotel