From 31f91cd976ba33c428a97af412c55bdc0149fef5 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 2 Nov 2022 12:27:03 +0100 Subject: [PATCH 1/5] Enable OXXO/Credit Card button and add OXXO contact message --- modules/ppcp-wc-gateway/services.php | 8 -------- .../ppcp-wc-gateway/src/Gateway/OXXO/OXXOGateway.php | 2 +- modules/ppcp-wc-gateway/src/WCGatewayModule.php | 10 ++-------- woocommerce-paypal-payments.php | 2 -- 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 2c495324d..b7199da93 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1920,10 +1920,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; }, @@ -2199,10 +2195,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 1711b8664..a2f661362 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/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index ce0ad3c0e..26c45c8d6 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -243,9 +243,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(); } ); @@ -279,10 +277,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(); } @@ -355,7 +349,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 71be57a0e..2d73b2a4b 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_' ); From 7b76a9f653c5a21d335889134814ee869341da79 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 2 Nov 2022 12:31:21 +0100 Subject: [PATCH 2/5] Do not check physical product on amount allowed --- .../src/Helper/CheckoutHelper.php | 17 ----------------- 1 file changed, 17 deletions(-) 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; - } - } - } } } } From 5fa1907d97bf88b3450803092a09a7e8a2b50ab7 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 3 Nov 2022 12:03:03 +0100 Subject: [PATCH 3/5] Add product validation for pui --- .../src/Helper/PayUponInvoiceHelper.php | 63 ++++++++++++++++--- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php index 6b9af84c8..61d2647fe 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; @@ -59,6 +60,10 @@ class PayUponInvoiceHelper { return false; } + if ( ! $this->is_valid_product() ) { + return false; + } + if ( ! $this->is_valid_currency() ) { return false; } @@ -70,6 +75,54 @@ class PayUponInvoiceHelper { 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 ( ! $this->checkout_helper->is_physical_product( $product ) ) { + return false; + } + } + } + + if ( is_wc_endpoint_url( 'order-pay' ) ) { + 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 ( ! $this->checkout_helper->is_physical_product( $product ) ) { + return false; + } + } + } + } + } + } + + return true; + } + /** * Checks if currency is allowed for PUI. * @@ -89,14 +142,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; - } } From faa9fbe9820cc2a2dfe70126f8f1a13b53f44564 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 3 Nov 2022 12:06:04 +0100 Subject: [PATCH 4/5] Consolidate conditional --- .../src/Helper/PayUponInvoiceHelper.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php index 61d2647fe..9854ae0fa 100644 --- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php @@ -60,15 +60,11 @@ class PayUponInvoiceHelper { return false; } - if ( ! $this->is_valid_product() ) { - return false; - } - - if ( ! $this->is_valid_currency() ) { - return false; - } - - if ( ! $this->checkout_helper->is_checkout_amount_allowed( 5, 2500 ) ) { + if ( + ! $this->is_valid_product() + || ! $this->is_valid_currency() + || ! $this->checkout_helper->is_checkout_amount_allowed( 5, 2500 ) + ) { return false; } From ba37b81869fc2cf5d21ee96f7cebcf53df3afc48 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 3 Nov 2022 12:25:59 +0100 Subject: [PATCH 5/5] Fix psalm --- .../src/Helper/PayUponInvoiceHelper.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php index 9854ae0fa..c682fd7e4 100644 --- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php @@ -92,14 +92,20 @@ class PayUponInvoiceHelper { $items = $cart->get_cart_contents(); foreach ( $items as $item ) { $product = wc_get_product( $item['product_id'] ); - if ( ! $this->checkout_helper->is_physical_product( $product ) ) { + 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 ); @@ -107,7 +113,7 @@ class PayUponInvoiceHelper { 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 ( ! $this->checkout_helper->is_physical_product( $product ) ) { + if ( $product && ! $this->checkout_helper->is_physical_product( $product ) ) { return false; } }