From bad4ed3a64ccb5fcf906cc693b72167ac3a3a7dd Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 22 Jul 2022 11:24:10 +0200 Subject: [PATCH 1/4] Check order currency on pay for order --- .../src/Helper/PayUponInvoiceHelper.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php index 32391bb0a..2b6e4f534 100644 --- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php @@ -86,7 +86,7 @@ class PayUponInvoiceHelper { return false; } - if ( 'EUR' !== get_woocommerce_currency() ) { + if ( ! $this->is_valid_currency() ) { return false; } @@ -137,4 +137,24 @@ class PayUponInvoiceHelper { return true; } + + /** + * Checks if currency is allowed for PUI. + * + * @return bool + */ + private function is_valid_currency(): bool { + global $wp; + $order_id = (int) $wp->query_vars['order-pay']; + if ( 0 === $order_id ) { + return 'EUR' === get_woocommerce_currency(); + } + + $order = wc_get_order( $order_id ); + if ( is_a( $order, WC_Order::class ) ) { + return 'EUR' === $order->get_currency(); + } + + return false; + } } From 55d57b59ce1d864238030759183ce36c82af2de6 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 22 Jul 2022 12:18:17 +0200 Subject: [PATCH 2/4] Ensure `order-pay` exists on query vars --- modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php index 2b6e4f534..8c1125348 100644 --- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php @@ -145,7 +145,7 @@ class PayUponInvoiceHelper { */ private function is_valid_currency(): bool { global $wp; - $order_id = (int) $wp->query_vars['order-pay']; + $order_id = isset( $wp->query_vars['order-pay'] ) ? (int) $wp->query_vars['order-pay'] : 0; if ( 0 === $order_id ) { return 'EUR' === get_woocommerce_currency(); } From a2e24240467845a2a66bb697614c4ae70b8fe871 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 9 Aug 2022 15:51:50 +0200 Subject: [PATCH 3/4] Add wc order to the class --- modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php index 1ac5ecb73..3814e0b88 100644 --- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php @@ -9,6 +9,8 @@ declare( strict_types=1 ); namespace WooCommerce\PayPalCommerce\WcGateway\Helper; +use WC_Order; + /** * Class PayUponInvoiceHelper */ From 65c8cce2a6ee50fcc0f309e80e17264959998af3 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 10 Aug 2022 10:44:36 +0200 Subject: [PATCH 4/4] Do not check store currency when registering pui gateway --- modules/ppcp-wc-gateway/src/WCGatewayModule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 853670025..b6a30b4d1 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -231,7 +231,7 @@ class WCGatewayModule implements ModuleInterface { add_action( 'init', function () use ( $c ) { - if ( 'DE' === $c->get( 'api.shop.country' ) && 'EUR' === $c->get( 'api.shop.currency' ) ) { + if ( 'DE' === $c->get( 'api.shop.country' ) ) { ( $c->get( 'wcgateway.pay-upon-invoice' ) )->init(); } @@ -312,7 +312,7 @@ class WCGatewayModule implements ModuleInterface { $methods[] = $container->get( 'wcgateway.card-button-gateway' ); } - if ( 'DE' === $container->get( 'api.shop.country' ) && 'EUR' === $container->get( 'api.shop.currency' ) ) { + if ( 'DE' === $container->get( 'api.shop.country' ) ) { $methods[] = $container->get( 'wcgateway.pay-upon-invoice-gateway' ); }