Check if DCC is enabled on PayPal account.

This commit is contained in:
Narek Zakarian 2022-09-02 14:39:41 +04:00
parent 809b28e29f
commit 23b7d312ad
3 changed files with 34 additions and 41 deletions

View file

@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer; use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
return function ( ContainerInterface $container, array $fields ): array { return function ( ContainerInterface $container, array $fields ): array {
@ -63,7 +64,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'credentials_production_heading' => array( 'credentials_production_heading' => array(
'heading' => __( 'API Credentials', 'woocommerce-paypal-payments' ), 'heading' => __( 'API Credentials', 'woocommerce-paypal-payments' ),
@ -73,7 +74,7 @@ return function ( ContainerInterface $container, array $fields ): array {
), ),
'state_from' => Environment::PRODUCTION, 'state_from' => Environment::PRODUCTION,
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'credentials_sandbox_heading' => array( 'credentials_sandbox_heading' => array(
'heading' => __( 'Sandbox API Credentials', 'woocommerce-paypal-payments' ), 'heading' => __( 'Sandbox API Credentials', 'woocommerce-paypal-payments' ),
@ -83,7 +84,7 @@ return function ( ContainerInterface $container, array $fields ): array {
), ),
'state_from' => Environment::SANDBOX, 'state_from' => Environment::SANDBOX,
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'Your account is connected to sandbox, no real charging takes place. To accept live payments, turn off sandbox mode and connect your live PayPal account.', 'woocommerce-paypal-payments' ), 'description' => __( 'Your account is connected to sandbox, no real charging takes place. To accept live payments, turn off sandbox mode and connect your live PayPal account.', 'woocommerce-paypal-payments' ),
), ),
@ -97,7 +98,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
// We need to have a button for each option (ppcp, express) // We need to have a button for each option (ppcp, express)
@ -113,7 +114,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'env' => Environment::PRODUCTION, 'env' => Environment::PRODUCTION,
'products' => array( 'PPCP' ), 'products' => array( 'PPCP' ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'ppcp_onboarding_production_express' => array( 'ppcp_onboarding_production_express' => array(
'type' => 'ppcp_onboarding', 'type' => 'ppcp_onboarding',
@ -125,7 +126,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'env' => Environment::PRODUCTION, 'env' => Environment::PRODUCTION,
'products' => array( 'EXPRESS_CHECKOUT' ), 'products' => array( 'EXPRESS_CHECKOUT' ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'ppcp_onboarding_sandbox_ppcp' => array( 'ppcp_onboarding_sandbox_ppcp' => array(
'type' => 'ppcp_onboarding', 'type' => 'ppcp_onboarding',
@ -137,7 +138,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'env' => Environment::SANDBOX, 'env' => Environment::SANDBOX,
'products' => array( 'PPCP' ), 'products' => array( 'PPCP' ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'Prior to accepting live payments, you can test payments on your WooCommerce platform in a safe PayPal sandbox environment.', 'woocommerce-paypal-payments' ), 'description' => __( 'Prior to accepting live payments, you can test payments on your WooCommerce platform in a safe PayPal sandbox environment.', 'woocommerce-paypal-payments' ),
), ),
'ppcp_onboarding_sandbox_express' => array( 'ppcp_onboarding_sandbox_express' => array(
@ -150,7 +151,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'env' => Environment::SANDBOX, 'env' => Environment::SANDBOX,
'products' => array( 'EXPRESS_CHECKOUT' ), 'products' => array( 'EXPRESS_CHECKOUT' ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'Prior to accepting live payments, you can test payments on your WooCommerce platform in a safe PayPal sandbox environment.', 'woocommerce-paypal-payments' ), 'description' => __( 'Prior to accepting live payments, you can test payments on your WooCommerce platform in a safe PayPal sandbox environment.', 'woocommerce-paypal-payments' ),
), ),
@ -168,7 +169,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'state_from' => Environment::PRODUCTION, 'state_from' => Environment::PRODUCTION,
'env' => Environment::PRODUCTION, 'env' => Environment::PRODUCTION,
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'Click to reset current credentials and use another account.', 'woocommerce-paypal-payments' ), 'description' => __( 'Click to reset current credentials and use another account.', 'woocommerce-paypal-payments' ),
), ),
'ppcp_disconnect_sandbox' => array( 'ppcp_disconnect_sandbox' => array(
@ -185,7 +186,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'state_from' => Environment::SANDBOX, 'state_from' => Environment::SANDBOX,
'env' => Environment::SANDBOX, 'env' => Environment::SANDBOX,
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'Click to reset current credentials and use another account.', 'woocommerce-paypal-payments' ), 'description' => __( 'Click to reset current credentials and use another account.', 'woocommerce-paypal-payments' ),
), ),
'toggle_manual_input' => array( 'toggle_manual_input' => array(
@ -197,7 +198,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'error_label' => array( 'error_label' => array(
'type' => 'ppcp-text', 'type' => 'ppcp-text',
@ -208,7 +209,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'sandbox_on' => array( 'sandbox_on' => array(
'title' => __( 'Sandbox', 'woocommerce-paypal-payments' ), 'title' => __( 'Sandbox', 'woocommerce-paypal-payments' ),
@ -221,7 +222,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'merchant_email_production' => array( 'merchant_email_production' => array(
'title' => __( 'Live Email address', 'woocommerce-paypal-payments' ), 'title' => __( 'Live Email address', 'woocommerce-paypal-payments' ),
@ -236,7 +237,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'merchant_id_production' => array( 'merchant_id_production' => array(
'title' => __( 'Live Merchant Id', 'woocommerce-paypal-payments' ), 'title' => __( 'Live Merchant Id', 'woocommerce-paypal-payments' ),
@ -250,7 +251,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'client_id_production' => array( 'client_id_production' => array(
'title' => __( 'Live Client Id', 'woocommerce-paypal-payments' ), 'title' => __( 'Live Client Id', 'woocommerce-paypal-payments' ),
@ -264,7 +265,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'client_secret_production' => array( 'client_secret_production' => array(
'title' => __( 'Live Secret Key', 'woocommerce-paypal-payments' ), 'title' => __( 'Live Secret Key', 'woocommerce-paypal-payments' ),
@ -278,7 +279,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'merchant_email_sandbox' => array( 'merchant_email_sandbox' => array(
@ -294,7 +295,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'merchant_id_sandbox' => array( 'merchant_id_sandbox' => array(
'title' => __( 'Sandbox Merchant Id', 'woocommerce-paypal-payments' ), 'title' => __( 'Sandbox Merchant Id', 'woocommerce-paypal-payments' ),
@ -308,7 +309,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'client_id_sandbox' => array( 'client_id_sandbox' => array(
'title' => __( 'Sandbox Client Id', 'woocommerce-paypal-payments' ), 'title' => __( 'Sandbox Client Id', 'woocommerce-paypal-payments' ),
@ -322,7 +323,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'client_secret_sandbox' => array( 'client_secret_sandbox' => array(
'title' => __( 'Sandbox Secret Key', 'woocommerce-paypal-payments' ), 'title' => __( 'Sandbox Secret Key', 'woocommerce-paypal-payments' ),
@ -336,7 +337,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'credentials_feature_onboarding_heading' => array( 'credentials_feature_onboarding_heading' => array(
@ -346,7 +347,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'See which features are available.', 'woocommerce-paypal-payments' ), 'description' => __( 'See which features are available.', 'woocommerce-paypal-payments' ),
), ),
'ppcp_dcc_status' => array( 'ppcp_dcc_status' => array(
@ -356,8 +357,8 @@ return function ( ContainerInterface $container, array $fields ): array {
'screens' => array( 'screens' => array(
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array( 'dcc' ),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'ppcp_pui_status' => array( 'ppcp_pui_status' => array(
'title' => __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' ), 'title' => __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' ),
@ -367,7 +368,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array( 'pui_ready' ), 'requirements' => array( 'pui_ready' ),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'tracking_enabled' => array( 'tracking_enabled' => array(
'title' => __( 'Tracking', 'woocommerce-paypal-payments' ), 'title' => __( 'Tracking', 'woocommerce-paypal-payments' ),
@ -380,7 +381,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
'input_class' => $container->get( 'wcgateway.settings.should-disable-tracking-checkbox' ) ? array( 'ppcp-disabled-checkbox' ) : array(), 'input_class' => $container->get( 'wcgateway.settings.should-disable-tracking-checkbox' ) ? array( 'ppcp-disabled-checkbox' ) : array(),
), ),
@ -391,7 +392,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'See which features are available.', 'woocommerce-paypal-payments' ), 'description' => __( 'See which features are available.', 'woocommerce-paypal-payments' ),
), ),
'prefix' => array( 'prefix' => array(
@ -415,7 +416,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
'logging_enabled' => array( 'logging_enabled' => array(
'title' => __( 'Logging', 'woocommerce-paypal-payments' ), 'title' => __( 'Logging', 'woocommerce-paypal-payments' ),
@ -430,7 +431,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
), ),
'requirements' => array(), 'requirements' => array(),
'gateway' => 'connection', 'gateway' => Settings::CONNECTION_TAB_ID,
), ),
); );

View file

@ -2146,13 +2146,13 @@ return array(
return 'https://www.paypal.com/bizsignup/entry?country.x=DE&product=payment_methods&capabilities=PAY_UPON_INVOICE'; return 'https://www.paypal.com/bizsignup/entry?country.x=DE&product=payment_methods&capabilities=PAY_UPON_INVOICE';
}, },
'wcgateway.settings.connection.dcc-status-text' => static function ( ContainerInterface $container ): string { 'wcgateway.settings.connection.dcc-status-text' => static function ( ContainerInterface $container ): string {
$dcc_applies = $container->get( 'api.helpers.dccapplies' ); $dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' );
assert( $dcc_applies instanceof DccApplies ); assert( $dcc_product_status instanceof DCCProductStatus );
$environment = $container->get( 'onboarding.environment' ); $environment = $container->get( 'onboarding.environment' );
assert( $environment instanceof Environment ); assert( $environment instanceof Environment );
$dcc_enabled = $dcc_applies->for_country_currency() || $dcc_applies->for_wc_payments(); $dcc_enabled = $dcc_product_status->dcc_is_active();
$enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' ); $enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' );
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' ); $disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );
@ -2185,9 +2185,7 @@ return array(
$environment = $container->get( 'onboarding.environment' ); $environment = $container->get( 'onboarding.environment' );
assert( $environment instanceof Environment ); assert( $environment instanceof Environment );
$shop_country = $container->get( 'api.shop.country' ); $pui_enabled = $pui_product_status->pui_is_active();
$pui_enabled = 'DE' === $shop_country && $pui_product_status->pui_is_active();
$enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' ); $enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' );
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' ); $disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );

View file

@ -390,12 +390,6 @@ $data_rows_html
) { ) {
continue; continue;
} }
if (
in_array( 'dcc', $config['requirements'], true )
&& ! $this->dcc_product_status->dcc_is_active()
) {
continue;
}
if ( if (
in_array( 'messages', $config['requirements'], true ) in_array( 'messages', $config['requirements'], true )
&& ! $this->messages_apply->for_country() && ! $this->messages_apply->for_country()