Fix phpcd (WIP)

This commit is contained in:
dinamiko 2022-04-14 17:17:56 +02:00
parent 42ce61de5b
commit e9cf818799
24 changed files with 487 additions and 175 deletions

View file

@ -145,8 +145,8 @@ class OnboardingAssets {
'error_messages' => array(
'no_credentials' => __( 'API credentials must be entered to save the settings.', 'woocommerce-paypal-payments' ),
),
'pui_endpoint' => \WC_AJAX::get_endpoint( 'ppc-pui' ),
'pui_nonce' => wp_create_nonce( 'ppc-pui' ),
'pui_endpoint' => \WC_AJAX::get_endpoint( 'ppc-pui' ),
'pui_nonce' => wp_create_nonce( 'ppc-pui' ),
);
}

View file

@ -9,47 +9,83 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Onboarding\Endpoint;
use Exception;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\Button\Endpoint\EndpointInterface;
use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
/**
* Class PayUponInvoiceEndpoint
*/
class PayUponInvoiceEndpoint implements EndpointInterface {
/**
* The settings.
*
* @var Settings
*/
protected $settings;
/**
* The request data.
*
* @var RequestData
*/
protected $request_data;
public function __construct(Settings $settings, RequestData $request_data)
{
$this->settings = $settings;
/**
* The logger.
*
* @var LoggerInterface
*/
protected $logger;
/**
* PayUponInvoiceEndpoint constructor.
*
* @param Settings $settings The settings.
* @param RequestData $request_data The request data.
* @param LoggerInterface $logger The logger.
*/
public function __construct( Settings $settings, RequestData $request_data, LoggerInterface $logger ) {
$this->settings = $settings;
$this->request_data = $request_data;
$this->logger = $logger;
}
public static function nonce(): string
{
/**
* The nonce.
*
* @return string
*/
public static function nonce(): string {
return 'ppc-pui';
}
public function handle_request(): bool
{
/**
* * Handles the request.
*
* @return bool
* @throws NotFoundException When order not found or handling failed.
*/
public function handle_request(): bool {
try {
$data = $this->request_data->read_request( $this->nonce() );
$this->settings->set('ppcp-onboarding-pui', $data['checked']);
$this->settings->set( 'ppcp-onboarding-pui', $data['checked'] );
$this->settings->persist();
} catch (\Exception $exception) {
} catch ( Exception $exception ) {
$this->logger->error( $exception->getMessage() );
}
wp_send_json_success([
$this->settings->get('ppcp-onboarding-pui'),
]);
wp_send_json_success(
array(
$this->settings->get( 'ppcp-onboarding-pui' ),
)
);
return true;
}
}

View file

@ -97,7 +97,7 @@ class OnboardingModule implements ModuleInterface {
);
add_action(
'wc_ajax_' . 'ppc-pui',
'wc_ajax_ppc-pui',
static function () use ( $c ) {
$endpoint = $c->get( 'onboarding.endpoint.pui' );
$endpoint->handle_request();

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Onboarding\Render;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
/**
* Class OnboardingRenderer
@ -30,6 +31,8 @@ class OnboardingOptionsRenderer {
private $country;
/**
* The settings.
*
* @var Settings
*/
protected $settings;
@ -37,13 +40,14 @@ class OnboardingOptionsRenderer {
/**
* OnboardingOptionsRenderer constructor.
*
* @param string $module_url The module url (for assets).
* @param string $country 2-letter country code of the shop.
* @param string $module_url The module url (for assets).
* @param string $country 2-letter country code of the shop.
* @param Settings $settings The settings.
*/
public function __construct( string $module_url, string $country, Settings $settings) {
public function __construct( string $module_url, string $country, Settings $settings ) {
$this->module_url = $module_url;
$this->country = $country;
$this->settings = $settings;
$this->settings = $settings;
}
/**
@ -66,16 +70,22 @@ class OnboardingOptionsRenderer {
</li>
<li>' . $this->render_dcc( $is_shop_supports_dcc ) . '</li>' .
$this->render_pui_option()
. '</ul>';
. '</ul>';
}
/**
* Renders pui option.
*
* @return string
* @throws NotFoundException When setting is not found.
*/
private function render_pui_option(): string {
if($this->country === 'DE') {
if ( 'DE' === $this->country ) {
$checked = 'checked';
if($this->settings->has('ppcp-onboarding-pui') && $this->settings->get('ppcp-onboarding-pui') !== '1') {
if ( $this->settings->has( 'ppcp-onboarding-pui' ) && $this->settings->get( 'ppcp-onboarding-pui' ) !== '1' ) {
$checked = '';
}
return '<label><input type="checkbox" id="ppcp-onboarding-pui" '.$checked.'> ' .
return '<label><input type="checkbox" id="ppcp-onboarding-pui" ' . $checked . '> ' .
__( 'Onboard with Pay Upon Invoice', 'woocommerce-paypal-payments' ) . '
</label>';
}