magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Unable to checkout with PayPal through Braintree

Open n2diving-dgx opened this issue 1 year ago • 66 comments

Preconditions and environment

Upon upgrading our production site from M2.4.5-p2 to M2.4.6 we discovered customers were unable to checkout via PayPal through Braintree.

We were unable to find any workaround.

Building Magento 2.4.6
+ cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
+ /usr/local/apache/bin/httpd -v
Server version: Apache/2.4.46 (Unix)
Server built:   Jun 16 2021 21:29:21
+ mysql -V
mysql  Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)
+ php -v
PHP 8.1.17 (cli) (built: Mar 17 2023 09:39:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.17, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.17, Copyright (c), by Zend Technologies
+ php /usr/local/bin/composer -V
Composer version 2.3.5 2022-04-13 16:43:00

Steps to reproduce

Fresh Install of M2.4.6 in environment as above Open browser "incognito" window using Windows 11 and Google Chrome Login to Magento admin backend

Nav to Admin>Stores>Configure>General>Web>Default Cookie Settings If necessary, set the Cookie Domain to the appropriate domain value (so Demo Customer will be able to login on front end) Save Config Nav to Admin>Stores>Configure>Sales>Payment Methods Select Merchant Country as United States and Save Config Configure Braintree Payments (by GENE Commerce v4.5.0) Enter known valid sandbox credentials for Merchant ID, Public Key, Private Key and Validate Credentials In the Enable PayPal through Braintree section... Set Enable PayPal through Braintree = Yes Set Display on Shopping Cart = Yes Save Config Flush Magento Cache

Open separate tab on incognito browser and navigate to frontend Successfully Sign In using Demo Customer Access credentials Click Add-to-Cart for Affirm Water Bottle (or anyother product) Observe "spinner" remains over count box in upper right hand corner of page and does not clear NO message "You added the Affirm Water Bottle to your shopping cart." appears Clicking cart icon displays "You have no items in your shopping cart" Add-to-Cart two or three more times for the Affirm Water Bottle Click the Luma Store icon to return to home page [ Although the website is not hung, it's useless because nothing can successfully added to cart, this behavior appears to be related to the PayPal button appearing in the mini-cart ]

Return to backend Nav to Admin>Stores>Configure>Sales>Payment Methods Configure Braintree Payments (by GENE Commerce v4.5.0) In the Enable PayPal through Braintree section Set Display on Shopping Cart = No Save Config Flush Magento Cache

Return to frontend You should still be on the Luma store home page Use your web browser "refresh" function to reload the page The green circle with the check mark and the message "You added the Affirm Water Bottle to your shopping cart." appears several times. The count box in the upper right corner will now equal the number of times add-to-cart was previously clicked. Click the cart icon and Proceed to Checkout Shipping Method select Fixed Flat Rate Payment Method select PayPal Click the large yellow PayPal button Rarely, the PayPal "modal box" zooms out surrounded by dark background, and remains open as normal, If the PayPal modal box remains open, close it and add another item to cart then Proceed to Checkout again In most tests the modal box zooms out for a moment and closes, then Message "PayPal Checkout could not be initialized. Please contact store owner." appears. and you are unable to proceed to place an order.

Expected result

During checkout upon selecting PayPal as the Payment Method then clicking the large yellow PayPal button the PayPal modal box appears and the customer is able to successfully make payment and checkout.

Actual result

During checkout upon selecting PayPal as the Payment Method then clicking the large yellow PayPal button the PayPal modal box appears for a moment before automatically closing and the customer is unable to make payment or complete the order.

Additional information

Tested with both our sandbox and production Braintree creditials, in both production and development environments, PayPal as payment method is essentially not functional although for some reason under certain unknown circumstances it will work as expected for a specific customer checkout. It did work as expected on M2.4.5-p2

I was unable to find any workaround and the PayPal payment method is currently disabled on our M2.4.6 production website.

Release note

No response

Triage and priority

  • [X] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

n2diving-dgx avatar Mar 20 '23 02:03 n2diving-dgx

Hi @n2diving-dgx. Thank you for your report. To speed up processing of this issue, 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:


Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :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.

m2-assistant[bot] avatar Mar 20 '23 02:03 m2-assistant[bot]

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:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • [ ] 5. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Mar 20 '23 05:03 m2-assistant[bot]

After consultation, I have learned that the Braintree V4.5.0 module in M2.4.6 includes new functionality and is now passing individual cart line items to PayPal. Previously, the Braintree V4.4.0 version in M2.4.5 and earlier did NOT pass cart line items to PayPal just the Grand Total amount on the order. However, there is an issue in that when the cart line items do not add up to the Grand Total, for example if there is a separate sales tax line item, then PayPal through Braintree will fail as a payment method on checkout, the modal box will automatically close and Magento will display an error message to the customer "PayPal Checkout could not be initialized."

There is a configuration option found under Advanced Braintree Settings for Send Cart Line Items, which defaults to Yes. Setting "Send Cart Line Items" = NO does allow the PayPal login modal box to zoom out and remain... it is possible to login to PayPal using the modal box, but upon clicking the "Complete Purchase" button, the modal box closes and returns to the Magento checkout flow where a pink box declares "Something went wrong with your request. Please try again later." simultaneously an error for "Call to undefined method..." is logged in exception.log file.

** main.CRITICAL: Error: Call to undefined method Magento\Sales\Api\Data\OrderExtension::getGwBasePrice() in /www/releases/vendor/paypal/module-braintree-core/Gateway/Request/Level23ProcessingDataBuilder.php:188 **

As of now, there is no workaround that allows checkout using PayPal through Braintree on M2.4.6

Screenshot 2023-03-21 052308

n2diving-dgx avatar Mar 20 '23 17:03 n2diving-dgx

same issue, thought it was just related to the PayPal buttons (was getting error when trying to add to cart) and on the cart page when PayPal through Braintree was enabled and display on shopping cart was enabled.

Was able to duplicate error when using paypal as a checkout method.

Rich07082 avatar Mar 22 '23 15:03 Rich07082

Hi @engcom-Bravo. 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:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • [ ] 5. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Mar 28 '23 11:03 m2-assistant[bot]

Hi @engcom-Dash. 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:

    1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    1. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
    1. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
      - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
      - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

m2-assistant[bot] avatar Mar 28 '23 12:03 m2-assistant[bot]

Hi @n2diving-dgx ,

Verified the issue in 2.4.6- Magento instance and the issue is reproducible,Hence we are confirming the issue.Kindly Refer the Screenshots.

Preconditions: Magento version 2.4.6 PHP 8.1 Braintree Payment Module Configured.

Steps to reproduce: As per given main description Steps

Braintree configuration pay3 Display on Shopping Cart is YES pay4 Display on Shopping Cart is NO pay1 pay2

Here attached the video reference placing the order with paypal:

https://user-images.githubusercontent.com/60198592/228395014-b838e1fa-3db5-4c64-a979-84eaed6354cb.mp4

We are getting actual result as per the description ,Hence we are confirming the issue in 2.4.6-develop instance.

Regards,

engcom-Dash avatar Mar 29 '23 00:03 engcom-Dash

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

github-jira-sync-bot avatar Mar 29 '23 00:03 github-jira-sync-bot

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

m2-assistant[bot] avatar Mar 29 '23 00:03 m2-assistant[bot]

We have the same issue and opened another issue. I had closed the other issue, but we have also postet the error log of the server, maybe this could be interesting: https://github.com/magento/magento2/issues/37325

Cupropituvanso avatar Apr 02 '23 21:04 Cupropituvanso

This issue seems to stem for the "Gift Wrapping" Section within /Magento/vendor/paypal/module-braintree-core/Gateway/Request/Level23ProcessingDataBuilder.php

Commenting out lines 186-189 & 198-232 allows PayPal via Braintree to process without errors

Under Advanced Braintree Setttings "Send Cart Lines" Should be set to NO, if items are not being added to the mini-cart

CollegeSewing avatar Apr 04 '23 11:04 CollegeSewing

This ticket is correctly tagged "Priority: P0" - i.e. mission critical functionality for sites accepting PayPal payments through Braintree for which there is no work around other than revert to M2.4.5 The only thing to do to remain on M2.4.6 is turn off accepting payments via PayPal, which in our case means PayPal is losing hundreds of USD per day and at least a other sites are likely in the same situation so in actuality this means PayPal losses are possibly thousands of USD in fees per day! Plus an unknown impact of the merchant not offering a PayPal payment method to customers. I expect if the question were asked of PayPal "What is the impact on my sales as a result of not offering PayPal as a payment method?" their reply would be something like "significant".

Yet two+ weeks have passed and it is not even assigned to a developer much less a hotfix.

n2diving-dgx avatar Apr 04 '23 12:04 n2diving-dgx

@n2diving-dgx

Have you attempted my fix above

With Magento 2.4.6 lines 186-189 & 198-232 within vendor/paypal/module-braintree-core/Gateway/Request/Level23ProcessingDataBuilder.php there is added function for "Gift Wrapping" which is not referenced in Magento 2.4.5

Commenting out the above lines in my testing "fixes" the PayPal via Braintree within Magento 2.4.6

CollegeSewing avatar Apr 04 '23 14:04 CollegeSewing

still seem to have an issue in the cart(after applying above fix).

https://test.nationalfleetparts.com/checkout/cart/

Also if you have the mini cart enabled seems to be an issue adding items to the cart.

rich

Rich07082 avatar Apr 04 '23 23:04 Rich07082

@n2diving-dgx

Have you attempted my fix above

With Magento 2.4.6 lines 186 through 232 within vendor/paypal/module-braintree-core/Gateway/Request/Level23ProcessingDataBuilder.php there is added function for "Gift Wrapping" which is not referenced in Magento 2.4.5

Commenting out the above lines in my testing "fixes" the PayPal via Braintree within Magento 2.4.6

No change, but I wasn't using the gift card functions at all.

n2diving-dgx avatar Apr 04 '23 23:04 n2diving-dgx

@Rich07082 Under Advanced Braintree Setttings "Send Cart Lines" Should be set to NO Send_Cart_Lines Items will then be added to the Mini Cart

@n2diving-dgx I can't confirm regarding the Gift Card (Lines 192-195) but I can confirm the issue with gwBasePrice relates to Gift Wrapping as per your comment (on lines 186-190 203-232)

Braintree_GiftWrap

CollegeSewing avatar Apr 05 '23 07:04 CollegeSewing

Under Advanced Braintree Setttings "Send Cart Lines" Should be set to NO

this worked along with commenting out the lines.

rich

Rich07082 avatar Apr 05 '23 11:04 Rich07082

Had same issue since upgrade to 2.4.6 Didn't actually notice until customer told me today 10 days later!

Tried commenting out lines 186-232 in Level23ProcessingDataBuilder.php but this left an error with undefined variable $baseCustomerBalAmountUsed (to do with store credits but never use them).

Have now left lines 192-195 in and payments are processing okay.

Anyone who has had this problem might want to check the inventory_reservation table in their database. It seems that stock was being reserved even though the payments were failing, resulting in stock being unavailable to order.

VJW-WSS avatar Apr 05 '23 16:04 VJW-WSS

@VJW-WSS I've updated my original comment above to reflect

CollegeSewing avatar Apr 05 '23 17:04 CollegeSewing

@magento give me 2.4-develop instance

amjadm61 avatar Apr 13 '23 10:04 amjadm61

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

Hi @amjadm61, here is your Magento Instance: https://3c8bfc21c232c3a136530903891d23cb.instances-prod.magento-community.engineering Admin access: https://3c8bfc21c232c3a136530903891d23cb.instances-prod.magento-community.engineering/admin_b706 Login: 543b9380 Password: f39daed88b74

another error when trying to checkout. Haven't seen this one mentioned yet and the above fix bypasses one error but this comes after.

[2023-04-14T17:41:07.362337+00:00] main.CRITICAL: Exception: Warning: Undefined variable $baseCustomerBalAmountUsed in vendor/paypal/module-braintree-core/Gateway/Request/Level23ProcessingDataBuilder.php on line 240 in /public_html/vendor/magento/framework/App/ErrorHandler.php:62

Rich

Rich07082 avatar Apr 14 '23 17:04 Rich07082

anything with this? Been over a month, seems like a pretty big issue.

rich

Rich07082 avatar Apr 21 '23 11:04 Rich07082

Looks like we haven't had any update yet..

quyendam2612 avatar Apr 27 '23 01:04 quyendam2612

Hi there, is there any update on this issue? Timescale to resolution?

Is there an official patch file available in the meantime?

nicholasfishjgm avatar May 10 '23 09:05 nicholasfishjgm

For anyone experiencing the same issue, here is a temporary patch file that comments out the gift wrap settings, but avoids commenting out any $variables that are required further down the file.

ISSUE-37242-braintree-paypal-gw.patch

For reference too, we did not have to update the Braintree 'Send Cart Line Items', this may vary for different stores.

Please note: The above is untested in a production environment and so please use with caution!!

nicholasfishjgm avatar May 10 '23 09:05 nicholasfishjgm

Hey, thanks a lot @nicholasfishjgm - that helps for now. But an official update by the maintainers would still be very appreciated.

nordcomputer avatar May 10 '23 10:05 nordcomputer

We also have this issue

elioermini avatar May 18 '23 18:05 elioermini

Just to follow on from @nicholasfishjgm last comment...

We have had to revert this from Production due to other PayPal issues. We are not sure yet if this it directly affected by the above issue/patch, or if there are further PayPal issues with 2.4.6.

On 'high' value PayPal orders (seems to be £1900+) the customer gets the error "PayPal Checkout could not be initialized. Please contact the store owner" with a corresponding network error:

    "paymentResource": {
        "errorName": "VALIDATION_ERROR",
        "errorMessage": "Invalid request - see details --- transactions[0]:Item amount must add up to specified amount subtotal (or total if amount details not specified)",
        "errorDetails": [
            {
                "field": "transactions[0]",
                "issue": "Item amount must add up to specified amount subtotal (or total if amount details not specified)"
            }
        ],
        "debugId": "8f0b04e899294",
        "paypalHttpStatus": 400
    }
}

UPDATE

The issue only occurs when two of the same item are in the cart. It seems to be using single unitAmount but the unitTaxAmount is already calculated with the quantity.

For example:

  • Item is £0.32
  • Two items are added so it's £0.64 subtotal (32*2)
  • The tax amount should show as 6p but is showing as 13p
Screenshot 2023-05-22 at 13 00 29

This appears unrelated to the original issue so will open as a new ticket.

domabbott92 avatar May 22 '23 10:05 domabbott92