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.47k stars 9.28k forks source link

Unable to checkout with PayPal through Braintree #37242

Open n2diving-dgx opened 1 year ago

n2diving-dgx commented 1 year ago

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

m2-assistant[bot] commented 1 year ago

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:

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:

n2diving-dgx commented 1 year ago

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

Rich07082 commented 1 year ago

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.

m2-assistant[bot] commented 1 year ago

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:

m2-assistant[bot] commented 1 year ago

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:


engcom-Dash commented 1 year ago

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,

github-jira-sync-bot commented 1 year ago

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

m2-assistant[bot] commented 1 year ago

: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.

Cupropituvanso commented 1 year ago

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

CollegeSewing commented 1 year ago

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

n2diving-dgx commented 1 year ago

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.

CollegeSewing commented 1 year ago

@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

Rich07082 commented 1 year ago

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

n2diving-dgx commented 1 year ago

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

CollegeSewing commented 1 year ago

@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

Rich07082 commented 1 year ago

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

this worked along with commenting out the lines.

rich

VJW-WSS commented 1 year ago

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.

CollegeSewing commented 1 year ago

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

amjadm61 commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

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

magento-deployment-service[bot] commented 1 year ago

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

Rich07082 commented 1 year ago

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 commented 1 year ago

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

rich

quyendam2612 commented 1 year ago

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

nicholasfishjgm commented 1 year ago

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

Is there an official patch file available in the meantime?

nicholasfishjgm commented 1 year ago

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!!

nordcomputer commented 1 year ago

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

elioermini commented 1 year ago

We also have this issue

domabbott92 commented 1 year ago

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:

Screenshot 2023-05-22 at 13 00 29

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

ThisIsRuddy commented 1 year ago

Same issue here,

Shipping Items Lines not including a unitTaxAmont seems to be breaking the total sum for us

j-lloyd-slc commented 1 year ago

paypal/module-braintree-core v4.5.0 seems to assume the existence of gift wrapping, gift card and customer balance features that are not native to Magento Open Source (perhaps they are Adobe Commerce exclusives?).

When patching, rather than commenting out lines where variables are set to values derived from non-existent extension attributes etc., it is possible to simply assign a zero value instead. This ensures that the variables are not missing when expected later in the code. Since these features do not exist, zero seems like an appropriate value for their contribution to the totals.

It is worth noting that in addition to assuming native features that do not exist, this module does not accommodate 3rd party features that provide similar functionality (and otherwise integrate well).

Patching the canSendLineItems function in vendor/paypal/module-braintree-core/Gateway/Config/Config.php to return false will prevent a mistaken config change from crippling PayPal checkout. (It is unfortunate that this value is only checked after the line item data is compiled.)

andrewdaluz commented 1 year ago

Another issue I found with Braintree was when trying to do SPLIT invoices. When I create the first invoice, everything goes fine. When I try to create a second invoice with the other items left I get an error "Token Invalid".

The issue is related to the code in vendor/paypal/module-braintree-core/Gateway/Request/VaultCaptureDataBuilder.php line 43

        return [
            'amount' => $this->formatPrice($this->subjectReader->readAmount($buildSubject)),
            'paymentMethodToken' => is_null($paymentToken) ?? $paymentToken->getGatewayToken()
        ];

The null coalesce command is wrong as you can see if the object $paymentToken is not null it will return a false and then return false as a paymentMethodToken value.

My solution was:

            'paymentMethodToken' => !$paymentToken ? null : $paymentToken->getGatewayToken()
andrewdaluz commented 1 year ago

I found another issue: when you do a partial invoice with an order that doesn't have a credit card saved. You're going to invoice 1 item in the order, this will set the transaction within this order item's amount. But when you try to invoice another item, you'll receive an error message: "Cannot determine payment method". By reviewing the code it seems like the partial invoice is enabled/working only with PayPal and it's not working for Credit Card with no CreditCard Token saved.

andrewdaluz commented 1 year ago

For the issue reported above I found out that Braintree is no longer saving tokenized credit cards for the transaction (probably for security purposes, which I agree). The problem is that on previous version our client was able to do Partial Invoice with both scenarios:

This issue is related to the change on vendor/paypal/module-braintree-core/Gateway/Request/VaultDataBuilder.php The code before the upgrade:

    public function build(array $buildSubject): array
    {
        return [
            self::OPTIONS => [
                self::STORE_IN_VAULT_ON_SUCCESS => true
            ]
        ];
    }

New Code:

    public function build(array $buildSubject): array
    {
        $result = [];
        $paymentDO = $this->subjectReader->readPayment($buildSubject);
        $payment = $paymentDO->getPayment();
        $data = $payment->getAdditionalInformation();

        if (!empty($data[VaultConfigProvider::IS_ACTIVE_CODE])) {
            $result[self::OPTIONS] = [
                self::STORE_IN_VAULT_ON_SUCCESS => true
            ];
        }

        return $result;
    }

To allow our client to have the ability for Partial Invoicing for all scenarios within credit cards I had to create a patch to rollback these changes.

live4soccer7 commented 1 year ago

I had the same issues with adding to cart and not being able to checkout via braintree. I believe CC and paypal. I'm on 2.4.6-p1. Disabling line items resolved the cart for me and I just attempted to comment out the suggested lines. I sure hope this is resolved in the next patch release. Getting paid is arguably the most important aspect/functionality of the store.

live4soccer7 commented 1 year ago

This allowed paypal payments to come through. I have seen multiple items in a single order and multiple quantities of these items as well.

It is probably a separate issue, but braintree CC payments do not work and simply hang with a loading symbol.

edit: Braintree CC payments was a separate issue caused by google captcha v2.

With the above fixes paypal braintree payments have been working.

Cupropituvanso commented 1 year ago

Is this bug on any roadmap? It prevents us from upgrading and on the other hand we have to work with other bugs which are solved in the newer versions.

live4soccer7 commented 1 year ago

Hopefully. I the meantime the solution/workaround suggested does work.

kartikmaniyar commented 11 months ago

Thank you everyone for your feedback!

GENE Commerce is responsible for developing the Magento Braintree extension. I would like to tell you that this issue is already been fixed in Magento v2.4.7-beta1 that has already been released on June 13, 2023. Here, you can find the v2.4.7-beta1 release notes for the Braintree: https://experienceleague.adobe.com/docs/commerce-operations/release/notes/adobe-commerce/2-4-7.html?lang=en#braintree

We already have a patch ready for Magento/Adobe v2.4.6 and its patch versions for the issue reported here. You can download the patch from this link: https://support.gene.co.uk/support/solutions/articles/35000227790-patch-for-unable-to-checkout-via-paypal-through-braintree-in-magento-v2-4-6-and-v2-4-6-p1-p2

Also if you have any technical issues or concerns regarding our Magento Braintree extension, you can reach out to us by raising a support ticket from here: https://support.gene.co.uk/support/home

nordcomputer commented 11 months ago

Thank you @kartikmaniyar! I have been waiting ages for an official patch. Time to move our installation to the current release :D

adriansanta commented 11 months ago

@kartikmaniyar unfortunately, the patch you provided is not working for us (adobe commerce 2.4.6-p2). we still get: Processor Response Text: Declined (2046) Additional Processor Response: 2046 : ITEM_TOTAL_MISMATCH

Do we have to create a ticket on the GENE site as well?

Please advise, thank you

nomis11uk commented 11 months ago

We have also installed the patch on 2.4.6-p2 but still getting the same error 'PayPal Checkout could not be initialized'

live4soccer7 commented 11 months ago

Can anyone confirm if this is fixed in 2.4.6-p3 that was released today?

adriansanta commented 11 months ago

also @kartikmaniyar, please note that SEPA is not working as expected.

Transaction has not localPayment attribute

This is happening in \PayPal\Braintree\Gateway\Helper\SubjectReader::readLocalPayment because it looks for the localPayment attribute but braintree now responds with something different.

For SEPA for example, if we dump the $transaction object, we get:

Also, paymentId and fundingSource are missing from the SEPA objects. What seems to be the equivalent for those are captureId and bankReferenceToken, respectively.

see https://developer.paypal.com/braintree/docs/reference/response/transaction/php#sepa_debit_account_detail for reference

Please consider this when working on a new version/patch. We are using on our own workaround until the official fix is released:

fix-sepa-dedicated-attribute.patch

Thank you

nomis11uk commented 11 months ago

@live4soccer7 just tried 2.4.6-p3 but still get 'PayPal Checkout could not be initialized. Please contact the store owner.'

live4soccer7 commented 11 months ago

@nomis11uk Did you uncomment lines 192-195? This is how I have mine on p1 (updating to p3 in a couple days). It does work just fine on p1.

nomis11uk commented 11 months ago

@live4soccer7 No but I have already applied the patch. Waiting to hear from GENE Commerce.

live4soccer7 commented 11 months ago

@nomis11uk after updating did you see if the patch is still installed/active?

nomis11uk commented 11 months ago

@live4soccer7 yes, the patched files are unchanged after upgrading to p3