Add necessary config for preview scripts

This commit is contained in:
Narek Zakarian 2022-11-02 17:36:08 +04:00
parent 7a0350ea7a
commit 0596f84b21
4 changed files with 38 additions and 22 deletions

View file

@ -58,6 +58,13 @@ class SettingsPageAssets {
*/
private $country;
/**
* Whether Pay Later button is enabled either for checkout, cart or product page.
*
* @var bool
*/
protected $is_pay_later_button_enabled;
/**
* Assets constructor.
*
@ -67,6 +74,7 @@ class SettingsPageAssets {
* @param string $client_id The PayPal SDK client ID.
* @param string $currency 3-letter currency code of the shop.
* @param string $country 2-letter country code of the shop.
* @param bool $is_pay_later_button_enabled Whether Pay Later button is enabled either for checkout, cart or product page.
*/
public function __construct(
string $module_url,
@ -74,14 +82,16 @@ class SettingsPageAssets {
SubscriptionHelper $subscription_helper,
string $client_id,
string $currency,
string $country
string $country,
bool $is_pay_later_button_enabled
) {
$this->module_url = $module_url;
$this->version = $version;
$this->subscription_helper = $subscription_helper;
$this->client_id = $client_id;
$this->currency = $currency;
$this->country = $country;
$this->module_url = $module_url;
$this->version = $version;
$this->subscription_helper = $subscription_helper;
$this->client_id = $client_id;
$this->currency = $currency;
$this->country = $country;
$this->is_pay_later_button_enabled = $is_pay_later_button_enabled;
}
/**
@ -161,6 +171,7 @@ class SettingsPageAssets {
'currency' => $this->currency,
'country' => $this->country,
'integration_date' => PAYPAL_INTEGRATION_DATE,
'is_pay_later_button_enabled' => $this->is_pay_later_button_enabled,
)
);
}

View file

@ -39,7 +39,7 @@ class SettingsStatus {
* @return bool true if is enabled, otherwise false.
* @throws NotFoundException When a setting was not found.
*/
public function pay_later_messaging_is_enabled(): bool {
public function is_pay_later_messaging_enabled(): bool {
$messaging_enabled = $this->settings->has( 'pay_later_messaging_enabled' ) && $this->settings->get( 'pay_later_messaging_enabled' );
$selected_locations = $this->settings->has( 'pay_later_messaging_locations' ) ? $this->settings->get( 'pay_later_messaging_locations' ) : array();
@ -53,8 +53,8 @@ class SettingsStatus {
* @return bool true if is enabled, otherwise false.
* @throws NotFoundException When a setting was not found.
*/
public function pay_later_messaging_is_enabled_for_location( string $location ): bool {
if ( ! $this->pay_later_messaging_is_enabled() ) {
public function is_pay_later_messaging_enabled_for_location( string $location ): bool {
if ( ! $this->is_pay_later_messaging_enabled() ) {
return false;
}
@ -73,11 +73,11 @@ class SettingsStatus {
* @return bool true if is enabled, otherwise false.
* @throws NotFoundException When a setting was not found.
*/
public function pay_later_button_is_enabled(): bool {
$messaging_enabled = $this->settings->has( 'pay_later_button_enabled' ) && $this->settings->get( 'pay_later_button_enabled' );
public function is_pay_later_button_enabled(): bool {
$pay_later_button_enabled = $this->settings->has( 'pay_later_button_enabled' ) && $this->settings->get( 'pay_later_button_enabled' );
$selected_locations = $this->settings->has( 'pay_later_button_locations' ) ? $this->settings->get( 'pay_later_button_locations' ) : array();
return $messaging_enabled && ! empty( $selected_locations );
return $pay_later_button_enabled && ! empty( $selected_locations );
}
/**
@ -87,8 +87,8 @@ class SettingsStatus {
* @return bool true if is enabled, otherwise false.
* @throws NotFoundException When a setting was not found.
*/
public function pay_later_button_is_enabled_for_location( string $location ): bool {
if ( ! $this->pay_later_button_is_enabled() ) {
public function is_pay_later_button_enabled_for_location( string $location ): bool {
if ( ! $this->is_pay_later_button_enabled() ) {
return false;
}
@ -108,8 +108,8 @@ class SettingsStatus {
* @return bool true if is enabled, otherwise false.
* @throws NotFoundException When a setting was not found.
*/
public function pay_later_button_is_enabled_for_context( string $context ): bool {
if ( ! $this->pay_later_button_is_enabled() ) {
public function is_pay_later_button_enabled_for_context( string $context ): bool {
if ( ! $this->is_pay_later_button_enabled() ) {
return false;
}
@ -119,9 +119,9 @@ class SettingsStatus {
return false;
}
$enabled_for_current_location = $this->pay_later_button_is_enabled_for_location( $context );
$enabled_for_product = $this->pay_later_button_is_enabled_for_location( 'product' );
$enabled_for_mini_cart = $this->pay_later_button_is_enabled_for_location( 'mini-cart' );
$enabled_for_current_location = $this->is_pay_later_button_enabled_for_location( $context );
$enabled_for_product = $this->is_pay_later_button_enabled_for_location( 'product' );
$enabled_for_mini_cart = $this->is_pay_later_button_enabled_for_location( 'mini-cart' );
return $context === 'product' ? $enabled_for_product || $enabled_for_mini_cart : $enabled_for_current_location;
}

View file

@ -578,7 +578,7 @@ $data_rows_html
}
return $this->is_paypal_checkout_screen()
&& ( $this->paypal_vaulting_is_enabled() || $this->settings_status->pay_later_messaging_is_enabled() );
&& ( $this->paypal_vaulting_is_enabled() || $this->settings_status->is_pay_later_messaging_enabled() );
}
}

View file

@ -31,6 +31,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Notice\GatewayWithoutPayPalAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
@ -154,13 +155,17 @@ class WCGatewayModule implements ModuleInterface {
);
if ( $c->has( 'wcgateway.url' ) ) {
$settings_status = $c->get( 'wcgateway.settings.status' );
assert( $settings_status instanceof SettingsStatus );
$assets = new SettingsPageAssets(
$c->get( 'wcgateway.url' ),
$c->get( 'ppcp.asset-version' ),
$c->get( 'subscription.helper' ),
$c->get( 'button.client_id' ),
$c->get( 'api.shop.currency' ),
$c->get( 'api.shop.country' )
$c->get( 'api.shop.country' ),
$settings_status->is_pay_later_button_enabled()
);
$assets->register_assets();
}