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

Undefined Array Key "gold" in PayPal Braintree Config #39022

Open steveberrill opened 1 month ago

steveberrill commented 1 month ago

Preconditions and environment

Environment:

Magento Version: 2.4.7-p1 paypal/module-braintree-core: 4.6.1-p1 PHP Version: 8.3

When using the paypal/module-braintree-core module in Magento 2, an Undefined array key "gold" warning is triggered during checkout. This occurs in the getCreditButtonColor() method of the PayPal\Braintree\Gateway\Config\PayPal\Config class.

Code Example:

The issue is located in the getCreditButtonColor() method in the Config.php file:

public function getCreditButtonColor(string $area = self::BUTTON_AREA_CART, string $type = 'credit'): ?string
{
    $value = $this->getButtonStyle($area, self::KEY_BUTTON_COLOR, $type);
    $options = $this->creditColorSource->toRawValues();
    return $options[$value]; // Causes the warning if $value is not a valid key
}

Proposed Fix:

Update the method to check if the key exists in the $options array before accessing it:

public function getCreditButtonColor(string $area = self::BUTTON_AREA_CART, string $type = 'credit'): ?string
{
    $value = $this->getButtonStyle($area, self::KEY_BUTTON_COLOR, $type);
    $options = $this->creditColorSource->toRawValues();
    return isset($options[$value]) ? $options[$value] : null; // Safely handle missing keys
}

Steps to reproduce

Ensure that the paypal/module-braintree-core module is installed. Configure button colors in the Magento admin panel for the Braintree payment method. Proceed to checkout on the frontend. Observe the error in the logs or directly on the checkout page. Expected Behavior:

The method should gracefully handle cases where the specified color key (e.g., "gold") does not exist in the configuration, returning null or a default value instead of causing a warning.

Expected result

The method should gracefully handle cases where the specified color key (e.g., "gold") does not exist in the configuration, returning null or a default value instead of causing a warning.

Actual result

An Undefined array key "gold" warning is triggered, leading to a potential disruption in the checkout process and a cluttered error log.

Additional information

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 month ago

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

n2diving-dgx commented 1 month ago

I had this exact same issue upon upgrade from 2.4.6-p6 to 2.4.7-p1, in sandbox testing on development environment it did not occur but in my case it only occurred in production (... customers were unable to place orders regardless if they selected the PayPal payment method or not, that was an interesting hour I'm never getting back!) The workaround that appears to have resolved it was Stores > Configuration > Sales > Payment Methods > Additional Payment Solutions > PayPal Braintree > Configure > PayPal through Braintree > Styling > Checkout Page > PayPal Button and changing the button configuration, then Pay Later Messaging > Reset to Recommended Defaults. Finally, Save Config (and flushing magento cache). That resolved the error, and I was able to return to the button configuration and restore previous settings (including "Gold" color selection) without issue.

The key to reproducing this error might be the upgrade from 2.4.6 to 2.4.7 where PayPal credit was configured and enabled in 2.4.6 prior to the upgrade.

m2-assistant[bot] commented 1 month ago

Hi @engcom-Delta. 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-Delta commented 1 month ago

Hi @steveberrill,

Thanks for your reporting and collaboration. We have verified the issue in magento 2.4.7-p1, but we are unable to reproduce the issue. Kindly refer the screenshots.

Steps to reproduce

  1. Install magento 2.4.7-p1 image

  2. Enable & configure paypal/module-braintree-core: 4.6.1-p1

  3. Set PayPal Button color to Gold and apply image

  4. Access frontend

  5. Add an item to cart and navigate to checkout

  6. Observe the Paypal button in gold. image

  7. No Error displays in checkout related to button.

  8. Change the Paypal button color again e.g. Black and apply image

  9. Access frontend again and navigate to checkout. Button is displaying as expected with no error related to button. image

Please let us know if any other steps are needed to be performed. Thanks.

n2diving-dgx commented 1 month ago

Again... The key to reproducing this error might be the upgrade from 2.4.6 to 2.4.7 where PayPal credit was configured and enabled in 2.4.6 prior to the upgrade. The attempt to reproduce did not perform the upgrade first

steveberrill commented 1 month ago

Yes as I have upgraded from 2.4.5-p6 to 2.4.7-p1 on 3 installations and produced the same error.

engcom-Delta commented 2 weeks ago

Hi @steveberrill,

Thanks for your reporting and collaboration. We have verified the issue and it is reproducible. Hence, Confirming the issue.

Steps to Reproduce

  1. Install magento 2.4.6-p5 image

  2. Configure Braintree Payments - PayPal

  3. Configure PayPal button color to gold image

  4. Upgrade 2.4.6-p5 to 2.4.7-p2 image

  5. Access frontend and navigate to checkout.

  6. Observe checkout is blank and error displays in log. image image

Thanks.

github-jira-sync-bot commented 2 weeks ago

Unfortunately, not enough information was provided to create a Jira ticket. Please make sure you added the following label(s): Reproduced on 2.4.x, ^Area:.*

Once all required labels are present, please add Issue: Confirmed label again.

github-jira-sync-bot commented 2 weeks ago

Unfortunately, not enough information was provided to create a Jira ticket. Please make sure you added the following label(s): Reproduced on 2.4.x, ^Area:.*

Once all required labels are present, please add Issue: Confirmed label again.

github-jira-sync-bot commented 2 weeks ago

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

m2-assistant[bot] commented 2 weeks ago

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