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;
|
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
|
|
|
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\State;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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}
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $container A services container instance.
|
2021-07-20 14:56:37 +02:00
|
|
|
*/
|
|
|
|
public function run( ContainerInterface $container ): void {
|
|
|
|
add_action(
|
|
|
|
'woocommerce_system_status_report',
|
2021-07-26 16:08:32 +02:00
|
|
|
function () use ($container) {
|
|
|
|
|
|
|
|
/* @var State $state The state. */
|
|
|
|
$state = $container->get( 'onboarding.state' );
|
|
|
|
|
|
|
|
/* @var Bearer $bearer The bearer. */
|
|
|
|
$bearer = $container->get( 'api.bearer' );
|
|
|
|
|
|
|
|
/* @var DccApplies $dcc_applies The ddc applies. */
|
|
|
|
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
|
|
|
|
|
|
|
/* @var MessagesApply $messages_apply The messages apply. */
|
|
|
|
$messages_apply = $container->get( 'button.helper.messages-apply' );
|
|
|
|
|
|
|
|
/* @var Renderer $renderer The renderer. */
|
|
|
|
$renderer = $container->get( 'status-report.renderer' );
|
|
|
|
|
|
|
|
$items = array(
|
|
|
|
array(
|
|
|
|
'label' => esc_html__( 'Onboarded', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $this->onboarded( $bearer, $state ),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'label' => esc_html__( 'Shop country code', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => wc_get_base_location()['country'],
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'label' => esc_html__( 'PayPal card processing available in country', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $dcc_applies->for_country_currency()
|
|
|
|
? esc_html__( 'Yes', 'woocommerce-paypal-payments' )
|
|
|
|
: esc_html__( 'No', 'woocommerce-paypal-payments' ),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'label' => esc_html__( 'Pay Later messaging available in country', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $messages_apply->for_country()
|
|
|
|
? esc_html__( 'Yes', 'woocommerce-paypal-payments' )
|
|
|
|
: esc_html__( 'No', 'woocommerce-paypal-payments' ),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'label' => esc_html__( 'Vault enabled', 'woocommerce-paypal-payments' ),
|
|
|
|
'value' => $this->vault_enabled( $bearer ),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
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-22 15:39:57 +02:00
|
|
|
* @param State $state The state.
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-07-26 16:08:32 +02:00
|
|
|
private function onboarded( $bearer, $state): string {
|
|
|
|
try {
|
|
|
|
$token = $bearer->bearer();
|
|
|
|
} catch ( RuntimeException $exception ) {
|
|
|
|
return esc_html__('No', 'woocommerce-paypal-payments');
|
|
|
|
}
|
|
|
|
|
2021-07-22 15:39:57 +02:00
|
|
|
$current_state = $state->current_state();
|
2021-07-26 16:08:32 +02:00
|
|
|
if($token->is_valid() && $current_state === $state::STATE_ONBOARDED) {
|
|
|
|
return esc_html__('Yes', 'woocommerce-paypal-payments');
|
2021-07-22 15:39:57 +02:00
|
|
|
}
|
2021-07-26 16:08:32 +02:00
|
|
|
|
|
|
|
return esc_html__('No', 'woocommerce-paypal-payments');
|
2021-07-22 15:39:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* It returns whether vaulting is enabled or not.
|
|
|
|
*
|
|
|
|
* @param Bearer $bearer The bearer.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function vault_enabled( $bearer ) {
|
|
|
|
try {
|
|
|
|
$token = $bearer->bearer();
|
|
|
|
return $token->vaulting_available()
|
|
|
|
? esc_html__( 'Yes', 'woocommerce-paypal-payments' )
|
|
|
|
: esc_html__( 'No', 'woocommerce-paypal-payments' );
|
|
|
|
} catch ( RuntimeException $exception ) {
|
|
|
|
return esc_html__( 'No', 'woocommerce-paypal-payments' );
|
|
|
|
}
|
2021-07-20 14:56:37 +02:00
|
|
|
}
|
|
|
|
}
|