diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php index 32391bb0a..7f9b26805 100644 --- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php @@ -21,6 +21,32 @@ use WC_Product_Variation; */ class PayUponInvoiceHelper { + /** + * The selected shop country. + * + * @var string + */ + protected $shop_country; + + /** + * The PUI seller product status. + * + * @var PayUponInvoiceProductStatus + */ + protected $pui_product_status; + + /** + * PayUponInvoiceHelper constructor. + * + * @param string $shop_country The selected shop country. + * @param PayUponInvoiceProductStatus $pui_product_status The PUI seller product status. + */ + public function __construct( string $shop_country, PayUponInvoiceProductStatus $pui_product_status ) { + + $this->shop_country = $shop_country; + $this->pui_product_status = $pui_product_status; + } + /** * Ensures date is valid and at least 18 years back. * @@ -137,4 +163,17 @@ class PayUponInvoiceHelper { return true; } + + /** + * Checks whether PUI is ready in admin screen. + * + * @return bool + */ + public function is_pui_ready_in_admin(): bool { + if ( $this->pui_product_status->pui_is_active() && $this->shop_country === 'DE' ) { + return true; + } + + return false; + } } diff --git a/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php b/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php index 3a1d9bdc0..26eae1479 100644 --- a/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php +++ b/tests/PHPUnit/WcGateway/Helper/PayUponInvoiceHelperTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\WcGateway\Helper; use DateTime; +use Mockery; use WooCommerce\PayPalCommerce\TestCase; class PayUponInvoiceHelperTest extends TestCase @@ -13,7 +14,8 @@ class PayUponInvoiceHelperTest extends TestCase */ public function testValidateBirthDate($input, $output) { - $this->assertSame((new PayUponInvoiceHelper())->validate_birth_date($input), $output); + $pui_product_status = Mockery::mock(PayUponInvoiceProductStatus::class); + $this->assertSame((new PayUponInvoiceHelper('DE', $pui_product_status))->validate_birth_date($input), $output); } public function datesProvider(): array{