2021-07-20 14:56:37 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* The status report module.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\PayPalCommerce\StatusReport
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace WooCommerce\PayPalCommerce\StatusReport;
|
|
|
|
|
|
|
|
use Dhii\Container\ServiceProvider;
|
|
|
|
use Dhii\Modular\Module\ModuleInterface;
|
|
|
|
use Interop\Container\ServiceProviderInterface;
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
2021-07-26 16:08:32 +02:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
2021-07-20 14:56:37 +02:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
2021-11-22 18:20:00 +02:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencySupport;
|
2021-07-20 14:56:37 +02:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
|
|
|
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
2021-11-22 18:21:01 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Compat\PPEC\PPECHelper;
|
2021-07-20 14:56:37 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\State;
|
2021-11-24 11:52:14 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Webhooks\WebhookInfoStorage;
|
2021-07-20 14:56:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class StatusReportModule
|
|
|
|
*/
|
|
|
|
class StatusReportModule implements ModuleInterface {
|
|
|
|
|
|
|
|
/**
|
2021-07-21 11:31:56 +02:00
|
|
|
* {@inheritDoc}
|
2021-07-20 14:56:37 +02:00
|
|
|
*/
|
|
|
|
public function setup(): ServiceProviderInterface {
|
|
|
|
return new ServiceProvider(
|
|
|
|
require __DIR__ . '/../services.php',
|
|
|
|
require __DIR__ . '/../extensions.php'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-21 11:31:56 +02:00
|
|
|
* {@inheritDoc}
|
|
|
|
*
|
2021-08-30 08:10:43 +02:00
|
|
|
* @param ContainerInterface $c A services container instance.
|
2021-07-20 14:56:37 +02:00
|
|
|
*/
|
2021-08-30 08:10:43 +02:00
|
|
|
public function run( ContainerInterface $c ): void {
|
2021-07-20 14:56:37 +02:00
|
|
|
add_action(
|
|
|
|
'woocommerce_system_status_report',
|
2021-08-30 08:10:43 +02:00
|
|
|
function () use ( $c ) {
|
2021-11-19 17:25:47 +02:00
|
|
|
$settings = $c->get( 'wcgateway.settings' );
|
|
|
|
assert( $settings instanceof ContainerInterface );
|
2021-07-26 16:08:32 +02:00
|
|
|
|
|
|
|
/* @var State $state The state. */
|
2021-08-30 08:10:43 +02:00
|
|
|
$state = $c->get( 'onboarding.state' );
|
2021-07-26 16:08:32 +02:00
|
|
|
|
|
|
|
/* @var Bearer $bearer The bearer. */
|
2021-08-30 08:10:43 +02:00
|
|
|
$bearer = $c->get( 'api.bearer' );
|
2021-07-26 16:08:32 +02:00
|
|
|
|
2021-11-22 18:20:00 +02:00
|
|
|
$currency_support = $c->get( 'api.helpers.currency-support' );
|
|
|
|
assert( $currency_support instanceof CurrencySupport );
|
|
|
|
|
2021-07-26 16:08:32 +02:00
|
|
|
/* @var DccApplies $dcc_applies The ddc applies. */
|
2021-08-30 08:10:43 +02:00
|
|
|
$dcc_applies = $c->get( 'api.helpers.dccapplies' );
|
2021-07-26 16:08:32 +02:00
|
|
|
|
|
|
|
/* @var MessagesApply $messages_apply The messages apply. */
|
2021-08-30 08:10:43 +02:00
|
|
|
$messages_apply = $c->get( 'button.helper.messages-apply' );
|
2021-07-26 16:08:32 +02:00
|
|
|
|
2021-11-24 11:52:14 +02:00
|
|
|
$last_webhook_storage = $c->get( 'webhook.last-webhook-storage' );
|
|
|
|
assert( $last_webhook_storage instanceof WebhookInfoStorage );
|
|
|
|
|
2021-07-26 16:08:32 +02:00
|
|
|
/* @var Renderer $renderer The renderer. */
|
2021-08-30 08:10:43 +02:00
|
|
|
$renderer = $c->get( 'status-report.renderer' );
|
2021-07-26 16:08:32 +02:00
|
|
|
|
2021-11-22 18:21:01 +02:00
|
|
|
$had_ppec_plugin = PPECHelper::is_plugin_configured();
|
|
|
|
|
2021-07-26 16:08:32 +02:00
|
|
|
$items = array(
|
|
|
|
array(
|
2021-11-25 10:33:54 +02:00
|
|
|
'label' => esc_html__( 'Onboarded', 'woocommerce-paypal-payments' ),
|
|
|
|
'exported_label' => 'Onboarded',
|
|
|
|
'description' => esc_html__( 'Whether PayPal account is correctly configured or not.', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $this->bool_to_text(
|
2021-11-19 17:25:08 +02:00
|
|
|
$this->onboarded( $bearer, $state )
|
|
|
|
),
|
2021-07-26 16:08:32 +02:00
|
|
|
),
|
|
|
|
array(
|
2021-11-25 10:33:54 +02:00
|
|
|
'label' => esc_html__( 'Shop country code', 'woocommerce-paypal-payments' ),
|
|
|
|
'exported_label' => 'Shop country code',
|
|
|
|
'description' => esc_html__( 'Country / State value on Settings / General / Store Address.', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => wc_get_base_location()['country'],
|
2021-07-26 16:08:32 +02:00
|
|
|
),
|
2021-11-22 18:20:00 +02:00
|
|
|
array(
|
2021-11-25 10:33:54 +02:00
|
|
|
'label' => esc_html__( 'WooCommerce currency supported', 'woocommerce-paypal-payments' ),
|
|
|
|
'exported_label' => 'WooCommerce currency supported',
|
|
|
|
'description' => esc_html__( 'Whether PayPal supports the default store currency or not.', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $this->bool_to_text(
|
2021-11-22 18:20:00 +02:00
|
|
|
$currency_support->supports_wc_currency()
|
|
|
|
),
|
|
|
|
),
|
2021-07-26 16:08:32 +02:00
|
|
|
array(
|
2021-11-25 10:33:54 +02:00
|
|
|
'label' => esc_html__( 'PayPal card processing available in country', 'woocommerce-paypal-payments' ),
|
|
|
|
'exported_label' => 'PayPal card processing available in country',
|
|
|
|
'description' => esc_html__( 'Whether PayPal card processing is available in country or not.', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $this->bool_to_text(
|
2021-11-19 17:25:08 +02:00
|
|
|
$dcc_applies->for_country_currency()
|
|
|
|
),
|
2021-07-26 16:08:32 +02:00
|
|
|
),
|
|
|
|
array(
|
2021-11-25 10:33:54 +02:00
|
|
|
'label' => esc_html__( 'Pay Later messaging available in country', 'woocommerce-paypal-payments' ),
|
|
|
|
'exported_label' => 'Pay Later messaging available in country',
|
|
|
|
'description' => esc_html__( 'Whether Pay Later is available in country or not.', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $this->bool_to_text(
|
2021-11-19 17:25:08 +02:00
|
|
|
$messages_apply->for_country()
|
|
|
|
),
|
2021-07-26 16:08:32 +02:00
|
|
|
),
|
2021-11-24 11:52:14 +02:00
|
|
|
array(
|
2021-11-25 10:33:54 +02:00
|
|
|
'label' => esc_html__( 'Webhook status', 'woocommerce-paypal-payments' ),
|
|
|
|
'exported_label' => 'Webhook status',
|
|
|
|
'description' => esc_html__( 'Whether we received webhooks successfully.', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $last_webhook_storage->is_empty() ? 'Unknown' : 'OK',
|
2021-11-24 11:52:14 +02:00
|
|
|
),
|
2021-07-26 16:08:32 +02:00
|
|
|
array(
|
2021-11-25 10:33:54 +02:00
|
|
|
'label' => esc_html__( 'Vault enabled', 'woocommerce-paypal-payments' ),
|
|
|
|
'exported_label' => 'Vault enabled',
|
|
|
|
'description' => esc_html__( 'Whether vaulting is enabled on PayPal account or not.', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $this->bool_to_text(
|
2021-11-19 17:25:08 +02:00
|
|
|
$this->vault_enabled( $bearer )
|
|
|
|
),
|
2021-07-26 16:08:32 +02:00
|
|
|
),
|
2021-11-19 17:25:47 +02:00
|
|
|
array(
|
2021-11-25 10:33:54 +02:00
|
|
|
'label' => esc_html__( 'Logging enabled', 'woocommerce-paypal-payments' ),
|
|
|
|
'exported_label' => 'Logging enabled',
|
|
|
|
'description' => esc_html__( 'Whether logging of plugin events and errors is enabled.', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $this->bool_to_text(
|
2021-11-19 17:25:47 +02:00
|
|
|
$settings->has( 'logging_enabled' ) && $settings->get( 'logging_enabled' )
|
|
|
|
),
|
|
|
|
),
|
2021-11-22 18:21:01 +02:00
|
|
|
array(
|
2021-11-25 10:33:54 +02:00
|
|
|
'label' => esc_html__( 'Used PayPal Checkout plugin', 'woocommerce-paypal-payments' ),
|
|
|
|
'exported_label' => 'Used PayPal Checkout plugin',
|
|
|
|
'description' => esc_html__( 'Whether the PayPal Checkout Gateway plugin was configured previously or not', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $this->bool_to_text(
|
2021-11-22 18:21:01 +02:00
|
|
|
$had_ppec_plugin
|
|
|
|
),
|
|
|
|
),
|
2021-07-26 16:08:32 +02:00
|
|
|
);
|
|
|
|
|
2021-07-22 15:39:57 +02:00
|
|
|
echo wp_kses_post(
|
|
|
|
$renderer->render(
|
|
|
|
esc_html__( 'WooCommerce PayPal Payments', 'woocommerce-paypal-payments' ),
|
|
|
|
$items
|
|
|
|
)
|
|
|
|
);
|
2021-07-20 14:56:37 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-21 11:31:56 +02:00
|
|
|
* {@inheritDoc}
|
2021-07-20 14:56:37 +02:00
|
|
|
*/
|
2021-07-22 15:39:57 +02:00
|
|
|
public function getKey() { }
|
|
|
|
|
|
|
|
/**
|
2021-07-26 16:08:32 +02:00
|
|
|
* It returns the current onboarding status.
|
2021-07-22 15:39:57 +02:00
|
|
|
*
|
2021-07-26 16:08:32 +02:00
|
|
|
* @param Bearer $bearer The bearer.
|
2021-07-27 14:29:05 +02:00
|
|
|
* @param State $state The state.
|
2021-11-19 17:25:08 +02:00
|
|
|
* @return bool
|
2021-07-22 15:39:57 +02:00
|
|
|
*/
|
2021-11-19 17:25:08 +02:00
|
|
|
private function onboarded( Bearer $bearer, State $state ): bool {
|
2021-07-26 16:08:32 +02:00
|
|
|
try {
|
|
|
|
$token = $bearer->bearer();
|
|
|
|
} catch ( RuntimeException $exception ) {
|
2021-11-19 17:25:08 +02:00
|
|
|
return false;
|
2021-07-26 16:08:32 +02:00
|
|
|
}
|
|
|
|
|
2021-07-22 15:39:57 +02:00
|
|
|
$current_state = $state->current_state();
|
2021-11-19 17:25:08 +02:00
|
|
|
return $token->is_valid() && $current_state === $state::STATE_ONBOARDED;
|
2021-07-22 15:39:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* It returns whether vaulting is enabled or not.
|
|
|
|
*
|
|
|
|
* @param Bearer $bearer The bearer.
|
2021-11-19 17:25:08 +02:00
|
|
|
* @return bool
|
2021-07-22 15:39:57 +02:00
|
|
|
*/
|
2021-11-19 17:25:08 +02:00
|
|
|
private function vault_enabled( Bearer $bearer ): bool {
|
2021-07-22 15:39:57 +02:00
|
|
|
try {
|
|
|
|
$token = $bearer->bearer();
|
2021-11-19 17:25:08 +02:00
|
|
|
return $token->vaulting_available();
|
2021-07-22 15:39:57 +02:00
|
|
|
} catch ( RuntimeException $exception ) {
|
2021-11-19 17:25:08 +02:00
|
|
|
return false;
|
2021-07-22 15:39:57 +02:00
|
|
|
}
|
2021-07-20 14:56:37 +02:00
|
|
|
}
|
2021-11-19 17:25:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the bool value to "Yes" or "No".
|
|
|
|
*
|
|
|
|
* @param bool $value The value.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function bool_to_text( bool $value ): string {
|
|
|
|
return $value
|
|
|
|
? esc_html__( 'Yes', 'woocommerce-paypal-payments' )
|
|
|
|
: esc_html__( 'No', 'woocommerce-paypal-payments' );
|
|
|
|
}
|
2021-07-20 14:56:37 +02:00
|
|
|
}
|