make environment listen to the correct sandbox option key

This commit is contained in:
David Remer 2020-06-30 07:49:25 +03:00
parent e6638aa6a4
commit aa2e7e7427
2 changed files with 13 additions and 2 deletions

View file

@ -87,7 +87,8 @@ return [
return new State($environment, $settings);
},
'onboarding.environment' => function(ContainerInterface $container) : Environment {
return new Environment();
$settings = $container->get('wcgateway.settings');
return new Environment($settings);
},
'onboarding.assets' => function(ContainerInterface $container) : OnboardingAssets {

View file

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\Onboarding;
use Psr\Container\ContainerInterface;
class Environment
{
@ -16,9 +18,17 @@ class Environment
public const OPTION_KEY = 'ppcp-env';
private $settings;
public function __construct(ContainerInterface $settings)
{
$this->settings = $settings;
}
public function currentEnvironment() : string
{
return (string) get_option(self::OPTION_KEY, self::PRODUCTION);
return (
$this->settings->has('sandbox_on') && wc_string_to_bool($this->settings->get('sandbox_on'))
) ? self::SANDBOX : self::PRODUCTION;
}
public function currentEnvironmentIs(string $environment) : bool {