Merge pull request #1507 from woocommerce/PCP-1846-log-subscription-mode-configuration-in-system-report

log Subscription Mode configuration in system report (1846)
This commit is contained in:
Emili Castells 2023-07-18 15:38:28 +02:00 committed by GitHub
commit a58900f1f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 19 deletions

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\StatusReport; namespace WooCommerce\PayPalCommerce\StatusReport;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider; use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface; use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface; use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
@ -49,6 +50,8 @@ class StatusReportModule implements ModuleInterface {
$settings = $c->get( 'wcgateway.settings' ); $settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof ContainerInterface ); assert( $settings instanceof ContainerInterface );
$subscriptions_mode_settings = $c->get( 'wcgateway.settings.fields.subscriptions_mode' ) ?: array();
/* @var State $state The state. */ /* @var State $state The state. */
$state = $c->get( 'onboarding.state' ); $state = $c->get( 'onboarding.state' );
@ -61,6 +64,9 @@ class StatusReportModule implements ModuleInterface {
/* @var MessagesApply $messages_apply The messages apply. */ /* @var MessagesApply $messages_apply The messages apply. */
$messages_apply = $c->get( 'button.helper.messages-apply' ); $messages_apply = $c->get( 'button.helper.messages-apply' );
/* @var SubscriptionHelper $subscription_helper The subscription helper class. */
$subscription_helper = $c->get( 'subscription.helper' );
$last_webhook_storage = $c->get( 'webhook.last-webhook-storage' ); $last_webhook_storage = $c->get( 'webhook.last-webhook-storage' );
assert( $last_webhook_storage instanceof WebhookEventStorage ); assert( $last_webhook_storage instanceof WebhookEventStorage );
@ -167,6 +173,20 @@ class StatusReportModule implements ModuleInterface {
), ),
); );
// For now only show this status if PPCP_FLAG_SUBSCRIPTIONS_API is true.
if ( defined( 'PPCP_FLAG_SUBSCRIPTIONS_API' ) && PPCP_FLAG_SUBSCRIPTIONS_API ) {
$items[] = array(
'label' => esc_html__( 'Subscriptions Mode', 'woocommerce-paypal-payments' ),
'exported_label' => 'Subscriptions Mode',
'description' => esc_html__( 'Whether subscriptions are active and their mode.', 'woocommerce-paypal-payments' ),
'value' => $this->subscriptions_mode_text(
$subscription_helper->plugin_is_active(),
$settings->has( 'subscriptions_mode' ) ? (string) $settings->get( 'subscriptions_mode' ) : '',
$subscriptions_mode_settings
),
);
}
echo wp_kses_post( echo wp_kses_post(
$renderer->render( $renderer->render(
esc_html__( 'WooCommerce PayPal Payments', 'woocommerce-paypal-payments' ), esc_html__( 'WooCommerce PayPal Payments', 'woocommerce-paypal-payments' ),
@ -200,6 +220,27 @@ class StatusReportModule implements ModuleInterface {
return $token->is_valid() && $current_state === $state::STATE_ONBOARDED; return $token->is_valid() && $current_state === $state::STATE_ONBOARDED;
} }
/**
* Returns the text associated with the subscriptions mode status.
*
* @param bool $is_plugin_active Indicates if the WooCommerce Subscriptions plugin is active.
* @param string $subscriptions_mode The subscriptions mode stored in settings.
* @param array $field_settings The subscriptions mode field settings.
* @return string
*/
private function subscriptions_mode_text( bool $is_plugin_active, string $subscriptions_mode, array $field_settings ): string {
if ( ! $is_plugin_active || ! $field_settings || $subscriptions_mode === 'disable_paypal_subscriptions' ) {
return 'Disabled';
}
if ( ! $subscriptions_mode ) {
$subscriptions_mode = $field_settings['default'] ?? '';
}
// Return the options value or if it's missing from options the settings value.
return $field_settings['options'][ $subscriptions_mode ] ?? $subscriptions_mode;
}
/** /**
* Checks if reference transactions are enabled in account. * Checks if reference transactions are enabled in account.
* *

View file

@ -385,6 +385,28 @@ return array(
return array_key_exists( $current_page_id, $sections ); return array_key_exists( $current_page_id, $sections );
}, },
'wcgateway.settings.fields.subscriptions_mode' => static function ( ContainerInterface $container ): array {
return array(
'title' => __( 'Subscriptions Mode', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'desc_tip' => true,
'description' => __( 'Utilize PayPal Vaulting for flexible subscription processing with saved payment methods, create “PayPal Subscriptions” to bill customers at regular intervals, or disable PayPal for subscription-type products.', 'woocommerce-paypal-payments' ),
'default' => 'vaulting_api',
'options' => array(
'vaulting_api' => __( 'PayPal Vaulting', 'woocommerce-paypal-payments' ),
'subscriptions_api' => __( 'PayPal Subscriptions', 'woocommerce-paypal-payments' ),
'disable_paypal_subscriptions' => __( 'Disable PayPal for subscriptions', 'woocommerce-paypal-payments' ),
),
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'paypal',
);
},
'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array { 'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array {
$should_render_settings = $container->get( 'wcgateway.settings.should-render-settings' ); $should_render_settings = $container->get( 'wcgateway.settings.should-render-settings' );
@ -797,25 +819,7 @@ return array(
'requirements' => array(), 'requirements' => array(),
'gateway' => 'paypal', 'gateway' => 'paypal',
), ),
'subscriptions_mode' => array( 'subscriptions_mode' => $container->get( 'wcgateway.settings.fields.subscriptions_mode' ),
'title' => __( 'Subscriptions Mode', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'desc_tip' => true,
'description' => __( 'Utilize PayPal Vaulting for flexible subscription processing with saved payment methods, create “PayPal Subscriptions” to bill customers at regular intervals, or disable PayPal for subscription-type products.', 'woocommerce-paypal-payments' ),
'default' => 'vaulting_api',
'options' => array(
'vaulting_api' => __( 'PayPal Vaulting', 'woocommerce-paypal-payments' ),
'subscriptions_api' => __( 'PayPal Subscriptions', 'woocommerce-paypal-payments' ),
'disable_paypal_subscriptions' => __( 'Disable PayPal for subscriptions', 'woocommerce-paypal-payments' ),
),
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'paypal',
),
'vault_enabled' => array( 'vault_enabled' => array(
'title' => __( 'Vaulting', 'woocommerce-paypal-payments' ), 'title' => __( 'Vaulting', 'woocommerce-paypal-payments' ),
'type' => 'checkbox', 'type' => 'checkbox',