diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index e1f70c956..b8971bd3f 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1964,10 +1964,6 @@ return array( $fields['disable_cards']['options'] = $card_options; $fields['card_icons']['options'] = array_merge( $dark_versions, $card_options ); - if ( defined( 'PPCP_FLAG_SEPARATE_APM_BUTTONS' ) && PPCP_FLAG_SEPARATE_APM_BUTTONS === false ) { - unset( $fields['allow_card_button_gateway'] ); - } - return $fields; }, @@ -2245,10 +2241,6 @@ return array( return $container->get( 'api.shop.is-latin-america' ); }, 'wcgateway.settings.allow_card_button_gateway' => static function ( ContainerInterface $container ): bool { - if ( defined( 'PPCP_FLAG_SEPARATE_APM_BUTTONS' ) && PPCP_FLAG_SEPARATE_APM_BUTTONS === false ) { - return false; - } - $settings = $container->get( 'wcgateway.settings' ); assert( $settings instanceof ContainerInterface ); diff --git a/modules/ppcp-wc-gateway/src/Gateway/OXXO/OXXOGateway.php b/modules/ppcp-wc-gateway/src/Gateway/OXXO/OXXOGateway.php index 704d978c7..52bcac0e3 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/OXXO/OXXOGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/OXXO/OXXOGateway.php @@ -77,7 +77,7 @@ class OXXOGateway extends WC_Payment_Gateway { $this->id = self::ID; $this->method_title = __( 'OXXO', 'woocommerce-paypal-payments' ); - $this->method_description = __( 'OXXO is a Mexican chain of convenience stores.', 'woocommerce-paypal-payments' ); + $this->method_description = __( 'OXXO is a Mexican chain of convenience stores.
*Get PayPal account permission to use OXXO payment functionality by contacting us at (+52) 800-925-0304', 'woocommerce-paypal-payments' ); $this->title = $this->get_option( 'title', $this->method_title ); $this->description = $this->get_option( 'description', __( 'OXXO allows you to pay bills and online purchases in-store with cash.', 'woocommerce-paypal-payments' ) ); diff --git a/modules/ppcp-wc-gateway/src/Helper/CheckoutHelper.php b/modules/ppcp-wc-gateway/src/Helper/CheckoutHelper.php index 977144024..bd21df4c2 100644 --- a/modules/ppcp-wc-gateway/src/Helper/CheckoutHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/CheckoutHelper.php @@ -35,14 +35,6 @@ class CheckoutHelper { if ( $cart_total < $minimum || $cart_total > $maximum ) { return false; } - - $items = $cart->get_cart_contents(); - foreach ( $items as $item ) { - $product = wc_get_product( $item['product_id'] ); - if ( is_a( $product, WC_Product::class ) && ! $this->is_physical_product( $product ) ) { - return false; - } - } } if ( is_wc_endpoint_url( 'order-pay' ) ) { @@ -61,15 +53,6 @@ class CheckoutHelper { if ( $order_total < $minimum || $order_total > $maximum ) { return false; } - - foreach ( $order->get_items() as $item_id => $item ) { - if ( is_a( $item, WC_Order_Item_Product::class ) ) { - $product = wc_get_product( $item->get_product_id() ); - if ( is_a( $product, WC_Product::class ) && ! $this->is_physical_product( $product ) ) { - return false; - } - } - } } } } diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php index 63a721e51..b5a011c15 100644 --- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php @@ -10,6 +10,7 @@ declare( strict_types=1 ); namespace WooCommerce\PayPalCommerce\WcGateway\Helper; use WC_Order; +use WC_Order_Item_Product; use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; @@ -66,12 +67,66 @@ class PayUponInvoiceHelper { return false; } - if ( ! $this->is_valid_currency() ) { + if ( + ! $this->is_valid_product() + || ! $this->is_valid_currency() + || ! $this->checkout_helper->is_checkout_amount_allowed( 5, 2500 ) + ) { return false; } - if ( ! $this->checkout_helper->is_checkout_amount_allowed( 5, 2500 ) ) { - return false; + return true; + } + + /** + * Checks whether PUI gateway is enabled. + * + * @return bool True if PUI gateway is enabled, otherwise false. + */ + public function is_pui_gateway_enabled(): bool { + $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' ); + return isset( $gateway_settings['enabled'] ) && $gateway_settings['enabled'] === 'yes' && 'DE' === $this->api_shop_country; + } + + /** + * Checks if product is valid for PUI. + * + * @return bool + */ + private function is_valid_product(): bool { + $cart = WC()->cart ?? null; + if ( $cart && ! is_checkout_pay_page() ) { + $items = $cart->get_cart_contents(); + foreach ( $items as $item ) { + $product = wc_get_product( $item['product_id'] ); + if ( $product && ! $this->checkout_helper->is_physical_product( $product ) ) { + return false; + } + } + } + + if ( is_wc_endpoint_url( 'order-pay' ) ) { + /** + * Needed for WordPress `query_vars`. + * + * @psalm-suppress InvalidGlobal + */ + global $wp; + + if ( isset( $wp->query_vars['order-pay'] ) && absint( $wp->query_vars['order-pay'] ) > 0 ) { + $order_id = absint( $wp->query_vars['order-pay'] ); + $order = wc_get_order( $order_id ); + if ( is_a( $order, WC_Order::class ) ) { + foreach ( $order->get_items() as $item_id => $item ) { + if ( is_a( $item, WC_Order_Item_Product::class ) ) { + $product = wc_get_product( $item->get_product_id() ); + if ( $product && ! $this->checkout_helper->is_physical_product( $product ) ) { + return false; + } + } + } + } + } } return true; @@ -129,14 +184,4 @@ class PayUponInvoiceHelper { return false; } - - /** - * Checks whether PUI gateway is enabled. - * - * @return bool True if PUI gateway is enabled, otherwise false. - */ - public function is_pui_gateway_enabled(): bool { - $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' ); - return isset( $gateway_settings['enabled'] ) && $gateway_settings['enabled'] === 'yes' && 'DE' === $this->api_shop_country; - } } diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 18a39b57e..7ad4d64bc 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -247,9 +247,7 @@ class WCGatewayModule implements ModuleInterface { ( $c->get( 'wcgateway.pay-upon-invoice' ) )->init(); } - if ( defined( 'PPCP_FLAG_OXXO' ) && PPCP_FLAG_OXXO === true ) { - ( $c->get( 'wcgateway.oxxo' ) )->init(); - } + ( $c->get( 'wcgateway.oxxo' ) )->init(); } ); @@ -283,10 +281,6 @@ class WCGatewayModule implements ModuleInterface { add_action( 'wc_ajax_ppc-oxxo', static function () use ( $c ) { - if ( defined( 'PPCP_FLAG_OXXO' ) && PPCP_FLAG_OXXO === false ) { - return; - } - $endpoint = $c->get( 'wcgateway.endpoint.oxxo' ); $endpoint->handle_request(); } @@ -359,7 +353,7 @@ class WCGatewayModule implements ModuleInterface { $methods[] = $container->get( 'wcgateway.pay-upon-invoice-gateway' ); } - if ( defined( 'PPCP_FLAG_OXXO' ) && PPCP_FLAG_OXXO === true && 'MX' === $shop_country ) { + if ( 'MX' === $shop_country ) { $methods[] = $container->get( 'wcgateway.oxxo-gateway' ); } diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index a9aa6b7bc..6f61e7e0a 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -26,8 +26,6 @@ define( 'PAYPAL_SANDBOX_API_URL', 'https://api.sandbox.paypal.com' ); define( 'PAYPAL_INTEGRATION_DATE', '2022-04-13' ); define( 'PPCP_FLAG_SUBSCRIPTION', true ); -define( 'PPCP_FLAG_OXXO', apply_filters( 'woocommerce_paypal_payments_enable_oxxo_feature', false ) ); -define( 'PPCP_FLAG_SEPARATE_APM_BUTTONS', apply_filters( 'woocommerce_paypal_payments_enable_separate_apm_buttons_feature', false ) ); ! defined( 'CONNECT_WOO_CLIENT_ID' ) && define( 'CONNECT_WOO_CLIENT_ID', 'AcCAsWta_JTL__OfpjspNyH7c1GGHH332fLwonA5CwX4Y10mhybRZmHLA0GdRbwKwjQIhpDQy0pluX_P' ); ! defined( 'CONNECT_WOO_SANDBOX_CLIENT_ID' ) && define( 'CONNECT_WOO_SANDBOX_CLIENT_ID', 'AYmOHbt1VHg-OZ_oihPdzKEVbU3qg0qXonBcAztuzniQRaKE0w1Hr762cSFwd4n8wxOl-TCWohEa0XM_' );