mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Check for features are available on PayPal, reorder the sections
This commit is contained in:
parent
6742229345
commit
a693829815
2 changed files with 164 additions and 102 deletions
|
@ -16,7 +16,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
|||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
return function ( ContainerInterface $container, array $fields ): array {
|
||||
|
||||
|
@ -33,50 +32,6 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
|
||||
$module_url = $container->get( 'wcgateway.url' );
|
||||
|
||||
$dash_icon_yes = '<span class="dashicons dashicons-yes"></span>';
|
||||
$dash_icon_no = '<span class="dashicons dashicons-no"></span>';
|
||||
|
||||
$connected_to_paypal_markup = sprintf(
|
||||
'<p>%1$s %2$s</p><p><button type="button" class="button ppcp-disconnect sandbox">%3$s</button></p>',
|
||||
esc_html__( 'Status: Connected', 'woocommerce-paypal-payments' ),
|
||||
$dash_icon_yes,
|
||||
esc_html__( 'Disconnect Account', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
$enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' );
|
||||
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );
|
||||
|
||||
$dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' );
|
||||
|
||||
$dcc_button_text = $dcc_enabled
|
||||
? esc_html__( 'Disable Advanced Card Payments', 'woocommerce-paypal-payments' )
|
||||
: esc_html__( 'Enable Advanced Card Payments', 'woocommerce-paypal-payments' );
|
||||
|
||||
$dcc_status = sprintf(
|
||||
'<p>%1$s %2$s</p><p><a href="%3$s" class="button">%4$s</a></p>',
|
||||
$dcc_enabled ? $enabled_status_text : $disabled_status_text,
|
||||
$dcc_enabled ? $dash_icon_yes : $dash_icon_no,
|
||||
admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=ppcp-credit-card-gateway' ),
|
||||
esc_html( $dcc_button_text )
|
||||
);
|
||||
|
||||
$pui_enabled = $settings->has( 'products_pui_enabled' ) && $settings->get( 'products_pui_enabled' );
|
||||
|
||||
$pui_button_text = $pui_enabled
|
||||
? esc_html__( 'Disable Pay Upon Invoice', 'woocommerce-paypal-payments' )
|
||||
: esc_html__( 'Enable Pay Upon Invoice', 'woocommerce-paypal-payments' );
|
||||
|
||||
$pui_status = sprintf(
|
||||
'<p>%1$s %2$s</p><p><a href="%3$s" class="button">%4$s</a></p>',
|
||||
$pui_enabled ? $enabled_status_text : $disabled_status_text,
|
||||
$pui_enabled ? $dash_icon_yes : $dash_icon_no,
|
||||
admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' ),
|
||||
esc_html( $pui_button_text )
|
||||
);
|
||||
|
||||
$connection_fields = array(
|
||||
'ppcp_onboarading_header' => array(
|
||||
'type' => 'ppcp-text',
|
||||
|
@ -215,7 +170,11 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
'ppcp_disconnect_sandbox' => array(
|
||||
'title' => __( 'Disconnect from PayPal Sandbox', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'ppcp-text',
|
||||
'text' => $connected_to_paypal_markup,
|
||||
'text' => sprintf(
|
||||
'<p>%1$s <span class="dashicons dashicons-yes"></span></p><p><button type="button" class="button ppcp-disconnect sandbox">%2$s</button></p>',
|
||||
esc_html__( 'Status: Connected', 'woocommerce-paypal-payments' ),
|
||||
esc_html__( 'Disconnect Account', 'woocommerce-paypal-payments' )
|
||||
),
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
|
@ -236,26 +195,6 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
'requirements' => array(),
|
||||
'gateway' => 'connection',
|
||||
),
|
||||
'ppcp_dcc_status' => array(
|
||||
'title' => __( 'Advanced Credit & Debit Crad Payments', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'ppcp-text',
|
||||
'text' => $dcc_status,
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'connection',
|
||||
),
|
||||
'ppcp_pui_status' => array(
|
||||
'title' => __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'ppcp-text',
|
||||
'text' => $pui_status,
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array( 'pui_ready' ),
|
||||
'gateway' => 'connection',
|
||||
),
|
||||
'error_label' => array(
|
||||
'type' => 'ppcp-text',
|
||||
'text' => '<label class="error" id="ppcp-form-errors-label"></label>',
|
||||
|
@ -395,21 +334,64 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
'requirements' => array(),
|
||||
'gateway' => 'connection',
|
||||
),
|
||||
'logging_enabled' => array(
|
||||
'title' => __( 'Logging', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
'label' => __( 'Enable logging. ', 'woocommerce-paypal-payments' ) .
|
||||
' <a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">' . __( 'View logs', 'woocommerce-paypal-payments' ) . '</a>',
|
||||
'description' => __( 'Enable logging of unexpected behavior. This can also log private data and should only be enabled in a development or stage environment.', 'woocommerce-paypal-payments' ),
|
||||
'default' => false,
|
||||
|
||||
'credentials_feature_onboarding_heading' => array(
|
||||
'heading' => __( 'Feature Onboarding', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'ppcp-heading',
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'state_from' => Environment::SANDBOX,
|
||||
'requirements' => array(),
|
||||
'gateway' => 'connection',
|
||||
'description' => __( 'See which features are available.', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'ppcp_dcc_status' => array(
|
||||
'title' => __( 'Advanced Credit and Debit Card Payments', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'ppcp-text',
|
||||
'text' => $container->get( 'wcgateway.settings.connection.dcc-status-text' ),
|
||||
'screens' => array(
|
||||
State::STATE_START,
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'connection',
|
||||
),
|
||||
'ppcp_pui_status' => array(
|
||||
'title' => __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'ppcp-text',
|
||||
'text' => $container->get( 'wcgateway.settings.connection.pui-status-text' ),
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array( 'pui_ready' ),
|
||||
'gateway' => 'connection',
|
||||
),
|
||||
'tracking_enabled' => array(
|
||||
'title' => __( 'Tracking', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
'label' => $container->get( 'wcgateway.settings.tracking-label' ),
|
||||
'description' => __( 'Allows to send shipment tracking numbers to PayPal for PayPal transactions.', 'woocommerce-paypal-payments' ),
|
||||
'default' => false,
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'connection',
|
||||
'input_class' => $container->get( 'wcgateway.settings.should-disable-tracking-checkbox' ) ? array( 'ppcp-disabled-checkbox' ) : array(),
|
||||
),
|
||||
|
||||
'credentials_integration_configuration_heading' => array(
|
||||
'heading' => __( 'Integration configuration', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'ppcp-heading',
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'state_from' => Environment::SANDBOX,
|
||||
'requirements' => array(),
|
||||
'gateway' => 'connection',
|
||||
'description' => __( 'See which features are available.', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
'prefix' => array(
|
||||
'title' => __( 'Invoice prefix', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'text',
|
||||
|
@ -433,19 +415,20 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
'requirements' => array(),
|
||||
'gateway' => 'connection',
|
||||
),
|
||||
'tracking_enabled' => array(
|
||||
'title' => __( 'Tracking', 'woocommerce-paypal-payments' ),
|
||||
'logging_enabled' => array(
|
||||
'title' => __( 'Logging', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
'label' => $container->get( 'wcgateway.settings.tracking-label' ),
|
||||
'description' => __( 'Allows to send shipment tracking numbers to PayPal for PayPal transactions.', 'woocommerce-paypal-payments' ),
|
||||
'label' => __( 'Enable logging. ', 'woocommerce-paypal-payments' ) .
|
||||
' <a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">' . __( 'View logs', 'woocommerce-paypal-payments' ) . '</a>',
|
||||
'description' => __( 'Enable logging of unexpected behavior. This can also log private data and should only be enabled in a development or stage environment.', 'woocommerce-paypal-payments' ),
|
||||
'default' => false,
|
||||
'screens' => array(
|
||||
State::STATE_START,
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'connection',
|
||||
'input_class' => $container->get( 'wcgateway.settings.should-disable-tracking-checkbox' ) ? array( 'ppcp-disabled-checkbox' ) : array(),
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesDisclaimers;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\FeesRenderer;
|
||||
|
@ -2132,4 +2133,82 @@ return array(
|
|||
|
||||
return $tracking_label;
|
||||
},
|
||||
'wcgateway.enable-dcc-url-sandbox' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.sandbox.paypal.com/bizsignup/entry/product/ppcp';
|
||||
},
|
||||
'wcgateway.enable-dcc-url-live' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.paypal.com/bizsignup/entry/product/ppcp';
|
||||
},
|
||||
'wcgateway.enable-pui-url-sandbox' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.sandbox.paypal.com/bizsignup/entry?country.x=DE&product=payment_methods&capabilities=PAY_UPON_INVOICE';
|
||||
},
|
||||
'wcgateway.enable-pui-url-live' => static function ( ContainerInterface $container ): string {
|
||||
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 {
|
||||
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
||||
assert( $dcc_applies instanceof DccApplies );
|
||||
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
$dcc_enabled = $dcc_applies->for_country_currency() || $dcc_applies->for_wc_payments();
|
||||
|
||||
$enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' );
|
||||
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );
|
||||
|
||||
$dcc_button_text = $dcc_enabled
|
||||
? esc_html__( 'Settings', 'woocommerce-paypal-payments' )
|
||||
: esc_html__( 'Enable Advanced Card Payments', 'woocommerce-paypal-payments' );
|
||||
|
||||
$enable_dcc_url = $environment->current_environment_is( Environment::PRODUCTION )
|
||||
? $container->get('wcgateway.enable-dcc-url-live')
|
||||
: $container->get('wcgateway.enable-dcc-url-sandbox');
|
||||
|
||||
$dcc_button_url = $dcc_enabled
|
||||
? admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=ppcp-credit-card-gateway' )
|
||||
: $enable_dcc_url;
|
||||
|
||||
return sprintf(
|
||||
'<p>%1$s %2$s</p><p><a target="_blank" href="%3$s" class="button">%4$s</a></p>',
|
||||
$dcc_enabled ? $enabled_status_text : $disabled_status_text,
|
||||
$dcc_enabled ? '<span class="dashicons dashicons-yes"></span>' : '<span class="dashicons dashicons-no"></span>',
|
||||
esc_url( $dcc_button_url ),
|
||||
esc_html( $dcc_button_text )
|
||||
);
|
||||
},
|
||||
'wcgateway.settings.connection.pui-status-text' => static function ( ContainerInterface $container ): string {
|
||||
$pui_product_status = $container->get( 'wcgateway.pay-upon-invoice-product-status' );
|
||||
assert( $pui_product_status instanceof PayUponInvoiceProductStatus );
|
||||
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
$shop_country = $container->get( 'api.shop.country' );
|
||||
|
||||
$pui_enabled = 'DE' === $shop_country && $pui_product_status->pui_is_active();
|
||||
|
||||
$enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' );
|
||||
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );
|
||||
|
||||
$enable_pui_url = $environment->current_environment_is( Environment::PRODUCTION )
|
||||
? $container->get('wcgateway.enable-pui-url-live')
|
||||
: $container->get('wcgateway.enable-pui-url-sandbox');
|
||||
|
||||
$pui_button_url = $pui_enabled
|
||||
? admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' )
|
||||
: $enable_pui_url;
|
||||
|
||||
$pui_button_text = $pui_enabled
|
||||
? esc_html__( 'Settings', 'woocommerce-paypal-payments' )
|
||||
: esc_html__( 'Enable Pay Upon Invoice', 'woocommerce-paypal-payments' );
|
||||
|
||||
return sprintf(
|
||||
'<p>%1$s %2$s</p><p><a target="_blank" href="%3$s" class="button">%4$s</a></p>',
|
||||
$pui_enabled ? $enabled_status_text : $disabled_status_text,
|
||||
$pui_enabled ? '<span class="dashicons dashicons-yes"></span>' : '<span class="dashicons dashicons-no"></span>',
|
||||
esc_url( $pui_button_url ),
|
||||
esc_html( $pui_button_text )
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue