magento2
magento2 copied to clipboard
Undefined Array Key "gold" in PayPal Braintree Config
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
- The issue occurs when the configuration value for button colors contains keys not present in the $options array.
- Adding error handling for undefined array keys helps prevent similar issues in the future.
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”.
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:
@magento give me 2.4-develop instance- upcoming 2.4.x release- For more details, review the Magento Contributor Assistant documentation.
- Add a comment to assign the issue:
@magento I am working on this - To learn more about issue processing workflow, refer to the Code Contributions.
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.
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.
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:
- [ ] 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: XXXXXlabel to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced 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: Confirmedonce verification is complete. - [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
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
-
Install magento 2.4.7-p1
-
Enable & configure paypal/module-braintree-core: 4.6.1-p1
-
Set PayPal Button color to Gold and apply
-
Access frontend
-
Add an item to cart and navigate to checkout
-
Observe the Paypal button in gold.
-
No Error displays in checkout related to button.
-
Change the Paypal button color again e.g. Black and apply
-
Access frontend again and navigate to checkout. Button is displaying as expected with no error related to button.
Please let us know if any other steps are needed to be performed. Thanks.
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
Yes as I have upgraded from 2.4.5-p6 to 2.4.7-p1 on 3 installations and produced the same error.
Hi @steveberrill,
Thanks for your reporting and collaboration. We have verified the issue and it is reproducible. Hence, Confirming the issue.
Steps to Reproduce
-
Install magento 2.4.6-p5
-
Configure Braintree Payments - PayPal
-
Configure PayPal button color to gold
-
Upgrade 2.4.6-p5 to 2.4.7-p2
-
Access frontend and navigate to checkout.
-
Observe checkout is blank and error displays in log.
Thanks.
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.
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.
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12849 is successfully created for this GitHub issue.
: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.