prepare code to work with connection tab

This commit is contained in:
Narek Zakarian 2022-08-24 16:36:35 +04:00
parent 2cbdfdf3bb
commit 4a8c8eeb8e
4 changed files with 26 additions and 6 deletions

View file

@ -26,6 +26,7 @@ use WooCommerce\PayPalCommerce\WcGateway\FundingSource\FundingSourceRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
use Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\Webhooks\Status\WebhooksStatusPage;
@ -290,6 +291,9 @@ class PayPalGateway extends \WC_Payment_Gateway {
* @return string
*/
private function define_method_title(): string {
if ( $this->is_connection_tab() ) {
return __( 'Account Setup', 'woocommerce-paypal-payments' );
}
if ( $this->is_credit_card_tab() ) {
return __( 'PayPal Card Processing', 'woocommerce-paypal-payments' );
}
@ -312,6 +316,10 @@ class PayPalGateway extends \WC_Payment_Gateway {
* @return string
*/
private function define_method_description(): string {
if ( $this->is_connection_tab() ) {
return '';
}
if ( $this->is_credit_card_tab() ) {
return __(
'Accept debit and credit cards, and local payment methods.',
@ -374,6 +382,16 @@ class PayPalGateway extends \WC_Payment_Gateway {
&& WebhooksStatusPage::ID === $this->page_id;
}
/**
* Whether we are on the connection tab.
*
* @return bool true if is connection tab, otherwise false
*/
protected function is_connection_tab() : bool {
return is_admin()
&& Settings::CONNECTION_TAB_ID === $this->page_id;
}
/**
* Whether we are on the PayPal settings tab.
*

View file

@ -33,10 +33,11 @@ trait PageMatcherTrait {
}
$gateway_page_id_map = array(
PayPalGateway::ID => 'paypal',
CreditCardGateway::ID => 'dcc', // TODO: consider using just the gateway ID for PayPal and DCC too.
CardButtonGateway::ID => CardButtonGateway::ID,
WebhooksStatusPage::ID => WebhooksStatusPage::ID,
Settings::CONNECTION_TAB_ID => 'connection',
PayPalGateway::ID => 'paypal',
CreditCardGateway::ID => 'dcc', // TODO: consider using just the gateway ID for PayPal and DCC too.
CardButtonGateway::ID => CardButtonGateway::ID,
WebhooksStatusPage::ID => WebhooksStatusPage::ID,
);
return array_key_exists( $current_page_id, $gateway_page_id_map )
&& in_array( $gateway_page_id_map[ $current_page_id ], $allowed_gateways, true );

View file

@ -77,7 +77,7 @@ class SectionsRenderer {
foreach ( $this->sections as $id => $label ) {
$url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $id );
if ( in_array( $id, array( CreditCardGateway::ID, WebhooksStatusPage::ID ), true ) ) {
if ( in_array( $id, array( Settings::CONNECTION_TAB_ID, CreditCardGateway::ID, WebhooksStatusPage::ID ), true ) ) {
// We need section=ppcp-gateway for the webhooks page because it is not a gateway,
// and for DCC because otherwise it will not render the page if gateway is not available (country/currency).
// Other gateways render fields differently, and their pages are not expected to work when gateway is not available.

View file

@ -17,7 +17,8 @@ use Psr\Container\ContainerInterface;
*/
class Settings implements ContainerInterface {
const KEY = 'woocommerce-ppcp-settings';
const KEY = 'woocommerce-ppcp-settings';
const CONNECTION_TAB_ID = 'ppcp-connection';
/**
* The settings.