move dcc settings in extra section

This commit is contained in:
David Remer 2020-09-02 09:56:04 +03:00
parent e7cbd23155
commit df7e22006b
5 changed files with 61 additions and 17 deletions

View file

@ -23,6 +23,7 @@ use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use Inpsyde\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
use Inpsyde\PayPalCommerce\WcGateway\Processor\OrderProcessor;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsListener;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
@ -81,6 +82,9 @@ return array(
static function ( ContainerInterface $container ): AuthorizeOrderActionNotice {
return new AuthorizeOrderActionNotice();
},
'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
return new SectionsRenderer();
},
'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer {
$settings = $container->get( 'wcgateway.settings' );
$state = $container->get( 'onboarding.state' );

View file

@ -123,20 +123,6 @@ class CreditCardGateway extends PayPalGateway {
);
}
/**
* Renders the settings.
*
* @return string
*/
public function generate_ppcp_html(): string {
ob_start();
$this->settings_renderer->render( true );
$content = ob_get_contents();
ob_end_clean();
return $content;
}
/**
* Returns the title of the gateway.
*

View file

@ -0,0 +1,41 @@
<?php
declare( strict_types=1 );
namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
class SectionsRenderer {
public const KEY = 'ppcp-tab';
public function should_render() : bool {
global $current_section;
return $current_section === PayPalGateway::ID;
}
public function render() {
if (! $this->should_render()) {
return;
}
$current = ! isset($_GET[self::KEY]) ? 'paypal' : sanitize_text_field(wp_unslash($_GET[self::KEY]));
$sections = [
'paypal' => __( 'PayPal', 'paypal-for-woocommerce' ),
'dcc' => __( 'Credit Card', 'paypal-for-woocommerce' ),
];
echo '<ul class="subsubsub">';
$array_keys = array_keys( $sections );
foreach ( $sections as $id => $label ) {
$url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&' . self::KEY . '=' . $id );
echo '<li><a href="' . $url . '" class="' . ( $current == $id ? 'current' : '' ) . '">' . esc_html($label) . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
}
echo '</ul><br class="clear" />';
return;
}
}

View file

@ -209,11 +209,10 @@ class SettingsRenderer {
/**
* Renders the settings.
*
* @param bool $is_dcc Whether it is the DCC gateway or not.
*/
public function render( bool $is_dcc ) {
public function render() {
$is_dcc = isset($_GET[SectionsRenderer::KEY]) && 'dcc' === sanitize_text_field(wp_unslash($_GET[SectionsRenderer::KEY]));
$nonce = wp_create_nonce( SettingsListener::NONCE );
?>
<input type="hidden" name="ppcp-nonce" value="<?php echo esc_attr( $nonce ); ?>">

View file

@ -22,6 +22,7 @@ use Inpsyde\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
use Interop\Container\ServiceProviderInterface;
@ -56,6 +57,19 @@ class WcGatewayModule implements ModuleInterface {
$this->register_checkout_paypal_address_preset( $container );
$this->ajax_gateway_enabler( $container );
add_action(
'woocommerce_sections_checkout',
function() use ($container) {
$section_renderer = $container->get('wcgateway.settings.sections-renderer');
/**
* The Section Renderer.
*
* @var SectionsRenderer $section_renderer
*/
$section_renderer->render();
}
);
add_filter(
Repository::NOTICES_FILTER,
static function ( $notices ) use ( $container ): array {