-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from woocommerce/PT-51-plugin-information---s…
…upport Add PayPal onboarding information to WooCommerce system status
- Loading branch information
Showing
12 changed files
with
331 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
/** | ||
* The status report module extensions. | ||
* | ||
* @package WooCommerce\PayPalCommerce\StatusReport | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WooCommerce\PayPalCommerce\StatusReport; | ||
|
||
return array(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* The status report module. | ||
* | ||
* @package WooCommerce\PayPalCommerce\StatusReport | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WooCommerce\PayPalCommerce\StatusReport; | ||
|
||
use Dhii\Modular\Module\ModuleInterface; | ||
|
||
return static function (): ModuleInterface { | ||
return new StatusReportModule(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* The status report module services. | ||
* | ||
* @package WooCommerce\PayPalCommerce\StatusReport | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WooCommerce\PayPalCommerce\StatusReport; | ||
|
||
return array( | ||
'status-report.renderer' => static function ( $container ): Renderer { | ||
return new Renderer(); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* The status report renderer. | ||
* | ||
* @package WooCommerce\PayPalCommerce\StatusReport | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WooCommerce\PayPalCommerce\StatusReport; | ||
|
||
/** | ||
* Class Renderer | ||
*/ | ||
class Renderer { | ||
|
||
/** | ||
* It renders the status report content. | ||
* | ||
* @param string $title The title. | ||
* @param array $items The items. | ||
* @return false|string | ||
*/ | ||
public function render( string $title, array $items ) { | ||
ob_start(); | ||
?> | ||
<table class="wc_status_table widefat" id="status"> | ||
<thead> | ||
<tr> | ||
<th colspan="3" data-export-label="<?php echo esc_attr( $title ); ?>"> | ||
<h2><?php echo esc_attr( $title ); ?></h2> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php | ||
foreach ( $items as $item ) { | ||
?> | ||
<tr> | ||
<td data-export-label="<?php echo esc_attr( $item['label'] ); ?>"><?php echo esc_attr( $item['label'] ); ?></td> | ||
<td class="help"><?php echo wc_help_tip( $item['description'] ); ?></td> | ||
<td><?php echo esc_attr( $item['value'] ); ?></td> | ||
</tr> | ||
<?php | ||
} | ||
?> | ||
</tbody> | ||
</table> | ||
<?php | ||
return ob_get_clean(); | ||
} | ||
} |
148 changes: 148 additions & 0 deletions
148
modules/ppcp-status-report/src/class-statusreportmodule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?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; | ||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer; | ||
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 { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setup(): ServiceProviderInterface { | ||
return new ServiceProvider( | ||
require __DIR__ . '/../services.php', | ||
require __DIR__ . '/../extensions.php' | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param ContainerInterface $container A services container instance. | ||
*/ | ||
public function run( ContainerInterface $container ): void { | ||
add_action( | ||
'woocommerce_system_status_report', | ||
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' ), | ||
'description' => esc_html__( 'Whether PayPal account is correctly configured or not.', 'woocommerce-paypal-payments' ), | ||
'value' => $this->onboarded( $bearer, $state ), | ||
), | ||
array( | ||
'label' => esc_html__( 'Shop country code', 'woocommerce-paypal-payments' ), | ||
'description' => esc_html__( 'Country / State value on Settings / General / Store Address.', 'woocommerce-paypal-payments' ), | ||
'value' => wc_get_base_location()['country'], | ||
), | ||
array( | ||
'label' => esc_html__( 'PayPal card processing available in country', 'woocommerce-paypal-payments' ), | ||
'description' => esc_html__( 'Whether PayPal card processing is available in country or not.', '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' ), | ||
'description' => esc_html__( 'Whether Pay Later is available in country or not.', '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' ), | ||
'description' => esc_html__( 'Whether vaulting is enabled on PayPal account or not.', 'woocommerce-paypal-payments' ), | ||
'value' => $this->vault_enabled( $bearer ), | ||
), | ||
); | ||
|
||
echo wp_kses_post( | ||
$renderer->render( | ||
esc_html__( 'WooCommerce PayPal Payments', 'woocommerce-paypal-payments' ), | ||
$items | ||
) | ||
); | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getKey() { } | ||
|
||
/** | ||
* It returns the current onboarding status. | ||
* | ||
* @param Bearer $bearer The bearer. | ||
* @param State $state The state. | ||
* @return string | ||
*/ | ||
private function onboarded( $bearer, $state ): string { | ||
try { | ||
$token = $bearer->bearer(); | ||
} catch ( RuntimeException $exception ) { | ||
return esc_html__( 'No', 'woocommerce-paypal-payments' ); | ||
} | ||
|
||
$current_state = $state->current_state(); | ||
if ( $token->is_valid() && $current_state === $state::STATE_ONBOARDED ) { | ||
return esc_html__( 'Yes', 'woocommerce-paypal-payments' ); | ||
} | ||
|
||
return esc_html__( 'No', 'woocommerce-paypal-payments' ); | ||
} | ||
|
||
/** | ||
* 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' ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.