Merge branch 'trunk' into refactor-saved-credit-card

This commit is contained in:
dinamiko 2022-08-11 14:38:26 +02:00
commit 0f47b2ef37
2 changed files with 25 additions and 3 deletions

View file

@ -9,6 +9,8 @@ declare( strict_types=1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Helper;
use WC_Order;
/**
* Class PayUponInvoiceHelper
*/
@ -46,7 +48,7 @@ class PayUponInvoiceHelper {
return false;
}
if ( 'EUR' !== get_woocommerce_currency() ) {
if ( ! $this->is_valid_currency() ) {
return false;
}
@ -56,4 +58,24 @@ class PayUponInvoiceHelper {
return true;
}
/**
* Checks if currency is allowed for PUI.
*
* @return bool
*/
private function is_valid_currency(): bool {
global $wp;
$order_id = isset( $wp->query_vars['order-pay'] ) ? (int) $wp->query_vars['order-pay'] : 0;
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;
}
}

View file

@ -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' );
}