From cf0b5b0e25d8a491b3470e82b1c7fc04d982111d Mon Sep 17 00:00:00 2001 From: David Remer Date: Fri, 28 Aug 2020 08:13:45 +0300 Subject: [PATCH] code styles for the wc gateway module --- .../src/Helper/EarlyOrderHandler.php | 2 +- modules.local/ppcp-wc-gateway/extensions.php | 141 +- modules.local/ppcp-wc-gateway/module.php | 7 +- modules.local/ppcp-wc-gateway/services.php | 3053 +++++++++-------- .../Admin/OrderTablePaymentStatusColumn.php | 87 - .../class-ordertablepaymentstatuscolumn.php | 140 + ...php => class-paymentstatusorderdetail.php} | 23 +- .../Checkout/CheckoutPayPalAddressPreset.php | 124 - .../src/Checkout/DisableGateways.php | 67 - .../class-checkoutpaypaladdresspreset.php | 152 + .../src/Checkout/class-disablegateways.php | 112 + .../src/Endpoint/ReturnUrlEndpoint.php | 52 - .../src/Endpoint/class-returnurlendpoint.php | 86 + ...eption.php => class-notfoundexception.php} | 8 + .../src/Gateway/WcGatewayInterface.php | 10 - ...ateway.php => class-creditcardgateway.php} | 89 +- ...PalGateway.php => class-paypalgateway.php} | 189 +- .../src/Gateway/class-wcgatewayinterface.php | 18 + ...p => class-authorizeorderactionnotice.php} | 37 +- ...otice.php => class-connectadminnotice.php} | 45 +- .../Processor/AuthorizedPaymentsProcessor.php | 110 - .../src/Processor/OrderProcessor.php | 165 - .../class-authorizedpaymentsprocessor.php | 182 + .../src/Processor/class-orderprocessor.php | 272 ++ .../src/Settings/SettingsListener.php | 201 -- .../{Settings.php => class-settings.php} | 60 +- .../src/Settings/class-settingslistener.php | 277 ++ ...enderer.php => class-settingsrenderer.php} | 186 +- ...ayModule.php => class-wcgatewaymodule.php} | 158 +- .../CheckoutPayPalAddressPresetTest.php | 2 +- .../WcGateway/Gateway/WcGatewayTest.php | 6 +- .../AuthorizedPaymentsProcessorTest.php | 10 +- .../Processor/OrderProcessorTest.php | 2 +- 33 files changed, 3453 insertions(+), 2620 deletions(-) delete mode 100644 modules.local/ppcp-wc-gateway/src/Admin/OrderTablePaymentStatusColumn.php create mode 100644 modules.local/ppcp-wc-gateway/src/Admin/class-ordertablepaymentstatuscolumn.php rename modules.local/ppcp-wc-gateway/src/Admin/{PaymentStatusOrderDetail.php => class-paymentstatusorderdetail.php} (60%) delete mode 100644 modules.local/ppcp-wc-gateway/src/Checkout/CheckoutPayPalAddressPreset.php delete mode 100644 modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php create mode 100644 modules.local/ppcp-wc-gateway/src/Checkout/class-checkoutpaypaladdresspreset.php create mode 100644 modules.local/ppcp-wc-gateway/src/Checkout/class-disablegateways.php delete mode 100644 modules.local/ppcp-wc-gateway/src/Endpoint/ReturnUrlEndpoint.php create mode 100644 modules.local/ppcp-wc-gateway/src/Endpoint/class-returnurlendpoint.php rename modules.local/ppcp-wc-gateway/src/Exception/{NotFoundException.php => class-notfoundexception.php} (60%) delete mode 100644 modules.local/ppcp-wc-gateway/src/Gateway/WcGatewayInterface.php rename modules.local/ppcp-wc-gateway/src/Gateway/{CreditCardGateway.php => class-creditcardgateway.php} (65%) rename modules.local/ppcp-wc-gateway/src/Gateway/{PayPalGateway.php => class-paypalgateway.php} (52%) create mode 100644 modules.local/ppcp-wc-gateway/src/Gateway/class-wcgatewayinterface.php rename modules.local/ppcp-wc-gateway/src/Notice/{AuthorizeOrderActionNotice.php => class-authorizeorderactionnotice.php} (68%) rename modules.local/ppcp-wc-gateway/src/Notice/{ConnectAdminNotice.php => class-connectadminnotice.php} (54%) delete mode 100644 modules.local/ppcp-wc-gateway/src/Processor/AuthorizedPaymentsProcessor.php delete mode 100644 modules.local/ppcp-wc-gateway/src/Processor/OrderProcessor.php create mode 100644 modules.local/ppcp-wc-gateway/src/Processor/class-authorizedpaymentsprocessor.php create mode 100644 modules.local/ppcp-wc-gateway/src/Processor/class-orderprocessor.php delete mode 100644 modules.local/ppcp-wc-gateway/src/Settings/SettingsListener.php rename modules.local/ppcp-wc-gateway/src/Settings/{Settings.php => class-settings.php} (68%) create mode 100644 modules.local/ppcp-wc-gateway/src/Settings/class-settingslistener.php rename modules.local/ppcp-wc-gateway/src/Settings/{SettingsRenderer.php => class-settingsrenderer.php} (50%) rename modules.local/ppcp-wc-gateway/src/{WcGatewayModule.php => class-wcgatewaymodule.php} (55%) diff --git a/modules.local/ppcp-button/src/Helper/EarlyOrderHandler.php b/modules.local/ppcp-button/src/Helper/EarlyOrderHandler.php index b56015dd8..fd521cad9 100644 --- a/modules.local/ppcp-button/src/Helper/EarlyOrderHandler.php +++ b/modules.local/ppcp-button/src/Helper/EarlyOrderHandler.php @@ -108,6 +108,6 @@ class EarlyOrderHandler { /** * Patch Order so we have the \WC_Order id added. */ - return $this->orderProcessor->patchOrder( $wcOrder, $order ); + return $this->orderProcessor->patch_order( $wcOrder, $order ); } } diff --git a/modules.local/ppcp-wc-gateway/extensions.php b/modules.local/ppcp-wc-gateway/extensions.php index 8c7611e86..d52216bb2 100644 --- a/modules.local/ppcp-wc-gateway/extensions.php +++ b/modules.local/ppcp-wc-gateway/extensions.php @@ -1,4 +1,9 @@ static function (ContainerInterface $container): string { - $settings = $container->get('wcgateway.settings'); - return $settings->has('merchant_email') ? (string) $settings->get('merchant_email') : ''; - }, - 'api.merchant_id' => static function (ContainerInterface $container): string { - $settings = $container->get('wcgateway.settings'); - return $settings->has('merchant_id') ? (string) $settings->get('merchant_id') : ''; - }, - 'api.partner_merchant_id' => static function (): string { - // ToDo: Replace with the real merchant id of platform - return 'KQ8FCM66JFGDL'; - }, - 'api.key' => static function (ContainerInterface $container): string { - $settings = $container->get('wcgateway.settings'); - $key = $settings->has('client_id') ? (string) $settings->get('client_id') : ''; - return $key; - }, - 'api.secret' => static function (ContainerInterface $container): string { - $settings = $container->get('wcgateway.settings'); - return $settings->has('client_secret') ? (string) $settings->get('client_secret') : ''; - }, - 'api.prefix' => static function (ContainerInterface $container): string { - $settings = $container->get('wcgateway.settings'); - return $settings->has('prefix') ? (string) $settings->get('prefix') : 'WC-'; - }, - 'api.endpoint.order' => static function (ContainerInterface $container): OrderEndpoint { - $orderFactory = $container->get('api.factory.order'); - $patchCollectionFactory = $container->get('api.factory.patch-collection-factory'); - $logger = $container->get('woocommerce.logger.woocommerce'); - /** - * @var SessionHandler $sessionHandler - */ - $sessionHandler = $container->get('session.handler'); - $bnCode = $sessionHandler->bnCode(); + 'api.merchant_email' => static function ( ContainerInterface $container ): string { + $settings = $container->get( 'wcgateway.settings' ); + return $settings->has( 'merchant_email' ) ? (string) $settings->get( 'merchant_email' ) : ''; + }, + 'api.merchant_id' => static function ( ContainerInterface $container ): string { + $settings = $container->get( 'wcgateway.settings' ); + return $settings->has( 'merchant_id' ) ? (string) $settings->get( 'merchant_id' ) : ''; + }, + 'api.partner_merchant_id' => static function (): string { + // @ToDo: Replace with the real merchant id of platform + return 'KQ8FCM66JFGDL'; + }, + 'api.key' => static function ( ContainerInterface $container ): string { + $settings = $container->get( 'wcgateway.settings' ); + $key = $settings->has( 'client_id' ) ? (string) $settings->get( 'client_id' ) : ''; + return $key; + }, + 'api.secret' => static function ( ContainerInterface $container ): string { + $settings = $container->get( 'wcgateway.settings' ); + return $settings->has( 'client_secret' ) ? (string) $settings->get( 'client_secret' ) : ''; + }, + 'api.prefix' => static function ( ContainerInterface $container ): string { + $settings = $container->get( 'wcgateway.settings' ); + return $settings->has( 'prefix' ) ? (string) $settings->get( 'prefix' ) : 'WC-'; + }, + 'api.endpoint.order' => static function ( ContainerInterface $container ): OrderEndpoint { + $order_factory = $container->get( 'api.factory.order' ); + $patch_collection_factory = $container->get( 'api.factory.patch-collection-factory' ); + $logger = $container->get( 'woocommerce.logger.woocommerce' ); + /** + * The session handler. + * + * @var SessionHandler $session_handler + */ + $session_handler = $container->get( 'session.handler' ); + $bn_code = $session_handler->bnCode(); - /** - * @var Settings $settings - */ - $settings = $container->get('wcgateway.settings'); - $intent = $settings->has('intent') && strtoupper((string) $settings->get('intent')) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE'; - $applicationContextRepository = $container->get('api.repository.application-context'); - $paypalRequestId = $container->get('api.repository.paypal-request-id'); - return new OrderEndpoint( - $container->get('api.host'), - $container->get('api.bearer'), - $orderFactory, - $patchCollectionFactory, - $intent, - $logger, - $applicationContextRepository, - $paypalRequestId, - $bnCode - ); - }, - 'woocommerce.logger.woocommerce' => function (ContainerInterface $container): LoggerInterface { - $settings = $container->get('wcgateway.settings'); - if (! function_exists('wc_get_logger') || ! $settings->has('logging_enabled') || ! $settings->get('logging_enabled')) { - return new NullLogger(); - } + /** + * The settings. + * + * @var Settings $settings + */ + $settings = $container->get( 'wcgateway.settings' ); + $intent = $settings->has( 'intent' ) && strtoupper( (string) $settings->get( 'intent' ) ) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE'; + $application_context_repository = $container->get( 'api.repository.application-context' ); + $pay_pal_request_id_repository = $container->get( 'api.repository.paypal-request-id' ); + return new OrderEndpoint( + $container->get( 'api.host' ), + $container->get( 'api.bearer' ), + $order_factory, + $patch_collection_factory, + $intent, + $logger, + $application_context_repository, + $pay_pal_request_id_repository, + $bn_code + ); + }, + 'woocommerce.logger.woocommerce' => function ( ContainerInterface $container ): LoggerInterface { + $settings = $container->get( 'wcgateway.settings' ); + if ( ! function_exists( 'wc_get_logger' ) || ! $settings->has( 'logging_enabled' ) || ! $settings->get( 'logging_enabled' ) ) { + return new NullLogger(); + } - $source = $container->get('woocommerce.logger.source'); - return new WooCommerceLogger( - wc_get_logger(), - $source - ); - }, -]; + $source = $container->get( 'woocommerce.logger.source' ); + return new WooCommerceLogger( + wc_get_logger(), + $source + ); + }, +); diff --git a/modules.local/ppcp-wc-gateway/module.php b/modules.local/ppcp-wc-gateway/module.php index 63760ca0b..0a1c15428 100644 --- a/modules.local/ppcp-wc-gateway/module.php +++ b/modules.local/ppcp-wc-gateway/module.php @@ -1,4 +1,9 @@ static function (ContainerInterface $container): PayPalGateway { - $orderProcessor = $container->get('wcgateway.order-processor'); - $settingsRenderer = $container->get('wcgateway.settings.render'); - $authorizedPayments = $container->get('wcgateway.processor.authorized-payments'); - $notice = $container->get('wcgateway.notice.authorize-order-action'); - $settings = $container->get('wcgateway.settings'); - $sessionHandler = $container->get('session.handler'); +return array( + 'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway { + $order_processor = $container->get( 'wcgateway.order-processor' ); + $settings_renderer = $container->get( 'wcgateway.settings.render' ); + $authorized_payments = $container->get( 'wcgateway.processor.authorized-payments' ); + $notice = $container->get( 'wcgateway.notice.authorize-order-action' ); + $settings = $container->get( 'wcgateway.settings' ); + $session_handler = $container->get( 'session.handler' ); - return new PayPalGateway( - $settingsRenderer, - $orderProcessor, - $authorizedPayments, - $notice, - $settings, - $sessionHandler - ); - }, - 'wcgateway.credit-card-gateway' => static function (ContainerInterface $container): CreditCardGateway { - $orderProcessor = $container->get('wcgateway.order-processor'); - $settingsRenderer = $container->get('wcgateway.settings.render'); - $authorizedPayments = $container->get('wcgateway.processor.authorized-payments'); - $notice = $container->get('wcgateway.notice.authorize-order-action'); - $settings = $container->get('wcgateway.settings'); - $moduleUrl = $container->get('wcgateway.url'); - $sessionHandler = $container->get('session.handler'); - return new CreditCardGateway( - $settingsRenderer, - $orderProcessor, - $authorizedPayments, - $notice, - $settings, - $moduleUrl, - $sessionHandler - ); - }, - 'wcgateway.disabler' => static function (ContainerInterface $container): DisableGateways { - $sessionHandler = $container->get('session.handler'); - $settings = $container->get('wcgateway.settings'); - return new DisableGateways($sessionHandler, $settings); - }, - 'wcgateway.settings' => static function (ContainerInterface $container): Settings { - return new Settings(); - }, - 'wcgateway.notice.connect' => static function (ContainerInterface $container): ConnectAdminNotice { - $state = $container->get('onboarding.state'); - $settings = $container->get('wcgateway.settings'); - return new ConnectAdminNotice($state, $settings); - }, - 'wcgateway.notice.authorize-order-action' => - static function (ContainerInterface $container): AuthorizeOrderActionNotice { - return new AuthorizeOrderActionNotice(); - }, - 'wcgateway.settings.render' => static function (ContainerInterface $container): SettingsRenderer { - $settings = $container->get('wcgateway.settings'); - $state = $container->get('onboarding.state'); - $fields = $container->get('wcgateway.settings.fields'); - $dccApplies = $container->get('api.helpers.dccapplies'); - $messagesApply = $container->get('button.helper.messages-apply'); - return new SettingsRenderer( - $settings, - $state, - $fields, - $dccApplies, - $messagesApply - ); - }, - 'wcgateway.settings.listener' => static function (ContainerInterface $container): SettingsListener { - $settings = $container->get('wcgateway.settings'); - $fields = $container->get('wcgateway.settings.fields'); - $webhookRegistrar = $container->get('webhook.registrar'); - $state = $container->get('onboarding.state'); + return new PayPalGateway( + $settings_renderer, + $order_processor, + $authorized_payments, + $notice, + $settings, + $session_handler + ); + }, + 'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway { + $order_processor = $container->get( 'wcgateway.order-processor' ); + $settings_renderer = $container->get( 'wcgateway.settings.render' ); + $authorized_payments = $container->get( 'wcgateway.processor.authorized-payments' ); + $notice = $container->get( 'wcgateway.notice.authorize-order-action' ); + $settings = $container->get( 'wcgateway.settings' ); + $moduleUrl = $container->get( 'wcgateway.url' ); + $session_handler = $container->get( 'session.handler' ); + return new CreditCardGateway( + $settings_renderer, + $order_processor, + $authorized_payments, + $notice, + $settings, + $moduleUrl, + $session_handler + ); + }, + 'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways { + $session_handler = $container->get( 'session.handler' ); + $settings = $container->get( 'wcgateway.settings' ); + return new DisableGateways( $session_handler, $settings ); + }, + 'wcgateway.settings' => static function ( ContainerInterface $container ): Settings { + return new Settings(); + }, + 'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice { + $state = $container->get( 'onboarding.state' ); + $settings = $container->get( 'wcgateway.settings' ); + return new ConnectAdminNotice( $state, $settings ); + }, + 'wcgateway.notice.authorize-order-action' => + static function ( ContainerInterface $container ): AuthorizeOrderActionNotice { + return new AuthorizeOrderActionNotice(); + }, + 'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer { + $settings = $container->get( 'wcgateway.settings' ); + $state = $container->get( 'onboarding.state' ); + $fields = $container->get( 'wcgateway.settings.fields' ); + $dcc_applies = $container->get( 'api.helpers.dccapplies' ); + $messages_apply = $container->get( 'button.helper.messages-apply' ); + return new SettingsRenderer( + $settings, + $state, + $fields, + $dcc_applies, + $messages_apply + ); + }, + 'wcgateway.settings.listener' => static function ( ContainerInterface $container ): SettingsListener { + $settings = $container->get( 'wcgateway.settings' ); + $fields = $container->get( 'wcgateway.settings.fields' ); + $webhook_registrar = $container->get( 'webhook.registrar' ); + $state = $container->get( 'onboarding.state' ); - global $wpdb; - $cacheFactory = new CachePoolFactory($wpdb); - $pool = $cacheFactory->createCachePool('ppcp-token'); - return new SettingsListener($settings, $fields, $webhookRegistrar, $pool, $state); - }, - 'wcgateway.order-processor' => static function (ContainerInterface $container): OrderProcessor { + global $wpdb; + $cache_pool_factory = new CachePoolFactory( $wpdb ); + $pool = $cache_pool_factory->createCachePool( 'ppcp-token' ); + return new SettingsListener( $settings, $fields, $webhook_registrar, $pool, $state ); + }, + 'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor { - $sessionHandler = $container->get('session.handler'); - $cartRepository = $container->get('api.repository.cart'); - $orderEndpoint = $container->get('api.endpoint.order'); - $paymentsEndpoint = $container->get('api.endpoint.payments'); - $orderFactory = $container->get('api.factory.order'); - $threeDsecure = $container->get('button.helper.three-d-secure'); - $authorizedPaymentsProcessor = $container->get('wcgateway.processor.authorized-payments'); - $settings = $container->get('wcgateway.settings'); - return new OrderProcessor( - $sessionHandler, - $cartRepository, - $orderEndpoint, - $paymentsEndpoint, - $orderFactory, - $threeDsecure, - $authorizedPaymentsProcessor, - $settings - ); - }, - 'wcgateway.processor.authorized-payments' => static function (ContainerInterface $container): AuthorizedPaymentsProcessor { - $orderEndpoint = $container->get('api.endpoint.order'); - $paymentsEndpoint = $container->get('api.endpoint.payments'); - return new AuthorizedPaymentsProcessor($orderEndpoint, $paymentsEndpoint); - }, - 'wcgateway.admin.order-payment-status' => static function (ContainerInterface $container): PaymentStatusOrderDetail { - return new PaymentStatusOrderDetail(); - }, - 'wcgateway.admin.orders-payment-status-column' => static function (ContainerInterface $container): OrderTablePaymentStatusColumn { - $settings = $container->get('wcgateway.settings'); - return new OrderTablePaymentStatusColumn($settings); - }, + $session_handler = $container->get( 'session.handler' ); + $cart_repository = $container->get( 'api.repository.cart' ); + $order_endpoint = $container->get( 'api.endpoint.order' ); + $payments_endpoint = $container->get( 'api.endpoint.payments' ); + $order_factory = $container->get( 'api.factory.order' ); + $threed_secure = $container->get( 'button.helper.three-d-secure' ); + $authorized_payments_processor = $container->get( 'wcgateway.processor.authorized-payments' ); + $settings = $container->get( 'wcgateway.settings' ); + return new OrderProcessor( + $session_handler, + $cart_repository, + $order_endpoint, + $payments_endpoint, + $order_factory, + $threed_secure, + $authorized_payments_processor, + $settings + ); + }, + 'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor { + $order_endpoint = $container->get( 'api.endpoint.order' ); + $payments_endpoint = $container->get( 'api.endpoint.payments' ); + return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint ); + }, + 'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ): PaymentStatusOrderDetail { + return new PaymentStatusOrderDetail(); + }, + 'wcgateway.admin.orders-payment-status-column' => static function ( ContainerInterface $container ): OrderTablePaymentStatusColumn { + $settings = $container->get( 'wcgateway.settings' ); + return new OrderTablePaymentStatusColumn( $settings ); + }, - 'wcgateway.settings.fields' => static function (ContainerInterface $container): array { - $settings = $container->get('wcgateway.settings'); - $sandboxText = $settings->has('sandbox_on') && $settings->get('sandbox_on') ? - __( - 'You are currently in the sandbox mode to test your installation. You can switch this, by clicking ', - 'woocommerce-paypal-commerce-gateway' - ) : __( - 'You are in live mode. This means, you can receive money into your account. You can switch this, by clicking ', - 'woocommerce-paypal-commerce-gateway' - ); - $sandboxText = sprintf( - $sandboxText, - 'save', - 'reset' - ); + 'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array { + $settings = $container->get( 'wcgateway.settings' ); + $sandbox_text = $settings->has( 'sandbox_on' ) && $settings->get( 'sandbox_on' ) ? + __( + 'You are currently in the sandbox mode to test your installation. You can switch this, by clicking ', + 'woocommerce-paypal-commerce-gateway' + ) : __( + 'You are in live mode. This means, you can receive money into your account. You can switch this, by clicking ', + 'woocommerce-paypal-commerce-gateway' + ); + $sandbox_text = sprintf( + $sandbox_text, + 'save', + 'reset' + ); - $merchantEmailText = sprintf( - __( - 'You are connected with your email address %1$s. + $merchant_email_text = sprintf( + __( + 'You are connected with your email address %1$s. If you want to change this settings, please click ', - 'woocommerce-paypal-commerce-gateway' - ), - $settings->has('merchant_email') ? $settings->get('merchant_email') : '', - 'save', - 'reset' - ); - $fields = [ - 'ppcp_onboarding' => [ - 'title' => __('Connect to PayPal', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp_onboarding', - 'screens' => [ - State::STATE_PROGRESSIVE, - ], - 'requirements' => [], - 'gateway' => 'all', - ], - 'sandbox_on' => [ - 'title' => __('Sandbox', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('To test your Woocommerce installation, you can use the sandbox mode.', 'woocommerce-paypal-commerce-gateway'), - 'default' => 0, - 'screens' => [ - State::STATE_START, - ], - 'requirements' => [], - 'gateway' => 'all', - ], - 'sandbox_on_info' => [ - 'title' => __('Sandbox', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-text', - 'text' => $sandboxText, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'hidden' => 'sandbox_on', - 'requirements' => [], - 'gateway' => 'all', - ], - 'merchant_email' => [ - 'title' => __('Email address', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'text', - 'required' => true, - 'desc_tip' => true, - 'description' => __('The email address of your PayPal account.', 'woocommerce-paypal-commerce-gateway'), - 'default' => '', - 'screens' => [ - State::STATE_START, - ], - 'requirements' => [], - 'gateway' => 'all', - ], - 'merchant_email_info' => [ - 'title' => __('Email address', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-text', - 'text' => $merchantEmailText, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'hidden' => 'merchant_email', - 'requirements' => [], - 'gateway' => 'all', - ], - 'toggle_manual_input' => [ - 'type' => 'ppcp-text', - 'title' => __('Manual mode', 'woocommerce-paypla-commerce-gateway'), - 'text' => '', - 'screens' => [ - State::STATE_START, - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'all', - ], - 'client_id' => [ - 'title' => __('Client Id', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-text-input', - 'desc_tip' => true, - 'description' => __('The client id of your api ', 'woocommerce-paypal-commerce-gateway'), - 'default' => false, - 'screens' => [ - State::STATE_START, - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'all', - ], - 'client_secret' => [ - 'title' => __('Secret Key', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-password', - 'desc_tip' => true, - 'description' => __('The secret key of your api', 'woocommerce-paypal-commerce-gateway'), - 'default' => false, - 'screens' => [ - State::STATE_START, - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'all', - ], - 'title' => [ - 'title' => __('Title', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'text', - 'description' => __( - 'This controls the title which the user sees during checkout.', - 'woocommerce-paypal-commerce-gateway' - ), - 'default' => __('PayPal', 'woocommerce-paypal-commerce-gateway'), - 'desc_tip' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'dcc_gateway_title' => [ - 'title' => __('Title', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'text', - 'description' => __( - 'This controls the title which the user sees during checkout.', - 'woocommerce-paypal-commerce-gateway' - ), - 'default' => __('Credit Cards', 'woocommerce-paypal-commerce-gateway'), - 'desc_tip' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'dcc', - ], - 'description' => [ - 'title' => __('Description', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'text', - 'desc_tip' => true, - 'description' => __( - 'This controls the description which the user sees during checkout.', - 'woocommerce-paypal-commerce-gateway' - ), - 'default' => __( - 'Pay via PayPal; you can pay with your credit card if you don\'t have a PayPal account.', - 'woocommerce-paypal-commerce-gateway' - ), - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'dcc_gateway_description' => [ - 'title' => __('Description', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'text', - 'desc_tip' => true, - 'description' => __( - 'This controls the description which the user sees during checkout.', - 'woocommerce-paypal-commerce-gateway' - ), - 'default' => __( - 'Pay with your credit card.', - 'woocommerce-paypal-commerce-gateway' - ), - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'dcc', - ], - 'intent' => [ - 'title' => __('Intent', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'capture', - 'desc_tip' => true, - 'description' => __( - 'The intent to either capture payment immediately or authorize a payment for an order after order creation.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'capture' => __('Capture', 'woocommerce-paypal-commerce-gateway'), - 'authorize' => __('Authorize', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'all', - ], - 'capture_for_virtual_only' => [ - 'title' => __('Capture Virtual-Only Orders ', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'default' => false, - 'desc_tip' => true, - 'description' => __( - 'If the order contains exclusively virtual items, enable this to immediately capture, rather than authorize, the transaction.', - 'woocommerce-paypal-commerce-gateway' - ), - 'label' => __('Capture Virtual-Only Orders', 'woocommerce-paypal-commerce-gateway'), - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'all', - ], - 'payee_preferred' => [ - 'title' => __('Instant Payments ', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'default' => false, - 'desc_tip' => true, - 'description' => __( - 'If you enable this setting, PayPal will be instructed not to allow the buyer to use funding sources that take additional time to complete (for example, eChecks). Instead, the buyer will be required to use an instant funding source, such as an instant transfer, a credit/debit card, or PayPal Credit.', - 'woocommerce-paypal-commerce-gateway' - ), - 'label' => __('Require Instant Payment', 'woocommerce-paypal-commerce-gateway'), - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'brand_name' => [ - 'title' => __('Brand Name', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'text', - 'default' => get_bloginfo('name'), - 'desc_tip' => true, - 'description' => __( - 'Control the name of your shop, customers will see in the PayPal process.', - 'woocommerce-paypal-commerce-gateway' - ), - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'landing_page' => [ - 'title' => __('Landing Page', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Type of PayPal page to display.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - ApplicationContext::LANDING_PAGE_LOGIN => __('Login (PayPal account login)', 'woocommerce-paypal-commerce-gateway'), - ApplicationContext::LANDING_PAGE_BILLING => __('Billing (Non-PayPal account)', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'disable_funding' => [ - 'title' => __('Disable funding sources', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-multiselect', - 'class' => ['wc-enhanced-select'], - 'default' => [], - 'desc_tip' => true, - 'description' => __( - 'By default all possible funding sources will be shown. You can disable some sources, if you wish.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'card' => _x('Credit or debit cards', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'credit' => _x('PayPal Credit', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'sepa' => _x('SEPA-Lastschrift', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'bancontact' => _x('Bancontact', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'eps' => _x('eps', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'giropay' => _x('giropay', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'ideal' => _x('iDEAL', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'mybank' => _x('MyBank', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'p24' => _x('Przelewy24', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'sofort' => _x('Sofort', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'vault_enabled' => [ - 'title' => __('Vaulting', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'desc_tip' => true, - 'label' => __('Enable vaulting', 'woocommerce-paypal-commerce-gateway'), - 'description' => __('Enables you to store payment tokens for subscriptions.', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'screens' => [ - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], + 'woocommerce-paypal-commerce-gateway' + ), + $settings->has( 'merchant_email' ) ? $settings->get( 'merchant_email' ) : '', + 'save', + 'reset' + ); + $fields = array( + 'ppcp_onboarding' => array( + 'title' => __( 'Connect to PayPal', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp_onboarding', + 'screens' => array( + State::STATE_PROGRESSIVE, + ), + 'requirements' => array(), + 'gateway' => 'all', + ), + 'sandbox_on' => array( + 'title' => __( 'Sandbox', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'To test your Woocommerce installation, you can use the sandbox mode.', 'woocommerce-paypal-commerce-gateway' ), + 'default' => 0, + 'screens' => array( + State::STATE_START, + ), + 'requirements' => array(), + 'gateway' => 'all', + ), + 'sandbox_on_info' => array( + 'title' => __( 'Sandbox', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-text', + 'text' => $sandbox_text, + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'hidden' => 'sandbox_on', + 'requirements' => array(), + 'gateway' => 'all', + ), + 'merchant_email' => array( + 'title' => __( 'Email address', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'text', + 'required' => true, + 'desc_tip' => true, + 'description' => __( 'The email address of your PayPal account.', 'woocommerce-paypal-commerce-gateway' ), + 'default' => '', + 'screens' => array( + State::STATE_START, + ), + 'requirements' => array(), + 'gateway' => 'all', + ), + 'merchant_email_info' => array( + 'title' => __( 'Email address', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-text', + 'text' => $merchant_email_text, + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'hidden' => 'merchant_email', + 'requirements' => array(), + 'gateway' => 'all', + ), + 'toggle_manual_input' => array( + 'type' => 'ppcp-text', + 'title' => __( 'Manual mode', 'woocommerce-paypla-commerce-gateway' ), + 'text' => '', + 'screens' => array( + State::STATE_START, + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'all', + ), + 'client_id' => array( + 'title' => __( 'Client Id', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-text-input', + 'desc_tip' => true, + 'description' => __( 'The client id of your api ', 'woocommerce-paypal-commerce-gateway' ), + 'default' => false, + 'screens' => array( + State::STATE_START, + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'all', + ), + 'client_secret' => array( + 'title' => __( 'Secret Key', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-password', + 'desc_tip' => true, + 'description' => __( 'The secret key of your api', 'woocommerce-paypal-commerce-gateway' ), + 'default' => false, + 'screens' => array( + State::STATE_START, + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'all', + ), + 'title' => array( + 'title' => __( 'Title', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'text', + 'description' => __( + 'This controls the title which the user sees during checkout.', + 'woocommerce-paypal-commerce-gateway' + ), + 'default' => __( 'PayPal', 'woocommerce-paypal-commerce-gateway' ), + 'desc_tip' => true, + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'dcc_gateway_title' => array( + 'title' => __( 'Title', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'text', + 'description' => __( + 'This controls the title which the user sees during checkout.', + 'woocommerce-paypal-commerce-gateway' + ), + 'default' => __( 'Credit Cards', 'woocommerce-paypal-commerce-gateway' ), + 'desc_tip' => true, + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'dcc', + ), + 'description' => array( + 'title' => __( 'Description', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'text', + 'desc_tip' => true, + 'description' => __( + 'This controls the description which the user sees during checkout.', + 'woocommerce-paypal-commerce-gateway' + ), + 'default' => __( + 'Pay via PayPal; you can pay with your credit card if you don\'t have a PayPal account.', + 'woocommerce-paypal-commerce-gateway' + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'dcc_gateway_description' => array( + 'title' => __( 'Description', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'text', + 'desc_tip' => true, + 'description' => __( + 'This controls the description which the user sees during checkout.', + 'woocommerce-paypal-commerce-gateway' + ), + 'default' => __( + 'Pay with your credit card.', + 'woocommerce-paypal-commerce-gateway' + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'dcc', + ), + 'intent' => array( + 'title' => __( 'Intent', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'capture', + 'desc_tip' => true, + 'description' => __( + 'The intent to either capture payment immediately or authorize a payment for an order after order creation.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'capture' => __( 'Capture', 'woocommerce-paypal-commerce-gateway' ), + 'authorize' => __( 'Authorize', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'all', + ), + 'capture_for_virtual_only' => array( + 'title' => __( 'Capture Virtual-Only Orders ', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'default' => false, + 'desc_tip' => true, + 'description' => __( + 'If the order contains exclusively virtual items, enable this to immediately capture, rather than authorize, the transaction.', + 'woocommerce-paypal-commerce-gateway' + ), + 'label' => __( 'Capture Virtual-Only Orders', 'woocommerce-paypal-commerce-gateway' ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'all', + ), + 'payee_preferred' => array( + 'title' => __( 'Instant Payments ', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'default' => false, + 'desc_tip' => true, + 'description' => __( + 'If you enable this setting, PayPal will be instructed not to allow the buyer to use funding sources that take additional time to complete (for example, eChecks). Instead, the buyer will be required to use an instant funding source, such as an instant transfer, a credit/debit card, or PayPal Credit.', + 'woocommerce-paypal-commerce-gateway' + ), + 'label' => __( 'Require Instant Payment', 'woocommerce-paypal-commerce-gateway' ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'brand_name' => array( + 'title' => __( 'Brand Name', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'text', + 'default' => get_bloginfo( 'name' ), + 'desc_tip' => true, + 'description' => __( + 'Control the name of your shop, customers will see in the PayPal process.', + 'woocommerce-paypal-commerce-gateway' + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'landing_page' => array( + 'title' => __( 'Landing Page', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Type of PayPal page to display.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + ApplicationContext::LANDING_PAGE_LOGIN => __( 'Login (PayPal account login)', 'woocommerce-paypal-commerce-gateway' ), + ApplicationContext::LANDING_PAGE_BILLING => __( 'Billing (Non-PayPal account)', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'disable_funding' => array( + 'title' => __( 'Disable funding sources', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-multiselect', + 'class' => array( 'wc-enhanced-select' ), + 'default' => array(), + 'desc_tip' => true, + 'description' => __( + 'By default all possible funding sources will be shown. You can disable some sources, if you wish.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'card' => _x( 'Credit or debit cards', 'Name of payment method', 'woocommerce-paypal-commerce-gateway' ), + 'credit' => _x( 'PayPal Credit', 'Name of payment method', 'woocommerce-paypal-commerce-gateway' ), + 'sepa' => _x( 'SEPA-Lastschrift', 'Name of payment method', 'woocommerce-paypal-commerce-gateway' ), + 'bancontact' => _x( 'Bancontact', 'Name of payment method', 'woocommerce-paypal-commerce-gateway' ), + 'eps' => _x( 'eps', 'Name of payment method', 'woocommerce-paypal-commerce-gateway' ), + 'giropay' => _x( 'giropay', 'Name of payment method', 'woocommerce-paypal-commerce-gateway' ), + 'ideal' => _x( 'iDEAL', 'Name of payment method', 'woocommerce-paypal-commerce-gateway' ), + 'mybank' => _x( 'MyBank', 'Name of payment method', 'woocommerce-paypal-commerce-gateway' ), + 'p24' => _x( 'Przelewy24', 'Name of payment method', 'woocommerce-paypal-commerce-gateway' ), + 'sofort' => _x( 'Sofort', 'Name of payment method', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'vault_enabled' => array( + 'title' => __( 'Vaulting', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'desc_tip' => true, + 'label' => __( 'Enable vaulting', 'woocommerce-paypal-commerce-gateway' ), + 'description' => __( 'Enables you to store payment tokens for subscriptions.', 'woocommerce-paypal-commerce-gateway' ), + 'default' => true, + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), - 'logging_enabled' => [ - 'title' => __('Logging', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'desc_tip' => true, - 'label' => __('Enable logging', 'woocommerce-paypal-commerce-gateway'), - '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-commerce-gateway'), - 'default' => false, - 'screens' => [ - State::STATE_START, - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'all', - ], - 'prefix' => [ - 'title' => __('Installation prefix', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'text', - 'desc_tip' => true, - 'description' => __('If you use your PayPal account with more than one installation, please use a distinct prefix to seperate those installations. Please do not use numbers in your prefix.', 'woocommerce-paypal-commerce-gateway'), - 'default' => 'WC-', - 'screens' => [ - State::STATE_START, - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'all', - ], + 'logging_enabled' => array( + 'title' => __( 'Logging', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'desc_tip' => true, + 'label' => __( 'Enable logging', 'woocommerce-paypal-commerce-gateway' ), + '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-commerce-gateway' ), + 'default' => false, + 'screens' => array( + State::STATE_START, + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'all', + ), + 'prefix' => array( + 'title' => __( 'Installation prefix', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'text', + 'desc_tip' => true, + 'description' => __( 'If you use your PayPal account with more than one installation, please use a distinct prefix to seperate those installations. Please do not use numbers in your prefix.', 'woocommerce-paypal-commerce-gateway' ), + 'default' => 'WC-', + 'screens' => array( + State::STATE_START, + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'all', + ), - //General button styles - 'button_style_heading' => [ - 'heading' => __('Checkout', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-heading', - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_layout' => [ - 'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'vertical', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'vertical' => __('Vertical', 'woocommerce-paypal-commerce-gateway'), - 'horizontal' => __('Horizontal', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_tagline' => [ - 'title' => __('Tagline', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'default' => true, - 'label' => __('Enable tagline', 'woocommerce-paypal-commerce-gateway'), - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-commerce-gateway' - ), - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_label' => [ - 'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'paypal', - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'paypal' => __('PayPal', 'woocommerce-paypal-commerce-gateway'), - 'checkout' => __('PayPal Checkout', 'woocommerce-paypal-commerce-gateway'), - 'buynow' => __('PayPal Buy Now', 'woocommerce-paypal-commerce-gateway'), - 'pay' => __('Pay with PayPal', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_color' => [ - 'title' => __('Color', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'gold' => __('Gold (Recommended)', 'woocommerce-paypal-commerce-gateway'), - 'blue' => __('Blue', 'woocommerce-paypal-commerce-gateway'), - 'silver' => __('Silver', 'woocommerce-paypal-commerce-gateway'), - 'black' => __('Black', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_shape' => [ - 'title' => __('Shape', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'pill' => __('Pill', 'woocommerce-paypal-commerce-gateway'), - 'rect' => __('Rectangle', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'message_heading' => [ - 'heading' => __('Credit Messaging on Checkout', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-heading', - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_enabled' => [ - 'title' => __('Enable message on Checkout', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable on Checkout', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_layout' => [ - 'title' => __('Credit Messaging layout', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'text', - 'desc_tip' => true, - 'description' => __( - 'The layout of the message.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'text' => __('Text', 'woocommerce-paypal-commerce-gateway'), - 'flex' => __('Flex', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_logo' => [ - 'title' => __('Credit Messaging logo', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'primary', - 'desc_tip' => true, - 'description' => __( - 'What logo the text message contains. Only applicable, when the layout style Text is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'primary' => __('Primary', 'woocommerce-paypal-commerce-gateway'), - 'alternative' => __('Alternative', 'woocommerce-paypal-commerce-gateway'), - 'inline' => __('Inline', 'woocommerce-paypal-commerce-gateway'), - 'none' => __('None', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_position' => [ - 'title' => __('Credit Messaging logo position', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'left', - 'desc_tip' => true, - 'description' => __( - 'The position of the logo. Only applicable, when the layout style Text is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'left' => __('Left', 'woocommerce-paypal-commerce-gateway'), - 'right' => __('Right', 'woocommerce-paypal-commerce-gateway'), - 'top' => __('Top', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_color' => [ - 'title' => __('Credit Messaging text color', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'black', - 'desc_tip' => true, - 'description' => __( - 'The color of the text. Only applicable, when the layout style Text is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'black' => __('Black', 'woocommerce-paypal-commerce-gateway'), - 'white' => __('White', 'woocommerce-paypal-commerce-gateway'), - 'monochrome' => __('Monochrome', 'woocommerce-paypal-commerce-gateway'), - 'grayscale' => __('Grayscale', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_flex_color' => [ - 'title' => __('Credit Messaging color', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'blue', - 'desc_tip' => true, - 'description' => __( - 'The color of the text. Only applicable, when the layout style Flex is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'blue' => __('Blue', 'woocommerce-paypal-commerce-gateway'), - 'black' => __('Black', 'woocommerce-paypal-commerce-gateway'), - 'white' => __('White', 'woocommerce-paypal-commerce-gateway'), - 'white-no-border' => __('White no border', 'woocommerce-paypal-commerce-gateway'), - 'gray' => __('Gray', 'woocommerce-paypal-commerce-gateway'), - 'monochrome' => __('Monochrome', 'woocommerce-paypal-commerce-gateway'), - 'grayscale' => __('Grayscale', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_flex_ratio' => [ - 'title' => __('Credit Messaging ratio', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => '1x1', - 'desc_tip' => true, - 'description' => __( - 'The color of the text. Only applicable, when the layout style Flex is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - '1x1' => __('1x1', 'woocommerce-paypal-commerce-gateway'), - '1x4' => __('1x4', 'woocommerce-paypal-commerce-gateway'), - '8x1' => __('8x1', 'woocommerce-paypal-commerce-gateway'), - '20x1' => __('20x1', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], + // General button styles + 'button_style_heading' => array( + 'heading' => __( 'Checkout', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'vertical', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-commerce-gateway' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'default' => true, + 'label' => __( 'Enable tagline', 'woocommerce-paypal-commerce-gateway' ), + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-commerce-gateway' + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'paypal', + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-commerce-gateway' ), + 'checkout' => __( 'PayPal Checkout', 'woocommerce-paypal-commerce-gateway' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-commerce-gateway' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-commerce-gateway' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-commerce-gateway' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-commerce-gateway' ), + 'black' => __( 'Black', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-commerce-gateway' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'message_heading' => array( + 'heading' => __( 'Credit Messaging on Checkout', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_enabled' => array( + 'title' => __( 'Enable message on Checkout', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'Enable on Checkout', 'woocommerce-paypal-commerce-gateway' ), + 'default' => true, + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_layout' => array( + 'title' => __( 'Credit Messaging layout', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'text', + 'desc_tip' => true, + 'description' => __( + 'The layout of the message.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'text' => __( 'Text', 'woocommerce-paypal-commerce-gateway' ), + 'flex' => __( 'Flex', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_logo' => array( + 'title' => __( 'Credit Messaging logo', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'primary', + 'desc_tip' => true, + 'description' => __( + 'What logo the text message contains. Only applicable, when the layout style Text is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'primary' => __( 'Primary', 'woocommerce-paypal-commerce-gateway' ), + 'alternative' => __( 'Alternative', 'woocommerce-paypal-commerce-gateway' ), + 'inline' => __( 'Inline', 'woocommerce-paypal-commerce-gateway' ), + 'none' => __( 'None', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_position' => array( + 'title' => __( 'Credit Messaging logo position', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'left', + 'desc_tip' => true, + 'description' => __( + 'The position of the logo. Only applicable, when the layout style Text is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'left' => __( 'Left', 'woocommerce-paypal-commerce-gateway' ), + 'right' => __( 'Right', 'woocommerce-paypal-commerce-gateway' ), + 'top' => __( 'Top', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_color' => array( + 'title' => __( 'Credit Messaging text color', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'black', + 'desc_tip' => true, + 'description' => __( + 'The color of the text. Only applicable, when the layout style Text is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'black' => __( 'Black', 'woocommerce-paypal-commerce-gateway' ), + 'white' => __( 'White', 'woocommerce-paypal-commerce-gateway' ), + 'monochrome' => __( 'Monochrome', 'woocommerce-paypal-commerce-gateway' ), + 'grayscale' => __( 'Grayscale', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_flex_color' => array( + 'title' => __( 'Credit Messaging color', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'blue', + 'desc_tip' => true, + 'description' => __( + 'The color of the text. Only applicable, when the layout style Flex is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'blue' => __( 'Blue', 'woocommerce-paypal-commerce-gateway' ), + 'black' => __( 'Black', 'woocommerce-paypal-commerce-gateway' ), + 'white' => __( 'White', 'woocommerce-paypal-commerce-gateway' ), + 'white-no-border' => __( 'White no border', 'woocommerce-paypal-commerce-gateway' ), + 'gray' => __( 'Gray', 'woocommerce-paypal-commerce-gateway' ), + 'monochrome' => __( 'Monochrome', 'woocommerce-paypal-commerce-gateway' ), + 'grayscale' => __( 'Grayscale', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_flex_ratio' => array( + 'title' => __( 'Credit Messaging ratio', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => '1x1', + 'desc_tip' => true, + 'description' => __( + 'The color of the text. Only applicable, when the layout style Flex is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + '1x1' => __( '1x1', 'woocommerce-paypal-commerce-gateway' ), + '1x4' => __( '1x4', 'woocommerce-paypal-commerce-gateway' ), + '8x1' => __( '8x1', 'woocommerce-paypal-commerce-gateway' ), + '20x1' => __( '20x1', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), - //Single product page - 'button_product_heading' => [ - 'heading' => __('Button on Single product', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-heading', - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_product_enabled' => [ - 'title' => __('Enable buttons on Single Product', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable on Single Product', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_product_layout' => [ - 'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'horizontal', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'vertical' => __('Vertical', 'woocommerce-paypal-commerce-gateway'), - 'horizontal' => __('Horizontal', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_product_tagline' => [ - 'title' => __('Tagline', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable tagline', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-commerce-gateway' - ), - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_product_label' => [ - 'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'paypal', - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'paypal' => __('PayPal', 'woocommerce-paypal-commerce-gateway'), - 'checkout' => __('PayPal Checkout', 'woocommerce-paypal-commerce-gateway'), - 'buynow' => __('PayPal Buy Now', 'woocommerce-paypal-commerce-gateway'), - 'pay' => __('Pay with PayPal', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_product_color' => [ - 'title' => __('Color', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'gold' => __('Gold (Recommended)', 'woocommerce-paypal-commerce-gateway'), - 'blue' => __('Blue', 'woocommerce-paypal-commerce-gateway'), - 'silver' => __('Silver', 'woocommerce-paypal-commerce-gateway'), - 'black' => __('Black', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_product_shape' => [ - 'title' => __('Shape', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'pill' => __('Pill', 'woocommerce-paypal-commerce-gateway'), - 'rect' => __('Rectangle', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], + // Single product page + 'button_product_heading' => array( + 'heading' => __( 'Button on Single product', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_enabled' => array( + 'title' => __( 'Enable buttons on Single Product', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'Enable on Single Product', 'woocommerce-paypal-commerce-gateway' ), + 'default' => true, + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'horizontal', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-commerce-gateway' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'Enable tagline', 'woocommerce-paypal-commerce-gateway' ), + 'default' => true, + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-commerce-gateway' + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'paypal', + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-commerce-gateway' ), + 'checkout' => __( 'PayPal Checkout', 'woocommerce-paypal-commerce-gateway' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-commerce-gateway' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-commerce-gateway' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-commerce-gateway' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-commerce-gateway' ), + 'black' => __( 'Black', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_product_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-commerce-gateway' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), - 'message_product_heading' => [ - 'heading' => __('Credit Messaging on Single product', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-heading', - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_product_enabled' => [ - 'title' => __('Enable message on Single Product', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable on Single Product', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_product_layout' => [ - 'title' => __('Credit Messaging layout', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'text', - 'desc_tip' => true, - 'description' => __( - 'The layout of the message.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'text' => __('Text', 'woocommerce-paypal-commerce-gateway'), - 'flex' => __('Flex', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_product_logo' => [ - 'title' => __('Credit Messaging logo', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'primary', - 'desc_tip' => true, - 'description' => __( - 'What logo the text message contains. Only applicable, when the layout style Text is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'primary' => __('Primary', 'woocommerce-paypal-commerce-gateway'), - 'alternative' => __('Alternative', 'woocommerce-paypal-commerce-gateway'), - 'inline' => __('Inline', 'woocommerce-paypal-commerce-gateway'), - 'none' => __('None', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_product_position' => [ - 'title' => __('Credit Messaging logo position', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'left', - 'desc_tip' => true, - 'description' => __( - 'The position of the logo. Only applicable, when the layout style Text is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'left' => __('Left', 'woocommerce-paypal-commerce-gateway'), - 'right' => __('Right', 'woocommerce-paypal-commerce-gateway'), - 'top' => __('Top', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_product_color' => [ - 'title' => __('Credit Messaging text color', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'black', - 'desc_tip' => true, - 'description' => __( - 'The color of the text. Only applicable, when the layout style Text is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'black' => __('Black', 'woocommerce-paypal-commerce-gateway'), - 'white' => __('White', 'woocommerce-paypal-commerce-gateway'), - 'monochrome' => __('Monochrome', 'woocommerce-paypal-commerce-gateway'), - 'grayscale' => __('Grayscale', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_product_flex_color' => [ - 'title' => __('Credit Messaging color', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'blue', - 'desc_tip' => true, - 'description' => __( - 'The color of the text. Only applicable, when the layout style Flex is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'blue' => __('Blue', 'woocommerce-paypal-commerce-gateway'), - 'black' => __('Black', 'woocommerce-paypal-commerce-gateway'), - 'white' => __('White', 'woocommerce-paypal-commerce-gateway'), - 'white-no-border' => __('White no border', 'woocommerce-paypal-commerce-gateway'), - 'gray' => __('Gray', 'woocommerce-paypal-commerce-gateway'), - 'monochrome' => __('Monochrome', 'woocommerce-paypal-commerce-gateway'), - 'grayscale' => __('Grayscale', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_product_flex_ratio' => [ - 'title' => __('Credit Messaging ratio', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => '1x1', - 'desc_tip' => true, - 'description' => __( - 'The color of the text. Only applicable, when the layout style Flex is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - '1x1' => __('1x1', 'woocommerce-paypal-commerce-gateway'), - '1x4' => __('1x4', 'woocommerce-paypal-commerce-gateway'), - '8x1' => __('8x1', 'woocommerce-paypal-commerce-gateway'), - '20x1' => __('20x1', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], + 'message_product_heading' => array( + 'heading' => __( 'Credit Messaging on Single product', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_product_enabled' => array( + 'title' => __( 'Enable message on Single Product', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'Enable on Single Product', 'woocommerce-paypal-commerce-gateway' ), + 'default' => true, + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_product_layout' => array( + 'title' => __( 'Credit Messaging layout', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'text', + 'desc_tip' => true, + 'description' => __( + 'The layout of the message.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'text' => __( 'Text', 'woocommerce-paypal-commerce-gateway' ), + 'flex' => __( 'Flex', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_product_logo' => array( + 'title' => __( 'Credit Messaging logo', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'primary', + 'desc_tip' => true, + 'description' => __( + 'What logo the text message contains. Only applicable, when the layout style Text is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'primary' => __( 'Primary', 'woocommerce-paypal-commerce-gateway' ), + 'alternative' => __( 'Alternative', 'woocommerce-paypal-commerce-gateway' ), + 'inline' => __( 'Inline', 'woocommerce-paypal-commerce-gateway' ), + 'none' => __( 'None', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_product_position' => array( + 'title' => __( 'Credit Messaging logo position', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'left', + 'desc_tip' => true, + 'description' => __( + 'The position of the logo. Only applicable, when the layout style Text is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'left' => __( 'Left', 'woocommerce-paypal-commerce-gateway' ), + 'right' => __( 'Right', 'woocommerce-paypal-commerce-gateway' ), + 'top' => __( 'Top', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_product_color' => array( + 'title' => __( 'Credit Messaging text color', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'black', + 'desc_tip' => true, + 'description' => __( + 'The color of the text. Only applicable, when the layout style Text is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'black' => __( 'Black', 'woocommerce-paypal-commerce-gateway' ), + 'white' => __( 'White', 'woocommerce-paypal-commerce-gateway' ), + 'monochrome' => __( 'Monochrome', 'woocommerce-paypal-commerce-gateway' ), + 'grayscale' => __( 'Grayscale', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_product_flex_color' => array( + 'title' => __( 'Credit Messaging color', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'blue', + 'desc_tip' => true, + 'description' => __( + 'The color of the text. Only applicable, when the layout style Flex is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'blue' => __( 'Blue', 'woocommerce-paypal-commerce-gateway' ), + 'black' => __( 'Black', 'woocommerce-paypal-commerce-gateway' ), + 'white' => __( 'White', 'woocommerce-paypal-commerce-gateway' ), + 'white-no-border' => __( 'White no border', 'woocommerce-paypal-commerce-gateway' ), + 'gray' => __( 'Gray', 'woocommerce-paypal-commerce-gateway' ), + 'monochrome' => __( 'Monochrome', 'woocommerce-paypal-commerce-gateway' ), + 'grayscale' => __( 'Grayscale', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_product_flex_ratio' => array( + 'title' => __( 'Credit Messaging ratio', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => '1x1', + 'desc_tip' => true, + 'description' => __( + 'The color of the text. Only applicable, when the layout style Flex is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + '1x1' => __( '1x1', 'woocommerce-paypal-commerce-gateway' ), + '1x4' => __( '1x4', 'woocommerce-paypal-commerce-gateway' ), + '8x1' => __( '8x1', 'woocommerce-paypal-commerce-gateway' ), + '20x1' => __( '20x1', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), - //Mini cart settings - 'button_mini-cart_heading' => [ - 'heading' => __('Mini Cart', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-heading', - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_mini-cart_enabled' => [ - 'title' => __('Buttons on Mini Cart', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable on Mini Cart', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_mini-cart_layout' => [ - 'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'horizontal', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'vertical' => __('Vertical', 'woocommerce-paypal-commerce-gateway'), - 'horizontal' => __('Horizontal', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_mini-cart_tagline' => [ - 'title' => __('Tagline', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable tagline', 'woocommerce-paypal-commerce-gateway'), - 'default' => false, - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-commerce-gateway' - ), - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_mini-cart_label' => [ - 'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'paypal', - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'paypal' => __('PayPal', 'woocommerce-paypal-commerce-gateway'), - 'checkout' => __('PayPal Checkout', 'woocommerce-paypal-commerce-gateway'), - 'buynow' => __('PayPal Buy Now', 'woocommerce-paypal-commerce-gateway'), - 'pay' => __('Pay with PayPal', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_mini-cart_color' => [ - 'title' => __('Color', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'gold' => __('Gold (Recommended)', 'woocommerce-paypal-commerce-gateway'), - 'blue' => __('Blue', 'woocommerce-paypal-commerce-gateway'), - 'silver' => __('Silver', 'woocommerce-paypal-commerce-gateway'), - 'black' => __('Black', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_mini-cart_shape' => [ - 'title' => __('Shape', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'pill' => __('Pill', 'woocommerce-paypal-commerce-gateway'), - 'rect' => __('Rectangle', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], + // Mini cart settings + 'button_mini-cart_heading' => array( + 'heading' => __( 'Mini Cart', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_enabled' => array( + 'title' => __( 'Buttons on Mini Cart', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'Enable on Mini Cart', 'woocommerce-paypal-commerce-gateway' ), + 'default' => true, + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'horizontal', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-commerce-gateway' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'Enable tagline', 'woocommerce-paypal-commerce-gateway' ), + 'default' => false, + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-commerce-gateway' + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'paypal', + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-commerce-gateway' ), + 'checkout' => __( 'PayPal Checkout', 'woocommerce-paypal-commerce-gateway' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-commerce-gateway' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-commerce-gateway' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-commerce-gateway' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-commerce-gateway' ), + 'black' => __( 'Black', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_mini-cart_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-commerce-gateway' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), - //Cart settings - 'button_cart_heading' => [ - 'heading' => __('Cart', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-heading', - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_cart_enabled' => [ - 'title' => __('Buttons on Cart', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable on Cart', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_cart_layout' => [ - 'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'horizontal', - 'desc_tip' => true, - 'description' => __( - 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'vertical' => __('Vertical', 'woocommerce-paypal-commerce-gateway'), - 'horizontal' => __('Horizontal', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_cart_tagline' => [ - 'title' => __('Tagline', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable tagline', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'desc_tip' => true, - 'description' => __( - 'Add the tagline. This line will only show up, if you select a horizontal layout.', - 'woocommerce-paypal-commerce-gateway' - ), - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_cart_label' => [ - 'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'paypal', - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'paypal' => __('PayPal', 'woocommerce-paypal-commerce-gateway'), - 'checkout' => __('PayPal Checkout', 'woocommerce-paypal-commerce-gateway'), - 'buynow' => __('PayPal Buy Now', 'woocommerce-paypal-commerce-gateway'), - 'pay' => __('Pay with PayPal', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_cart_color' => [ - 'title' => __('Color', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'gold', - 'desc_tip' => true, - 'description' => __( - 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'gold' => __('Gold (Recommended)', 'woocommerce-paypal-commerce-gateway'), - 'blue' => __('Blue', 'woocommerce-paypal-commerce-gateway'), - 'silver' => __('Silver', 'woocommerce-paypal-commerce-gateway'), - 'black' => __('Black', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], - 'button_cart_shape' => [ - 'title' => __('Shape', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'rect', - 'desc_tip' => true, - 'description' => __( - 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'pill' => __('Pill', 'woocommerce-paypal-commerce-gateway'), - 'rect' => __('Rectangle', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - 'gateway' => 'paypal', - ], + // Cart settings + 'button_cart_heading' => array( + 'heading' => __( 'Cart', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_enabled' => array( + 'title' => __( 'Buttons on Cart', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'Enable on Cart', 'woocommerce-paypal-commerce-gateway' ), + 'default' => true, + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_layout' => array( + 'title' => __( 'Button Layout', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'horizontal', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'vertical' => __( 'Vertical', 'woocommerce-paypal-commerce-gateway' ), + 'horizontal' => __( 'Horizontal', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_tagline' => array( + 'title' => __( 'Tagline', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'Enable tagline', 'woocommerce-paypal-commerce-gateway' ), + 'default' => true, + 'desc_tip' => true, + 'description' => __( + 'Add the tagline. This line will only show up, if you select a horizontal layout.', + 'woocommerce-paypal-commerce-gateway' + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_label' => array( + 'title' => __( 'Button Label', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'paypal', + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'paypal' => __( 'PayPal', 'woocommerce-paypal-commerce-gateway' ), + 'checkout' => __( 'PayPal Checkout', 'woocommerce-paypal-commerce-gateway' ), + 'buynow' => __( 'PayPal Buy Now', 'woocommerce-paypal-commerce-gateway' ), + 'pay' => __( 'Pay with PayPal', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_color' => array( + 'title' => __( 'Color', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'gold', + 'desc_tip' => true, + 'description' => __( + 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'gold' => __( 'Gold (Recommended)', 'woocommerce-paypal-commerce-gateway' ), + 'blue' => __( 'Blue', 'woocommerce-paypal-commerce-gateway' ), + 'silver' => __( 'Silver', 'woocommerce-paypal-commerce-gateway' ), + 'black' => __( 'Black', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), + 'button_cart_shape' => array( + 'title' => __( 'Shape', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'rect', + 'desc_tip' => true, + 'description' => __( + 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'pill' => __( 'Pill', 'woocommerce-paypal-commerce-gateway' ), + 'rect' => __( 'Rectangle', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), - 'message_cart_heading' => [ - 'heading' => __('Credit Messaging on Cart', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-heading', - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_cart_enabled' => [ - 'title' => __('Enable message on Single Product', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable on Single Product', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_cart_layout' => [ - 'title' => __('Credit Messaging layout', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'text', - 'desc_tip' => true, - 'description' => __( - 'The layout of the message.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'text' => __('Text', 'woocommerce-paypal-commerce-gateway'), - 'flex' => __('Flex', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_cart_logo' => [ - 'title' => __('Credit Messaging logo', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'primary', - 'desc_tip' => true, - 'description' => __( - 'What logo the text message contains. Only applicable, when the layout style Text is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'primary' => __('Primary', 'woocommerce-paypal-commerce-gateway'), - 'alternative' => __('Alternative', 'woocommerce-paypal-commerce-gateway'), - 'inline' => __('Inline', 'woocommerce-paypal-commerce-gateway'), - 'none' => __('None', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_cart_position' => [ - 'title' => __('Credit Messaging logo position', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'left', - 'desc_tip' => true, - 'description' => __( - 'The position of the logo. Only applicable, when the layout style Text is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'left' => __('Left', 'woocommerce-paypal-commerce-gateway'), - 'right' => __('Right', 'woocommerce-paypal-commerce-gateway'), - 'top' => __('Top', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_cart_color' => [ - 'title' => __('Credit Messaging text color', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'black', - 'desc_tip' => true, - 'description' => __( - 'The color of the text. Only applicable, when the layout style Text is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'black' => __('Black', 'woocommerce-paypal-commerce-gateway'), - 'white' => __('White', 'woocommerce-paypal-commerce-gateway'), - 'monochrome' => __('Monochrome', 'woocommerce-paypal-commerce-gateway'), - 'grayscale' => __('Grayscale', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_cart_flex_color' => [ - 'title' => __('Credit Messaging color', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'blue', - 'desc_tip' => true, - 'description' => __( - 'The color of the text. Only applicable, when the layout style Flex is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'blue' => __('Blue', 'woocommerce-paypal-commerce-gateway'), - 'black' => __('Black', 'woocommerce-paypal-commerce-gateway'), - 'white' => __('White', 'woocommerce-paypal-commerce-gateway'), - 'white-no-border' => __('White no border', 'woocommerce-paypal-commerce-gateway'), - 'gray' => __('Gray', 'woocommerce-paypal-commerce-gateway'), - 'monochrome' => __('Monochrome', 'woocommerce-paypal-commerce-gateway'), - 'grayscale' => __('Grayscale', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], - 'message_cart_flex_ratio' => [ - 'title' => __('Credit Messaging ratio', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => '1x1', - 'desc_tip' => true, - 'description' => __( - 'The color of the text. Only applicable, when the layout style Flex is used.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - '1x1' => __('1x1', 'woocommerce-paypal-commerce-gateway'), - '1x4' => __('1x4', 'woocommerce-paypal-commerce-gateway'), - '8x1' => __('8x1', 'woocommerce-paypal-commerce-gateway'), - '20x1' => __('20x1', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => ['messages'], - 'gateway' => 'paypal', - ], + 'message_cart_heading' => array( + 'heading' => __( 'Credit Messaging on Cart', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_cart_enabled' => array( + 'title' => __( 'Enable message on Single Product', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'checkbox', + 'label' => __( 'Enable on Single Product', 'woocommerce-paypal-commerce-gateway' ), + 'default' => true, + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_cart_layout' => array( + 'title' => __( 'Credit Messaging layout', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'text', + 'desc_tip' => true, + 'description' => __( + 'The layout of the message.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'text' => __( 'Text', 'woocommerce-paypal-commerce-gateway' ), + 'flex' => __( 'Flex', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_cart_logo' => array( + 'title' => __( 'Credit Messaging logo', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'primary', + 'desc_tip' => true, + 'description' => __( + 'What logo the text message contains. Only applicable, when the layout style Text is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'primary' => __( 'Primary', 'woocommerce-paypal-commerce-gateway' ), + 'alternative' => __( 'Alternative', 'woocommerce-paypal-commerce-gateway' ), + 'inline' => __( 'Inline', 'woocommerce-paypal-commerce-gateway' ), + 'none' => __( 'None', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_cart_position' => array( + 'title' => __( 'Credit Messaging logo position', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'left', + 'desc_tip' => true, + 'description' => __( + 'The position of the logo. Only applicable, when the layout style Text is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'left' => __( 'Left', 'woocommerce-paypal-commerce-gateway' ), + 'right' => __( 'Right', 'woocommerce-paypal-commerce-gateway' ), + 'top' => __( 'Top', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_cart_color' => array( + 'title' => __( 'Credit Messaging text color', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'black', + 'desc_tip' => true, + 'description' => __( + 'The color of the text. Only applicable, when the layout style Text is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'black' => __( 'Black', 'woocommerce-paypal-commerce-gateway' ), + 'white' => __( 'White', 'woocommerce-paypal-commerce-gateway' ), + 'monochrome' => __( 'Monochrome', 'woocommerce-paypal-commerce-gateway' ), + 'grayscale' => __( 'Grayscale', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_cart_flex_color' => array( + 'title' => __( 'Credit Messaging color', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => 'blue', + 'desc_tip' => true, + 'description' => __( + 'The color of the text. Only applicable, when the layout style Flex is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'blue' => __( 'Blue', 'woocommerce-paypal-commerce-gateway' ), + 'black' => __( 'Black', 'woocommerce-paypal-commerce-gateway' ), + 'white' => __( 'White', 'woocommerce-paypal-commerce-gateway' ), + 'white-no-border' => __( 'White no border', 'woocommerce-paypal-commerce-gateway' ), + 'gray' => __( 'Gray', 'woocommerce-paypal-commerce-gateway' ), + 'monochrome' => __( 'Monochrome', 'woocommerce-paypal-commerce-gateway' ), + 'grayscale' => __( 'Grayscale', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), + 'message_cart_flex_ratio' => array( + 'title' => __( 'Credit Messaging ratio', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'select', + 'class' => array( 'wc-enhanced-select' ), + 'default' => '1x1', + 'desc_tip' => true, + 'description' => __( + 'The color of the text. Only applicable, when the layout style Flex is used.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + '1x1' => __( '1x1', 'woocommerce-paypal-commerce-gateway' ), + '1x4' => __( '1x4', 'woocommerce-paypal-commerce-gateway' ), + '8x1' => __( '8x1', 'woocommerce-paypal-commerce-gateway' ), + '20x1' => __( '20x1', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + ), - 'disable_cards' => [ - 'title' => __('Disable specific credit cards', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-multiselect', - 'class' => ['wc-enhanced-select'], - 'default' => [], - 'desc_tip' => true, - 'description' => __( - 'By default all possible credit cards will be accepted. You can disable some cards, if you wish.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'visa' => _x('Visa', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'mastercard' => _x('Mastercard', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'amex' => _x('American Express', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'discover' => _x('Discover', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'jcb' => _x('JCB', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'elo' => _x('Elo', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'hiper' => _x('Hiper', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_ONBOARDED, - ], - 'requirements' => [ - 'dcc', - ], - 'gateway' => 'dcc', - ], - 'card_icons' => [ - 'title' => __('Show logo of the following credit cards', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-multiselect', - 'class' => ['wc-enhanced-select'], - 'default' => [], - 'desc_tip' => true, - 'description' => __( - 'Define, which cards you want to display in your checkout..', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'visa' => _x('Visa', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'mastercard' => _x('Mastercard', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'amex' => _x('American Express', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'discover' => _x('Discover', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'jcb' => _x('JCB', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'elo' => _x('Elo', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - 'hiper' => _x('Hiper', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_ONBOARDED, - ], - 'requirements' => [ - 'dcc', - ], - 'gateway' => 'dcc', - ], - ]; - if (! defined('PPCP_FLAG_SUBSCRIPTION') || ! PPCP_FLAG_SUBSCRIPTION) { - unset($fields['vault_enabled']); - } - return $fields; - }, + 'disable_cards' => array( + 'title' => __( 'Disable specific credit cards', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-multiselect', + 'class' => array( 'wc-enhanced-select' ), + 'default' => array(), + 'desc_tip' => true, + 'description' => __( + 'By default all possible credit cards will be accepted. You can disable some cards, if you wish.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'visa' => _x( 'Visa', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'mastercard' => _x( 'Mastercard', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'amex' => _x( 'American Express', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'discover' => _x( 'Discover', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'jcb' => _x( 'JCB', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'elo' => _x( 'Elo', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'hiper' => _x( 'Hiper', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array( + 'dcc', + ), + 'gateway' => 'dcc', + ), + 'card_icons' => array( + 'title' => __( 'Show logo of the following credit cards', 'woocommerce-paypal-commerce-gateway' ), + 'type' => 'ppcp-multiselect', + 'class' => array( 'wc-enhanced-select' ), + 'default' => array(), + 'desc_tip' => true, + 'description' => __( + 'Define, which cards you want to display in your checkout..', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => array( + 'visa' => _x( 'Visa', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'mastercard' => _x( 'Mastercard', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'amex' => _x( 'American Express', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'discover' => _x( 'Discover', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'jcb' => _x( 'JCB', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'elo' => _x( 'Elo', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + 'hiper' => _x( 'Hiper', 'Name of credit card', 'woocommerce-paypal-commerce-gateway' ), + ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array( + 'dcc', + ), + 'gateway' => 'dcc', + ), + ); + if ( ! defined( 'PPCP_FLAG_SUBSCRIPTION' ) || ! PPCP_FLAG_SUBSCRIPTION ) { + unset( $fields['vault_enabled'] ); + } + return $fields; + }, - 'wcgateway.checkout.address-preset' => static function(ContainerInterface $container): CheckoutPayPalAddressPreset { + 'wcgateway.checkout.address-preset' => static function( ContainerInterface $container ): CheckoutPayPalAddressPreset { - return new CheckoutPayPalAddressPreset( - $container->get('session.handler') - ); - }, - 'wcgateway.url' => static function (ContainerInterface $container): string { - return plugins_url( - '/modules.local/ppcp-wc-gateway/', - dirname(__FILE__, 3) . '/woocommerce-paypal-commerce-gateway.php' - ); - }, - 'wcgateway.endpoint.return-url' => static function (ContainerInterface $container) : ReturnUrlEndpoint { - $gateway = $container->get('wcgateway.paypal-gateway'); - $endpoint = $container->get('api.endpoint.order'); - $prefix = $container->get('api.prefix'); - return new ReturnUrlEndpoint( - $gateway, - $endpoint, - $prefix - ); - }, -]; + return new CheckoutPayPalAddressPreset( + $container->get( 'session.handler' ) + ); + }, + 'wcgateway.url' => static function ( ContainerInterface $container ): string { + return plugins_url( + '/modules.local/ppcp-wc-gateway/', + dirname( __FILE__, 3 ) . '/woocommerce-paypal-commerce-gateway.php' + ); + }, + 'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ) : ReturnUrlEndpoint { + $gateway = $container->get( 'wcgateway.paypal-gateway' ); + $endpoint = $container->get( 'api.endpoint.order' ); + $prefix = $container->get( 'api.prefix' ); + return new ReturnUrlEndpoint( + $gateway, + $endpoint, + $prefix + ); + }, +); diff --git a/modules.local/ppcp-wc-gateway/src/Admin/OrderTablePaymentStatusColumn.php b/modules.local/ppcp-wc-gateway/src/Admin/OrderTablePaymentStatusColumn.php deleted file mode 100644 index 5ac7e0123..000000000 --- a/modules.local/ppcp-wc-gateway/src/Admin/OrderTablePaymentStatusColumn.php +++ /dev/null @@ -1,87 +0,0 @@ -settings = $settings; - } - - public function register( array $columns ): array { - if ( ! $this->settings->has( 'intent' ) || $this->settings->get( 'intent' ) !== self::INTENT ) { - return $columns; - } - - $statusColumnPosition = array_search( self::AFTER_COLUMN_KEY, array_keys( $columns ), true ); - $toInsertPosition = false === $statusColumnPosition ? count( $columns ) : $statusColumnPosition + 1; - - $columns = array_merge( - array_slice( $columns, 0, $toInsertPosition ), - array( - self::COLUMN_KEY => __( 'Payment Captured', 'woocommerce-paypal-commerce-gateway' ), - ), - array_slice( $columns, $toInsertPosition ) - ); - - return $columns; - } - - public function render( string $column, int $wcOrderId ) { - if ( ! $this->settings->has( 'intent' ) || $this->settings->get( 'intent' ) !== self::INTENT ) { - return; - } - - if ( self::COLUMN_KEY !== $column ) { - return; - } - - $wcOrder = wc_get_order( $wcOrderId ); - - if ( ! is_a( $wcOrder, \WC_Order::class ) || ! $this->renderForOrder( $wcOrder ) ) { - return; - } - - if ( $this->isCaptured( $wcOrder ) ) { - $this->renderCompletedStatus(); - return; - } - - $this->renderIncompletedStatus(); - } - - private function renderForOrder( \WC_Order $order ): bool { - return ! empty( $order->get_meta( PayPalGateway::CAPTURED_META_KEY ) ); - } - - private function isCaptured( \WC_Order $wcOrder ): bool { - $captured = $wcOrder->get_meta( PayPalGateway::CAPTURED_META_KEY ); - return wc_string_to_bool( $captured ); - } - - private function renderCompletedStatus() { - printf( - ' - %s - ', - esc_html__( 'Payment captured', 'woocommerce-paypal-commerce-gateway' ) - ); - } - - private function renderIncompletedStatus() { - printf( - '%s', - esc_html__( 'Not captured', 'woocommerce-paypal-commerce-gateway' ) - ); - } -} diff --git a/modules.local/ppcp-wc-gateway/src/Admin/class-ordertablepaymentstatuscolumn.php b/modules.local/ppcp-wc-gateway/src/Admin/class-ordertablepaymentstatuscolumn.php new file mode 100644 index 000000000..be1a14baa --- /dev/null +++ b/modules.local/ppcp-wc-gateway/src/Admin/class-ordertablepaymentstatuscolumn.php @@ -0,0 +1,140 @@ +settings = $settings; + } + + /** + * Register the columns. + * + * @param array $columns The existing columns. + * + * @return array + */ + public function register( array $columns ): array { + if ( ! $this->settings->has( 'intent' ) || $this->settings->get( 'intent' ) !== self::INTENT ) { + return $columns; + } + + $status_column_position = array_search( self::AFTER_COLUMN_KEY, array_keys( $columns ), true ); + $to_insert_position = false === $status_column_position ? count( $columns ) : $status_column_position + 1; + + $columns = array_merge( + array_slice( $columns, 0, $to_insert_position ), + array( + self::COLUMN_KEY => __( 'Payment Captured', 'woocommerce-paypal-commerce-gateway' ), + ), + array_slice( $columns, $to_insert_position ) + ); + + return $columns; + } + + /** + * Render the column. + * + * @param string $column The column. + * @param int $wc_order_id The id or the Woocommerce order. + */ + public function render( string $column, int $wc_order_id ) { + if ( ! $this->settings->has( 'intent' ) || $this->settings->get( 'intent' ) !== self::INTENT ) { + return; + } + + if ( self::COLUMN_KEY !== $column ) { + return; + } + + $wc_order = wc_get_order( $wc_order_id ); + + if ( ! is_a( $wc_order, \WC_Order::class ) || ! $this->render_for_order( $wc_order ) ) { + return; + } + + if ( $this->is_captured( $wc_order ) ) { + $this->render_completed_status(); + return; + } + + $this->render_incomplete_status(); + } + + /** + * Whether to render the authorization status of an order or not. + * + * @param \WC_Order $order The Woocommerce order. + * + * @return bool + */ + private function render_for_order( \WC_Order $order ): bool { + return ! empty( $order->get_meta( PayPalGateway::CAPTURED_META_KEY ) ); + } + + /** + * Whether the order has been captured or not. + * + * @param \WC_Order $wc_order The Woocommerce order. + * + * @return bool + */ + private function is_captured( \WC_Order $wc_order ): bool { + $captured = $wc_order->get_meta( PayPalGateway::CAPTURED_META_KEY ); + return wc_string_to_bool( $captured ); + } + + /** + * Renders the captured status. + */ + private function render_completed_status() { + printf( + ' + %s + ', + esc_html__( 'Payment captured', 'woocommerce-paypal-commerce-gateway' ) + ); + } + + /** + * Renders the "not captured" status. + */ + private function render_incomplete_status() { + printf( + '%s', + esc_html__( 'Not captured', 'woocommerce-paypal-commerce-gateway' ) + ); + } +} diff --git a/modules.local/ppcp-wc-gateway/src/Admin/PaymentStatusOrderDetail.php b/modules.local/ppcp-wc-gateway/src/Admin/class-paymentstatusorderdetail.php similarity index 60% rename from modules.local/ppcp-wc-gateway/src/Admin/PaymentStatusOrderDetail.php rename to modules.local/ppcp-wc-gateway/src/Admin/class-paymentstatusorderdetail.php index 050ef37ec..de7f59b7f 100644 --- a/modules.local/ppcp-wc-gateway/src/Admin/PaymentStatusOrderDetail.php +++ b/modules.local/ppcp-wc-gateway/src/Admin/class-paymentstatusorderdetail.php @@ -1,4 +1,9 @@ get_meta( PayPalGateway::INTENT_META_KEY ); - $captured = $wcOrder->get_meta( PayPalGateway::CAPTURED_META_KEY ); + /** + * Renders the not captured information. + * + * @param int $wc_order_id The Woocommerce order id. + */ + public function render( int $wc_order_id ) { + $wc_order = new \WC_Order( $wc_order_id ); + $intent = $wc_order->get_meta( PayPalGateway::INTENT_META_KEY ); + $captured = $wc_order->get_meta( PayPalGateway::CAPTURED_META_KEY ); if ( strcasecmp( $intent, 'AUTHORIZE' ) !== 0 ) { return; @@ -31,7 +44,7 @@ class PaymentStatusOrderDetail { esc_html__( 'To capture the payment select capture action from the list below.', 'woocommerce-paypal-commerce-gateway' - ), + ) ); } } diff --git a/modules.local/ppcp-wc-gateway/src/Checkout/CheckoutPayPalAddressPreset.php b/modules.local/ppcp-wc-gateway/src/Checkout/CheckoutPayPalAddressPreset.php deleted file mode 100644 index e9613b2db..000000000 --- a/modules.local/ppcp-wc-gateway/src/Checkout/CheckoutPayPalAddressPreset.php +++ /dev/null @@ -1,124 +0,0 @@ -sessionHandler = $sessionHandler; - } - - /** - * @wp-hook woocommerce_checkout_get_value - * @param string|null - * @param string $fieldId - * - * @return string|null - */ - public function filterCheckoutFiled( $defaultValue, $fieldId ): ?string { - if ( ! is_string( $defaultValue ) ) { - $defaultValue = null; - } - - if ( ! is_string( $fieldId ) ) { - return $defaultValue; - } - - return $this->readPresetForField( $fieldId ) ?? $defaultValue; - } - - private function readPresetForField( string $fieldId ): ?string { - $order = $this->sessionHandler->order(); - if ( ! $order ) { - return null; - } - - $shipping = $this->readShippingFromOrder(); - $payer = $order->payer(); - - $addressMap = array( - 'billing_address_1' => 'addressLine1', - 'billing_address_2' => 'addressLine2', - 'billing_postcode' => 'postalCode', - 'billing_country' => 'countryCode', - 'billing_city' => 'adminArea2', - 'billing_state' => 'adminArea1', - ); - $payerNameMap = array( - 'billing_last_name' => 'surname', - 'billing_first_name' => 'givenName', - ); - $payerMap = array( - 'billing_email' => 'emailAddress', - ); - $payerPhoneMap = array( - 'billing_phone' => 'nationalNumber', - ); - - if ( array_key_exists( $fieldId, $addressMap ) && $shipping ) { - return $shipping->address()->{$addressMap[ $fieldId ]}() ?: null; - } - - if ( array_key_exists( $fieldId, $payerNameMap ) && $payer ) { - return $payer->name()->{$payerNameMap[ $fieldId ]}() ?: null; - } - - if ( array_key_exists( $fieldId, $payerMap ) && $payer ) { - return $payer->{$payerMap[ $fieldId ]}() ?: null; - } - - if ( - array_key_exists( $fieldId, $payerPhoneMap ) - && $payer - && $payer->phone() - && $payer->phone()->phone() - ) { - return $payer->phone()->phone()->{$payerPhoneMap[ $fieldId ]}() ?: null; - } - - return null; - } - - private function readShippingFromOrder(): ?Shipping { - $order = $this->sessionHandler->order(); - if ( ! $order ) { - return null; - } - - if ( array_key_exists( $order->id(), $this->shippingCache ) ) { - return $this->shippingCache[ $order->id() ]; - } - - $shipping = null; - foreach ( $this->sessionHandler->order()->purchaseUnits() as $unit ) { - $shipping = $unit->shipping(); - if ( $shipping ) { - break; - } - } - - $this->shippingCache[ $order->id() ] = $shipping; - - return $shipping; - } -} diff --git a/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php b/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php deleted file mode 100644 index 9ff238d54..000000000 --- a/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php +++ /dev/null @@ -1,67 +0,0 @@ -sessionHandler = $sessionHandler; - $this->settings = $settings; - } - - public function handler( array $methods ): array { - if ( ! isset( $methods[ PayPalGateway::ID ] ) && ! isset( $methods[ CreditCardGateway::ID ] ) ) { - return $methods; - } - if ( - ! $this->settings->has( 'merchant_email' ) - || ! is_email( $this->settings->get( 'merchant_email' ) ) - ) { - unset( $methods[ PayPalGateway::ID ] ); - unset( $methods[ CreditCardGateway::ID ] ); - return $methods; - } - - if ( ! $this->settings->has( 'client_id' ) || empty( $this->settings->get( 'client_id' ) ) ) { - unset( $methods[ CreditCardGateway::ID ] ); - } - - if ( ! $this->needsToDisableGateways() ) { - return $methods; - } - - if ( $this->isCreditCard() ) { - return array( CreditCardGateway::ID => $methods[ CreditCardGateway::ID ] ); - } - return array( PayPalGateway::ID => $methods[ PayPalGateway::ID ] ); - } - - private function needsToDisableGateways(): bool { - return $this->sessionHandler->order() !== null; - } - - private function isCreditCard(): bool { - $order = $this->sessionHandler->order(); - if ( ! $order ) { - return false; - } - if ( ! $order->paymentSource() || ! $order->paymentSource()->card() ) { - return false; - } - return true; - } -} diff --git a/modules.local/ppcp-wc-gateway/src/Checkout/class-checkoutpaypaladdresspreset.php b/modules.local/ppcp-wc-gateway/src/Checkout/class-checkoutpaypaladdresspreset.php new file mode 100644 index 000000000..c8b350ea9 --- /dev/null +++ b/modules.local/ppcp-wc-gateway/src/Checkout/class-checkoutpaypaladdresspreset.php @@ -0,0 +1,152 @@ +session_handler = $session_handler; + } + + /** + * Filters the checkout fields to replace values if necessary. + * + * @wp-hook woocommerce_checkout_get_value + * + * @param string|null $default_value The default value. + * @param string $field_id The field ID. + * + * @return string|null + */ + public function filter_checkout_field( $default_value, $field_id ): ?string { + if ( ! is_string( $default_value ) ) { + $default_value = null; + } + + if ( ! is_string( $field_id ) ) { + return $default_value; + } + + return $this->read_preset_for_field( $field_id ) ?? $default_value; + } + + /** + * Returns the value for a checkout field from an PayPal order if given. + * + * @param string $field_id The ID of the field. + * + * @return string|null + */ + private function read_preset_for_field( string $field_id ): ?string { + $order = $this->session_handler->order(); + if ( ! $order ) { + return null; + } + + $shipping = $this->read_shipping_from_order(); + $payer = $order->payer(); + + $address_map = array( + 'billing_address_1' => 'addressLine1', + 'billing_address_2' => 'addressLine2', + 'billing_postcode' => 'postalCode', + 'billing_country' => 'countryCode', + 'billing_city' => 'adminArea2', + 'billing_state' => 'adminArea1', + ); + $payer_name_map = array( + 'billing_last_name' => 'surname', + 'billing_first_name' => 'givenName', + ); + $payer_map = array( + 'billing_email' => 'emailAddress', + ); + $payer_phone_map = array( + 'billing_phone' => 'nationalNumber', + ); + + if ( array_key_exists( $field_id, $address_map ) && $shipping ) { + return $shipping->address()->{$address_map[ $field_id ]}() ? $shipping->address()->{$address_map[ $field_id ]}() : null; + } + + if ( array_key_exists( $field_id, $payer_name_map ) && $payer ) { + return $payer->name()->{$payer_name_map[ $field_id ]}() ? $payer->name()->{$payer_name_map[ $field_id ]}() : null; + } + + if ( array_key_exists( $field_id, $payer_map ) && $payer ) { + return $payer->{$payer_map[ $field_id ]}() ? $payer->{$payer_map[ $field_id ]}() : null; + } + + if ( + array_key_exists( $field_id, $payer_phone_map ) + && $payer + && $payer->phone() + && $payer->phone()->phone() + ) { + return $payer->phone()->phone()->{$payer_phone_map[ $field_id ]}() ? $payer->phone()->phone()->{$payer_phone_map[ $field_id ]}() : null; + } + + return null; + } + + /** + * Returns the Shipping object for an order, if given. + * + * @return Shipping|null + */ + private function read_shipping_from_order(): ?Shipping { + $order = $this->session_handler->order(); + if ( ! $order ) { + return null; + } + + if ( array_key_exists( $order->id(), $this->shipping_cache ) ) { + return $this->shipping_cache[ $order->id() ]; + } + + $shipping = null; + foreach ( $this->session_handler->order()->purchaseUnits() as $unit ) { + $shipping = $unit->shipping(); + if ( $shipping ) { + break; + } + } + + $this->shipping_cache[ $order->id() ] = $shipping; + + return $shipping; + } +} diff --git a/modules.local/ppcp-wc-gateway/src/Checkout/class-disablegateways.php b/modules.local/ppcp-wc-gateway/src/Checkout/class-disablegateways.php new file mode 100644 index 000000000..9812d15c7 --- /dev/null +++ b/modules.local/ppcp-wc-gateway/src/Checkout/class-disablegateways.php @@ -0,0 +1,112 @@ +session_handler = $session_handler; + $this->settings = $settings; + } + + /** + * Controls the logic for enabling/disabling gateways. + * + * @param array $methods The Gateways. + * + * @return array + */ + public function handler( array $methods ): array { + if ( ! isset( $methods[ PayPalGateway::ID ] ) && ! isset( $methods[ CreditCardGateway::ID ] ) ) { + return $methods; + } + if ( + ! $this->settings->has( 'merchant_email' ) + || ! is_email( $this->settings->get( 'merchant_email' ) ) + ) { + unset( $methods[ PayPalGateway::ID ] ); + unset( $methods[ CreditCardGateway::ID ] ); + return $methods; + } + + if ( ! $this->settings->has( 'client_id' ) || empty( $this->settings->get( 'client_id' ) ) ) { + unset( $methods[ CreditCardGateway::ID ] ); + } + + if ( ! $this->needs_to_disable_gateways() ) { + return $methods; + } + + if ( $this->is_credit_card() ) { + return array( CreditCardGateway::ID => $methods[ CreditCardGateway::ID ] ); + } + return array( PayPalGateway::ID => $methods[ PayPalGateway::ID ] ); + } + + /** + * Whether the Gateways need to be disabled. When we come to the checkout with a running PayPal + * session, we need to disable the other Gateways, so the customer can smoothly sail through the + * process. + * + * @return bool + */ + private function needs_to_disable_gateways(): bool { + return $this->session_handler->order() !== null; + } + + /** + * Whether the current PayPal session is done via DCC payment. + * + * @return bool + */ + private function is_credit_card(): bool { + $order = $this->session_handler->order(); + if ( ! $order ) { + return false; + } + if ( ! $order->paymentSource() || ! $order->paymentSource()->card() ) { + return false; + } + return true; + } +} diff --git a/modules.local/ppcp-wc-gateway/src/Endpoint/ReturnUrlEndpoint.php b/modules.local/ppcp-wc-gateway/src/Endpoint/ReturnUrlEndpoint.php deleted file mode 100644 index 8f105d4a8..000000000 --- a/modules.local/ppcp-wc-gateway/src/Endpoint/ReturnUrlEndpoint.php +++ /dev/null @@ -1,52 +0,0 @@ -gateway = $gateway; - $this->orderEndpoint = $orderEndpoint; - $this->prefix = $prefix; - } - - public function handleRequest() { - - if ( ! isset( $_GET['token'] ) ) { - exit; - } - $token = sanitize_text_field( wp_unslash( $_GET['token'] ) ); - $order = $this->orderEndpoint->order( $token ); - if ( ! $order ) { - exit; - } - - $wcOrderId = $this->sanitize_custom_id( $order->purchaseUnits()[0]->customId() ); - if ( ! $wcOrderId ) { - exit; - } - - $wcOrder = wc_get_order( $wcOrderId ); - if ( ! $wcOrder ) { - exit; - } - - $success = $this->gateway->process_payment( $wcOrderId ); - if ( isset( $success['result'] ) && $success['result'] === 'success' ) { - wp_redirect( $success['redirect'] ); - exit; - } - wp_redirect( wc_get_checkout_url() ); - exit; - } -} diff --git a/modules.local/ppcp-wc-gateway/src/Endpoint/class-returnurlendpoint.php b/modules.local/ppcp-wc-gateway/src/Endpoint/class-returnurlendpoint.php new file mode 100644 index 000000000..9114eb539 --- /dev/null +++ b/modules.local/ppcp-wc-gateway/src/Endpoint/class-returnurlendpoint.php @@ -0,0 +1,86 @@ +gateway = $gateway; + $this->order_endpoint = $order_endpoint; + $this->prefix = $prefix; + } + + /** + * Handles the incoming request. + */ + public function handle_request() { + + // phpcs:disable WordPress.Security.NonceVerification.Recommended + if ( ! isset( $_GET['token'] ) ) { + exit(); + } + + $token = sanitize_text_field( wp_unslash( $_GET['token'] ) ); + // phpcs:enable WordPress.Security.NonceVerification.Recommended + $order = $this->order_endpoint->order( $token ); + if ( ! $order ) { + exit(); + } + + $wc_order_id = $this->sanitize_custom_id( $order->purchaseUnits()[0]->customId() ); + if ( ! $wc_order_id ) { + exit(); + } + + $wc_order = wc_get_order( $wc_order_id ); + if ( ! $wc_order ) { + exit(); + } + + $success = $this->gateway->process_payment( $wc_order_id ); + if ( isset( $success['result'] ) && 'success' === $success['result'] ) { + wp_safe_redirect( $success['redirect'] ); + exit(); + } + wp_safe_redirect( wc_get_checkout_url() ); + exit(); + } +} diff --git a/modules.local/ppcp-wc-gateway/src/Exception/NotFoundException.php b/modules.local/ppcp-wc-gateway/src/Exception/class-notfoundexception.php similarity index 60% rename from modules.local/ppcp-wc-gateway/src/Exception/NotFoundException.php rename to modules.local/ppcp-wc-gateway/src/Exception/class-notfoundexception.php index 886dfd03c..9ff4de6e7 100644 --- a/modules.local/ppcp-wc-gateway/src/Exception/NotFoundException.php +++ b/modules.local/ppcp-wc-gateway/src/Exception/class-notfoundexception.php @@ -1,4 +1,9 @@ id = self::ID; - $this->orderProcessor = $orderProcessor; - $this->authorizedPayments = $authorizedPayments; - $this->notice = $notice; - $this->settingsRenderer = $settingsRenderer; - $this->config = $config; - $this->sessionHandler = $sessionHandler; + $this->id = self::ID; + $this->order_processor = $order_processor; + $this->authorized_payments = $authorized_payments_processor; + $this->notice = $notice; + $this->settings_renderer = $settings_renderer; + $this->config = $config; + $this->session_handler = $session_handler; if ( defined( 'PPCP_FLAG_SUBSCRIPTION' ) && PPCP_FLAG_SUBSCRIPTION @@ -82,9 +103,12 @@ class CreditCardGateway extends PayPalGateway { ) ); - $this->moduleUrl = $moduleUrl; + $this->module_url = $module_url; } + /** + * Initialize the form fields. + */ public function init_form_fields() { $this->form_fields = array( 'enabled' => array( @@ -99,15 +123,25 @@ class CreditCardGateway extends PayPalGateway { ); } + /** + * Renders the settings. + * + * @return string + */ public function generate_ppcp_html(): string { ob_start(); - $this->settingsRenderer->render( true ); + $this->settings_renderer->render( true ); $content = ob_get_contents(); ob_end_clean(); return $content; } + /** + * Returns the title of the gateway. + * + * @return string + */ public function get_title() { if ( is_admin() ) { @@ -119,12 +153,12 @@ class CreditCardGateway extends PayPalGateway { return $title; } - $titleOptions = $this->cardLabels(); - $images = array_map( - function ( string $type ) use ( $titleOptions ): string { + $title_options = $this->card_labels(); + $images = array_map( + function ( string $type ) use ( $title_options ): string { return ' '; }, @@ -133,7 +167,12 @@ class CreditCardGateway extends PayPalGateway { return $title . implode( '', $images ); } - private function cardLabels(): array { + /** + * Returns an array of credit card names. + * + * @return array + */ + private function card_labels(): array { return array( 'visa' => _x( 'Visa', diff --git a/modules.local/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules.local/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php similarity index 52% rename from modules.local/ppcp-wc-gateway/src/Gateway/PayPalGateway.php rename to modules.local/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php index 24df0b164..b7dd49dc1 100644 --- a/modules.local/ppcp-wc-gateway/src/Gateway/PayPalGateway.php +++ b/modules.local/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php @@ -1,59 +1,100 @@ id = self::ID; - $this->orderProcessor = $orderProcessor; - $this->authorizedPayments = $authorizedPayments; - $this->notice = $notice; - $this->settingsRenderer = $settingsRenderer; - $this->config = $config; - $this->sessionHandler = $sessionHandler; + $this->id = self::ID; + $this->order_processor = $order_processor; + $this->authorized_payments = $authorized_payments_processor; + $this->notice = $notice; + $this->settings_renderer = $settings_renderer; + $this->config = $config; + $this->session_handler = $session_handler; if ( defined( 'PPCP_FLAG_SUBSCRIPTION' ) && PPCP_FLAG_SUBSCRIPTION @@ -97,11 +138,19 @@ class PayPalGateway extends \WC_Payment_Gateway { ); } + /** + * Whether the Gateway needs to be setup. + * + * @return bool + */ public function needs_setup(): bool { return true; } + /** + * Initializes the form fields. + */ public function init_form_fields() { $this->form_fields = array( 'enabled' => array( @@ -116,10 +165,17 @@ class PayPalGateway extends \WC_Payment_Gateway { ); } - public function process_payment( $orderId ): ?array { + /** + * Process a payment for an Woocommerce order. + * + * @param int $order_id The Woocommerce order id. + * + * @return array|null + */ + public function process_payment( $order_id ): ?array { global $woocommerce; - $wcOrder = wc_get_order( $orderId ); - if ( ! is_a( $wcOrder, \WC_Order::class ) ) { + $wc_order = wc_get_order( $order_id ); + if ( ! is_a( $wc_order, \WC_Order::class ) ) { return null; } @@ -127,26 +183,26 @@ class PayPalGateway extends \WC_Payment_Gateway { * If the WC_Order is payed through the approved webhook. */ //phpcs:disable WordPress.Security.NonceVerification.Recommended - if ( isset( $_REQUEST['ppcp-resume-order'] ) && $wcOrder->has_status( 'processing' ) ) { + if ( isset( $_REQUEST['ppcp-resume-order'] ) && $wc_order->has_status( 'processing' ) ) { return array( 'result' => 'success', - 'redirect' => $this->get_return_url( $wcOrder ), + 'redirect' => $this->get_return_url( $wc_order ), ); } //phpcs:enable WordPress.Security.NonceVerification.Recommended try { - if ( $this->orderProcessor->process( $wcOrder, $woocommerce ) ) { + if ( $this->order_processor->process( $wc_order, $woocommerce ) ) { return array( 'result' => 'success', - 'redirect' => $this->get_return_url( $wcOrder ), + 'redirect' => $this->get_return_url( $wc_order ), ); } } catch ( PayPalApiException $error ) { if ( $error->hasDetail( 'INSTRUMENT_DECLINED' ) ) { $host = $this->config->has( 'sandbox_on' ) && $this->config->get( 'sandbox_on' ) ? 'https://www.sandbox.paypal.com/' : 'https://www.paypal.com/'; - $url = $host . 'checkoutnow?token=' . $this->sessionHandler->order()->id(); + $url = $host . 'checkoutnow?token=' . $this->session_handler->order()->id(); return array( 'result' => 'success', @@ -154,7 +210,7 @@ class PayPalGateway extends \WC_Payment_Gateway { ); } - $this->sessionHandler->destroySessionData(); + $this->session_handler->destroySessionData(); wc_add_notice( __( 'Something went wrong. Please try again.', @@ -167,54 +223,71 @@ class PayPalGateway extends \WC_Payment_Gateway { return null; } - public function captureAuthorizedPayment( \WC_Order $wcOrder ): bool { - $isProcessed = $this->authorizedPayments->process( $wcOrder ); - $this->renderAuthorizationMessageForStatus( $this->authorizedPayments->lastStatus() ); + /** + * Captures an authorized payment for an Woocommerce order. + * + * @param \WC_Order $wc_order The Woocommerce order. + * + * @return bool + */ + public function capture_authorized_payment( \WC_Order $wc_order ): bool { + $is_processed = $this->authorized_payments->process( $wc_order ); + $this->render_authorization_message_for_status( $this->authorized_payments->last_status() ); - if ( $isProcessed ) { - $wcOrder->add_order_note( + if ( $is_processed ) { + $wc_order->add_order_note( __( 'Payment successfully captured.', 'woocommerce-paypal-commerce-gateway' ) ); - $wcOrder->set_status( 'processing' ); - $wcOrder->update_meta_data( self::CAPTURED_META_KEY, 'true' ); - $wcOrder->save(); + $wc_order->set_status( 'processing' ); + $wc_order->update_meta_data( self::CAPTURED_META_KEY, 'true' ); + $wc_order->save(); return true; } - if ( $this->authorizedPayments->lastStatus() === AuthorizedPaymentsProcessor::ALREADY_CAPTURED ) { - if ( $wcOrder->get_status() === 'on-hold' ) { - $wcOrder->add_order_note( + if ( $this->authorized_payments->last_status() === AuthorizedPaymentsProcessor::ALREADY_CAPTURED ) { + if ( $wc_order->get_status() === 'on-hold' ) { + $wc_order->add_order_note( __( 'Payment successfully captured.', 'woocommerce-paypal-commerce-gateway' ) ); - $wcOrder->set_status( 'processing' ); + $wc_order->set_status( 'processing' ); } - $wcOrder->update_meta_data( self::CAPTURED_META_KEY, 'true' ); - $wcOrder->save(); + $wc_order->update_meta_data( self::CAPTURED_META_KEY, 'true' ); + $wc_order->save(); return true; } return false; } - private function renderAuthorizationMessageForStatus( string $status ) { + /** + * Displays the notice for a status. + * + * @param string $status The status. + */ + private function render_authorization_message_for_status( string $status ) { - $messageMapping = array( + $message_mapping = array( AuthorizedPaymentsProcessor::SUCCESSFUL => AuthorizeOrderActionNotice::SUCCESS, AuthorizedPaymentsProcessor::ALREADY_CAPTURED => AuthorizeOrderActionNotice::ALREADY_CAPTURED, AuthorizedPaymentsProcessor::INACCESSIBLE => AuthorizeOrderActionNotice::NO_INFO, AuthorizedPaymentsProcessor::NOT_FOUND => AuthorizeOrderActionNotice::NOT_FOUND, ); - $displayMessage = ( isset( $messageMapping[ $status ] ) ) ? - $messageMapping[ $status ] + $display_message = ( isset( $message_mapping[ $status ] ) ) ? + $message_mapping[ $status ] : AuthorizeOrderActionNotice::FAILED; - $this->notice->displayMessage( $displayMessage ); + $this->notice->display_message( $display_message ); } + /** + * Renders the settings. + * + * @return string + */ public function generate_ppcp_html(): string { ob_start(); - $this->settingsRenderer->render( false ); + $this->settings_renderer->render( false ); $content = ob_get_contents(); ob_end_clean(); return $content; diff --git a/modules.local/ppcp-wc-gateway/src/Gateway/class-wcgatewayinterface.php b/modules.local/ppcp-wc-gateway/src/Gateway/class-wcgatewayinterface.php new file mode 100644 index 000000000..d4b1e946c --- /dev/null +++ b/modules.local/ppcp-wc-gateway/src/Gateway/class-wcgatewayinterface.php @@ -0,0 +1,18 @@ +currentMessage(); + $message = $this->current_message(); if ( ! $message ) { return null; } @@ -26,7 +39,12 @@ class AuthorizeOrderActionNotice { return new Message( $message['message'], $message['type'] ); } - private function currentMessage(): array { + /** + * Returns the current message. + * + * @return array + */ + private function current_message(): array { $messages[ self::NO_INFO ] = array( 'message' => __( 'Could not retrieve information. Try again later.', @@ -67,18 +85,23 @@ class AuthorizeOrderActionNotice { if ( ! isset( $_GET[ self::QUERY_PARAM ] ) ) { // Input ok. return array(); } - $messageId = absint( $_GET[ self::QUERY_PARAM ] ); // Input ok. + $message_id = absint( $_GET[ self::QUERY_PARAM ] ); // Input ok. //phpcs:enable WordPress.Security.NonceVerification.Recommended - return ( isset( $messages[ $messageId ] ) ) ? $messages[ $messageId ] : array(); + return ( isset( $messages[ $message_id ] ) ) ? $messages[ $message_id ] : array(); } - public function displayMessage( int $messageCode ): void { + /** + * Adds the query parameter for the message to 'redirect_post_location'. + * + * @param int $message_code The message code. + */ + public function display_message( int $message_code ): void { add_filter( 'redirect_post_location', - static function ( $location ) use ( $messageCode ) { + static function ( $location ) use ( $message_code ) { return add_query_arg( self::QUERY_PARAM, - $messageCode, + $message_code, $location ); } diff --git a/modules.local/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php b/modules.local/ppcp-wc-gateway/src/Notice/class-connectadminnotice.php similarity index 54% rename from modules.local/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php rename to modules.local/ppcp-wc-gateway/src/Notice/class-connectadminnotice.php index 5a565ed09..3b9dca118 100644 --- a/modules.local/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php +++ b/modules.local/ppcp-wc-gateway/src/Notice/class-connectadminnotice.php @@ -1,4 +1,9 @@ state = $state; $this->settings = $settings; } - public function connectMessage(): ?Message { - if ( ! $this->shouldDisplay() ) { + /** + * Returns the message. + * + * @return Message|null + */ + public function connect_message(): ?Message { + if ( ! $this->should_display() ) { return null; } $message = sprintf( - /* translators: %1$s the gateway name */ + /* translators: %1$s the gateway name. */ __( 'PayPal Payments is almost ready. To get started, connect your account.', 'woocommerce-paypal-commerce-gateway' ), - // TODO: find a better way to get the url admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' ) ); return new Message( $message, 'warning' ); } - protected function shouldDisplay(): bool { - // TODO: decide on what condition to display + /** + * Whether the message should display. + * + * @return bool + */ + protected function should_display(): bool { return $this->state->currentState() < State::STATE_PROGRESSIVE; } } diff --git a/modules.local/ppcp-wc-gateway/src/Processor/AuthorizedPaymentsProcessor.php b/modules.local/ppcp-wc-gateway/src/Processor/AuthorizedPaymentsProcessor.php deleted file mode 100644 index acb8a7279..000000000 --- a/modules.local/ppcp-wc-gateway/src/Processor/AuthorizedPaymentsProcessor.php +++ /dev/null @@ -1,110 +0,0 @@ -orderEndpoint = $orderEndpoint; - $this->paymentsEndpoint = $paymentsEndpoint; - } - - public function process( \WC_Order $wcOrder ): bool { - try { - $order = $this->payPalOrderFromWcOrder( $wcOrder ); - } catch ( Exception $exception ) { - if ( $exception->getCode() === 404 ) { - $this->lastStatus = self::NOT_FOUND; - return false; - } - $this->lastStatus = self::INACCESSIBLE; - return false; - } - - $authorizations = $this->allAuthorizations( $order ); - - if ( ! $this->areAuthorizationToCapture( ...$authorizations ) ) { - $this->lastStatus = self::ALREADY_CAPTURED; - return false; - } - - try { - $this->captureAuthorizations( ...$authorizations ); - } catch ( Exception $exception ) { - $this->lastStatus = self::FAILED; - return false; - } - - $this->lastStatus = self::SUCCESSFUL; - return true; - } - - public function lastStatus(): string { - - return $this->lastStatus; - } - - private function payPalOrderFromWcOrder( \WC_Order $wcOrder ): Order { - $orderId = $wcOrder->get_meta( PayPalGateway::ORDER_ID_META_KEY ); - return $this->orderEndpoint->order( $orderId ); - } - - private function allAuthorizations( Order $order ): array { - $authorizations = array(); - foreach ( $order->purchaseUnits() as $purchaseUnit ) { - foreach ( $purchaseUnit->payments()->authorizations() as $authorization ) { - $authorizations[] = $authorization; - } - } - - return $authorizations; - } - - private function areAuthorizationToCapture( Authorization ...$authorizations ): bool { - return (bool) count( $this->authorizationsToCapture( ...$authorizations ) ); - } - - private function captureAuthorizations( Authorization ...$authorizations ) { - $uncapturedAuthorizations = $this->authorizationsToCapture( ...$authorizations ); - foreach ( $uncapturedAuthorizations as $authorization ) { - $this->paymentsEndpoint->capture( $authorization->id() ); - } - } - - /** - * @param Authorization ...$authorizations - * @return Authorization[] - */ - private function authorizationsToCapture( Authorization ...$authorizations ): array { - return array_filter( - $authorizations, - static function ( Authorization $authorization ): bool { - return $authorization->status()->is( AuthorizationStatus::CREATED ) - || $authorization->status()->is( AuthorizationStatus::PENDING ); - } - ); - } -} diff --git a/modules.local/ppcp-wc-gateway/src/Processor/OrderProcessor.php b/modules.local/ppcp-wc-gateway/src/Processor/OrderProcessor.php deleted file mode 100644 index d235e117e..000000000 --- a/modules.local/ppcp-wc-gateway/src/Processor/OrderProcessor.php +++ /dev/null @@ -1,165 +0,0 @@ -sessionHandler = $sessionHandler; - $this->cartRepository = $cartRepository; - $this->orderEndpoint = $orderEndpoint; - $this->paymentsEndpoint = $paymentsEndpoint; - $this->orderFactory = $orderFactory; - $this->threedSecure = $threedSecure; - $this->authorizedPaymentsProcessor = $authorizedPaymentsProcessor; - $this->settings = $settings; - } - - public function process( \WC_Order $wcOrder, \WooCommerce $woocommerce ): bool { - $order = $this->sessionHandler->order(); - $wcOrder->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $order->id() ); - $wcOrder->update_meta_data( PayPalGateway::INTENT_META_KEY, $order->intent() ); - - $errorMessage = null; - if ( ! $order || ! $this->orderIsApproved( $order ) ) { - $errorMessage = __( - 'The payment has not been approved yet.', - 'woocommerce-paypal-commerce-gateway' - ); - } - if ( $errorMessage ) { - $this->lastError = sprintf( - // translators: %s is the message of the error. - __( 'Payment error: %s', 'woocommerce-paypal-commerce-gateway' ), - $errorMessage - ); - return false; - } - - $order = $this->patchOrder( $wcOrder, $order ); - if ( $order->intent() === 'CAPTURE' ) { - $order = $this->orderEndpoint->capture( $order ); - } - - if ( $order->intent() === 'AUTHORIZE' ) { - $order = $this->orderEndpoint->authorize( $order ); - $wcOrder->update_meta_data( PayPalGateway::CAPTURED_META_KEY, 'false' ); - } - - $wcOrder->update_status( - 'on-hold', - __( 'Awaiting payment.', 'woocommerce-paypal-commerce-gateway' ) - ); - if ( $order->status()->is( OrderStatus::COMPLETED ) && $order->intent() === 'CAPTURE' ) { - $wcOrder->update_status( - 'processing', - __( 'Payment received.', 'woocommerce-paypal-commerce-gateway' ) - ); - } - - if ( $this->captureAuthorizedDownloads( $order ) && $this->authorizedPaymentsProcessor->process( $wcOrder ) ) { - $wcOrder->add_order_note( - __( 'Payment successfully captured.', 'woocommerce-paypal-commerce-gateway' ) - ); - $wcOrder->update_meta_data( PayPalGateway::CAPTURED_META_KEY, 'true' ); - $wcOrder->update_status( 'processing' ); - } - $woocommerce->cart->empty_cart(); - $this->sessionHandler->destroySessionData(); - $this->lastError = ''; - return true; - } - - private function captureAuthorizedDownloads( Order $order ): bool { - if ( - ! $this->settings->has( 'capture_for_virtual_only' ) - || ! $this->settings->get( 'capture_for_virtual_only' ) - ) { - return false; - } - - if ( $order->intent() === 'CAPTURE' ) { - return false; - } - - /** - * We fetch the order again as the authorize endpoint (from which the Order derives) - * drops the item's category, making it impossible to check, if purchase units contain - * physical goods. - */ - $order = $this->orderEndpoint->order( $order->id() ); - - foreach ( $order->purchaseUnits() as $unit ) { - if ( $unit->containsPhysicalGoodsItems() ) { - return false; - } - } - return true; - } - - public function lastError(): string { - - return $this->lastError; - } - - public function patchOrder( \WC_Order $wcOrder, Order $order ): Order { - $updatedOrder = $this->orderFactory->fromWcOrder( $wcOrder, $order ); - $order = $this->orderEndpoint->patchOrderWith( $order, $updatedOrder ); - return $order; - } - - private function orderIsApproved( Order $order ): bool { - - if ( $order->status()->is( OrderStatus::APPROVED ) ) { - return true; - } - - if ( ! $order->paymentSource() || ! $order->paymentSource()->card() ) { - return false; - } - - $isApproved = in_array( - $this->threedSecure->proceedWithOrder( $order ), - array( - ThreeDSecure::NO_DECISION, - ThreeDSecure::PROCCEED, - ), - true - ); - return $isApproved; - } -} diff --git a/modules.local/ppcp-wc-gateway/src/Processor/class-authorizedpaymentsprocessor.php b/modules.local/ppcp-wc-gateway/src/Processor/class-authorizedpaymentsprocessor.php new file mode 100644 index 000000000..62b899eca --- /dev/null +++ b/modules.local/ppcp-wc-gateway/src/Processor/class-authorizedpaymentsprocessor.php @@ -0,0 +1,182 @@ +order_endpoint = $order_endpoint; + $this->payments_endpoint = $payments_endpoint; + } + + /** + * Process a Woocommerce order. + * + * @param \WC_Order $wc_order The Woocommerce order. + * + * @return bool + */ + public function process( \WC_Order $wc_order ): bool { + try { + $order = $this->paypal_order_from_wc_order( $wc_order ); + } catch ( Exception $exception ) { + if ( $exception->getCode() === 404 ) { + $this->last_status = self::NOT_FOUND; + return false; + } + $this->last_status = self::INACCESSIBLE; + return false; + } + + $authorizations = $this->all_authorizations( $order ); + + if ( ! $this->are_authorzations_to_capture( ...$authorizations ) ) { + $this->last_status = self::ALREADY_CAPTURED; + return false; + } + + try { + $this->capture_authorizations( ...$authorizations ); + } catch ( Exception $exception ) { + $this->last_status = self::FAILED; + return false; + } + + $this->last_status = self::SUCCESSFUL; + return true; + } + + /** + * Returns the last status. + * + * @return string + */ + public function last_status(): string { + + return $this->last_status; + } + + /** + * Returns the PayPal order from a given Woocommerce order. + * + * @param \WC_Order $wc_order The Woocommerce order. + * + * @return Order + */ + private function paypal_order_from_wc_order( \WC_Order $wc_order ): Order { + $order_id = $wc_order->get_meta( PayPalGateway::ORDER_ID_META_KEY ); + return $this->order_endpoint->order( $order_id ); + } + + /** + * Returns all Authorizations from an order. + * + * @param Order $order The order. + * + * @return array + */ + private function all_authorizations( Order $order ): array { + $authorizations = array(); + foreach ( $order->purchaseUnits() as $purchase_unit ) { + foreach ( $purchase_unit->payments()->authorizations() as $authorization ) { + $authorizations[] = $authorization; + } + } + + return $authorizations; + } + + /** + * Whether Authorizations need to be captured. + * + * @param Authorization ...$authorizations All Authorizations. + * + * @return bool + */ + private function are_authorzations_to_capture( Authorization ...$authorizations ): bool { + return (bool) count( $this->authorizations_to_capture( ...$authorizations ) ); + } + + /** + * Captures the authorizations. + * + * @param Authorization ...$authorizations All authorizations. + */ + private function capture_authorizations( Authorization ...$authorizations ) { + $uncaptured_authorizations = $this->authorizations_to_capture( ...$authorizations ); + foreach ( $uncaptured_authorizations as $authorization ) { + $this->payments_endpoint->capture( $authorization->id() ); + } + } + + /** + * The authorizations which need to be captured. + * + * @param Authorization ...$authorizations All Authorizations. + * @return Authorization[] + */ + private function authorizations_to_capture( Authorization ...$authorizations ): array { + return array_filter( + $authorizations, + static function ( Authorization $authorization ): bool { + return $authorization->status()->is( AuthorizationStatus::CREATED ) + || $authorization->status()->is( AuthorizationStatus::PENDING ); + } + ); + } +} diff --git a/modules.local/ppcp-wc-gateway/src/Processor/class-orderprocessor.php b/modules.local/ppcp-wc-gateway/src/Processor/class-orderprocessor.php new file mode 100644 index 000000000..659f8e2fb --- /dev/null +++ b/modules.local/ppcp-wc-gateway/src/Processor/class-orderprocessor.php @@ -0,0 +1,272 @@ +session_handler = $session_handler; + $this->cart_repository = $cart_repository; + $this->order_endpoint = $order_endpoint; + $this->payments_endpoint = $payments_endpoint; + $this->order_factory = $order_factory; + $this->threed_secure = $three_d_secure; + $this->authorized_payments_processor = $authorized_payments_processor; + $this->settings = $settings; + } + + /** + * Processes a given Woocommerce order and captured/authorizes the connected PayPal orders. + * + * @param \WC_Order $wc_order The Woocommerce order. + * @param \WooCommerce $woocommerce The Woocommerce object. + * + * @return bool + */ + public function process( \WC_Order $wc_order, \WooCommerce $woocommerce ): bool { + $order = $this->session_handler->order(); + $wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $order->id() ); + $wc_order->update_meta_data( PayPalGateway::INTENT_META_KEY, $order->intent() ); + + $error_message = null; + if ( ! $order || ! $this->order_is_approved( $order ) ) { + $error_message = __( + 'The payment has not been approved yet.', + 'woocommerce-paypal-commerce-gateway' + ); + } + if ( $error_message ) { + $this->last_error = sprintf( + // translators: %s is the message of the error. + __( 'Payment error: %s', 'woocommerce-paypal-commerce-gateway' ), + $error_message + ); + return false; + } + + $order = $this->patch_order( $wc_order, $order ); + if ( $order->intent() === 'CAPTURE' ) { + $order = $this->order_endpoint->capture( $order ); + } + + if ( $order->intent() === 'AUTHORIZE' ) { + $order = $this->order_endpoint->authorize( $order ); + $wc_order->update_meta_data( PayPalGateway::CAPTURED_META_KEY, 'false' ); + } + + $wc_order->update_status( + 'on-hold', + __( 'Awaiting payment.', 'woocommerce-paypal-commerce-gateway' ) + ); + if ( $order->status()->is( OrderStatus::COMPLETED ) && $order->intent() === 'CAPTURE' ) { + $wc_order->update_status( + 'processing', + __( 'Payment received.', 'woocommerce-paypal-commerce-gateway' ) + ); + } + + if ( $this->capture_authorized_downloads( $order ) && $this->authorized_payments_processor->process( $wc_order ) ) { + $wc_order->add_order_note( + __( 'Payment successfully captured.', 'woocommerce-paypal-commerce-gateway' ) + ); + $wc_order->update_meta_data( PayPalGateway::CAPTURED_META_KEY, 'true' ); + $wc_order->update_status( 'processing' ); + } + $woocommerce->cart->empty_cart(); + $this->session_handler->destroySessionData(); + $this->last_error = ''; + return true; + } + + /** + * Returns if an order should be captured immediately. + * + * @param Order $order The PayPal order. + * + * @return bool + */ + private function capture_authorized_downloads( Order $order ): bool { + if ( + ! $this->settings->has( 'capture_for_virtual_only' ) + || ! $this->settings->get( 'capture_for_virtual_only' ) + ) { + return false; + } + + if ( $order->intent() === 'CAPTURE' ) { + return false; + } + + /** + * We fetch the order again as the authorize endpoint (from which the Order derives) + * drops the item's category, making it impossible to check, if purchase units contain + * physical goods. + */ + $order = $this->order_endpoint->order( $order->id() ); + + foreach ( $order->purchaseUnits() as $unit ) { + if ( $unit->containsPhysicalGoodsItems() ) { + return false; + } + } + return true; + } + + /** + * Returns the last error. + * + * @return string + */ + public function last_error(): string { + + return $this->last_error; + } + + /** + * Patches a given PayPal order with a Woocommerce order. + * + * @param \WC_Order $wc_order The Woocommerce order. + * @param Order $order The PayPal order. + * + * @return Order + */ + public function patch_order( \WC_Order $wc_order, Order $order ): Order { + $updated_order = $this->order_factory->fromWcOrder( $wc_order, $order ); + $order = $this->order_endpoint->patchOrderWith( $order, $updated_order ); + return $order; + } + + /** + * Whether a given order is approved. + * + * @param Order $order The order. + * + * @return bool + */ + private function order_is_approved( Order $order ): bool { + + if ( $order->status()->is( OrderStatus::APPROVED ) ) { + return true; + } + + if ( ! $order->paymentSource() || ! $order->paymentSource()->card() ) { + return false; + } + + $is_approved = in_array( + $this->threed_secure->proceedWithOrder( $order ), + array( + ThreeDSecure::NO_DECISION, + ThreeDSecure::PROCCEED, + ), + true + ); + return $is_approved; + } +} diff --git a/modules.local/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules.local/ppcp-wc-gateway/src/Settings/SettingsListener.php deleted file mode 100644 index f1b3fb4a6..000000000 --- a/modules.local/ppcp-wc-gateway/src/Settings/SettingsListener.php +++ /dev/null @@ -1,201 +0,0 @@ -settings = $settings; - $this->settingFields = $settingFields; - $this->webhookRegistrar = $webhookRegistrar; - $this->cache = $cache; - $this->state = $state; - } - - public function listen() { - - if ( ! $this->isValidUpdateRequest() ) { - return; - } - - /** - * Nonce verification is done in self::isValidUpdateRequest - */ - //phpcs:disable WordPress.Security.NonceVerification.Missing - //phpcs:disable WordPress.Security.NonceVerification.Recommended - if ( isset( $_POST['save'] ) && sanitize_text_field( wp_unslash( $_POST['save'] ) ) === 'reset' ) { - $this->settings->reset(); - $this->settings->persist(); - $this->webhookRegistrar->unregister(); - if ( $this->cache->has( PayPalBearer::CACHE_KEY ) ) { - $this->cache->delete( PayPalBearer::CACHE_KEY ); - } - return; - } - - //phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - //phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated - /** - * Sanitization is done at a later stage. - */ - $rawData = ( isset( $_POST['ppcp'] ) ) ? (array) wp_unslash( $_POST['ppcp'] ) : array(); - $settings = $this->retrieveSettingsFromRawData( $rawData ); - if ( $_GET['section'] === PayPalGateway::ID ) { - $settings['enabled'] = isset( $_POST['woocommerce_ppcp-gateway_enabled'] ) - && absint( $_POST['woocommerce_ppcp-gateway_enabled'] ) === 1; - } - if ( $_GET['section'] === CreditCardGateway::ID ) { - $dccEnabledPostKey = 'woocommerce_ppcp-credit-card-gateway_enabled'; - $settings['dcc_gateway_enabled'] = isset( $_POST[ $dccEnabledPostKey ] ) - && absint( $_POST[ $dccEnabledPostKey ] ) === 1; - } - $this->maybeRegisterWebhooks( $settings ); - - foreach ( $settings as $id => $value ) { - $this->settings->set( $id, $value ); - } - $this->settings->persist(); - if ( $this->cache->has( PayPalBearer::CACHE_KEY ) ) { - $this->cache->delete( PayPalBearer::CACHE_KEY ); - } - //phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotValidated - //phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - //phpcs:enable WordPress.Security.NonceVerification.Missing - } - - private function maybeRegisterWebhooks( array $settings ) { - - if ( ! $this->settings->has( 'client_id' ) && $settings['client_id'] ) { - $this->webhookRegistrar->register(); - } - if ( $this->settings->has( 'client_id' ) && $this->settings->get( 'client_id' ) ) { - $currentSecret = $this->settings->has( 'client_secret' ) ? - $this->settings->get( 'client_secret' ) : ''; - if ( - $settings['client_id'] !== $this->settings->get( 'client_id' ) - || $settings['client_secret'] !== $currentSecret - ) { - $this->webhookRegistrar->unregister(); - $this->webhookRegistrar->register(); - } - } - } - - //phpcs:disable Inpsyde.CodeQuality.NestingLevel.MaxExceeded - //phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh - //phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong - private function retrieveSettingsFromRawData( array $rawData ): array { - if ( ! isset( $_GET['section'] ) ) { - return array(); - } - $settings = array(); - foreach ( $this->settingFields as $key => $config ) { - if ( ! in_array( $this->state->currentState(), $config['screens'], true ) ) { - continue; - } - if ( - $config['gateway'] === 'dcc' - && sanitize_text_field( wp_unslash( $_GET['section'] ) ) !== 'ppcp-credit-card-gateway' - ) { - continue; - } - if ( - $config['gateway'] === 'paypal' - && sanitize_text_field( wp_unslash( $_GET['section'] ) ) !== 'ppcp-gateway' - ) { - continue; - } - switch ( $config['type'] ) { - case 'checkbox': - $settings[ $key ] = isset( $rawData[ $key ] ); - break; - case 'text': - case 'ppcp-text-input': - case 'ppcp-password': - $settings[ $key ] = isset( $rawData[ $key ] ) ? sanitize_text_field( $rawData[ $key ] ) : ''; - break; - case 'password': - if ( empty( $rawData[ $key ] ) ) { - break; - } - $settings[ $key ] = sanitize_text_field( $rawData[ $key ] ); - break; - case 'ppcp-multiselect': - $values = isset( $rawData[ $key ] ) ? (array) $rawData[ $key ] : array(); - $valuesToSave = array(); - foreach ( $values as $index => $rawValue ) { - $value = sanitize_text_field( $rawValue ); - if ( ! in_array( $value, array_keys( $config['options'] ), true ) ) { - continue; - } - $valuesToSave[] = $value; - } - $settings[ $key ] = $valuesToSave; - break; - case 'select': - $options = array_keys( $config['options'] ); - $settings[ $key ] = isset( $rawData[ $key ] ) && in_array( - sanitize_text_field( $rawData[ $key ] ), - $options, - true - ) ? sanitize_text_field( $rawData[ $key ] ) : null; - break; - } - } - return $settings; - } - //phpcs:enable Inpsyde.CodeQuality.NestingLevel.MaxExceeded - //phpcs:enable Generic.Metrics.CyclomaticComplexity.TooHigh - - private function isValidUpdateRequest(): bool { - - if ( - ! isset( $_REQUEST['section'] ) - || ! in_array( - sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ), - array( 'ppcp-gateway', 'ppcp-credit-card-gateway' ), - true - ) - ) { - return false; - } - - if ( ! current_user_can( 'manage_options' ) ) { - return false; - } - - if ( - ! isset( $_POST['ppcp-nonce'] ) - || ! wp_verify_nonce( - sanitize_text_field( wp_unslash( $_POST['ppcp-nonce'] ) ), - self::NONCE - ) - ) { - return false; - } - return true; - } -} diff --git a/modules.local/ppcp-wc-gateway/src/Settings/Settings.php b/modules.local/ppcp-wc-gateway/src/Settings/class-settings.php similarity index 68% rename from modules.local/ppcp-wc-gateway/src/Settings/Settings.php rename to modules.local/ppcp-wc-gateway/src/Settings/class-settings.php index d836b733a..5601ab9a7 100644 --- a/modules.local/ppcp-wc-gateway/src/Settings/Settings.php +++ b/modules.local/ppcp-wc-gateway/src/Settings/class-settings.php @@ -1,23 +1,39 @@ has( $id ) ) { throw new NotFoundException(); @@ -25,24 +41,45 @@ class Settings implements ContainerInterface { return $this->settings[ $id ]; } + /** + * Whether a value exists. + * + * @param string $id The value identificator. + * + * @return bool + */ public function has( $id ) { $this->load(); return array_key_exists( $id, $this->settings ); } + /** + * Sets a value. + * + * @param string $id The value identificator. + * @param mixed $value The value. + */ public function set( $id, $value ) { $this->load(); $this->settings[ $id ] = $value; } + /** + * Stores the settings to the database. + */ public function persist() { update_option( self::KEY, $this->settings ); } + /** + * Resets the onboarding. + * + * @return bool + */ public function reset(): bool { $this->load(); - $fieldsToReset = array( + $fields_to_reset = array( 'enabled', 'dcc_gateway_enabled', 'intent', @@ -50,13 +87,18 @@ class Settings implements ContainerInterface { 'client_secret', 'merchant_email', ); - foreach ( $fieldsToReset as $id ) { + foreach ( $fields_to_reset as $id ) { $this->settings[ $id ] = null; } return true; } + /** + * Loads the settings. + * + * @return bool + */ private function load(): bool { if ( $this->settings ) { diff --git a/modules.local/ppcp-wc-gateway/src/Settings/class-settingslistener.php b/modules.local/ppcp-wc-gateway/src/Settings/class-settingslistener.php new file mode 100644 index 000000000..63350128e --- /dev/null +++ b/modules.local/ppcp-wc-gateway/src/Settings/class-settingslistener.php @@ -0,0 +1,277 @@ +settings = $settings; + $this->setting_fields = $setting_fields; + $this->webhook_registrar = $webhook_registrar; + $this->cache = $cache; + $this->state = $state; + } + + /** + * Listens to the request. + * + * @throws \Inpsyde\PayPalCommerce\WcGateway\Exception\NotFoundException When a setting was not found. + * @throws \Psr\SimpleCache\InvalidArgumentException When the argument was invalid. + */ + public function listen() { + + if ( ! $this->is_valid_update_request() ) { + return; + } + + /** + * Nonce verification has been done in is_valid_update_request(). + * + * phpcs:disable WordPress.Security.NonceVerification.Missing + * phpcs:disable WordPress.Security.NonceVerification.Recommended + */ + if ( isset( $_POST['save'] ) && sanitize_text_field( wp_unslash( $_POST['save'] ) ) === 'reset' ) { + $this->settings->reset(); + $this->settings->persist(); + $this->webhook_registrar->unregister(); + if ( $this->cache->has( PayPalBearer::CACHE_KEY ) ) { + $this->cache->delete( PayPalBearer::CACHE_KEY ); + } + return; + } + + /** + * Sanitization is done in retrieve_settings_from_raw_data(). + * + * phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + */ + $raw_data = ( isset( $_POST['ppcp'] ) ) ? (array) wp_unslash( $_POST['ppcp'] ) : array(); + // phpcs:enable phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + $settings = $this->retrieve_settings_from_raw_data( $raw_data ); + if ( isset( $_GET['section'] ) && PayPalGateway::ID === $_GET['section'] ) { + $settings['enabled'] = isset( $_POST['woocommerce_ppcp-gateway_enabled'] ) + && 1 === absint( $_POST['woocommerce_ppcp-gateway_enabled'] ); + } + if ( isset( $_GET['section'] ) && CreditCardGateway::ID === $_GET['section'] ) { + $dcc_enabled_post_key = 'woocommerce_ppcp-credit-card-gateway_enabled'; + $settings['dcc_gateway_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 ); + } + $this->settings->persist(); + if ( $this->cache->has( PayPalBearer::CACHE_KEY ) ) { + $this->cache->delete( PayPalBearer::CACHE_KEY ); + } + + // phpcs:enable WordPress.Security.NonceVerification.Missing + // phpcs:enable WordPress.Security.NonceVerification.Recommended + } + + /** + * Depending on the settings change, we might need to register or unregister the Webhooks at PayPal. + * + * @param array $settings The settings. + * + * @throws \Inpsyde\PayPalCommerce\WcGateway\Exception\NotFoundException If a setting hasn't been found. + */ + private function maybe_register_webhooks( array $settings ) { + + if ( ! $this->settings->has( 'client_id' ) && $settings['client_id'] ) { + $this->webhook_registrar->register(); + } + if ( $this->settings->has( 'client_id' ) && $this->settings->get( 'client_id' ) ) { + $current_secret = $this->settings->has( 'client_secret' ) ? + $this->settings->get( 'client_secret' ) : ''; + if ( + $settings['client_id'] !== $this->settings->get( 'client_id' ) + || $settings['client_secret'] !== $current_secret + ) { + $this->webhook_registrar->unregister(); + $this->webhook_registrar->register(); + } + } + } + + /** + * Sanitizes the settings input data and returns a valid settings array. + * + * @param array $raw_data The Raw data. + * + * @return array + */ + private function retrieve_settings_from_raw_data( array $raw_data ): array { + /** + * Nonce verification has already been done. + * phpcs:disable WordPress.Security.NonceVerification.Recommended + */ + if ( ! isset( $_GET['section'] ) ) { + return array(); + } + $settings = array(); + foreach ( $this->setting_fields as $key => $config ) { + if ( ! in_array( $this->state->currentState(), $config['screens'], true ) ) { + continue; + } + if ( + 'dcc' === $config['gateway'] + && sanitize_text_field( wp_unslash( $_GET['section'] ) ) !== 'ppcp-credit-card-gateway' + ) { + continue; + } + if ( + 'paypal' === $config['gateway'] + && sanitize_text_field( wp_unslash( $_GET['section'] ) ) !== 'ppcp-gateway' + ) { + continue; + } + switch ( $config['type'] ) { + case 'checkbox': + $settings[ $key ] = isset( $raw_data[ $key ] ); + break; + case 'text': + case 'ppcp-text-input': + case 'ppcp-password': + $settings[ $key ] = isset( $raw_data[ $key ] ) ? sanitize_text_field( $raw_data[ $key ] ) : ''; + break; + case 'password': + if ( empty( $raw_data[ $key ] ) ) { + break; + } + $settings[ $key ] = sanitize_text_field( $raw_data[ $key ] ); + break; + case 'ppcp-multiselect': + $values = isset( $raw_data[ $key ] ) ? (array) $raw_data[ $key ] : array(); + $values_to_save = array(); + foreach ( $values as $index => $raw_value ) { + $value = sanitize_text_field( $raw_value ); + if ( ! in_array( $value, array_keys( $config['options'] ), true ) ) { + continue; + } + $values_to_save[] = $value; + } + $settings[ $key ] = $values_to_save; + break; + case 'select': + $options = array_keys( $config['options'] ); + $settings[ $key ] = isset( $raw_data[ $key ] ) && in_array( + sanitize_text_field( $raw_data[ $key ] ), + $options, + true + ) ? sanitize_text_field( $raw_data[ $key ] ) : null; + break; + } + } + + // phpcs:enable WordPress.Security.NonceVerification.Recommended + return $settings; + } + + /** + * Evaluates whether the current request is supposed to update the settings. + * + * @return bool + */ + private function is_valid_update_request(): bool { + + if ( + ! isset( $_REQUEST['section'] ) + || ! in_array( + sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ), + array( 'ppcp-gateway', 'ppcp-credit-card-gateway' ), + true + ) + ) { + return false; + } + + if ( ! current_user_can( 'manage_options' ) ) { + return false; + } + + if ( + ! isset( $_POST['ppcp-nonce'] ) + || ! wp_verify_nonce( + sanitize_text_field( wp_unslash( $_POST['ppcp-nonce'] ) ), + self::NONCE + ) + ) { + return false; + } + return true; + } +} diff --git a/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php b/modules.local/ppcp-wc-gateway/src/Settings/class-settingsrenderer.php similarity index 50% rename from modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php rename to modules.local/ppcp-wc-gateway/src/Settings/class-settingsrenderer.php index 3f34097aa..a83421e9c 100644 --- a/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php +++ b/modules.local/ppcp-wc-gateway/src/Settings/class-settingsrenderer.php @@ -1,4 +1,9 @@ settings = $settings; - $this->state = $state; - $this->fields = $fields; - $this->dccApplies = $dccApplies; - $this->messagesApply = $messagesApply; + $this->settings = $settings; + $this->state = $state; + $this->fields = $fields; + $this->dcc_applies = $dcc_applies; + $this->messages_apply = $messages_apply; } - //phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType - public function renderMultiSelect( $field, $key, $config, $value ): string { + /** + * Renders the multiselect field. + * + * @param string $field The current field HTML. + * @param string $key The current key. + * @param array $config The configuration array. + * @param string $value The current value. + * + * @return string + */ + public function render_multiselect( $field, $key, $config, $value ): string { - if ( $config['type'] !== 'ppcp-multiselect' ) { + if ( 'ppcp-multiselect' !== $config['type'] ) { return $field; } $options = array(); - foreach ( $config['options'] as $optionKey => $optionValue ) { - $selected = ( in_array( $optionKey, $value, true ) ) ? 'selected="selected"' : ''; + foreach ( $config['options'] as $option_key => $option_value ) { + $selected = ( in_array( $option_key, $value, true ) ) ? 'selected="selected"' : ''; - $options[] = ''; } @@ -62,9 +117,19 @@ class SettingsRenderer { return $html; } - public function renderPassword( $field, $key, $config, $value ): string { + /** + * Renders the password input field. + * + * @param string $field The current field HTML. + * @param string $key The current key. + * @param array $config The configuration array. + * @param string $value The current value. + * + * @return string + */ + public function render_password( $field, $key, $config, $value ): string { - if ( $config['type'] !== 'ppcp-password' ) { + if ( 'ppcp-password' !== $config['type'] ) { return $field; } @@ -84,9 +149,20 @@ class SettingsRenderer { return $html; } - public function renderTextInput( $field, $key, $config, $value ): string { - if ( $config['type'] !== 'ppcp-text-input' ) { + /** + * Renders the text input field. + * + * @param string $field The current field HTML. + * @param string $key The current key. + * @param array $config The configuration array. + * @param string $value The current value. + * + * @return string + */ + public function render_text_input( $field, $key, $config, $value ): string { + + if ( 'ppcp-text-input' !== $config['type'] ) { return $field; } @@ -106,9 +182,19 @@ class SettingsRenderer { return $html; } - public function renderHeading( $field, $key, $config, $value ): string { + /** + * Renders the heading field. + * + * @param string $field The current field HTML. + * @param string $key The current key. + * @param array $config The configuration array. + * @param string $value The current value. + * + * @return string + */ + public function render_heading( $field, $key, $config, $value ): string { - if ( $config['type'] !== 'ppcp-heading' ) { + if ( 'ppcp-heading' !== $config['type'] ) { return $field; } @@ -120,11 +206,13 @@ class SettingsRenderer { return $html; } - //phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType - //phpcs:disable Inpsyde.CodeQuality.NestingLevel.High - //phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong - public function render( bool $isDcc ) { + /** + * Renders the settings. + * + * @param bool $is_dcc Whether it is the DCC gateway or not. + */ + public function render( bool $is_dcc ) { $nonce = wp_create_nonce( SettingsListener::NONCE ); ?> @@ -134,21 +222,21 @@ class SettingsRenderer { if ( ! in_array( $this->state->currentState(), $config['screens'], true ) ) { continue; } - if ( $isDcc && ! in_array( $config['gateway'], array( 'all', 'dcc' ), true ) ) { + if ( $is_dcc && ! in_array( $config['gateway'], array( 'all', 'dcc' ), true ) ) { continue; } - if ( ! $isDcc && ! in_array( $config['gateway'], array( 'all', 'paypal' ), true ) ) { + if ( ! $is_dcc && ! in_array( $config['gateway'], array( 'all', 'paypal' ), true ) ) { continue; } if ( in_array( 'dcc', $config['requirements'], true ) - && ! $this->dccApplies->forCountryCurrency() + && ! $this->dcc_applies->forCountryCurrency() ) { continue; } if ( in_array( 'messages', $config['requirements'], true ) - && ! $this->messagesApply->forCountry() + && ! $this->messages_apply->forCountry() ) { continue; } @@ -156,12 +244,12 @@ class SettingsRenderer { $key = 'ppcp[' . $field . ']'; $id = 'ppcp-' . $field; $config['id'] = $id; - $thTd = $config['type'] !== 'ppcp-heading' ? 'td' : 'th'; - $colspan = $config['type'] !== 'ppcp-heading' ? 1 : 2; + $th_td = 'ppcp-heading' !== $config['type'] ? 'td' : 'th'; + $colspan = 'ppcp-heading' !== $config['type'] ? 1 : 2; ?> - +