add setting and manage availability of dcc gateway

This commit is contained in:
David Remer 2020-09-02 13:52:40 +03:00
parent f9e64abe14
commit 57a6f8b85c
7 changed files with 22 additions and 10 deletions

View file

@ -288,6 +288,16 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'dcc_enabled' => array(
'title' => __( 'Enable/Disable' ),
'type' => 'checkbox',
'default' => false,
'gateway' => 'dcc',
'requirements' => array(),
'screens' => array(
State::STATE_ONBOARDED,
),
),
'dcc_gateway_title' => array(
'title' => __( 'Title', 'paypal-for-woocommerce' ),
'type' => 'text',
@ -298,7 +308,6 @@ return array(
'default' => __( 'Credit Cards', 'paypal-for-woocommerce' ),
'desc_tip' => true,
'screens' => array(
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
),
'requirements' => array(),
@ -336,7 +345,6 @@ return array(
'paypal-for-woocommerce'
),
'screens' => array(
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
),
'requirements' => array(),

View file

@ -197,4 +197,8 @@ class CreditCardGateway extends PayPalGateway {
),
);
}
public function is_available() : bool {
return $this->config->has('dcc_enabled') && $this->config->get('dcc_enabled');
}
}

View file

@ -81,7 +81,7 @@ class Settings implements ContainerInterface {
$this->load();
$fields_to_reset = array(
'enabled',
'dcc_gateway_enabled',
'dcc_enabled',
'intent',
'client_id',
'client_secret',

View file

@ -122,13 +122,13 @@ class SettingsListener {
if ( ! isset( $_GET[ SectionsRenderer::KEY ] ) || PayPalGateway::ID === $_GET[ SectionsRenderer::KEY ] ) {
$settings['enabled'] = isset( $_POST['woocommerce_ppcp-gateway_enabled'] )
&& 1 === absint( $_POST['woocommerce_ppcp-gateway_enabled'] );
$this->maybe_register_webhooks( $settings );
}
if ( isset( $_GET[ SectionsRenderer::KEY ] ) && CreditCardGateway::ID === $_GET[ SectionsRenderer::KEY ] ) {
$dcc_enabled_post_key = 'woocommerce_ppcp-credit-card-gateway_enabled';
$settings['dcc_gateway_enabled'] = isset( $_POST[ $dcc_enabled_post_key ] )
$settings['dcc_enabled'] = isset( $_POST[ $dcc_enabled_post_key ] )
&& 1 === absint( $_POST[ $dcc_enabled_post_key ] );
}
$this->maybe_register_webhooks( $settings );
foreach ( $settings as $id => $value ) {
$this->settings->set( $id, $value );

View file

@ -144,7 +144,7 @@ class WcGatewayModule implements ModuleInterface {
$settings = $container->get( 'wcgateway.settings' );
$key = PayPalGateway::ID === $_POST['gateway_id'] ? 'enabled' : '';
if ( CreditCardGateway::ID === $_POST['gateway_id'] ) {
$key = 'dcc_gateway_enabled';
$key = 'dcc_enabled';
}
if ( ! $key ) {
return;