mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
✨ Create new environment detection helper methods
This commit is contained in:
parent
90d2c77a5a
commit
2c35059e4b
1 changed files with 31 additions and 6 deletions
|
@ -5,7 +5,7 @@
|
|||
* @package WooCommerce\PayPalCommerce\WcGateway\Helper
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Helper;
|
||||
|
||||
|
@ -16,20 +16,27 @@ use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
|||
*/
|
||||
class Environment {
|
||||
|
||||
/**
|
||||
* Name of the production environment.
|
||||
*/
|
||||
public const PRODUCTION = 'production';
|
||||
public const SANDBOX = 'sandbox';
|
||||
|
||||
/**
|
||||
* Name of the sandbox environment.
|
||||
*/
|
||||
public const SANDBOX = 'sandbox';
|
||||
|
||||
/**
|
||||
* The Settings.
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $settings;
|
||||
private ContainerInterface $settings;
|
||||
|
||||
/**
|
||||
* Environment constructor.
|
||||
*
|
||||
* @param ContainerInterface $settings The Settings.
|
||||
* @param ContainerInterface $settings The settings.
|
||||
*/
|
||||
public function __construct( ContainerInterface $settings ) {
|
||||
$this->settings = $settings;
|
||||
|
@ -40,7 +47,7 @@ class Environment {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function current_environment(): string {
|
||||
public function current_environment() : string {
|
||||
return (
|
||||
$this->settings->has( 'sandbox_on' ) && $this->settings->get( 'sandbox_on' )
|
||||
) ? self::SANDBOX : self::PRODUCTION;
|
||||
|
@ -53,7 +60,25 @@ class Environment {
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function current_environment_is( string $environment ): bool {
|
||||
public function current_environment_is( string $environment ) : bool {
|
||||
return $this->current_environment() === $environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current environment is sandbox.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_sandbox() : bool {
|
||||
return $this->current_environment_is( self::SANDBOX );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current environment is production.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_production() : bool {
|
||||
return $this->current_environment_is( self::PRODUCTION );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue