method to check if PUI is ready in admin screen

This commit is contained in:
Narek Zakarian 2022-08-12 16:50:05 +04:00
parent 396352775b
commit 10da1f8067
2 changed files with 42 additions and 1 deletions

View file

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

View file

@ -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{