Use the Payment setting model to check if the gateway is enabled.

Once the new settings module is permanently enabled, this model can be passed as a dependency to the styling helper class. For now, we must pass it this way to avoid errors when the new settings module is disabled.
This commit is contained in:
Narek Zakarian 2025-02-27 19:26:42 +04:00
parent e913f60885
commit 447666f9e0
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7

View file

@ -86,13 +86,13 @@ class StylingSettingsMapHelper {
return $this->mapped_disabled_funding_value( $styling_models, $payment_settings );
case 'googlepay_button_enabled':
return $this->mapped_button_enabled_value( $styling_models, 'ppcp-googlepay' );
return $this->mapped_button_enabled_value( $styling_models, 'ppcp-googlepay', $payment_settings );
case 'applepay_button_enabled':
return $this->mapped_button_enabled_value( $styling_models, 'ppcp-applepay' );
return $this->mapped_button_enabled_value( $styling_models, 'ppcp-applepay', $payment_settings );
case 'pay_later_button_enabled':
return $this->mapped_button_enabled_value( $styling_models, 'pay-later' );
return $this->mapped_button_enabled_value( $styling_models, 'pay-later', $payment_settings );
default:
foreach ( $this->locations_map() as $old_location_name => $new_location_name ) {
@ -251,14 +251,15 @@ class StylingSettingsMapHelper {
*
* @param LocationStylingDTO[] $styling_models The list of location styling models.
* @param string $button_name The button name (see {@link self::BUTTON_NAMES}).
* @param PaymentSettings $payment_settings The payment settings model.
* @return int The enabled (1) or disabled (0) state.
* @throws RuntimeException If an invalid button name is provided.
*/
protected function mapped_button_enabled_value( array $styling_models, string $button_name ): ?int {
protected function mapped_button_enabled_value( array $styling_models, string $button_name, PaymentSettings $payment_settings ): ?int {
if ( ! in_array( $button_name, self::BUTTON_NAMES, true ) ) {
throw new RuntimeException( 'Wrong button name is provided.' );
}
var_dump($payment_settings->is_method_enabled($button_name));
$locations_to_context_map = $this->current_context_to_new_button_location_map();
$current_context = $locations_to_context_map[ $this->context() ] ?? '';